Skip to content

Commit 4b64253

Browse files
Merge pull request #15 from purkhusid/bazel-options
Add bazel options
2 parents 074e321 + b93488f commit 4b64253

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

src/main/java/com/bazel-diff/BazelClient.java

+20-10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.List;
1313
import java.util.Set;
1414
import java.util.stream.Collectors;
15+
import java.util.Arrays;
1516

1617
interface BazelClient {
1718
List<BazelTarget> queryAllTargets() throws IOException;
@@ -23,10 +24,14 @@ interface BazelClient {
2324
class BazelClientImpl implements BazelClient {
2425
private Path workingDirectory;
2526
private Path bazelPath;
27+
private List<String> startupOptions;
28+
private List<String> commandOptions;
2629

27-
BazelClientImpl(Path workingDirectory, Path bazelPath) {
30+
BazelClientImpl(Path workingDirectory, Path bazelPath, String startupOptions, String commandOptions) {
2831
this.workingDirectory = workingDirectory.normalize();
2932
this.bazelPath = bazelPath;
33+
this.startupOptions = startupOptions != null ? Arrays.asList(startupOptions.split(" ")): new ArrayList<String>();
34+
this.commandOptions = commandOptions != null ? Arrays.asList(commandOptions.split(" ")): new ArrayList<String>();
3035
}
3136

3237
@Override
@@ -94,15 +99,20 @@ public Set<BazelSourceFileTarget> convertFilepathsToSourceTargets(Set<Path> file
9499
}
95100

96101
private List<Build.Target> performBazelQuery(String query) throws IOException {
97-
ProcessBuilder pb = new ProcessBuilder(bazelPath.toString(),
98-
"query",
99-
query,
100-
"--output",
101-
"streamed_proto",
102-
"--order_output=no",
103-
"--show_progress=false",
104-
"--show_loading_progress=false"
105-
).directory(workingDirectory.toFile());
102+
List<String> cmd = new ArrayList<String>();
103+
104+
cmd.add((bazelPath.toString()));
105+
cmd.addAll(this.startupOptions);
106+
cmd.add("query");
107+
cmd.add("--output");
108+
cmd.add("streamed_proto");
109+
cmd.add("--order_output=no");
110+
cmd.add("--show_progress=false");
111+
cmd.add("--show_loading_progress=false");
112+
cmd.addAll(this.commandOptions);
113+
cmd.add(query);
114+
115+
ProcessBuilder pb = new ProcessBuilder(cmd).directory(workingDirectory.toFile());
106116
Process process = pb.start();
107117
ArrayList<Build.Target> targets = new ArrayList<>();
108118
while (true) {

src/main/java/com/bazel-diff/main.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class GenerateHashes implements Callable<Integer> {
8686
@Override
8787
public Integer call() {
8888
GitClient gitClient = new GitClientImpl(parent.workspacePath);
89-
BazelClient bazelClient = new BazelClientImpl(parent.workspacePath, parent.bazelPath);
89+
BazelClient bazelClient = new BazelClientImpl(parent.workspacePath, parent.bazelPath, parent.bazelStartupOptions, parent.bazelCommandOptions);
9090
TargetHashingClient hashingClient = new TargetHashingClientImpl(bazelClient);
9191
try {
9292
gitClient.ensureAllChangesAreCommitted();
@@ -142,6 +142,13 @@ class BazelDiff implements Callable<Integer> {
142142
@Option(names = {"-t", "--tests"}, scope = ScopeType.LOCAL, description = "Return only targets of kind 'test')")
143143
boolean testTargets;
144144

145+
@Option(names = {"-so", "--bazelStartupOptions"}, description = "Additional space separated Bazel client startup options used when invoking Bazel", scope = ScopeType.INHERIT)
146+
String bazelStartupOptions;
147+
148+
@Option(names = {"-co", "--bazelCommandOptions"}, description = "Additional space separated Bazel command options used when invoking Bazel", scope = ScopeType.INHERIT)
149+
String bazelCommandOptions;
150+
151+
@Override
145152
public Integer call() throws IOException {
146153
if (startingHashesJSONPath == null || !startingHashesJSONPath.canRead()) {
147154
System.out.println("startingHashesJSONPath does not exist! Exiting");
@@ -152,7 +159,7 @@ public Integer call() throws IOException {
152159
return ExitCode.USAGE;
153160
}
154161
GitClient gitClient = new GitClientImpl(workspacePath);
155-
BazelClient bazelClient = new BazelClientImpl(workspacePath, bazelPath);
162+
BazelClient bazelClient = new BazelClientImpl(workspacePath, bazelPath, bazelStartupOptions, bazelCommandOptions);
156163
TargetHashingClient hashingClient = new TargetHashingClientImpl(bazelClient);
157164
try {
158165
gitClient.ensureAllChangesAreCommitted();

0 commit comments

Comments
 (0)