Skip to content

Commit 3f151a8

Browse files
Merge pull request #114 from fa93hws/verbose-flag
2 parents 685bd6f + 3558243 commit 3f151a8

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ workspace.
139139
-V, --version Print version information and exit.
140140
-w, --workspacePath=<workspacePath>
141141
Path to Bazel workspace directory.
142-
--displayElapsedTime This flag controls whether to print out elapsed time
143-
for bazel query and content hashing
142+
-v, --verbose Display query string, missing files and elapsed time
144143
```
145144

146145
## Installing

src/main/java/com/bazel_diff/BazelClient.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class BazelClientImpl implements BazelClient {
2828
private Path bazelPath;
2929
private Boolean verbose;
3030
private Boolean keepGoing;
31-
private Boolean displayElapsedTime;
3231
private List<String> startupOptions;
3332
private List<String> commandOptions;
3433

@@ -38,24 +37,22 @@ class BazelClientImpl implements BazelClient {
3837
String startupOptions,
3938
String commandOptions,
4039
Boolean verbose,
41-
Boolean keepGoing,
42-
Boolean displayElapsedTime
40+
Boolean keepGoing
4341
) {
4442
this.workingDirectory = workingDirectory.normalize();
4543
this.bazelPath = bazelPath;
4644
this.startupOptions = startupOptions != null ? Arrays.asList(startupOptions.split(" ")): new ArrayList<String>();
4745
this.commandOptions = commandOptions != null ? Arrays.asList(commandOptions.split(" ")): new ArrayList<String>();
4846
this.verbose = verbose;
4947
this.keepGoing = keepGoing;
50-
this.displayElapsedTime = displayElapsedTime;
5148
}
5249

5350
@Override
5451
public List<BazelTarget> queryAllTargets() throws IOException {
5552
Instant queryStartTime = Instant.now();
5653
List<Build.Target> targets = performBazelQuery("'//external:all-targets' + '//...:all-targets'");
5754
Instant queryEndTime = Instant.now();
58-
if (displayElapsedTime) {
55+
if (verbose) {
5956
long querySeconds = Duration.between(queryStartTime, queryEndTime).getSeconds();
6057
System.out.printf("BazelDiff: All targets queried in %d seconds%n", querySeconds);
6158
}
@@ -69,7 +66,7 @@ public Map<String, BazelSourceFileTarget> queryAllSourcefileTargets() throws IOE
6966
Instant queryEndTime = Instant.now();
7067
Map<String, BazelSourceFileTarget> sourceFileTargets = processBazelSourcefileTargets(targets, true);
7168
Instant contentHashEndTime = Instant.now();
72-
if (displayElapsedTime) {
69+
if (verbose) {
7370
long querySeconds = Duration.between(queryStartTime, queryEndTime).getSeconds();
7471
long contentHashSeconds = Duration.between(queryEndTime, contentHashEndTime).getSeconds();
7572
System.out.printf("BazelDiff: All source files queried in %d seconds%n", querySeconds);

src/main/java/com/bazel_diff/VersionProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class VersionProvider implements IVersionProvider {
66
public String[] getVersion() throws Exception {
77
return new String[] {
8-
"3.2.2"
8+
"3.4.0"
99
};
1010
}
1111
}

src/main/java/com/bazel_diff/main.java

+10-12
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ class GenerateHashes implements Callable<Integer> {
3535
@Option(names = {"-s", "--seed-filepaths"}, description = "A text file containing a newline separated list of filepaths, each of these filepaths will be read and used as a seed for all targets.")
3636
File seedFilepaths;
3737

38-
@Option(names = {"--displayElapsedTime"}, description = "This flag controls whether to print out elapsed time for bazel query and content hashing")
39-
boolean displayElapsedTime;
40-
4138
@Parameters(index = "0", description = "The filepath to write the resulting JSON of dictionary target => SHA-256 values")
4239
File outputPath;
4340

@@ -48,9 +45,8 @@ public Integer call() {
4845
parent.bazelPath,
4946
parent.bazelStartupOptions,
5047
parent.bazelCommandOptions,
51-
BazelDiff.isVerbose(),
52-
parent.keepGoing,
53-
displayElapsedTime);
48+
parent.isVerbose(),
49+
parent.keepGoing);
5450
TargetHashingClient hashingClient = new TargetHashingClientImpl(bazelClient, new FilesClientImp());
5551
try {
5652
Instant generateHashStartTime = Instant.now();
@@ -68,7 +64,7 @@ public Integer call() {
6864
myWriter.write(gson.toJson(hashes));
6965
myWriter.close();
7066
Instant generateHashEndTime = Instant.now();
71-
if (displayElapsedTime) {
67+
if (parent.isVerbose()) {
7268
long generateHashSeconds = Duration.between(generateHashStartTime, generateHashEndTime).getSeconds();
7369
System.out.printf("BazelDiff: Generate-hashes command finishes in %d seconds%n", generateHashSeconds);
7470
}
@@ -113,6 +109,9 @@ class BazelDiff implements Callable<Integer> {
113109
@Option(names = {"-k", "--keep_going"}, negatable = true, description = "This flag controls if `bazel query` will be executed with the `--keep_going` flag or not. Disabling this flag allows you to catch configuration issues in your Bazel graph, but may not work for some Bazel setups. Defaults to `true`", scope = ScopeType.INHERIT)
114110
Boolean keepGoing = true;
115111

112+
@Option(names = {"-v", "--verbose"}, description = "Display query string, missing files and elapsed time", scope = ScopeType.INHERIT)
113+
Boolean verbose = false;
114+
116115
@Override
117116
public Integer call() throws IOException {
118117
if (startingHashesJSONPath == null || !startingHashesJSONPath.canRead()) {
@@ -132,9 +131,8 @@ public Integer call() throws IOException {
132131
bazelPath,
133132
bazelStartupOptions,
134133
bazelCommandOptions,
135-
BazelDiff.isVerbose(),
136-
keepGoing,
137-
false
134+
isVerbose(),
135+
keepGoing
138136
);
139137
TargetHashingClient hashingClient = new TargetHashingClientImpl(bazelClient, new FilesClientImp());
140138
Gson gson = new Gson();
@@ -167,9 +165,9 @@ public Integer call() throws IOException {
167165
return ExitCode.OK;
168166
}
169167

170-
static Boolean isVerbose() {
168+
Boolean isVerbose() {
171169
String verboseFlag = System.getProperty("VERBOSE", "false");
172-
return verboseFlag.equals("true");
170+
return verboseFlag.equals("true") || verbose;
173171
}
174172

175173
public static void main(String[] args) {

0 commit comments

Comments
 (0)