aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/proto
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/proto
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/proto')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryRule.java22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryRule.java b/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryRule.java
index 168f82f415..e7891c4eb2 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryRule.java
@@ -22,11 +22,8 @@ import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
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.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.packages.Attribute;
-import com.google.devtools.build.lib.packages.AttributeMap;
-import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.RuleClass.Builder;
import com.google.devtools.build.lib.util.FileType;
@@ -36,15 +33,16 @@ import com.google.devtools.build.lib.util.FileType;
*/
public final class BazelProtoLibraryRule implements RuleDefinition {
- private static final Attribute.LateBoundLabel<BuildConfiguration> PROTO_COMPILER =
- new Attribute.LateBoundLabel<BuildConfiguration>(
- "@com_google_protobuf//:protoc", ProtoConfiguration.class) {
- @Override
- public Label resolve(Rule rule, AttributeMap attributes, BuildConfiguration configuration) {
- Label label = configuration.getFragment(ProtoConfiguration.class).protoCompiler();
- return label != null ? label : getDefault();
- }
- };
+ private static final Label DEFAULT_PROTO_COMPILER =
+ Label.parseAbsoluteUnchecked("@com_google_protobuf//:protoc");
+ private static final Attribute.LateBoundDefault<?, Label> PROTO_COMPILER =
+ Attribute.LateBoundDefault.fromTargetConfiguration(
+ ProtoConfiguration.class,
+ DEFAULT_PROTO_COMPILER,
+ (rule, attributes, protoConfig) ->
+ protoConfig.protoCompiler() != null
+ ? protoConfig.protoCompiler()
+ : DEFAULT_PROTO_COMPILER);
@Override
public RuleClass build(Builder builder, final RuleDefinitionEnvironment env) {