Skip to content

Commit

Permalink
Remove unused late-bound attributes for target and execution platforms.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 168703757
  • Loading branch information
katre authored and philwo committed Sep 15, 2017
1 parent cd37941 commit c60f973
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,64 +15,18 @@
package com.google.devtools.build.lib.analysis;

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.collect.ImmutableList;
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 java.util.List;
import javax.annotation.Nullable;

/** Helper class to manage rules' use of platforms. */
public class PlatformSemantics {

public static final String TARGET_PLATFORMS_ATTR = ":target_platforms";
public static final String EXECUTION_PLATFORM_ATTR = ":execution_platform";
public static final String TOOLCHAINS_ATTR = "$toolchains";

/** Implementation for the :target_platform attribute. */
public static final Attribute.LateBoundLabelList<BuildConfiguration> TARGET_PLATFORM =
new Attribute.LateBoundLabelList<BuildConfiguration>(PlatformConfiguration.class) {
@Override
public List<Label> resolve(
Rule rule, AttributeMap attributes, BuildConfiguration configuration) {
// 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) {
// rule may be null for tests
if (rule == null || rule.getRuleClassObject().getRequiredToolchains().isEmpty()) {
return null;
}
return configuration.getFragment(PlatformConfiguration.class).getExecutionPlatform();
}
};

public static RuleClass.Builder platformAttributes(RuleClass.Builder builder) {
return builder
.add(
attr(TARGET_PLATFORMS_ATTR, LABEL_LIST)
.value(TARGET_PLATFORM)
.nonconfigurable("Used in toolchain resolution"))
.add(
attr(EXECUTION_PLATFORM_ATTR, LABEL)
.value(EXECUTION_PLATFORM)
.nonconfigurable("Used in toolchain resolution"))
.add(
attr(TOOLCHAINS_ATTR, LABEL_LIST)
.nonconfigurable("Used in toolchain resolution")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public void init(Builder builder) {

@Override
public ImmutableList<RuleSet> requires() {
return ImmutableList.of(CoreRules.INSTANCE);
return ImmutableList.of(CoreRules.INSTANCE, PLATFORM_RULES);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import com.google.common.base.Predicates;
import com.google.devtools.build.lib.analysis.BaseRuleClasses;
import com.google.devtools.build.lib.analysis.PlatformConfiguration;
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;
Expand Down Expand Up @@ -140,6 +141,7 @@ public RuleClass build(Builder builder, RuleDefinitionEnvironment env) {
attr(CcToolchain.CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME, LABEL)
.value(CppRuleClasses.ccToolchainAttribute(env)))
.setPreferredDependencyPredicate(Predicates.<String>or(CPP_SOURCE, C_SOURCE, CPP_HEADER))
.requiresConfigurationFragments(PlatformConfiguration.class)
.addRequiredToolchains(CppHelper.getCcToolchainType(env.getToolsRepository()))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ public void testTopLevelTargetsAreTrimmedWithTrimmedConfigurations() throws Exce
AnalysisResult res = update("//foo:x");
ConfiguredTarget topLevelTarget = Iterables.getOnlyElement(res.getTargetsToBuild());
assertThat(topLevelTarget.getConfiguration().getAllFragments().keySet())
.containsExactly(ruleClassProvider.getUniversalFragment(), PlatformConfiguration.class);
.containsExactly(ruleClassProvider.getUniversalFragment());
}

@Test
Expand Down

0 comments on commit c60f973

Please sign in to comment.