diff options
author | 2017-08-30 18:44:20 +0200 | |
---|---|---|
committer | 2017-08-31 13:36:14 +0200 | |
commit | 2b983bdf508e010a3d4ee9dbaf446b7666749799 (patch) | |
tree | 6029afbc0bf8114044958d1d900c617e8b8a428f /src/main/java/com/google/devtools/build | |
parent | f12402b2627f8eeb70ee24f457efe007206f9b42 (diff) |
Rollforward of c++ toolchain-relevant BUILD file and Bazel mocking changes. That is, a c++ toolchain is added, but a Bazel dependency on that toolchain is not.
PiperOrigin-RevId: 167006332
Diffstat (limited to 'src/main/java/com/google/devtools/build')
5 files changed, 64 insertions, 39 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java b/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java index 817f4d163e..f52d66f209 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java @@ -182,41 +182,60 @@ public class BaseRuleClasses { * Share common attributes across both base and Skylark base rules. */ public static RuleClass.Builder commonCoreAndSkylarkAttributes(RuleClass.Builder builder) { - return builder + return PlatformSemantics.platformAttributes(builder) // The visibility attribute is special: it is a nodep label, and loading the // necessary package groups is handled by {@link LabelVisitor#visitTargetVisibility}. // Package groups always have the null configuration so that they are not duplicated // needlessly. - .add(attr("visibility", NODEP_LABEL_LIST).orderIndependent().cfg(HOST) - .nonconfigurable("special attribute integrated more deeply into Bazel's core logic")) - .add(attr("deprecation", STRING).value(deprecationDefault) - .nonconfigurable("Used in core loading phase logic with no access to configs")) - .add(attr("tags", STRING_LIST).orderIndependent().taggable() - .nonconfigurable("low-level attribute, used in TargetUtils without configurations")) - .add(attr("generator_name", STRING).undocumented("internal") - .nonconfigurable("static structure of a rule")) - .add(attr("generator_function", STRING).undocumented("internal") - .nonconfigurable("static structure of a rule")) - .add(attr("generator_location", STRING).undocumented("internal") - .nonconfigurable("static structure of a rule")) - .add(attr("testonly", BOOLEAN).value(testonlyDefault) - .nonconfigurable("policy decision: rules testability should be consistent")) + .add( + attr("visibility", NODEP_LABEL_LIST) + .orderIndependent() + .cfg(HOST) + .nonconfigurable( + "special attribute integrated more deeply into Bazel's core logic")) + .add( + attr("deprecation", STRING) + .value(deprecationDefault) + .nonconfigurable("Used in core loading phase logic with no access to configs")) + .add( + attr("tags", STRING_LIST) + .orderIndependent() + .taggable() + .nonconfigurable("low-level attribute, used in TargetUtils without configurations")) + .add( + attr("generator_name", STRING) + .undocumented("internal") + .nonconfigurable("static structure of a rule")) + .add( + attr("generator_function", STRING) + .undocumented("internal") + .nonconfigurable("static structure of a rule")) + .add( + attr("generator_location", STRING) + .undocumented("internal") + .nonconfigurable("static structure of a rule")) + .add( + attr("testonly", BOOLEAN) + .value(testonlyDefault) + .nonconfigurable("policy decision: rules testability should be consistent")) .add(attr("features", STRING_LIST).orderIndependent()) .add(attr(":action_listener", LABEL_LIST).cfg(HOST).value(ACTION_LISTENER)) - .add(attr(RuleClass.COMPATIBLE_ENVIRONMENT_ATTR, LABEL_LIST) - .allowedRuleClasses(EnvironmentRule.RULE_NAME) - .cfg(Attribute.ConfigurationTransition.HOST) - .allowedFileTypes(FileTypeSet.NO_FILE) - .dontCheckConstraints() - .nonconfigurable("special logic for constraints and select: see ConstraintSemantics") - ) - .add(attr(RuleClass.RESTRICTED_ENVIRONMENT_ATTR, LABEL_LIST) - .allowedRuleClasses(EnvironmentRule.RULE_NAME) - .cfg(Attribute.ConfigurationTransition.HOST) - .allowedFileTypes(FileTypeSet.NO_FILE) - .dontCheckConstraints() - .nonconfigurable("special logic for constraints and select: see ConstraintSemantics") - ); + .add( + attr(RuleClass.COMPATIBLE_ENVIRONMENT_ATTR, LABEL_LIST) + .allowedRuleClasses(EnvironmentRule.RULE_NAME) + .cfg(Attribute.ConfigurationTransition.HOST) + .allowedFileTypes(FileTypeSet.NO_FILE) + .dontCheckConstraints() + .nonconfigurable( + "special logic for constraints and select: see ConstraintSemantics")) + .add( + attr(RuleClass.RESTRICTED_ENVIRONMENT_ATTR, LABEL_LIST) + .allowedRuleClasses(EnvironmentRule.RULE_NAME) + .cfg(Attribute.ConfigurationTransition.HOST) + .allowedFileTypes(FileTypeSet.NO_FILE) + .dontCheckConstraints() + .nonconfigurable( + "special logic for constraints and select: see ConstraintSemantics")); } public static RuleClass.Builder nameAttribute(RuleClass.Builder builder) { diff --git a/src/main/java/com/google/devtools/build/lib/analysis/PlatformOptions.java b/src/main/java/com/google/devtools/build/lib/analysis/PlatformOptions.java index 3376e9609d..3a84352105 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/PlatformOptions.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/PlatformOptions.java @@ -36,7 +36,7 @@ public class PlatformOptions extends FragmentOptions { @Option( name = "experimental_host_platform", converter = BuildConfiguration.LabelConverter.class, - defaultValue = "@bazel_tools//platforms:host_platform", + defaultValue = "@bazel_tools//tools/platforms:host_platform", documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, effectTags = {OptionEffectTag.UNKNOWN}, metadataTags = {OptionMetadataTag.HIDDEN}, @@ -49,7 +49,7 @@ public class PlatformOptions extends FragmentOptions { @Option( name = "experimental_platforms", converter = BuildConfiguration.LabelListConverter.class, - defaultValue = "@bazel_tools//platforms:target_platform", + defaultValue = "@bazel_tools//tools/platforms:target_platform", documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, effectTags = {OptionEffectTag.UNKNOWN}, metadataTags = {OptionMetadataTag.HIDDEN}, @@ -98,6 +98,8 @@ public class PlatformOptions extends FragmentOptions { public PlatformOptions getHost(boolean fallback) { PlatformOptions host = (PlatformOptions) getDefault(); host.platforms = ImmutableList.of(this.hostPlatform); + host.hostPlatform = this.hostPlatform; + host.extraToolchains = this.extraToolchains; return host; } diff --git a/src/main/java/com/google/devtools/build/lib/analysis/PlatformSemantics.java b/src/main/java/com/google/devtools/build/lib/analysis/PlatformSemantics.java index d93c5a6dea..45c967e551 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/PlatformSemantics.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/PlatformSemantics.java @@ -26,6 +26,7 @@ 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 java.util.List; +import javax.annotation.Nullable; /** Helper class to manage rules' use of platforms. */ public class PlatformSemantics { @@ -40,19 +41,22 @@ public class PlatformSemantics { @Override public List<Label> resolve( Rule rule, AttributeMap attributes, BuildConfiguration configuration) { - if (rule.getRuleClassObject().getRequiredToolchains().isEmpty()) { - return null; + // rule may be null for tests + if (rule == null || rule.getRuleClassObject().getRequiredToolchains().isEmpty()) { + return ImmutableList.of(); } return configuration.getFragment(PlatformConfiguration.class).getTargetPlatforms(); } }; /** Implementation for the :execution_platform attribute. */ + @Nullable public static final Attribute.LateBoundLabel<BuildConfiguration> EXECUTION_PLATFORM = new Attribute.LateBoundLabel<BuildConfiguration>(PlatformConfiguration.class) { @Override public Label resolve(Rule rule, AttributeMap attributes, BuildConfiguration configuration) { - if (rule.getRuleClassObject().getRequiredToolchains().isEmpty()) { + // rule may be null for tests + if (rule == null || rule.getRuleClassObject().getRequiredToolchains().isEmpty()) { return null; } return configuration.getFragment(PlatformConfiguration.class).getExecutionPlatform(); diff --git a/src/main/java/com/google/devtools/build/lib/analysis/ToolchainContext.java b/src/main/java/com/google/devtools/build/lib/analysis/ToolchainContext.java index 9cbdd475ac..16a29fd5df 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/ToolchainContext.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/ToolchainContext.java @@ -142,6 +142,8 @@ public class ToolchainContext { prerequisiteMap .keys() .stream() + // Keys in prerequisiteMap can be null, see {@link DependencyResolver#dependentNodeMap}. + .filter(attribute -> attribute != null) .filter(attribute -> attribute.getName().equals(PlatformSemantics.TOOLCHAINS_ATTR)) .findFirst(); Preconditions.checkState( diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java index 3e850d966d..6c8487364d 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java @@ -39,7 +39,6 @@ import com.google.devtools.build.lib.analysis.ActionsProvider; import com.google.devtools.build.lib.analysis.BaseRuleClasses; import com.google.devtools.build.lib.analysis.DefaultInfo; import com.google.devtools.build.lib.analysis.OutputGroupProvider; -import com.google.devtools.build.lib.analysis.PlatformSemantics; import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; import com.google.devtools.build.lib.analysis.skylark.SkylarkAttr.Descriptor; import com.google.devtools.build.lib.analysis.test.TestConfiguration; @@ -129,10 +128,9 @@ public class SkylarkRuleClassFunctions { /** Parent rule class for non-executable non-test Skylark rules. */ public static final RuleClass baseRule = BaseRuleClasses.commonCoreAndSkylarkAttributes( - PlatformSemantics.platformAttributes( - BaseRuleClasses.nameAttribute( - new RuleClass.Builder("$base_rule", RuleClassType.ABSTRACT, true)) - .add(attr("expect_failure", STRING)))) + BaseRuleClasses.nameAttribute( + new RuleClass.Builder("$base_rule", RuleClassType.ABSTRACT, true)) + .add(attr("expect_failure", STRING))) .build(); /** Parent rule class for executable non-test Skylark rules. */ |