aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools
diff options
context:
space:
mode:
authorGravatar Carmi Grushko <carmi@google.com>2016-12-03 01:08:58 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-12-05 10:20:59 +0000
commit67edce77dbd54d6748d4d09da5bf27a6019d3b5e (patch)
tree255f91592e5758e79b37101f42bd84c29aef3a0c /src/main/java/com/google/devtools
parent16d8fec128bee46dafe8bba0a45e6d7709dec792 (diff)
When a strict proto dep violation occurs, tell the user what they should fix.
-- PiperOrigin-RevId: 140912072 MOS_MIGRATED_REVID=140912072
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoAspect.java1
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java1
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java1
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoSkylarkCommon.java1
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java22
5 files changed, 23 insertions, 3 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoAspect.java
index 65e3c7664b..de5e8b9796 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoAspect.java
@@ -285,6 +285,7 @@ public class CcProtoAspect extends NativeAspectClass implements ConfiguredAspect
supportData.getDirectProtoSources(),
supportData.getTransitiveImports(),
supportData.getProtosInDirectDeps(),
+ ruleContext.getLabel().getCanonicalForm(),
outputs,
"C++",
true /* allowServices */);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java
index 43d8256c0b..3082275721 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java
@@ -212,6 +212,7 @@ public class JavaLiteProtoAspect extends NativeAspectClass implements Configured
supportData.getDirectProtoSources(),
supportData.getTransitiveImports(),
supportData.getProtosInDirectDeps(),
+ ruleContext.getLabel().getCanonicalForm(),
ImmutableList.of(sourceJar),
"JavaLite",
true /* allowServices */);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java
index d2e194ebf1..62205d5edb 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java
@@ -312,6 +312,7 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe
supportData.getDirectProtoSources(),
supportData.getTransitiveImports(),
supportData.getProtosInDirectDeps(),
+ ruleContext.getLabel().getCanonicalForm(),
ImmutableList.of(sourceJar),
"Java (Immutable)",
rpcSupport.allowServices(ruleContext));
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoSkylarkCommon.java b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoSkylarkCommon.java
index 87a659fd87..4135d4029a 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoSkylarkCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoSkylarkCommon.java
@@ -71,6 +71,7 @@ public class JavaProtoSkylarkCommon {
supportData.getDirectProtoSources(),
supportData.getTransitiveImports(),
supportData.getProtosInDirectDeps(),
+ skylarkRuleContext.getLabel().getCanonicalForm(),
ImmutableList.of(sourceJar),
"JavaLite",
true /* allowServices */);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java
index 233a28d1b4..8049af7fbb 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java
@@ -357,6 +357,7 @@ public class ProtoCompileActionBuilder {
protosToCompile,
transitiveSources,
protosInDirectDeps,
+ ruleContext.getLabel().getCanonicalForm(),
outputs,
"Descriptor Set",
allowServices);
@@ -380,6 +381,7 @@ public class ProtoCompileActionBuilder {
* method instead of the soup of methods above.
*
* @param toolchainInvocations See {@link #createCommandLineFromToolchains}.
+ * @param ruleLabel See {@link #createCommandLineFromToolchains}.
* @param outputs The artifacts that the resulting action must create.
* @param flavorName e.g., "Java (Immutable)"
* @param allowServices If false, the compilation will break if any .proto file has service
@@ -389,7 +391,8 @@ public class ProtoCompileActionBuilder {
List<ToolchainInvocation> toolchainInvocations,
Iterable<Artifact> protosToCompile,
NestedSet<Artifact> transitiveSources,
- NestedSet<Artifact> protosInDirectDeps,
+ @Nullable NestedSet<Artifact> protosInDirectDeps,
+ String ruleLabel,
Iterable<Artifact> outputs,
String flavorName,
boolean allowServices) {
@@ -424,6 +427,7 @@ public class ProtoCompileActionBuilder {
protosToCompile,
transitiveSources,
protosInDirectDeps,
+ ruleLabel,
allowServices,
ruleContext.getFragment(ProtoConfiguration.class).protocOpts()))
.setProgressMessage("Generating " + flavorName + " proto_library " + ruleContext.getLabel())
@@ -448,15 +452,17 @@ public class ProtoCompileActionBuilder {
* called. As some plugins rely on output from other plugins, their order matters.
*
* @param toolchainInvocations See {@link #createCommandLineFromToolchains}.
+ * @param ruleLabel Name of the proto_library for which we're compiling. This string is used to
+ * populate an error message format that's passed to proto-compiler.
* @param allowServices If false, the compilation will break if any .proto file has
- * service @return a command-line to pass to proto-compiler.
*/
@VisibleForTesting
static CustomCommandLine createCommandLineFromToolchains(
List<ToolchainInvocation> toolchainInvocations,
Iterable<Artifact> protosToCompile,
NestedSet<Artifact> transitiveSources,
- NestedSet<Artifact> protosInDirectDeps,
+ @Nullable NestedSet<Artifact> protosInDirectDeps,
+ String ruleLabel,
boolean allowServices,
ImmutableList<String> protocOpts) {
CustomCommandLine.Builder cmdLine = CustomCommandLine.builder();
@@ -498,6 +504,16 @@ public class ProtoCompileActionBuilder {
// Add include maps
cmdLine.add(new ProtoCommandLineArgv(protosInDirectDeps, transitiveSources));
+ if (protosInDirectDeps != null) {
+ // Note: the %s in the line below is used by proto-compiler. That is, the string we create
+ // here should have a literal %s in it.
+ cmdLine.add(
+ "--direct_dependencies_violation_msg=%s is imported, "
+ + "but "
+ + ruleLabel
+ + " doesn't directly depend on a proto_library that 'srcs' it.");
+ }
+
for (Artifact src : protosToCompile) {
cmdLine.addPath(src.getRootRelativePath());
}