Skip to content

Commit 16ca0ff

Browse files
Merge pull request #39 from Tinder/issue_36
Enable debug logging
2 parents b4bd222 + bc4df2d commit 16ca0ff

File tree

6 files changed

+49
-15
lines changed

6 files changed

+49
-15
lines changed

.bazelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
run --show_loading_progress=false --show_progress=false --ui_event_filters='ERROR'
1+
run -c opt --show_loading_progress=false --show_progress=false --ui_event_filters='ERROR'
2+
run:verbose -c dbg --show_loading_progress=true --show_progress=true --ui_event_filters='INFO,ERROR,DEBUG'

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ Open `bazel-diff-example.sh` to see how this is implemented. This is purely an e
6666
`bazel-diff` Command
6767

6868
```terminal
69-
Usage: bazel-diff [-htV] -b=<bazelPath> [-co=<bazelCommandOptions>]
70-
[-fh=<finalHashesJSONPath>] [-o=<outputPath>]
71-
[-sh=<startingHashesJSONPath>] [-so=<bazelStartupOptions>]
72-
-w=<workspacePath> [COMMAND]
69+
Usage: bazel-diff [-hV] [-aq=<avoidQuery>] -b=<bazelPath>
70+
[-co=<bazelCommandOptions>] [-fh=<finalHashesJSONPath>]
71+
[-o=<outputPath>] [-sh=<startingHashesJSONPath>]
72+
[-so=<bazelStartupOptions>] -w=<workspacePath> [COMMAND]
7373
Writes to a file the impacted targets between two Bazel graph JSON files
7474
-aq, --avoid-query=<avoidQuery>
7575
A Bazel query string, any targets that pass this query will
@@ -166,6 +166,14 @@ To run the project
166166
bazel run :bazel-diff -- bazel-diff -h
167167
```
168168

169+
#### Debugging
170+
171+
To run `bazel-diff` with debug logging, run your commands with the `verbose` config like so:
172+
173+
```terminal
174+
bazel run :bazel-diff --config=verbose -- bazel-diff -h
175+
```
176+
169177
### Run Via JAR Release
170178

