diff options
author | cpeyser <cpeyser@google.com> | 2017-11-18 16:48:08 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2017-11-18 16:50:06 -0800 |
commit | 1ea72aa77af17b413538f66521193c3d1b7657ad (patch) | |
tree | d28de3a3b2c1f1461f418cbcf222b9d753452bca /src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java | |
parent | 2af2bff08c2fab136ea0927242bd4f3fe05456bf (diff) |
Change default behavior for cc_toolchain.compiler and cc_toolchain.libc for
platform-based toolchain selection to match legacy behavior.
This is a change over previous behavior in the platform case, which was to throw if either of those attributes is not present. The default_toolchain field in CROSSTOOL gives a mapping from cc_toolchain.cpu values to toolchains - this map should be used with compiler and libc are not specified, as is currently the non-platforms, legacy behavior.
PiperOrigin-RevId: 176246316
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java | 17 |
1 files changed, 10 insertions, 7 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 f7fc13e4dc..c66dd9378b 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 @@ -601,18 +601,21 @@ public class CcToolchain implements RuleConfiguredTargetFactory { private CToolchain getToolchainFromAttributes( RuleContext ruleContext, CppConfiguration cppConfiguration) throws RuleErrorException { - for (String requiredAttr : ImmutableList.of("cpu", "compiler", "libc")) { - if (ruleContext.attributes().get(requiredAttr, Type.STRING).isEmpty()) { - ruleContext.throwWithRuleError( - String.format( - "Using cc_toolchain target requires the attribute '%s' to be present.", - requiredAttr)); - } + if (ruleContext.attributes().get("cpu", Type.STRING).isEmpty()) { + ruleContext.throwWithRuleError("Using cc_toolchain target requires the attribute 'cpu' " + + "to be present"); } + String cpu = ruleContext.attributes().get("cpu", Type.STRING); String compiler = ruleContext.attributes().get("compiler", Type.STRING); + if (compiler.isEmpty()) { + compiler = null; + } String libc = ruleContext.attributes().get("libc", Type.STRING); + if (libc.isEmpty()) { + libc = null; + } CrosstoolConfigurationIdentifier config = new CrosstoolConfigurationIdentifier(cpu, compiler, libc); |