diff options
author | 2018-05-30 11:12:00 -0700 | |
---|---|---|
committer | 2018-05-30 11:13:39 -0700 | |
commit | a14d421edc898f50e3d269a74c5844c587d56abe (patch) | |
tree | 233ece2adde8f1836296560378cf4adfbcecafc5 /src/main/java | |
parent | 252e3b817e444ddfe264e8cbc5f1203023e61926 (diff) |
Modify cc_toolchain_suite rule to allow selection of cc_toolchain label without reading the CROSSTOOL file.
As we want to reroute selecting the toolchain from CROSSTOOL through cc_toolchain, cc_toolchain_suite should have all the necesarry information for obtaining the cc_toolchain label without accessing the CROSSTOOL file.
In order to do that, besides the existing <toolchain.targetCpu>|<toolchain.compiler>, we add <cpu> type of key in 'toolchains' attribute of cc_toolchain_suite.
Now the selection of cc_toolchain label goes as follows:
1. Return toolchains[<cpu>|<compiler> if it exists
2. Return toolchains[<cpu>] if it exists
3. Fall back to the previous state: return toolchains[<toolchain.targetCpu>|<toolchain.compiler>]
RELNOTES: None.
PiperOrigin-RevId: 198588849
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java index e91ad2214d..e20e3a0d4c 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java @@ -14,10 +14,12 @@ package com.google.devtools.build.lib.rules.cpp; + import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.analysis.RedirectChaser; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.analysis.config.BuildConfiguration.Fragment; +import com.google.devtools.build.lib.analysis.config.BuildConfiguration.Options; import com.google.devtools.build.lib.analysis.config.BuildOptions; import com.google.devtools.build.lib.analysis.config.ConfigurationEnvironment; import com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactory; @@ -34,6 +36,7 @@ import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig; import com.google.devtools.common.options.OptionsParsingException; +import java.util.Map; import javax.annotation.Nullable; /** @@ -175,13 +178,26 @@ public class CppConfigurationLoader implements ConfigurationFragmentFactory { if (crosstoolTop instanceof Rule && ((Rule) crosstoolTop).getRuleClass().equals("cc_toolchain_suite")) { Rule ccToolchainSuite = (Rule) crosstoolTop; - ccToolchainLabel = NonconfigurableAttributeMapper.of(ccToolchainSuite) - .get("toolchains", BuildType.LABEL_DICT_UNARY) - .get(toolchain.getTargetCpu() + "|" + toolchain.getCompiler()); + + String desiredCpu = cpuTransformer.getTransformer().apply(options.get(Options.class).cpu); + String key = + desiredCpu + (cppOptions.cppCompiler == null ? "" : ("|" + cppOptions.cppCompiler)); + Map<String, Label> toolchains = + NonconfigurableAttributeMapper.of(ccToolchainSuite) + .get("toolchains", BuildType.LABEL_DICT_UNARY); + ccToolchainLabel = toolchains.get(key); if (ccToolchainLabel == null) { - throw new InvalidConfigurationException(String.format( - "cc_toolchain_suite '%s' does not contain a toolchain for CPU '%s' and compiler '%s'", - crosstoolTopLabel, toolchain.getTargetCpu(), toolchain.getCompiler())); + ccToolchainLabel = toolchains.get(toolchain.getTargetCpu() + "|" + toolchain.getCompiler()); + } + if (ccToolchainLabel == null) { + String errorMessage = + String.format( + "cc_toolchain_suite '%s' does not contain a toolchain for CPU '%s'", + crosstoolTopLabel, toolchain.getTargetCpu()); + if (cppOptions.cppCompiler != null) { + errorMessage = errorMessage + " and compiler " + cppOptions.cppCompiler; + } + throw new InvalidConfigurationException(errorMessage); } } else { throw new InvalidConfigurationException(String.format( |