diff --git a/.gitignore b/.gitignore index 40c74be..d092dc6 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,3 @@ out user.bazelrc !bazel-diff-example.sh .DS_Store -integration/BUILD.bazel diff --git a/integration/BUILD b/integration/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/integration/src/main/java/com/integration/BUILD b/integration/src/main/java/com/integration/BUILD index 419206e..ae975c2 100644 --- a/integration/src/main/java/com/integration/BUILD +++ b/integration/src/main/java/com/integration/BUILD @@ -4,7 +4,7 @@ java_library( name = "bazel-diff-integration-lib", srcs = glob(["*.java"]), deps = [ - "//src/main/java/com/integration/submodule:Submodule" + "//integration/src/main/java/com/integration/submodule:Submodule" ], visibility = ["//visibility:public"] ) diff --git a/integration/test/java/com/integration/BUILD b/integration/test/java/com/integration/BUILD index 0d1bcfa..9e66c64 100644 --- a/integration/test/java/com/integration/BUILD +++ b/integration/test/java/com/integration/BUILD @@ -9,8 +9,9 @@ java_test( java_library( name = "bazel-diff-integration-test-lib", srcs = glob(["*.java"]), + testonly = True, deps = [ - "//src/main/java/com/integration:bazel-diff-integration-lib", + "//integration/src/main/java/com/integration:bazel-diff-integration-lib", "@bazel_diff_maven//:junit_junit" ] ) diff --git a/src/main/java/com/bazel_diff/BazelClient.java b/src/main/java/com/bazel_diff/BazelClient.java index 398500a..2ae2824 100644 --- a/src/main/java/com/bazel_diff/BazelClient.java +++ b/src/main/java/com/bazel_diff/BazelClient.java @@ -20,7 +20,6 @@ interface BazelClient { List queryAllTargets() throws IOException; - Set convertFilepathsToSourceTargets(Set filepaths) throws IOException, NoSuchAlgorithmException; Set queryAllSourcefileTargets() throws IOException, NoSuchAlgorithmException; } @@ -28,15 +27,24 @@ class BazelClientImpl implements BazelClient { private Path workingDirectory; private Path bazelPath; private Boolean verbose; + private Boolean keepGoing; private List startupOptions; private List commandOptions; - BazelClientImpl(Path workingDirectory, Path bazelPath, String startupOptions, String commandOptions, Boolean verbose) { + BazelClientImpl( + Path workingDirectory, + Path bazelPath, + String startupOptions, + String commandOptions, + Boolean verbose, + Boolean keepGoing + ) { this.workingDirectory = workingDirectory.normalize(); this.bazelPath = bazelPath; this.startupOptions = startupOptions != null ? Arrays.asList(startupOptions.split(" ")): new ArrayList(); this.commandOptions = commandOptions != null ? Arrays.asList(commandOptions.split(" ")): new ArrayList(); this.verbose = verbose; + this.keepGoing = keepGoing; } @Override @@ -45,19 +53,6 @@ public List queryAllTargets() throws IOException { return targets.stream().map( target -> new BazelTargetImpl(target)).collect(Collectors.toList()); } - @Override - public Set convertFilepathsToSourceTargets(Set filepaths) throws IOException, NoSuchAlgorithmException { - Set sourceTargets = new HashSet<>(); - for (List partition : Iterables.partition(filepaths, 100)) { - String targetQuery = partition - .stream() - .map(path -> String.format("'%s'", path.toString())) - .collect(Collectors.joining(" + ")); - sourceTargets.addAll(processBazelSourcefileTargets(performBazelQuery(targetQuery), false)); - } - return sourceTargets; - } - @Override public Set queryAllSourcefileTargets() throws IOException, NoSuchAlgorithmException { return processBazelSourcefileTargets(performBazelQuery("kind('source file', deps(//...))"), true); @@ -99,7 +94,9 @@ private List performBazelQuery(String query) throws IOException { cmd.add("--output"); cmd.add("streamed_proto"); cmd.add("--order_output=no"); - cmd.add("--keep_going"); + if (keepGoing != null && keepGoing) { + cmd.add("--keep_going"); + } cmd.addAll(this.commandOptions); cmd.add("--query_file"); cmd.add(tempFile.toString()); diff --git a/src/main/java/com/bazel_diff/main.java b/src/main/java/com/bazel_diff/main.java index c75015f..267e3f3 100644 --- a/src/main/java/com/bazel_diff/main.java +++ b/src/main/java/com/bazel_diff/main.java @@ -38,7 +38,13 @@ class GenerateHashes implements Callable { @Override public Integer call() { - BazelClient bazelClient = new BazelClientImpl(parent.workspacePath, parent.bazelPath, parent.bazelStartupOptions, parent.bazelCommandOptions, BazelDiff.isVerbose()); + BazelClient bazelClient = new BazelClientImpl( + parent.workspacePath, + parent.bazelPath, + parent.bazelStartupOptions, + parent.bazelCommandOptions, + BazelDiff.isVerbose(), + parent.keepGoing); TargetHashingClient hashingClient = new TargetHashingClientImpl(bazelClient, new FilesClientImp()); try { Set seedFilepathsSet = new HashSet<>(); @@ -92,6 +98,9 @@ class BazelDiff implements Callable { @Option(names = {"-co", "--bazelCommandOptions"}, description = "Additional space separated Bazel command options used when invoking Bazel", scope = ScopeType.INHERIT) String bazelCommandOptions; + @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`") + Boolean keepGoing = true; + @Override public Integer call() throws IOException { if (startingHashesJSONPath == null || !startingHashesJSONPath.canRead()) { @@ -103,7 +112,14 @@ public Integer call() throws IOException { return ExitCode.USAGE; } GitClient gitClient = new GitClientImpl(workspacePath); - BazelClient bazelClient = new BazelClientImpl(workspacePath, bazelPath, bazelStartupOptions, bazelCommandOptions, BazelDiff.isVerbose()); + BazelClient bazelClient = new BazelClientImpl( + workspacePath, + bazelPath, + bazelStartupOptions, + bazelCommandOptions, + BazelDiff.isVerbose(), + keepGoing + ); TargetHashingClient hashingClient = new TargetHashingClientImpl(bazelClient, new FilesClientImp()); try { gitClient.ensureAllChangesAreCommitted();