diff options
author | 2016-03-02 13:21:23 +0000 | |
---|---|---|
committer | 2016-03-02 17:55:25 +0000 | |
commit | 37059e4ffd23fbc10828f61ab198b98c2ca7a8a9 (patch) | |
tree | 2fca20df137a92797b6266e48be2fefd5eae9094 | |
parent | 49c101f86531a607c853e90740dbba61bf5ac568 (diff) |
Canonicalize the name of the target itself for java indirect dep errors.
Otherwise it prints the wrong message when the target which is missing
a dependency is in a repository other than the default one.
--
Change-Id: I3762e6be911b79a133a2959fce3a8bf34d183232
Reviewed-on: https://bazel-review.googlesource.com/#/c/2782/
MOS_MIGRATED_REVID=116128663
-rw-r--r-- | src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/StrictJavaDepsPlugin.java | 18 | ||||
-rwxr-xr-x | src/test/shell/bazel/local_repository_test.sh | 14 |
2 files changed, 25 insertions, 7 deletions
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/StrictJavaDepsPlugin.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/StrictJavaDepsPlugin.java index e8c78d51a6..32590dd081 100644 --- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/StrictJavaDepsPlugin.java +++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/StrictJavaDepsPlugin.java @@ -165,11 +165,19 @@ public final class StrictJavaDepsPlugin extends BlazeJavaCompilerPlugin { missingTargetsStr.append(target); missingTargetsStr.append(" "); } - errWriter.print(String.format(dependencyModule.getFixMessage(), - USE_COLOR ? "\033[35m\033[1m" : "", - USE_COLOR ? "\033[0m" : "", - missingTargetsStr.toString(), - dependencyModule.getTargetLabel())); + String canonicalizedLabel; + if (dependencyModule.getTargetLabel() == null) { + canonicalizedLabel = null; + } else { + canonicalizedLabel = canonicalizeTarget(dependencyModule.getTargetLabel()); + } + errWriter.print( + String.format( + dependencyModule.getFixMessage(), + USE_COLOR ? "\033[35m\033[1m" : "", + USE_COLOR ? "\033[0m" : "", + missingTargetsStr.toString(), + canonicalizedLabel)); } } diff --git a/src/test/shell/bazel/local_repository_test.sh b/src/test/shell/bazel/local_repository_test.sh index 0546bc47b8..de146d3aba 100755 --- a/src/test/shell/bazel/local_repository_test.sh +++ b/src/test/shell/bazel/local_repository_test.sh @@ -348,7 +348,7 @@ EOF } # Creates an indirect dependency on X from A and make sure the error message -# refers to the correct label. +# refers to the correct label, both in an external repository and not. function test_indirect_dep_message() { local external_dir=$TEST_TMPDIR/ext-dir mkdir -p a b $external_dir/x @@ -391,6 +391,8 @@ java_library( ) EOF + cp -r a b $external_dir + touch $external_dir/WORKSPACE cat > $external_dir/x/X.java <<EOF package x; @@ -418,7 +420,15 @@ EOF bazel build //a:a >& $TEST_log && fail "Building //a:a should error out" expect_log "** Please add the following dependencies:" - expect_log "@x_repo//x to //a:a" + expect_log "@x_repo//x to //a" + + bazel build //a >& $TEST_log && fail "Building //a should error out" + expect_log "** Please add the following dependencies:" + expect_log "@x_repo//x to //a" + + bazel build @x_repo//a >& $TEST_log && fail "Building @x_repo//a should error out" + expect_log "** Please add the following dependencies:" + expect_log "@x_repo//x to @x_repo//a" } function test_external_includes() { |