From 7855b888c4de7e09d4bad0d93ad56e6acc9939ce Mon Sep 17 00:00:00 2001 From: cpeyser Date: Wed, 27 Sep 2017 13:33:52 -0400 Subject: Add 'compiler' and 'libc' attributes to cc_toolchain. If platform/toolchain resolution is used, use these attribute values to choose a CToolchain from --crosstool_top instead of --compiler and --glibc. PiperOrigin-RevId: 170217186 --- .../devtools/build/lib/rules/cpp/CppHelper.java | 33 +++++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java') diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java index 83649b6267..feaad45b72 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java @@ -318,14 +318,13 @@ public class CppHelper { } /** - * This almost trivial method looks up the given cc toolchain attribute on the rule context, makes - * sure that it refers to a rule that has a {@link CcToolchainProvider} - * (gives an error otherwise), and returns a reference to that {@link CcToolchainProvider}. - * The method only returns {@code null} if there is no such attribute - * (this is currently not an error). + * Makes sure that the given info collection has a {@link CcToolchainProvider} (gives an error + * otherwise), and returns a reference to that {@link CcToolchainProvider}. The method will only + * return {@code null}, if the toolchain attribute is undefined for the rule class. */ - @Nullable public static CcToolchainProvider getToolchain(RuleContext ruleContext, - String toolchainAttribute) { + @Nullable + public static CcToolchainProvider getToolchain( + RuleContext ruleContext, String toolchainAttribute) { if (!ruleContext.isAttrDefined(toolchainAttribute, LABEL)) { // TODO(bazel-team): Report an error or throw an exception in this case. return null; @@ -334,13 +333,8 @@ public class CppHelper { return getToolchain(ruleContext, dep); } - /** - * This almost trivial method makes sure that the given info collection has a {@link - * CcToolchainProvider} (gives an error otherwise), and returns a reference to that {@link - * CcToolchainProvider}. The method never returns {@code null}, even if there is no toolchain. - */ - public static CcToolchainProvider getToolchain(RuleContext ruleContext, - TransitiveInfoCollection dep) { + /** Returns the c++ toolchain type, or null if it is not specified on the rule class. */ + public static Label getToolchainTypeFromRuleClass(RuleContext ruleContext) { Label toolchainType; // TODO(b/65835260): Remove this conditional once j2objc can learn the toolchain type. if (ruleContext.attributes().has(CcToolchain.CC_TOOLCHAIN_TYPE_ATTRIBUTE_NAME)) { @@ -349,7 +343,18 @@ public class CppHelper { } else { toolchainType = null; } + return toolchainType; + } + + /** + * Makes sure that the given info collection has a {@link CcToolchainProvider} (gives an error + * otherwise), and returns a reference to that {@link CcToolchainProvider}. The method never + * returns {@code null}, even if there is no toolchain. + */ + public static CcToolchainProvider getToolchain( + RuleContext ruleContext, TransitiveInfoCollection dep) { + Label toolchainType = getToolchainTypeFromRuleClass(ruleContext); if (toolchainType != null && ruleContext .getFragment(PlatformConfiguration.class) -- cgit v1.2.3