aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java
diff options
context:
space:
mode:
authorGravatar mstaib <mstaib@google.com>2017-09-19 17:06:32 +0200
committerGravatar László Csomor <laszlocsomor@google.com>2017-09-19 17:18:55 +0200
commit807a9b236963ff863573050d5aba146a9bbe23db (patch)
tree62b94e0f55a8c3f2a6f806f0f2288a507a6a5f77 /src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java
parentfd62e761b5109a721aeec7879c7194404a512535 (diff)
LateBoundDefault: enforce access to a single fragment (or none).
Currently, there is no way to enforce that LateBoundDefaults only access the fragments that they declare. This means that LateBoundDefaults can fail to declare fragments at all, or declare the wrong ones, and still have no troubles. But when trimming, these fragments must be declared, because otherwise they will not necessarily be available. This change refactors LateBoundDefault to declare a single fragment type, not a set. All existing LateBoundDefaults use sets with a single element or no elements at all for their set of fragment classes, so this does not limit anything being done currently. To account for LateBoundDefaults which do not use configuration at all, typically those which only want to access the configured attribute map, it is possible for Void to be the fragment class which is requested. To account for LateBoundDefaults which need to access methods of the BuildConfiguration instance itself, it is possible for BuildConfiguration to be the fragment class which is requested; however, this is unsafe, so it is only a temporary state until a way to do this without also giving access to all of the fragments can be added. Drive-by refactoring: LateBoundDefaults' values are now typed. All actual production LateBoundDefaults were Label or List<Label> typed, through the LateBoundLabel and LateBoundLabelList subclasses. These subclasses have been removed, and LateBoundDefault has two type parameters, one for the type of its input, and one for the type of its output. RELNOTES: None. PiperOrigin-RevId: 169242278
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java23
1 files changed, 8 insertions, 15 deletions
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 fbf667e4d8..9b09be1b1a 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
@@ -35,7 +35,6 @@ import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
import com.google.devtools.build.lib.analysis.TransitiveInfoProviderMap;
import com.google.devtools.build.lib.analysis.TransitiveInfoProviderMapBuilder;
import com.google.devtools.build.lib.analysis.WrappingProvider;
-import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration.StrictDepsMode;
import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget;
import com.google.devtools.build.lib.cmdline.Label;
@@ -45,10 +44,8 @@ import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.packages.AspectDefinition;
import com.google.devtools.build.lib.packages.AspectParameters;
import com.google.devtools.build.lib.packages.Attribute;
-import com.google.devtools.build.lib.packages.Attribute.LateBoundLabel;
-import com.google.devtools.build.lib.packages.AttributeMap;
+import com.google.devtools.build.lib.packages.Attribute.LateBoundDefault;
import com.google.devtools.build.lib.packages.NativeAspectClass;
-import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider;
import com.google.devtools.build.lib.rules.java.JavaCompilationArtifacts;
import com.google.devtools.build.lib.rules.java.JavaCompilationHelper;
@@ -72,28 +69,24 @@ public class JavaLiteProtoAspect extends NativeAspectClass implements Configured
public static final String PROTO_TOOLCHAIN_ATTR = ":aspect_proto_toolchain_for_javalite";
- public static Attribute.LateBoundLabel<BuildConfiguration> getProtoToolchainLabel(
- String defaultValue) {
- return new Attribute.LateBoundLabel<BuildConfiguration>(
- defaultValue, ProtoConfiguration.class) {
- @Override
- public Label resolve(Rule rule, AttributeMap attributes, BuildConfiguration configuration) {
- return configuration.getFragment(ProtoConfiguration.class).protoToolchainForJavaLite();
- }
- };
+ public static LateBoundDefault<?, Label> getProtoToolchainLabel(String defaultValue) {
+ return LateBoundDefault.fromTargetConfiguration(
+ ProtoConfiguration.class,
+ Label.parseAbsoluteUnchecked(defaultValue),
+ (rule, attributes, protoConfig) -> protoConfig.protoToolchainForJavaLite());
}
private final JavaSemantics javaSemantics;
@Nullable private final String jacocoLabel;
private final String defaultProtoToolchainLabel;
- private final LateBoundLabel<BuildConfiguration> hostJdkAttribute;
+ private final LateBoundDefault<?, Label> hostJdkAttribute;
public JavaLiteProtoAspect(
JavaSemantics javaSemantics,
@Nullable String jacocoLabel,
String defaultProtoToolchainLabel,
- LateBoundLabel<BuildConfiguration> hostJdkAttribute) {
+ LateBoundDefault<?, Label> hostJdkAttribute) {
this.javaSemantics = javaSemantics;
this.jacocoLabel = jacocoLabel;
this.defaultProtoToolchainLabel = defaultProtoToolchainLabel;