aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/cpp
diff options
context:
space:
mode:
authorGravatar jcater <jcater@google.com>2018-05-16 09:26:25 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-05-16 09:28:18 -0700
commit83ebe8c8773eb8def96b0c5aa1517ee9b1625144 (patch)
treeff2647325a9c2e1ef24fed5ed9746c369e974f55 /src/main/java/com/google/devtools/build/lib/rules/cpp
parent8d2c8ae9ac41e7913cb67a8fa4b63453ddd17781 (diff)
Add libc_top attribute to cc_toolchain in preparation for moving config data out of CppConfiguration.
PiperOrigin-RevId: 196838680
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java21
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainRule.java38
2 files changed, 44 insertions, 15 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java
index 316c9a6d03..5209e1c230 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java
@@ -321,12 +321,14 @@ public class CcToolchain implements RuleConfiguredTargetFactory {
if (cppConfiguration.getFdoPath() != null) {
fdoZip = cppConfiguration.getFdoPath();
} else if (cppConfiguration.getFdoOptimizeLabel() != null) {
- Artifact fdoArtifact = ruleContext.getPrerequisiteArtifact(":fdo_optimize", Mode.TARGET);
+ Artifact fdoArtifact =
+ ruleContext.getPrerequisiteArtifact(CcToolchainRule.FDO_OPTIMIZE_ATTR, Mode.TARGET);
if (!fdoArtifact.isSourceArtifact()) {
ruleContext.ruleError("--fdo_optimize points to a target that is not an input file");
return null;
}
- Label fdoLabel = ruleContext.getPrerequisite(":fdo_optimize", Mode.TARGET).getLabel();
+ Label fdoLabel =
+ ruleContext.getPrerequisite(CcToolchainRule.FDO_OPTIMIZE_ATTR, Mode.TARGET).getLabel();
if (!fdoLabel
.getPackageIdentifier()
.getPathUnderExecRoot()
@@ -338,7 +340,8 @@ public class CcToolchain implements RuleConfiguredTargetFactory {
fdoZip = fdoArtifact.getPath().asFragment();
} else if (cppConfiguration.getFdoProfileLabel() != null) {
FdoProfileProvider fdoProvider =
- ruleContext.getPrerequisite(":fdo_profile", Mode.TARGET, FdoProfileProvider.PROVIDER);
+ ruleContext.getPrerequisite(
+ CcToolchainRule.FDO_PROFILE_ATTR, Mode.TARGET, FdoProfileProvider.PROVIDER);
fdoZip =
fdoProvider.getFdoPath() != null
? fdoProvider.getFdoPath()
@@ -746,7 +749,8 @@ public class CcToolchain implements RuleConfiguredTargetFactory {
}
private NestedSet<Artifact> inputsForLibc(RuleContext ruleContext) {
- TransitiveInfoCollection libc = ruleContext.getPrerequisite(":libc_top", Mode.TARGET);
+ TransitiveInfoCollection libc =
+ ruleContext.getPrerequisite(CcToolchainRule.LIBC_TOP_ATTR, Mode.TARGET);
return libc != null
? libc.getProvider(FileProvider.class).getFilesToBuild()
: NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER);
@@ -756,7 +760,8 @@ public class CcToolchain implements RuleConfiguredTargetFactory {
NestedSet<Artifact> crosstoolMiddleman) {
return NestedSetBuilder.<Artifact>stableOrder()
.addTransitive(crosstoolMiddleman)
- .addTransitive(AnalysisUtils.getMiddlemanFor(ruleContext, ":libc_top", Mode.TARGET))
+ .addTransitive(
+ AnalysisUtils.getMiddlemanFor(ruleContext, CcToolchainRule.LIBC_TOP_ATTR, Mode.TARGET))
.build();
}
@@ -768,7 +773,8 @@ public class CcToolchain implements RuleConfiguredTargetFactory {
RuleContext ruleContext, NestedSet<Artifact> link) {
return NestedSetBuilder.<Artifact>stableOrder()
.addTransitive(link)
- .addTransitive(AnalysisUtils.getMiddlemanFor(ruleContext, ":libc_top", Mode.TARGET))
+ .addTransitive(
+ AnalysisUtils.getMiddlemanFor(ruleContext, CcToolchainRule.LIBC_TOP_ATTR, Mode.TARGET))
.add(ruleContext.getPrerequisiteArtifact("$interface_library_builder", Mode.HOST))
.add(ruleContext.getPrerequisiteArtifact("$link_dynamic_library_tool", Mode.HOST))
.build();
@@ -874,7 +880,8 @@ public class CcToolchain implements RuleConfiguredTargetFactory {
private PathFragment calculateSysroot(RuleContext ruleContext, PathFragment defaultSysroot) {
- TransitiveInfoCollection sysrootTarget = ruleContext.getPrerequisite(":libc_top", Mode.TARGET);
+ TransitiveInfoCollection sysrootTarget =
+ ruleContext.getPrerequisite(CcToolchainRule.LIBC_TOP_ATTR, Mode.TARGET);
if (sysrootTarget == null) {
return defaultSysroot;
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainRule.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainRule.java
index 29831acc1c..a7bf17bf51 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainRule.java
@@ -30,6 +30,7 @@ import com.google.devtools.build.lib.analysis.TemplateVariableInfo;
import com.google.devtools.build.lib.analysis.config.HostTransition;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.packages.Attribute.LabelLateBoundDefault;
+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.Target;
@@ -40,6 +41,11 @@ import com.google.devtools.build.lib.syntax.Type;
* Rule definition for compiler definition.
*/
public final class CcToolchainRule implements RuleDefinition {
+
+ public static final String LIBC_TOP_ATTR = ":libc_top";
+ public static final String FDO_OPTIMIZE_ATTR = ":fdo_optimize";
+ public static final String FDO_PROFILE_ATTR = ":fdo_profile";
+
/**
* Determines if the given target is a cc_toolchain or one of its subclasses. New subclasses
* should be added to this method.
@@ -49,19 +55,31 @@ public final class CcToolchainRule implements RuleDefinition {
return ruleClass.endsWith("cc_toolchain");
}
- private static final LabelLateBoundDefault<?> LIBC_TOP =
+ private static Label getLabel(AttributeMap attributes, String attrName, Label defaultValue) {
+ if (attributes.has(attrName, LABEL)) {
+ Label value = attributes.get(attrName, LABEL);
+ if (value != null) {
+ return value;
+ }
+ }
+ return defaultValue;
+ }
+
+ private static final LabelLateBoundDefault<?> LIBC_TOP_VALUE =
LabelLateBoundDefault.fromTargetConfiguration(
CppConfiguration.class,
null,
- (rule, attributes, cppConfig) -> cppConfig.getSysrootLabel());
+ (rule, attributes, cppConfig) ->
+ // This avoids analyzing the label from the CROSSTOOL if the attribute is set.
+ getLabel(attributes, "libc_top", cppConfig.getSysrootLabel()));
- private static final LabelLateBoundDefault<?> FDO_OPTIMIZE_LABEL =
+ private static final LabelLateBoundDefault<?> FDO_OPTIMIZE_VALUE =
LabelLateBoundDefault.fromTargetConfiguration(
CppConfiguration.class,
null,
(rule, attributes, cppConfig) -> cppConfig.getFdoOptimizeLabel());
- private static final LabelLateBoundDefault<?> FDO_PROFILE_LABEL =
+ private static final LabelLateBoundDefault<?> FDO_PROFILE_VALUE =
LabelLateBoundDefault.fromTargetConfiguration(
CppConfiguration.class,
null,
@@ -149,13 +167,17 @@ public final class CcToolchainRule implements RuleDefinition {
null,
(rule, attributes, cppConfig) ->
shouldIncludeZipperInToolchain(cppConfig) ? zipper : null)))
- .add(attr(":libc_top", LABEL).value(LIBC_TOP))
- .add(attr(":fdo_optimize", LABEL).singleArtifact().value(FDO_OPTIMIZE_LABEL))
+
+ // TODO(b/78578234): Make this the default and remove the late-bound versions.
+ .add(attr("libc_top", LABEL).allowedFileTypes())
+ .add(attr(LIBC_TOP_ATTR, LABEL).value(LIBC_TOP_VALUE))
+
+ .add(attr(FDO_OPTIMIZE_ATTR, LABEL).singleArtifact().value(FDO_OPTIMIZE_VALUE))
.add(
- attr(":fdo_profile", LABEL)
+ attr(FDO_PROFILE_ATTR, LABEL)
.allowedRuleClasses("fdo_profile")
.mandatoryProviders(ImmutableList.of(FdoProfileProvider.PROVIDER.id()))
- .value(FDO_PROFILE_LABEL))
+ .value(FDO_PROFILE_VALUE))
.add(
attr(TransitiveLipoInfoProvider.LIPO_CONTEXT_COLLECTOR, LABEL)
.cfg(LipoContextCollectorTransition.INSTANCE)