Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ out
user.bazelrc
!bazel-diff-example.sh
.DS_Store
integration/BUILD.bazel
Empty file added integration/BUILD
Empty file.
2 changes: 1 addition & 1 deletion integration/src/main/java/com/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
)
3 changes: 2 additions & 1 deletion integration/test/java/com/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
)
29 changes: 13 additions & 16 deletions src/main/java/com/bazel_diff/BazelClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,31 @@

interface BazelClient {
List<BazelTarget> queryAllTargets() throws IOException;
Set<BazelSourceFileTarget> convertFilepathsToSourceTargets(Set<Path> filepaths) throws IOException, NoSuchAlgorithmException;
Set<BazelSourceFileTarget> queryAllSourcefileTargets() throws IOException, NoSuchAlgorithmException;
}

class BazelClientImpl implements BazelClient {
private Path workingDirectory;
private Path bazelPath;
private Boolean verbose;
private Boolean keepGoing;
private List<String> startupOptions;
private List<String> 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<String>();
this.commandOptions = commandOptions != null ? Arrays.asList(commandOptions.split(" ")): new ArrayList<String>();
this.verbose = verbose;
this.keepGoing = keepGoing;
}

@Override
Expand All @@ -45,19 +53,6 @@ public List<BazelTarget> queryAllTargets() throws IOException {
return targets.stream().map( target -> new BazelTargetImpl(target)).collect(Collectors.toList());
}

@Override
public Set<BazelSourceFileTarget> convertFilepathsToSourceTargets(Set<Path> filepaths) throws IOException, NoSuchAlgorithmException {
Set<BazelSourceFileTarget> sourceTargets = new HashSet<>();
for (List<Path> 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<BazelSourceFileTarget> queryAllSourcefileTargets() throws IOException, NoSuchAlgorithmException {
return processBazelSourcefileTargets(performBazelQuery("kind('source file', deps(//...))"), true);
Expand Down Expand Up @@ -99,7 +94,9 @@ private List<Build.Target> 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());
Expand Down
20 changes: 18 additions & 2 deletions src/main/java/com/bazel_diff/main.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ class GenerateHashes implements Callable<Integer> {

@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<Path> seedFilepathsSet = new HashSet<>();
Expand Down Expand Up @@ -92,6 +98,9 @@ class BazelDiff implements Callable<Integer> {
@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()) {
Expand All @@ -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();
Expand Down