Skip to content

Commit 5d52ce6

Browse files
Merge pull request #76 from Tinder/disable_keep_going_via_flag
Allows disabling `--keep_going` flag in queries
2 parents d642f32 + 7a59051 commit 5d52ce6

File tree

6 files changed

+34
-21
lines changed

6 files changed

+34
-21
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,3 @@ out
2626
user.bazelrc
2727
!bazel-diff-example.sh
2828
.DS_Store
29-
integration/BUILD.bazel

integration/BUILD

Whitespace-only changes.

integration/src/main/java/com/integration/BUILD

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ java_library(
44
name = "bazel-diff-integration-lib",
55
srcs = glob(["*.java"]),
66
deps = [
7-
"//src/main/java/com/integration/submodule:Submodule"
7+
"//integration/src/main/java/com/integration/submodule:Submodule"
88
],
99
visibility = ["//visibility:public"]
1010
)

integration/test/java/com/integration/BUILD

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ java_test(
99
java_library(
1010
name = "bazel-diff-integration-test-lib",
1111
srcs = glob(["*.java"]),
12+
testonly = True,
1213
deps = [
13-
"//src/main/java/com/integration:bazel-diff-integration-lib",
14+
"//integration/src/main/java/com/integration:bazel-diff-integration-lib",
1415
"@bazel_diff_maven//:junit_junit"
1516
]
1617
)

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

+13-16
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,31 @@
2020

2121
interface BazelClient {
2222
List<BazelTarget> queryAllTargets() throws IOException;
23-
Set<BazelSourceFileTarget> convertFilepathsToSourceTargets(Set<Path> filepaths) throws IOException, NoSuchAlgorithmException;
2423
Set<BazelSourceFileTarget> queryAllSourcefileTargets() throws IOException, NoSuchAlgorithmException;
2524
}
2625

2726
class BazelClientImpl implements BazelClient {
2827
private Path workingDirectory;
2928
private Path bazelPath;
3029
private Boolean verbose;
30+
private Boolean keepGoing;
3131
private List<String> startupOptions;
3232
private List<String> commandOptions;
3333

34-
BazelClientImpl(Path workingDirectory, Path bazelPath, String startupOptions, String commandOptions, Boolean verbose) {
34+
BazelClientImpl(
35+
Path workingDirectory,
36+
Path bazelPath,
37+
String startupOptions,
38+
String commandOptions,
39+
Boolean verbose,
40+
Boolean keepGoing
41+
) {
3542
this.workingDirectory = workingDirectory.normalize();
3643
this.bazelPath = bazelPath;
3744
this.startupOptions = startupOptions != null ? Arrays.asList(startupOptions.split(" ")): new ArrayList<String>();
3845
this.commandOptions = commandOptions != null ? Arrays.asList(commandOptions.split(" ")): new ArrayList<String>();
3946
this.verbose = verbose;
47+
this.keepGoing = keepGoing;
4048
}
4149

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

48-
@Override
49-
public Set<BazelSourceFileTarget> convertFilepathsToSourceTargets(Set<Path> filepaths) throws IOException, NoSuchAlgorithmException {
50-
Set<BazelSourceFileTarget> sourceTargets = new HashSet<>();
51-
for (List<Path> partition : Iterables.partition(filepaths, 100)) {
52-
String targetQuery = partition
53-
.stream()
54-
.map(path -> String.format("'%s'", path.toString()))
55-
.collect(Collectors.joining(" + "));
56-
sourceTargets.addAll(processBazelSourcefileTargets(performBazelQuery(targetQuery), false));
57-
}
58-
return sourceTargets;
59-
}
60-
6156
@Override
6257
public Set<BazelSourceFileTarget> queryAllSourcefileTargets() throws IOException, NoSuchAlgorithmException {
6358
return processBazelSourcefileTargets(performBazelQuery("kind('source file', deps(//...))"), true);
@@ -99,7 +94,9 @@ private List<Build.Target> performBazelQuery(String query) throws IOException {
9994
cmd.add("--output");
10095
cmd.add("streamed_proto");
10196
cmd.add("--order_output=no");
102-
cmd.add("--keep_going");
97+
if (keepGoing != null && keepGoing) {
98+
cmd.add("--keep_going");
99+
}
103100
cmd.addAll(this.commandOptions);
104101
cmd.add("--query_file");
105102
cmd.add(tempFile.toString());

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

+18-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ class GenerateHashes implements Callable<Integer> {
3838

3939
@Override
4040
public Integer call() {
41-
BazelClient bazelClient = new BazelClientImpl(parent.workspacePath, parent.bazelPath, parent.bazelStartupOptions, parent.bazelCommandOptions, BazelDiff.isVerbose());
41+
BazelClient bazelClient = new BazelClientImpl(
42+
parent.workspacePath,
43+
parent.bazelPath,
44+
parent.bazelStartupOptions,
45+
parent.bazelCommandOptions,
46+
BazelDiff.isVerbose(),
47+
parent.keepGoing);
4248
TargetHashingClient hashingClient = new TargetHashingClientImpl(bazelClient, new FilesClientImp());
4349
try {
4450
Set<Path> seedFilepathsSet = new HashSet<>();
@@ -92,6 +98,9 @@ class BazelDiff implements Callable<Integer> {
9298
@Option(names = {"-co", "--bazelCommandOptions"}, description = "Additional space separated Bazel command options used when invoking Bazel", scope = ScopeType.INHERIT)
9399
String bazelCommandOptions;
94100

101+
@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`")
102+
Boolean keepGoing = true;
103+
95104
@Override
96105
public Integer call() throws IOException {
97106
if (startingHashesJSONPath == null || !startingHashesJSONPath.canRead()) {
@@ -103,7 +112,14 @@ public Integer call() throws IOException {
103112
return ExitCode.USAGE;
104113
}
105114
GitClient gitClient = new GitClientImpl(workspacePath);
106-
BazelClient bazelClient = new BazelClientImpl(workspacePath, bazelPath, bazelStartupOptions, bazelCommandOptions, BazelDiff.isVerbose());
115+
BazelClient bazelClient = new BazelClientImpl(
116+
workspacePath,
117+
bazelPath,
118+
bazelStartupOptions,
119+
bazelCommandOptions,
120+
BazelDiff.isVerbose(),
121+
keepGoing
122+
);
107123
TargetHashingClient hashingClient = new TargetHashingClientImpl(bazelClient, new FilesClientImp());
108124
try {
109125
gitClient.ensureAllChangesAreCommitted();

0 commit comments

Comments
 (0)