aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/java_tools
diff options
context:
space:
mode:
authorGravatar cushon <cushon@google.com>2018-06-15 08:43:30 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-15 08:45:01 -0700
commit3aea081b6f91bffbc2c9c47d6cd034778f977e39 (patch)
tree91c2702c2947be072d88b800a12d9d3b7f6f4f00 /src/java_tools
parentfc0030c9b2261096cab72f7addfe7966915758dc (diff)
Include injecting rule kind in add_dep commands
add_dep uses this information for j_p_l rules. PiperOrigin-RevId: 200721230
Diffstat (limited to 'src/java_tools')
-rw-r--r--src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps/ImportDepsChecker.java11
-rw-r--r--src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/golden_proto_strictdeps.stderr.txt18
-rw-r--r--src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/golden_proto_strictdeps.txt15
-rw-r--r--src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l/A.java19
-rw-r--r--src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l/B.java16
-rw-r--r--src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l/p1.proto22
-rw-r--r--src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l/p2.proto22
-rw-r--r--src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/tests.bzl14
8 files changed, 136 insertions, 1 deletions
diff --git a/src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps/ImportDepsChecker.java b/src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps/ImportDepsChecker.java
index fe1a80a520..dc4dc37faf 100644
--- a/src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps/ImportDepsChecker.java
+++ b/src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps/ImportDepsChecker.java
@@ -293,6 +293,9 @@ public final class ImportDepsChecker implements Closeable {
.collect(ImmutableList.toImmutableList());
}
+ static final Attributes.Name TARGET_LABEL = new Attributes.Name("Target-Label");
+ static final Attributes.Name INJECTING_RULE_KIND = new Attributes.Name("Injecting-Rule-Kind");
+
@Nullable
private static String extractLabel(Path jarPath) {
try (JarFile jar = new JarFile(jarPath.toFile())) {
@@ -304,7 +307,13 @@ public final class ImportDepsChecker implements Closeable {
if (attributes == null) {
return null;
}
- return attributes.getValue("Target-Label");
+ String targetLabel = (String) attributes.get(TARGET_LABEL);
+ String injectingRuleKind = (String) attributes.get(INJECTING_RULE_KIND);
+ if (injectingRuleKind == null) {
+ return targetLabel;
+ } else {
+ return String.format("\"%s %s\"", targetLabel, injectingRuleKind);
+ }
} catch (IOException e) {
throw new UncheckedIOException(e);
}
diff --git a/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/golden_proto_strictdeps.stderr.txt b/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/golden_proto_strictdeps.stderr.txt
new file mode 100644
index 0000000000..78b59da345
--- /dev/null
+++ b/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/golden_proto_strictdeps.stderr.txt
@@ -0,0 +1,18 @@
+ERROR: The dependencies for the following 1 jar(s) are not complete.
+ 1.third_party/bazel/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l/liba-hjar.jar
+The details are listed below:
+Missing com.google.protobuf.GeneratedMessage
+Missing com.google.protobuf.MessageOrBuilder
+Indirectly missing class com.google.protobuf.GeneratedMessage. Referenced by:
+ p.P1$M1 (in j_p_l:p1 java_proto_library")
+ p.P2$M2 (in j_p_l:p2 java_proto_library")
+Indirectly missing class com.google.protobuf.MessageOrBuilder. Referenced by:
+ p.P1$M1OrBuilder (in j_p_l:p1 java_proto_library")
+ p.P2$M2OrBuilder (in j_p_l:p2 java_proto_library")
+===Total===
+missing=2
+incomplete=2
+missing_members=0
+*** Missing strict dependencies. Run the following command to fix ***
+
+ add_dep "//third_party/bazel/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l:p1 java_proto_library" "//third_party/bazel/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l:p2 java_proto_library" //third_party/bazel/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l/a
diff --git a/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/golden_proto_strictdeps.txt b/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/golden_proto_strictdeps.txt
new file mode 100644
index 0000000000..8c0bc21639
--- /dev/null
+++ b/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/golden_proto_strictdeps.txt
@@ -0,0 +1,15 @@
+Missing com.google.protobuf.GeneratedMessage
+Missing com.google.protobuf.MessageOrBuilder
+Indirectly missing class com.google.protobuf.GeneratedMessage. Referenced by:
+ p.P1$M1 (in j_p_l:p1 java_proto_library")
+ p.P2$M2 (in j_p_l:p2 java_proto_library")
+Indirectly missing class com.google.protobuf.MessageOrBuilder. Referenced by:
+ p.P1$M1OrBuilder (in j_p_l:p1 java_proto_library")
+ p.P2$M2OrBuilder (in j_p_l:p2 java_proto_library")
+===Total===
+missing=2
+incomplete=2
+missing_members=0
+*** Missing strict dependencies. Run the following command to fix ***
+
+ add_dep "//third_party/bazel/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l:p1 java_proto_library" "//third_party/bazel/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l:p2 java_proto_library" //third_party/bazel/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l/a
diff --git a/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l/A.java b/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l/A.java
new file mode 100644
index 0000000000..2492595e79
--- /dev/null
+++ b/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l/A.java
@@ -0,0 +1,19 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+class A {
+ B b;
+ p.P1.M1 m1;
+ p.P2.M2 m2;
+}
diff --git a/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l/B.java b/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l/B.java
new file mode 100644
index 0000000000..31df36888a
--- /dev/null
+++ b/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l/B.java
@@ -0,0 +1,16 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+class B {
+}
diff --git a/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l/p1.proto b/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l/p1.proto
new file mode 100644
index 0000000000..0a7c6b6654
--- /dev/null
+++ b/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l/p1.proto
@@ -0,0 +1,22 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+syntax = "proto2";
+
+option java_package = "p";
+
+package p1;
+
+message M1 {
+}
diff --git a/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l/p2.proto b/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l/p2.proto
new file mode 100644
index 0000000000..e9136cce0e
--- /dev/null
+++ b/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/testdata/j_p_l/p2.proto
@@ -0,0 +1,22 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+syntax = "proto2";
+
+option java_package = "p";
+
+package p2;
+
+message M2 {
+}
diff --git a/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/tests.bzl b/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/tests.bzl
index 452b138796..b32ef4beb4 100644
--- a/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/tests.bzl
+++ b/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/tests.bzl
@@ -13,6 +13,20 @@
# limitations under the License.
"""Helpers to create golden tests, to minimize code duplication."""
+def _compile_time_jars(ctx):
+ jars = depset([], transitive = [dep[JavaInfo].transitive_compile_time_jars for dep in ctx.attr.deps])
+ return [DefaultInfo(
+ files = jars,
+ runfiles = ctx.runfiles(transitive_files = jars),
+ )]
+
+compile_time_jars = rule(
+ attrs = {
+ "deps": attr.label_list(providers = ["java"]),
+ },
+ implementation = _compile_time_jars,
+)
+
def create_golden_test(
name,
golden_output_file,