171179
```terminal

integration/integration_test.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ bazel_path=$(which bazelisk)
66
previous_revision="HEAD^"
77
final_revision="HEAD"
88
output_dir="/tmp"
9-
modified_filepaths_output="$PWD/integration/modified_filepaths.txt"
9+
modified_filepaths_output="$workspace_path/modified_filepaths.txt"
1010
starting_hashes_json="$output_dir/starting_hashes.json"
1111
final_hashes_json="$output_dir/final_hashes_json.json"
1212
impacted_targets_path="$output_dir/impacted_targets.txt"
13+
shared_flags="--config=verbose"
1314

1415
export USE_BAZEL_VERSION=last_downstream_green
1516

@@ -20,13 +21,13 @@ containsElement () {
2021
return 1
2122
}
2223

23-
$bazel_path run :bazel-diff -- generate-hashes -w $workspace_path -b $bazel_path $starting_hashes_json
24+
$bazel_path run :bazel-diff $shared_flags -- generate-hashes -w $workspace_path -b $bazel_path $starting_hashes_json
2425

25-
$bazel_path run :bazel-diff -- generate-hashes -w $workspace_path -b $bazel_path -m $modified_filepaths_output $final_hashes_json
26+
$bazel_path run :bazel-diff $shared_flags -- generate-hashes -w $workspace_path -b $bazel_path -m $modified_filepaths_output $final_hashes_json
2627

2728
ruby ./integration/update_final_hashes.rb
2829

29-
$bazel_path run :bazel-diff -- -sh $starting_hashes_json -fh $final_hashes_json -w $workspace_path -b $bazel_path -o $impacted_targets_path -aq "attr('tags', 'manual', //...)"
30+
$bazel_path run :bazel-diff $shared_flags -- -sh $starting_hashes_json -fh $final_hashes_json -w $workspace_path -b $bazel_path -o $impacted_targets_path -aq "attr('tags', 'manual', //...)"
3031

3132
IFS=$'\n' read -d '' -r -a impacted_targets < $impacted_targets_path
3233
target1="//test/java/com/integration:bazel-diff-integration-test-lib"

src/main/java/com/bazel_diff/BUILD

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
load("@rules_java//java:defs.bzl", "java_binary", "java_library", "java_proto_library")
22
load("@rules_proto//proto:defs.bzl", "proto_library")
33

4+
config_setting(
5+
name = "enable_verbose",
6+
values = {
7+
"compilation_mode": "dbg",
8+
},
9+
)
10+
411
java_binary(
512
name = "bazel-diff",
613
main_class = "com.bazel_diff.BazelDiff",
714
runtime_deps = [":java-bazel-diff-lib"],
8-
visibility = ["//visibility:public"]
15+
visibility = ["//visibility:public"],
16+
jvm_flags = select({
17+
":enable_verbose": ["-DVERBOSE=true"],
18+
"//conditions:default": [],
19+
}),
920
)
1021

1122
java_library(
@@ -18,6 +29,10 @@ java_library(
1829
"@bazel_diff_maven//:com_google_code_gson_gson",
1930
"@bazel_diff_maven//:com_google_guava_guava"
2031
],
32+
javacopts = select({
33+
":enable_verbose": ["-AVERBOSE=true"],
34+
"//conditions:default": [],
35+
}),
2136
visibility = ["//test/java/com/bazel_diff:__pkg__"]
2237
)
2338

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ interface BazelClient {
2727
class BazelClientImpl implements BazelClient {
2828
private Path workingDirectory;
2929
private Path bazelPath;
30+
private Boolean verbose;
3031
private List<String> startupOptions;
3132
private List<String> commandOptions;
3233

33-
BazelClientImpl(Path workingDirectory, Path bazelPath, String startupOptions, String commandOptions) {
34+
BazelClientImpl(Path workingDirectory, Path bazelPath, String startupOptions, String commandOptions, Boolean verbose) {
3435
this.workingDirectory = workingDirectory.normalize();
3536
this.bazelPath = bazelPath;
3637
this.startupOptions = startupOptions != null ? Arrays.asList(startupOptions.split(" ")): new ArrayList<String>();
3738
this.commandOptions = commandOptions != null ? Arrays.asList(commandOptions.split(" ")): new ArrayList<String>();
39+
this.verbose = verbose;
3840
}
3941

4042
@Override
@@ -94,13 +96,15 @@ private List<Build.Target> performBazelQuery(String query) throws IOException {
9496

9597
List<String> cmd = new ArrayList<String>();
9698
cmd.add((bazelPath.toString()));
99+
if (verbose) {
100+
System.out.println(String.format("Executing Query: %s", query));
101+
cmd.add("--bazelrc=/dev/null");
102+
}
97103
cmd.addAll(this.startupOptions);
98104
cmd.add("query");
99105
cmd.add("--output");
100106
cmd.add("streamed_proto");
101107
cmd.add("--order_output=no");
102-
cmd.add("--show_progress=false");
103-
cmd.add("--show_loading_progress=false");
104108
cmd.add("--keep_going");
105109
cmd.addAll(this.commandOptions);
106110
cmd.add("--query_file");

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class GenerateHashes implements Callable<Integer> {
8888
@Override
8989
public Integer call() {
9090
GitClient gitClient = new GitClientImpl(parent.workspacePath);
91-
BazelClient bazelClient = new BazelClientImpl(parent.workspacePath, parent.bazelPath, parent.bazelStartupOptions, parent.bazelCommandOptions);
91+
BazelClient bazelClient = new BazelClientImpl(parent.workspacePath, parent.bazelPath, parent.bazelStartupOptions, parent.bazelCommandOptions, BazelDiff.isVerbose());
9292
TargetHashingClient hashingClient = new TargetHashingClientImpl(bazelClient);
9393
try {
9494
gitClient.ensureAllChangesAreCommitted();
@@ -161,7 +161,7 @@ public Integer call() throws IOException {
161161
return ExitCode.USAGE;
162162
}
163163
GitClient gitClient = new GitClientImpl(workspacePath);
164-
BazelClient bazelClient = new BazelClientImpl(workspacePath, bazelPath, bazelStartupOptions, bazelCommandOptions);
164+
BazelClient bazelClient = new BazelClientImpl(workspacePath, bazelPath, bazelStartupOptions, bazelCommandOptions, BazelDiff.isVerbose());
165165
TargetHashingClient hashingClient = new TargetHashingClientImpl(bazelClient);
166166
try {
167167
gitClient.ensureAllChangesAreCommitted();
@@ -202,6 +202,11 @@ public Integer call() throws IOException {
202202
return ExitCode.OK;
203203
}
204204

205+
static Boolean isVerbose() {
206+
String verboseFlag = System.getProperty("VERBOSE", "false");
207+
return verboseFlag.equals("true");
208+
}
209+
205210
public static void main(String[] args) {
206211
int exitCode = new CommandLine(new BazelDiff()).execute(args);
207212
System.exit(exitCode);

0 commit comments

Comments
 (0)