aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
diff options
context:
space:
mode:
authorGravatar cpeyser <cpeyser@google.com>2017-09-27 13:33:52 -0400
committerGravatar John Cater <jcater@google.com>2017-09-28 08:54:46 -0400
commit7855b888c4de7e09d4bad0d93ad56e6acc9939ce (patch)
tree43afc8a65b381a2b5a0cdcba00e0d8e9482b904c /src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
parent272561c6fda79926040cfaa292cb0b4e85fdb84b (diff)
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
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java33
1 files changed, 19 insertions, 14 deletions
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)