diff options
author | 2016-07-22 16:11:34 +0000 | |
---|---|---|
committer | 2016-07-22 20:10:53 +0000 | |
commit | 238bf4e778a39df24ebebf8be79e205d7a65e1e4 (patch) | |
tree | 25c52c67768cba2264fd4739353e4d09948c4c91 /src/main/java/com | |
parent | 60fde44443adfad255c89a6b9580e7ce1750a0e5 (diff) |
JavaBuilder: for jars that are produced by aspects (e.g., JavaProtoAspect), pass the name of the injecting rule (e.g., java_proto_library), if the rule registered it.
Registration is done using AspectParameters and a specially-named key.
--
MOS_MIGRATED_REVID=128179548
Diffstat (limited to 'src/main/java/com')
3 files changed, 30 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaProtoLibraryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaProtoLibraryRule.java index 990f0d2166..a263045ee0 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaProtoLibraryRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/proto/BazelJavaProtoLibraryRule.java @@ -16,19 +16,36 @@ package com.google.devtools.build.lib.bazel.rules.java.proto; import static com.google.devtools.build.lib.bazel.rules.java.proto.BazelJavaProtoAspect.SPEED_PROTO_RUNTIME_ATTR; import static com.google.devtools.build.lib.bazel.rules.java.proto.BazelJavaProtoAspect.SPEED_PROTO_RUNTIME_LABEL; +import static com.google.devtools.build.lib.packages.Aspect.INJECTING_RULE_KIND_PARAMETER_KEY; import static com.google.devtools.build.lib.packages.Attribute.attr; import static com.google.devtools.build.lib.packages.BuildType.LABEL; import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST; +import com.google.common.base.Function; import com.google.devtools.build.lib.analysis.BaseRuleClasses; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.packages.AspectParameters; +import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.packages.RuleClass; +import javax.annotation.Nullable; + /** Declaration of the {@code java_proto_library} rule. */ public class BazelJavaProtoLibraryRule implements RuleDefinition { + private static final Function<Rule, AspectParameters> ASPECT_PARAMETERS = + new Function<Rule, AspectParameters>() { + @Nullable + @Override + public AspectParameters apply(@Nullable Rule rule) { + return new AspectParameters.Builder() + .addAttribute(INJECTING_RULE_KIND_PARAMETER_KEY, "java_proto_library") + .build(); + } + }; + private final BazelJavaProtoAspect javaProtoAspect; public BazelJavaProtoLibraryRule(BazelJavaProtoAspect javaProtoAspect) { @@ -48,7 +65,7 @@ public class BazelJavaProtoLibraryRule implements RuleDefinition { attr("deps", LABEL_LIST) .allowedRuleClasses("proto_library") .allowedFileTypes() - .aspect(javaProtoAspect)) + .aspect(javaProtoAspect, ASPECT_PARAMETERS)) .add( attr(SPEED_PROTO_RUNTIME_ATTR, LABEL) .legacyAllowAnyFileType() diff --git a/src/main/java/com/google/devtools/build/lib/packages/Aspect.java b/src/main/java/com/google/devtools/build/lib/packages/Aspect.java index 93f3f4c248..8e0be0cfe1 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/Aspect.java +++ b/src/main/java/com/google/devtools/build/lib/packages/Aspect.java @@ -26,6 +26,10 @@ import com.google.devtools.build.lib.util.Preconditions; */ @Immutable public final class Aspect implements DependencyFilter.AttributeInfoProvider { + + /** */ + public static final String INJECTING_RULE_KIND_PARAMETER_KEY = "$injecting_rule_kind"; + // TODO(bazel-team): class objects are not really hashable or comparable for equality other than // by reference. We should identify the aspect here in a way that does not rely on comparison // by reference so that keys can be serialized and deserialized properly. diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompileAction.java index 028e9d1810..3d85c4eeb3 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompileAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompileAction.java @@ -14,6 +14,8 @@ package com.google.devtools.build.lib.rules.java; +import static com.google.common.collect.Iterables.getOnlyElement; +import static com.google.devtools.build.lib.packages.Aspect.INJECTING_RULE_KIND_PARAMETER_KEY; import static com.google.devtools.build.lib.util.Preconditions.checkNotNull; import static java.nio.charset.StandardCharsets.ISO_8859_1; @@ -21,6 +23,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Joiner; import com.google.common.base.Predicates; import com.google.common.collect.Collections2; +import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; @@ -717,7 +720,11 @@ public final class JavaCompileAction extends AbstractAction { if (owner instanceof AspectValue.AspectKey) { AspectValue.AspectKey aspectOwner = (AspectValue.AspectKey) owner; - result.append(" ").append(aspectOwner.getAspectClass().getName()); + ImmutableCollection<String> injectingRuleKind = + aspectOwner.getParameters().getAttribute(INJECTING_RULE_KIND_PARAMETER_KEY); + if (injectingRuleKind.size() == 1) { + result.append(' ').append(getOnlyElement(injectingRuleKind)); + } } return result.toString(); |