aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar rosica <rosica@google.com>2018-06-21 02:05:54 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-21 02:07:33 -0700
commitc97082475fc2b60251dc19d8882b668f1547b9b7 (patch)
treea25aa76bb1b2f6d98fcc3a76de6c8ca63c656bcd /src
parent5a9befc5602e71f7512074c303afbdcff5617cca (diff)
Extract logic from CROSSTOOL in CrosstoolInfo provider
CrosstoolInfo carries the necessary information from the CROSSTOOL text proto. Later on, instead from the CROSSTOOL file and the corresponding CToolchain, CrosstoolInfo will be derived from a skylark_crosstool rule implemented in Skylark. Therefore CToolchain involvement in CppConfiguration and CcToolchain creation needs to be eliminated. Work towards issue #5380 RELNOTES: None. PiperOrigin-RevId: 201491207
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java12
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java53
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java10
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java24
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppToolchainInfo.java191
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CrosstoolInfo.java636
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java6
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTestCase.java6
8 files changed, 799 insertions, 139 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 6de5145463..8aea1525a2 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
@@ -654,10 +654,18 @@ public class CcToolchain implements RuleConfiguredTargetFactory {
// If we found a toolchain, use it.
try {
+ toolchain =
+ CppToolchainInfo.addLegacyFeatures(
+ toolchain, cppConfiguration.getCrosstoolTopPathFragment());
+ CrosstoolInfo crosstoolInfo =
+ CrosstoolInfo.fromToolchain(
+ cppConfiguration.getCrosstoolFile().getProto(),
+ toolchain,
+ cppConfiguration.getCrosstoolTopPathFragment());
return CppToolchainInfo.create(
- toolchain,
cppConfiguration.getCrosstoolTopPathFragment(),
- cppConfiguration.getCcToolchainRuleLabel());
+ cppConfiguration.getCcToolchainRuleLabel(),
+ crosstoolInfo);
} catch (InvalidConfigurationException e) {
throw ruleContext.throwWithRuleError(e.getMessage());
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java
index 4b3f04c23e..5becc5aa3a 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java
@@ -692,7 +692,7 @@ public class CcToolchainFeatures implements Serializable {
private final ImmutableList<String> implies;
private final ImmutableList<String> provides;
- private Feature(CToolchain.Feature feature) throws InvalidConfigurationException {
+ Feature(CToolchain.Feature feature) throws InvalidConfigurationException {
this.name = feature.getName();
ImmutableList.Builder<FlagSet> flagSetBuilder = ImmutableList.builder();
for (CToolchain.FlagSet flagSet : feature.getFlagSetList()) {
@@ -888,7 +888,7 @@ public class CcToolchainFeatures implements Serializable {
private final boolean enabled;
private final ImmutableList<String> implies;
- private ActionConfig(CToolchain.ActionConfig actionConfig, PathFragment crosstoolTop)
+ ActionConfig(CToolchain.ActionConfig actionConfig, PathFragment crosstoolTop)
throws InvalidConfigurationException {
this.configName = actionConfig.getConfigName();
this.actionName = actionConfig.getActionName();
@@ -995,13 +995,13 @@ public class CcToolchainFeatures implements Serializable {
/** A description of how artifacts of a certain type are named. */
@Immutable
- private static class ArtifactNamePattern {
+ static class ArtifactNamePattern {
private final ArtifactCategory artifactCategory;
private final String prefix;
private final String extension;
- private ArtifactNamePattern(CToolchain.ArtifactNamePattern artifactNamePattern)
+ ArtifactNamePattern(CToolchain.ArtifactNamePattern artifactNamePattern)
throws InvalidConfigurationException {
ArtifactCategory foundCategory = null;
@@ -1269,14 +1269,13 @@ public class CcToolchainFeatures implements Serializable {
buildConfigurationCache();
/**
- * Constructs the feature configuration from a {@code CToolchain} protocol buffer.
+ * Constructs the feature configuration from a {@code crosstoolInfo}.
*
- * @param toolchain the toolchain configuration as specified by the user.
+ * @param crosstoolInfo the toolchain information as specified by the user.
* @throws InvalidConfigurationException if the configuration has logical errors.
*/
@VisibleForTesting
- public CcToolchainFeatures(CToolchain toolchain, PathFragment crosstoolTop)
- throws InvalidConfigurationException {
+ public CcToolchainFeatures(CrosstoolInfo crosstoolInfo) throws InvalidConfigurationException {
// Build up the feature/action config graph. We refer to features/action configs as
// 'selectables'.
// First, we build up the map of name -> selectables in one pass, so that earlier selectables
@@ -1288,8 +1287,7 @@ public class CcToolchainFeatures implements Serializable {
ImmutableMap.Builder<String, ActionConfig> actionConfigsByActionName = ImmutableMap.builder();
ImmutableList.Builder<String> defaultSelectablesBuilder = ImmutableList.builder();
- for (CToolchain.Feature toolchainFeature : toolchain.getFeatureList()) {
- Feature feature = new Feature(toolchainFeature);
+ for (Feature feature : crosstoolInfo.getFeatures()) {
selectablesBuilder.add(feature);
selectablesByName.put(feature.getName(), feature);
if (feature.isEnabled()) {
@@ -1297,8 +1295,7 @@ public class CcToolchainFeatures implements Serializable {
}
}
- for (CToolchain.ActionConfig toolchainActionConfig : toolchain.getActionConfigList()) {
- ActionConfig actionConfig = new ActionConfig(toolchainActionConfig, crosstoolTop);
+ for (ActionConfig actionConfig : crosstoolInfo.getActionConfigs()) {
selectablesBuilder.add(actionConfig);
selectablesByName.put(actionConfig.getName(), actionConfig);
actionConfigsByActionName.put(actionConfig.getActionName(), actionConfig);
@@ -1311,18 +1308,12 @@ public class CcToolchainFeatures implements Serializable {
this.selectables = selectablesBuilder.build();
this.selectablesByName = ImmutableMap.copyOf(selectablesByName);
- checkForActionNameDups(toolchain.getActionConfigList());
+ checkForActionNameDups(crosstoolInfo.getActionConfigs());
checkForActivatableDups(this.selectables);
this.actionConfigsByActionName = actionConfigsByActionName.build();
- ImmutableList.Builder<ArtifactNamePattern> artifactNamePatternsBuilder =
- ImmutableList.builder();
- for (CToolchain.ArtifactNamePattern artifactNamePattern :
- toolchain.getArtifactNamePatternList()) {
- artifactNamePatternsBuilder.add(new ArtifactNamePattern(artifactNamePattern));
- }
- this.artifactNamePatterns = artifactNamePatternsBuilder.build();
+ this.artifactNamePatterns = crosstoolInfo.getArtifactNamePatterns();
// Next, we build up all forward references for 'implies', 'requires', and 'provides' edges.
ImmutableMultimap.Builder<CrosstoolSelectable, CrosstoolSelectable> implies =
@@ -1336,32 +1327,32 @@ public class CcToolchainFeatures implements Serializable {
ImmutableMultimap.Builder<CrosstoolSelectable, CrosstoolSelectable> requiredBy =
ImmutableMultimap.builder();
- for (CToolchain.Feature toolchainFeature : toolchain.getFeatureList()) {
- String name = toolchainFeature.getName();
+ for (Feature feature : crosstoolInfo.getFeatures()) {
+ String name = feature.getName();
CrosstoolSelectable selectable = selectablesByName.get(name);
- for (CToolchain.FeatureSet requiredFeatures : toolchainFeature.getRequiresList()) {
+ for (ImmutableSet<String> requiredFeatures : feature.getRequires()) {
ImmutableSet.Builder<CrosstoolSelectable> allOf = ImmutableSet.builder();
- for (String requiredName : requiredFeatures.getFeatureList()) {
+ for (String requiredName : requiredFeatures) {
CrosstoolSelectable required = getActivatableOrFail(requiredName, name);
allOf.add(required);
requiredBy.put(required, selectable);
}
requires.put(selectable, allOf.build());
}
- for (String impliedName : toolchainFeature.getImpliesList()) {
+ for (String impliedName : feature.getImplies()) {
CrosstoolSelectable implied = getActivatableOrFail(impliedName, name);
impliedBy.put(implied, selectable);
implies.put(selectable, implied);
}
- for (String providesName : toolchainFeature.getProvidesList()) {
+ for (String providesName : feature.getProvides()) {
provides.put(selectable, providesName);
}
}
- for (CToolchain.ActionConfig toolchainActionConfig : toolchain.getActionConfigList()) {
- String name = toolchainActionConfig.getConfigName();
+ for (ActionConfig actionConfig : crosstoolInfo.getActionConfigs()) {
+ String name = actionConfig.getName();
CrosstoolSelectable selectable = selectablesByName.get(name);
- for (String impliedName : toolchainActionConfig.getImpliesList()) {
+ for (String impliedName : actionConfig.getImplies()) {
CrosstoolSelectable implied = getActivatableOrFail(impliedName, name);
impliedBy.put(implied, selectable);
implies.put(selectable, implied);
@@ -1389,10 +1380,10 @@ public class CcToolchainFeatures implements Serializable {
}
}
- private static void checkForActionNameDups(Iterable<CToolchain.ActionConfig> actionConfigs)
+ private static void checkForActionNameDups(Iterable<ActionConfig> actionConfigs)
throws InvalidConfigurationException {
Collection<String> actionNames = new HashSet<>();
- for (CToolchain.ActionConfig actionConfig : actionConfigs) {
+ for (ActionConfig actionConfig : actionConfigs) {
if (!actionNames.add(actionConfig.getActionName())) {
throw new InvalidConfigurationException(
"Invalid toolchain configuration: multiple action "
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
index 12aa64382d..efaabf0d9e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
@@ -42,7 +42,6 @@ import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig;
-import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CToolchain;
import java.util.Map;
import javax.annotation.Nullable;
@@ -219,12 +218,12 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
static CppConfiguration create(CppConfigurationParameters params)
throws InvalidConfigurationException {
- CrosstoolConfig.CToolchain toolchain = params.toolchain;
CppOptions cppOptions = params.cppOptions;
PathFragment crosstoolTopPathFragment =
params.crosstoolTop.getPackageIdentifier().getPathUnderExecRoot();
CppToolchainInfo cppToolchainInfo =
- CppToolchainInfo.create(toolchain, crosstoolTopPathFragment, params.ccToolchainLabel);
+ CppToolchainInfo.create(
+ crosstoolTopPathFragment, params.ccToolchainLabel, params.crosstoolInfo);
CompilationMode compilationMode = params.commonOptions.compilationMode;
@@ -267,7 +266,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
params.sysrootLabel,
coptsBuilder.build(),
cxxOpts,
- ImmutableList.copyOf(toolchain.getUnfilteredCxxFlagList()),
+ cppToolchainInfo.getUnfilteredCompilerOptions(/* sysroot= */ null),
ImmutableList.copyOf(cppOptions.conlyoptList),
cppToolchainInfo.configureAllLegacyLinkOptions(compilationMode, LinkingMode.STATIC),
cppToolchainInfo.configureAllLegacyLinkOptions(
@@ -1125,8 +1124,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
return cppOptions.useLLVMCoverageMapFormat;
}
- public static PathFragment computeDefaultSysroot(CToolchain toolchain) {
- String builtInSysroot = toolchain.getBuiltinSysroot();
+ public static PathFragment computeDefaultSysroot(String builtInSysroot) {
if (builtInSysroot.isEmpty()) {
return null;
}
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 48ec524c0b..a4e2d3f9a8 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
@@ -78,7 +78,6 @@ public class CppConfigurationLoader implements ConfigurationFragmentFactory {
* Value class for all the data needed to create a {@link CppConfiguration}.
*/
public static class CppConfigurationParameters {
- protected final CrosstoolConfig.CToolchain toolchain;
protected final CrosstoolConfigurationLoader.CrosstoolFile crosstoolFile;
protected final String cacheKeySuffix;
protected final BuildConfiguration.Options commonOptions;
@@ -90,9 +89,9 @@ public class CppConfigurationLoader implements ConfigurationFragmentFactory {
protected final Label fdoOptimizeLabel;
protected final Label sysrootLabel;
protected final CpuTransformer cpuTransformer;
+ protected final CrosstoolInfo crosstoolInfo;
CppConfigurationParameters(
- CrosstoolConfig.CToolchain toolchain,
CrosstoolConfigurationLoader.CrosstoolFile crosstoolFile,
String cacheKeySuffix,
BuildOptions buildOptions,
@@ -102,8 +101,8 @@ public class CppConfigurationLoader implements ConfigurationFragmentFactory {
Label ccToolchainLabel,
Label stlLabel,
Label sysrootLabel,
- CpuTransformer cpuTransformer) {
- this.toolchain = toolchain;
+ CpuTransformer cpuTransformer,
+ CrosstoolInfo crosstoolInfo) {
this.crosstoolFile = crosstoolFile;
this.cacheKeySuffix = cacheKeySuffix;
this.commonOptions = buildOptions.get(BuildConfiguration.Options.class);
@@ -115,6 +114,7 @@ public class CppConfigurationLoader implements ConfigurationFragmentFactory {
this.stlLabel = stlLabel;
this.sysrootLabel = sysrootLabel;
this.cpuTransformer = cpuTransformer;
+ this.crosstoolInfo = crosstoolInfo;
}
}
@@ -241,11 +241,19 @@ public class CppConfigurationLoader implements ConfigurationFragmentFactory {
: CrosstoolConfigurationLoader.getToolchainByIdentifier(
file.getProto(), identifier, desiredCpu, cppOptions.cppCompiler);
}
+ toolchain =
+ CppToolchainInfo.addLegacyFeatures(
+ toolchain, crosstoolTopLabel.getPackageIdentifier().getPathUnderExecRoot());
+
+ CrosstoolInfo crosstoolInfo =
+ CrosstoolInfo.fromToolchain(
+ file.getProto(),
+ toolchain,
+ crosstoolTopLabel.getPackageIdentifier().getPathUnderExecRoot());
Label sysrootLabel = getSysrootLabel(toolchain, cppOptions.libcTopLabel);
return new CppConfigurationParameters(
- toolchain,
file,
file.getMd5(),
options,
@@ -255,13 +263,15 @@ public class CppConfigurationLoader implements ConfigurationFragmentFactory {
ccToolchainLabel,
stlLabel,
sysrootLabel,
- cpuTransformer);
+ cpuTransformer,
+ crosstoolInfo);
}
@Nullable
public static Label getSysrootLabel(CrosstoolConfig.CToolchain toolchain, Label libcTopLabel)
throws InvalidConfigurationException {
- PathFragment defaultSysroot = CppConfiguration.computeDefaultSysroot(toolchain);
+ PathFragment defaultSysroot =
+ CppConfiguration.computeDefaultSysroot(toolchain.getBuiltinSysroot());
if ((libcTopLabel != null) && (defaultSysroot == null)) {
throw new InvalidConfigurationException(
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppToolchainInfo.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppToolchainInfo.java
index b71c213e11..7849ea52a6 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppToolchainInfo.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppToolchainInfo.java
@@ -30,11 +30,11 @@ import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.rules.cpp.CppActionConfigs.CppPlatform;
import com.google.devtools.build.lib.rules.cpp.Link.LinkingMode;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
+import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig;
import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CToolchain;
import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CToolchain.ArtifactNamePattern;
-import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.LinkingModeFlags;
import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.ToolPath;
import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.TextFormat;
@@ -58,7 +58,7 @@ import javax.annotation.Nullable;
@AutoCodec
@Immutable
public final class CppToolchainInfo {
- private CToolchain toolchain;
+ private final CrosstoolInfo crosstoolInfo;
private final PathFragment crosstoolTopPathFragment;
private final String toolchainIdentifier;
private final CcToolchainFeatures toolchainFeatures;
@@ -109,14 +109,14 @@ public final class CppToolchainInfo {
private final boolean supportsGoldLinker;
private final boolean toolchainNeedsPic;
- /** Creates a CppToolchainInfo from a toolchain. */
+ /** Creates a CppToolchainInfo from CROSSTOOL info encapsulated in {@link CrosstoolInfo}. */
public static CppToolchainInfo create(
- CToolchain inputToolchain, PathFragment crosstoolTopPathFragment, Label toolchainLabel)
+ PathFragment crosstoolTopPathFragment, Label toolchainLabel, CrosstoolInfo crosstoolInfo)
throws InvalidConfigurationException {
- CToolchain toolchain = addLegacyFeatures(inputToolchain, crosstoolTopPathFragment);
ImmutableMap<String, PathFragment> toolPaths =
- computeToolPaths(toolchain, crosstoolTopPathFragment);
- PathFragment defaultSysroot = CppConfiguration.computeDefaultSysroot(toolchain);
+ computeToolPaths(crosstoolInfo, crosstoolTopPathFragment);
+ PathFragment defaultSysroot =
+ CppConfiguration.computeDefaultSysroot(crosstoolInfo.getBuiltinSysroot());
ImmutableListMultimap.Builder<LinkingMode, String> linkOptionsFromLinkingModeBuilder =
ImmutableListMultimap.builder();
@@ -126,81 +126,103 @@ public final class CppToolchainInfo {
// - a "DYNAMIC" section in linking_mode_flags (even if no flags are needed)
// - a non-empty list in one of the dynamicLibraryLinkerFlag fields
// If none of the above contain data, then the toolchain can't do dynamic linking.
- boolean haveDynamicMode = false;
-
- for (LinkingModeFlags flags : toolchain.getLinkingModeFlagsList()) {
- LinkingMode realmode = CppConfiguration.importLinkingMode(flags.getMode());
- if (realmode == LinkingMode.DYNAMIC) {
- haveDynamicMode = true;
- }
- linkOptionsFromLinkingModeBuilder.putAll(realmode, flags.getLinkerFlagList());
- }
+ boolean haveDynamicMode = crosstoolInfo.hasDynamicLinkingModeFlags();
+ linkOptionsFromLinkingModeBuilder.putAll(
+ LinkingMode.DYNAMIC, crosstoolInfo.getDynamicLinkingModeFlags());
+ linkOptionsFromLinkingModeBuilder.putAll(
+ LinkingMode.LEGACY_FULLY_STATIC, crosstoolInfo.getFullyStaticLinkingModeFlags());
+ linkOptionsFromLinkingModeBuilder.putAll(
+ LinkingMode.STATIC, crosstoolInfo.getMostlyStaticLinkingModeFlags());
+ linkOptionsFromLinkingModeBuilder.putAll(
+ LinkingMode.LEGACY_MOSTLY_STATIC_LIBRARIES,
+ crosstoolInfo.getMostlyStaticLibrariesLinkingModeFlags());
ImmutableListMultimap.Builder<CompilationMode, String> cFlagsBuilder =
ImmutableListMultimap.builder();
ImmutableListMultimap.Builder<CompilationMode, String> cxxFlagsBuilder =
ImmutableListMultimap.builder();
- for (CrosstoolConfig.CompilationModeFlags flags : toolchain.getCompilationModeFlagsList()) {
- // Remove this when CROSSTOOL files no longer contain 'coverage'.
- if (flags.getMode() == CrosstoolConfig.CompilationMode.COVERAGE) {
- continue;
- }
- CompilationMode realmode = importCompilationMode(flags.getMode());
- cFlagsBuilder.putAll(realmode, flags.getCompilerFlagList());
- cxxFlagsBuilder.putAll(realmode, flags.getCxxFlagList());
- }
+ ImmutableListMultimap.Builder<CompilationMode, String> linkOptionsFromCompilationModeBuilder =
+ ImmutableListMultimap.builder();
+
+ cFlagsBuilder.putAll(
+ importCompilationMode(CrosstoolConfig.CompilationMode.OPT),
+ crosstoolInfo.getOptCompilationModeCompilerFlags());
+ cxxFlagsBuilder.putAll(
+ importCompilationMode(CrosstoolConfig.CompilationMode.OPT),
+ crosstoolInfo.getOptCompilationModeCxxFlags());
+ linkOptionsFromCompilationModeBuilder.putAll(
+ importCompilationMode(CrosstoolConfig.CompilationMode.OPT),
+ crosstoolInfo.getOptCompilationModeLinkerFlags());
+ cFlagsBuilder.putAll(
+ importCompilationMode(CrosstoolConfig.CompilationMode.DBG),
+ crosstoolInfo.getDbgCompilationModeCompilerFlags());
+ cxxFlagsBuilder.putAll(
+ importCompilationMode(CrosstoolConfig.CompilationMode.DBG),
+ crosstoolInfo.getDbgCompilationModeCxxFlags());
+ linkOptionsFromCompilationModeBuilder.putAll(
+ importCompilationMode(CrosstoolConfig.CompilationMode.DBG),
+ crosstoolInfo.getDbgCompilationModeLinkerFlags());
+ cFlagsBuilder.putAll(
+ importCompilationMode(CrosstoolConfig.CompilationMode.FASTBUILD),
+ crosstoolInfo.getFastbuildCompilationModeCompilerFlags());
+ cxxFlagsBuilder.putAll(
+ importCompilationMode(CrosstoolConfig.CompilationMode.FASTBUILD),
+ crosstoolInfo.getFastbuildCompilationModeCxxFlags());
+ linkOptionsFromCompilationModeBuilder.putAll(
+ importCompilationMode(CrosstoolConfig.CompilationMode.FASTBUILD),
+ crosstoolInfo.getFastbuildCompilationModeLinkerFlags());
try {
return new CppToolchainInfo(
- toolchain,
+ crosstoolInfo,
crosstoolTopPathFragment,
- toolchain.getToolchainIdentifier(),
+ crosstoolInfo.getToolchainIdentifier(),
toolPaths,
- toolchain.getCompiler(),
- toolchain.getAbiLibcVersion(),
- toolchain.getTargetCpu(),
- toolchain.getCcTargetOs(),
- ImmutableList.copyOf(toolchain.getCxxBuiltinIncludeDirectoryList()),
+ crosstoolInfo.getCompiler(),
+ crosstoolInfo.getAbiLibcVersion(),
+ crosstoolInfo.getTargetCpu(),
+ crosstoolInfo.getCcTargetOs(),
+ crosstoolInfo.getCxxBuiltinIncludeDirectories(),
defaultSysroot,
// The runtime sysroot should really be set from --grte_top. However, currently libc has
// no way to set the sysroot. The CROSSTOOL file does set the runtime sysroot, in the
// builtin_sysroot field. This implies that you can not arbitrarily mix and match
// Crosstool and libc versions, you must always choose compatible ones.
defaultSysroot,
- toolchain.getTargetLibc(),
- toolchain.getHostSystemName(),
- ImmutableList.copyOf(toolchain.getDynamicLibraryLinkerFlagList()),
- ImmutableList.copyOf(toolchain.getLinkerFlagList()),
+ crosstoolInfo.getTargetLibc(),
+ crosstoolInfo.getHostSystemName(),
+ crosstoolInfo.getDynamicLibraryLinkerFlags(),
+ crosstoolInfo.getLinkerFlags(),
linkOptionsFromLinkingModeBuilder.build(),
- computeLinkOptionsFromCompilationMode(toolchain),
- ImmutableList.copyOf(toolchain.getTestOnlyLinkerFlagList()),
- ImmutableList.copyOf(toolchain.getLdEmbedFlagList()),
- ImmutableList.copyOf(toolchain.getObjcopyEmbedFlagList()),
+ linkOptionsFromCompilationModeBuilder.build(),
+ crosstoolInfo.getTestOnlyLinkerFlags(),
+ crosstoolInfo.getLdEmbedFlags(),
+ crosstoolInfo.getObjcopyEmbedFlags(),
toolchainLabel,
toolchainLabel.getRelative(
- toolchain.hasStaticRuntimesFilegroup()
- ? toolchain.getStaticRuntimesFilegroup()
- : "static-runtime-libs-" + toolchain.getTargetCpu()),
+ !crosstoolInfo.getStaticRuntimesFilegroup().isEmpty()
+ ? crosstoolInfo.getStaticRuntimesFilegroup()
+ : "static-runtime-libs-" + crosstoolInfo.getTargetCpu()),
toolchainLabel.getRelative(
- toolchain.hasDynamicRuntimesFilegroup()
- ? toolchain.getDynamicRuntimesFilegroup()
- : "dynamic-runtime-libs-" + toolchain.getTargetCpu()),
- "_solib_" + toolchain.getTargetCpu(),
- toolchain.getAbiVersion(),
- toolchain.getTargetSystemName(),
- computeAdditionalMakeVariables(toolchain),
- ImmutableList.copyOf(toolchain.getCompilerFlagList()),
- ImmutableList.copyOf(toolchain.getCxxFlagList()),
+ !crosstoolInfo.getDynamicRuntimesFilegroup().isEmpty()
+ ? crosstoolInfo.getDynamicRuntimesFilegroup()
+ : "dynamic-runtime-libs-" + crosstoolInfo.getTargetCpu()),
+ "_solib_" + crosstoolInfo.getTargetCpu(),
+ crosstoolInfo.getAbiVersion(),
+ crosstoolInfo.getTargetSystemName(),
+ computeAdditionalMakeVariables(crosstoolInfo),
+ crosstoolInfo.getCompilerFlags(),
+ crosstoolInfo.getCxxFlags(),
cFlagsBuilder.build(),
cxxFlagsBuilder.build(),
- ImmutableList.copyOf(toolchain.getUnfilteredCxxFlagList()),
- toolchain.getSupportsFission(),
- toolchain.getSupportsStartEndLib(),
- toolchain.getSupportsEmbeddedRuntimes(),
- haveDynamicMode || !toolchain.getDynamicLibraryLinkerFlagList().isEmpty(),
- toolchain.getSupportsInterfaceSharedObjects(),
- toolchain.getSupportsGoldLinker(),
- toolchain.getNeedsPic());
+ crosstoolInfo.getUnfilteredCxxFlags(),
+ crosstoolInfo.supportsFission(),
+ crosstoolInfo.supportsStartEndLib(),
+ crosstoolInfo.supportsEmbeddedRuntimes(),
+ haveDynamicMode || !crosstoolInfo.getDynamicLibraryLinkerFlags().isEmpty(),
+ crosstoolInfo.supportsInterfaceSharedObjects(),
+ crosstoolInfo.supportsGoldLinker(),
+ crosstoolInfo.needsPic());
} catch (LabelSyntaxException e) {
// All of the above label.getRelative() calls are valid labels, and the crosstool_top
// was already checked earlier in the process.
@@ -210,7 +232,7 @@ public final class CppToolchainInfo {
@AutoCodec.Instantiator
CppToolchainInfo(
- CToolchain toolchain,
+ CrosstoolInfo crosstoolInfo,
PathFragment crosstoolTopPathFragment,
String toolchainIdentifier,
ImmutableMap<String, PathFragment> toolPaths,
@@ -250,11 +272,11 @@ public final class CppToolchainInfo {
boolean supportsGoldLinker,
boolean toolchainNeedsPic)
throws InvalidConfigurationException {
- this.toolchain = toolchain;
+ this.crosstoolInfo = crosstoolInfo;
this.crosstoolTopPathFragment = crosstoolTopPathFragment;
this.toolchainIdentifier = toolchainIdentifier;
- // Since this field can be derived from `toolchain`, it is re-derived instead of serialized.
- this.toolchainFeatures = new CcToolchainFeatures(toolchain, crosstoolTopPathFragment);
+ // Since this field can be derived from `crosstoolInfo`, it is re-derived instead of serialized.
+ this.toolchainFeatures = new CcToolchainFeatures(crosstoolInfo);
this.toolPaths = toolPaths;
this.compiler = compiler;
this.abiGlibcVersion = abiGlibcVersion;
@@ -304,7 +326,7 @@ public final class CppToolchainInfo {
// TODO(bazel-team): Remove this once bazel supports all crosstool flags through
// feature configuration, and all crosstools have been converted.
- private static CToolchain addLegacyFeatures(
+ public static CToolchain addLegacyFeatures(
CToolchain toolchain, PathFragment crosstoolTopPathFragment) {
CToolchain.Builder toolchainBuilder = CToolchain.newBuilder();
@@ -442,10 +464,11 @@ public final class CppToolchainInfo {
}
/**
- * Returns the computed {@link CToolchain} proto for this toolchain.
+ * Returns the {@link CrosstoolInfo} instance that was used to initialize this {@link
+ * CppToolchainInfo}.
*/
- public CToolchain getToolchain() {
- return toolchain;
+ public CrosstoolInfo getCrosstoolInfo() {
+ return crosstoolInfo;
}
/**
@@ -722,43 +745,29 @@ public final class CppToolchainInfo {
.build();
}
- private static ImmutableMap<String, String> computeAdditionalMakeVariables(CToolchain toolchain) {
+ private static ImmutableMap<String, String> computeAdditionalMakeVariables(
+ CrosstoolInfo crosstoolInfo) {
Map<String, String> makeVariablesBuilder = new HashMap<>();
// The following are to be used to allow some build rules to avoid the limits on stack frame
// sizes and variable-length arrays. Ensure that these are always set.
makeVariablesBuilder.put("STACK_FRAME_UNLIMITED", "");
makeVariablesBuilder.put(CppConfiguration.CC_FLAGS_MAKE_VARIABLE_NAME, "");
- for (CrosstoolConfig.MakeVariable variable : toolchain.getMakeVariableList()) {
- makeVariablesBuilder.put(variable.getName(), variable.getValue());
+ for (Pair<String, String> variable : crosstoolInfo.getMakeVariables()) {
+ makeVariablesBuilder.put(variable.getFirst(), variable.getSecond());
}
return ImmutableMap.copyOf(makeVariablesBuilder);
}
- private static ImmutableListMultimap<CompilationMode, String>
- computeLinkOptionsFromCompilationMode(CToolchain toolchain) {
- ImmutableListMultimap.Builder<CompilationMode, String> linkOptionsFromCompilationModeBuilder =
- ImmutableListMultimap.builder();
- for (CrosstoolConfig.CompilationModeFlags flags : toolchain.getCompilationModeFlagsList()) {
- // Remove this when CROSSTOOL files no longer contain 'coverage'.
- if (flags.getMode() == CrosstoolConfig.CompilationMode.COVERAGE) {
- continue;
- }
- CompilationMode realmode = importCompilationMode(flags.getMode());
- linkOptionsFromCompilationModeBuilder.putAll(realmode, flags.getLinkerFlagList());
- }
- return linkOptionsFromCompilationModeBuilder.build();
- }
-
private static ImmutableMap<String, PathFragment> computeToolPaths(
- CToolchain toolchain, PathFragment crosstoolTopPathFragment) {
+ CrosstoolInfo crosstoolInfo, PathFragment crosstoolTopPathFragment) {
Map<String, PathFragment> toolPathsCollector = Maps.newHashMap();
- for (CrosstoolConfig.ToolPath tool : toolchain.getToolPathList()) {
- String pathStr = tool.getPath();
+ for (Pair<String, String> tool : crosstoolInfo.getToolPaths()) {
+ String pathStr = tool.getSecond();
if (!PathFragment.isNormalized(pathStr)) {
throw new IllegalArgumentException("The include path '" + pathStr + "' is not normalized.");
}
PathFragment path = PathFragment.create(pathStr);
- toolPathsCollector.put(tool.getName(), crosstoolTopPathFragment.getRelative(path));
+ toolPathsCollector.put(tool.getFirst(), crosstoolTopPathFragment.getRelative(path));
}
if (toolPathsCollector.isEmpty()) {
@@ -774,7 +783,7 @@ public final class CppToolchainInfo {
tool -> {
if (tool == CppConfiguration.Tool.DWP) {
// When fission is unsupported, don't check for the dwp tool.
- return toolchain.getSupportsFission();
+ return crosstoolInfo.supportsFission();
} else if (tool == CppConfiguration.Tool.LLVM_PROFDATA) {
// TODO(tmsriram): Fix this to check if this is a llvm crosstool
// and return true. This needs changes to crosstool_config.proto.
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CrosstoolInfo.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CrosstoolInfo.java
new file mode 100644
index 0000000000..5b64ee6b22
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CrosstoolInfo.java
@@ -0,0 +1,636 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.rules.cpp;
+
+import com.google.common.collect.ImmutableList;
+import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
+import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
+import com.google.devtools.build.lib.packages.NativeInfo;
+import com.google.devtools.build.lib.packages.NativeProvider;
+import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.ActionConfig;
+import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.ArtifactNamePattern;
+import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Feature;
+import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
+import com.google.devtools.build.lib.util.Pair;
+import com.google.devtools.build.lib.vfs.PathFragment;
+import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CToolchain;
+import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CompilationModeFlags;
+import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CrosstoolRelease;
+import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.LinkingModeFlags;
+
+/** Information describing C++ toolchain derived from CROSSTOOL file. */
+@Immutable
+public class CrosstoolInfo extends NativeInfo {
+ public static final NativeProvider<CrosstoolInfo> PROVIDER =
+ new NativeProvider<CrosstoolInfo>(CrosstoolInfo.class, "CrosstoolInfo") {};
+
+ private final ImmutableList<ActionConfig> actionConfigs;
+ private final ImmutableList<Feature> features;
+ private final ImmutableList<ArtifactNamePattern> artifactNamePatterns;
+ private final ImmutableList<String> cxxBuiltinIncludeDirectories;
+
+ private final String majorVersion;
+ private final String minorVersion;
+ private final String toolchainIdentifier;
+ private final String hostSystemName;
+ private final String targetSystemName;
+ private final String targetCpu;
+ private final String targetLibc;
+ private final String compiler;
+ private final String abiVersion;
+ private final String abiLibcVersion;
+ private final boolean supportsGoldLinker;
+ private final boolean supportsStartEndLib;
+ private final boolean supportsInterfaceSharedObjects;
+ private final boolean supportsEmbeddedRuntimes;
+ private final String staticRuntimesFilegroup;
+ private final String dynamicRuntimesFilegroup;
+ private final boolean supportsFission;
+ private final boolean supportsDsym;
+ private final boolean needsPic;
+ private final ImmutableList<Pair<String, String>> toolPaths;
+ private final ImmutableList<String> compilerFlags;
+ private final ImmutableList<String> cxxFlags;
+ private final ImmutableList<String> unfilteredCxxFlags;
+ private final ImmutableList<String> linkerFlags;
+ private final ImmutableList<String> dynamicLibraryLinkerFlags;
+ private final ImmutableList<String> testOnlyLinkerFlags;
+ private final ImmutableList<String> objcopyEmbedFlags;
+ private final ImmutableList<String> ldEmbedFlags;
+ private final ImmutableList<String> optCompilationModeCompilerFlags;
+ private final ImmutableList<String> optCompilationModeCxxFlags;
+ private final ImmutableList<String> optCompilationModeLinkerFlags;
+ private final ImmutableList<String> dbgCompilationModeCompilerFlags;
+ private final ImmutableList<String> dbgCompilationModeCxxFlags;
+ private final ImmutableList<String> dbgCompilationModeLinkerFlags;
+ private final ImmutableList<String> fastbuildCompilationModeCompilerFlags;
+ private final ImmutableList<String> fastbuildCompilationModeCxxFlags;
+ private final ImmutableList<String> fastbuildCompilationModeLinkerFlags;
+ private final ImmutableList<String> mostlyStaticLinkingModeFlags;
+ private final ImmutableList<String> dynamicLinkingModeFlags;
+ private final ImmutableList<String> fullyStaticLinkingModeFlags;
+ private final ImmutableList<String> mostlyStaticLibrariesLinkingModeFlags;
+ private final ImmutableList<Pair<String, String>> makeVariables;
+ private final String builtinSysroot;
+ private final String defaultGrteTop;
+ private final ImmutableList<String> debianExtraRequires;
+ private final String ccTargetOs;
+ private final boolean hasDynamicLinkingModeFlags;
+
+ @AutoCodec.Instantiator
+ protected CrosstoolInfo(
+ ImmutableList<ActionConfig> actionConfigs,
+ ImmutableList<Feature> features,
+ ImmutableList<ArtifactNamePattern> artifactNamePatterns,
+ ImmutableList<String> cxxBuiltinIncludeDirectories,
+ String majorVersion,
+ String minorVersion,
+ String toolchainIdentifier,
+ String hostSystemName,
+ String targetSystemName,
+ String targetCpu,
+ String targetLibc,
+ String compiler,
+ String abiVersion,
+ String abiLibcVersion,
+ boolean supportsGoldLinker,
+ boolean supportsStartEndLib,
+ boolean supportsInterfaceSharedObjects,
+ boolean supportsEmbeddedRuntimes,
+ String staticRuntimesFilegroup,
+ String dynamicRuntimesFilegroup,
+ boolean supportsFission,
+ boolean supportsDsym,
+ boolean needsPic,
+ ImmutableList<Pair<String, String>> toolPaths,
+ ImmutableList<String> compilerFlags,
+ ImmutableList<String> cxxFlags,
+ ImmutableList<String> unfilteredCxxFlags,
+ ImmutableList<String> linkerFlags,
+ ImmutableList<String> dynamicLibraryLinkerFlags,
+ ImmutableList<String> testOnlyLinkerFlags,
+ ImmutableList<String> objcopyEmbedFlags,
+ ImmutableList<String> ldEmbedFlags,
+ ImmutableList<String> optCompilationModeCompilerFlags,
+ ImmutableList<String> optCompilationModeCxxFlags,
+ ImmutableList<String> optCompilationModeLinkerFlags,
+ ImmutableList<String> dbgCompilationModeCompilerFlags,
+ ImmutableList<String> dbgCompilationModeCxxFlags,
+ ImmutableList<String> dbgCompilationModeLinkerFlags,
+ ImmutableList<String> fastbuildCompilationModeCompilerFlags,
+ ImmutableList<String> fastbuildCompilationModeCxxFlags,
+ ImmutableList<String> fastbuildCompilationModeLinkerFlags,
+ ImmutableList<String> mostlyStaticLinkingModeFlags,
+ ImmutableList<String> dynamicLinkingModeFlags,
+ ImmutableList<String> fullyStaticLinkingModeFlags,
+ ImmutableList<String> mostlyStaticLibrariesLinkingModeFlags,
+ ImmutableList<Pair<String, String>> makeVariables,
+ String builtinSysroot,
+ String defaultGrteTop,
+ ImmutableList<String> debianExtraRequires,
+ String ccTargetOs,
+ boolean hasDynamicLinkingModeFlags) {
+ super(PROVIDER);
+ this.actionConfigs = actionConfigs;
+ this.features = features;
+ this.artifactNamePatterns = artifactNamePatterns;
+ this.cxxBuiltinIncludeDirectories = cxxBuiltinIncludeDirectories;
+ this.majorVersion = majorVersion;
+ this.minorVersion = minorVersion;
+ this.toolchainIdentifier = toolchainIdentifier;
+ this.hostSystemName = hostSystemName;
+ this.targetSystemName = targetSystemName;
+ this.targetCpu = targetCpu;
+ this.targetLibc = targetLibc;
+ this.compiler = compiler;
+ this.abiVersion = abiVersion;
+ this.abiLibcVersion = abiLibcVersion;
+ this.supportsGoldLinker = supportsGoldLinker;
+ this.supportsStartEndLib = supportsStartEndLib;
+ this.supportsInterfaceSharedObjects = supportsInterfaceSharedObjects;
+ this.supportsEmbeddedRuntimes = supportsEmbeddedRuntimes;
+ this.staticRuntimesFilegroup = staticRuntimesFilegroup;
+ this.dynamicRuntimesFilegroup = dynamicRuntimesFilegroup;
+ this.supportsFission = supportsFission;
+ this.supportsDsym = supportsDsym;
+ this.needsPic = needsPic;
+ this.toolPaths = toolPaths;
+ this.compilerFlags = compilerFlags;
+ this.cxxFlags = cxxFlags;
+ this.unfilteredCxxFlags = unfilteredCxxFlags;
+ this.linkerFlags = linkerFlags;
+ this.dynamicLibraryLinkerFlags = dynamicLibraryLinkerFlags;
+ this.testOnlyLinkerFlags = testOnlyLinkerFlags;
+ this.objcopyEmbedFlags = objcopyEmbedFlags;
+ this.ldEmbedFlags = ldEmbedFlags;
+ this.optCompilationModeCompilerFlags = optCompilationModeCompilerFlags;
+ this.optCompilationModeCxxFlags = optCompilationModeCxxFlags;
+ this.optCompilationModeLinkerFlags = optCompilationModeLinkerFlags;
+ this.dbgCompilationModeCompilerFlags = dbgCompilationModeCompilerFlags;
+ this.dbgCompilationModeCxxFlags = dbgCompilationModeCxxFlags;
+ this.dbgCompilationModeLinkerFlags = dbgCompilationModeLinkerFlags;
+ this.fastbuildCompilationModeCompilerFlags = fastbuildCompilationModeCompilerFlags;
+ this.fastbuildCompilationModeCxxFlags = fastbuildCompilationModeCxxFlags;
+ this.fastbuildCompilationModeLinkerFlags = fastbuildCompilationModeLinkerFlags;
+ this.mostlyStaticLinkingModeFlags = mostlyStaticLinkingModeFlags;
+ this.dynamicLinkingModeFlags = dynamicLinkingModeFlags;
+ this.fullyStaticLinkingModeFlags = fullyStaticLinkingModeFlags;
+ this.mostlyStaticLibrariesLinkingModeFlags = mostlyStaticLibrariesLinkingModeFlags;
+ this.makeVariables = makeVariables;
+ this.builtinSysroot = builtinSysroot;
+ this.defaultGrteTop = defaultGrteTop;
+ this.debianExtraRequires = debianExtraRequires;
+ this.ccTargetOs = ccTargetOs;
+ this.hasDynamicLinkingModeFlags = hasDynamicLinkingModeFlags;
+ }
+
+ public static CrosstoolInfo fromToolchain(
+ CrosstoolRelease file, CToolchain toolchain, PathFragment crosstoolTop)
+ throws InvalidConfigurationException {
+
+ ImmutableList.Builder<ActionConfig> actionConfigBuilder = ImmutableList.builder();
+ for (CToolchain.ActionConfig actionConfig : toolchain.getActionConfigList()) {
+ actionConfigBuilder.add(new ActionConfig(actionConfig, crosstoolTop));
+ }
+
+ ImmutableList.Builder<Feature> featureBuilder = ImmutableList.builder();
+ for (CToolchain.Feature feature : toolchain.getFeatureList()) {
+ featureBuilder.add(new Feature(feature));
+ }
+
+ ImmutableList.Builder<ArtifactNamePattern> artifactNamePatternBuilder = ImmutableList.builder();
+ for (CToolchain.ArtifactNamePattern artifactNamePattern :
+ toolchain.getArtifactNamePatternList()) {
+ artifactNamePatternBuilder.add(new ArtifactNamePattern(artifactNamePattern));
+ }
+
+ ImmutableList.Builder<String> optCompilationModeCompilerFlags = ImmutableList.builder();
+ ImmutableList.Builder<String> optCompilationModeCxxFlags = ImmutableList.builder();
+ ImmutableList.Builder<String> optCompilationModeLinkerFlags = ImmutableList.builder();
+ ImmutableList.Builder<String> dbgCompilationModeCompilerFlags = ImmutableList.builder();
+ ImmutableList.Builder<String> dbgCompilationModeCxxFlags = ImmutableList.builder();
+ ImmutableList.Builder<String> dbgCompilationModeLinkerFlags = ImmutableList.builder();
+ ImmutableList.Builder<String> fastbuildCompilationModeCompilerFlags = ImmutableList.builder();
+ ImmutableList.Builder<String> fastbuildCompilationModeCxxFlags = ImmutableList.builder();
+ ImmutableList.Builder<String> fastbuildCompilationModeLinkerFlags = ImmutableList.builder();
+
+ ImmutableList.Builder<String> fullyStaticLinkerFlags = ImmutableList.builder();
+ ImmutableList.Builder<String> mostlyStaticLinkerFlags = ImmutableList.builder();
+ ImmutableList.Builder<String> dynamicLinkerFlags = ImmutableList.builder();
+ ImmutableList.Builder<String> mostlyStaticLibrariesLinkerFlags = ImmutableList.builder();
+
+ for (CompilationModeFlags flag : toolchain.getCompilationModeFlagsList()) {
+ switch (flag.getMode()) {
+ case OPT:
+ optCompilationModeCompilerFlags.addAll(flag.getCompilerFlagList());
+ optCompilationModeCxxFlags.addAll(flag.getCxxFlagList());
+ optCompilationModeLinkerFlags.addAll(flag.getLinkerFlagList());
+ break;
+ case DBG:
+ dbgCompilationModeCompilerFlags.addAll(flag.getCompilerFlagList());
+ dbgCompilationModeCxxFlags.addAll(flag.getCxxFlagList());
+ dbgCompilationModeLinkerFlags.addAll(flag.getLinkerFlagList());
+ break;
+ case FASTBUILD:
+ fastbuildCompilationModeCompilerFlags.addAll(flag.getCompilerFlagList());
+ fastbuildCompilationModeCxxFlags.addAll(flag.getCxxFlagList());
+ fastbuildCompilationModeLinkerFlags.addAll(flag.getLinkerFlagList());
+ break;
+ default:
+ // CompilationMode.COVERAGE is ignored
+ }
+ }
+
+ boolean hasDynamicLinkingModeFlags = false;
+ for (LinkingModeFlags flag : toolchain.getLinkingModeFlagsList()) {
+ switch (flag.getMode()) {
+ case FULLY_STATIC:
+ fullyStaticLinkerFlags.addAll(flag.getLinkerFlagList());
+ break;
+ case MOSTLY_STATIC:
+ mostlyStaticLinkerFlags.addAll(flag.getLinkerFlagList());
+ break;
+ case DYNAMIC:
+ hasDynamicLinkingModeFlags = true;
+ dynamicLinkerFlags.addAll(flag.getLinkerFlagList());
+ break;
+ case MOSTLY_STATIC_LIBRARIES:
+ mostlyStaticLibrariesLinkerFlags.addAll(flag.getLinkerFlagList());
+ break;
+ }
+ }
+
+ return new CrosstoolInfo(
+ actionConfigBuilder.build(),
+ featureBuilder.build(),
+ artifactNamePatternBuilder.build(),
+ ImmutableList.copyOf(toolchain.getCxxBuiltinIncludeDirectoryList()),
+ file.getMajorVersion(),
+ file.getMinorVersion(),
+ toolchain.getToolchainIdentifier(),
+ toolchain.getHostSystemName(),
+ toolchain.getTargetSystemName(),
+ toolchain.getTargetCpu(),
+ toolchain.getTargetLibc(),
+ toolchain.getCompiler(),
+ toolchain.getAbiVersion(),
+ toolchain.getAbiLibcVersion(),
+ toolchain.getSupportsGoldLinker(),
+ toolchain.getSupportsStartEndLib(),
+ toolchain.getSupportsInterfaceSharedObjects(),
+ toolchain.getSupportsEmbeddedRuntimes(),
+ toolchain.getStaticRuntimesFilegroup(),
+ toolchain.getDynamicRuntimesFilegroup(),
+ toolchain.getSupportsFission(),
+ toolchain.getSupportsDsym(),
+ toolchain.getNeedsPic(),
+ toolchain
+ .getToolPathList()
+ .stream()
+ .map(a -> Pair.of(a.getName(), a.getPath()))
+ .collect(ImmutableList.toImmutableList()),
+ ImmutableList.copyOf(toolchain.getCompilerFlagList()),
+ ImmutableList.copyOf(toolchain.getCxxFlagList()),
+ ImmutableList.copyOf(toolchain.getUnfilteredCxxFlagList()),
+ ImmutableList.copyOf(toolchain.getLinkerFlagList()),
+ ImmutableList.copyOf(toolchain.getDynamicLibraryLinkerFlagList()),
+ ImmutableList.copyOf(toolchain.getTestOnlyLinkerFlagList()),
+ ImmutableList.copyOf(toolchain.getObjcopyEmbedFlagList()),
+ ImmutableList.copyOf(toolchain.getLdEmbedFlagList()),
+ optCompilationModeCompilerFlags.build(),
+ optCompilationModeCxxFlags.build(),
+ optCompilationModeLinkerFlags.build(),
+ dbgCompilationModeCompilerFlags.build(),
+ dbgCompilationModeCxxFlags.build(),
+ dbgCompilationModeLinkerFlags.build(),
+ fastbuildCompilationModeCompilerFlags.build(),
+ fastbuildCompilationModeCxxFlags.build(),
+ fastbuildCompilationModeLinkerFlags.build(),
+ mostlyStaticLinkerFlags.build(),
+ dynamicLinkerFlags.build(),
+ fullyStaticLinkerFlags.build(),
+ mostlyStaticLibrariesLinkerFlags.build(),
+ toolchain
+ .getMakeVariableList()
+ .stream()
+ .map(makeVariable -> Pair.of(makeVariable.getName(), makeVariable.getValue()))
+ .collect(ImmutableList.toImmutableList()),
+ toolchain.getBuiltinSysroot(),
+ toolchain.getDefaultGrteTop(),
+ ImmutableList.copyOf(toolchain.getDebianExtraRequiresList()),
+ toolchain.getCcTargetOs(),
+ hasDynamicLinkingModeFlags);
+ }
+
+ public ImmutableList<ActionConfig> getActionConfigs() {
+ return actionConfigs;
+ }
+
+ public ImmutableList<Feature> getFeatures() {
+ return features;
+ }
+
+ public ImmutableList<ArtifactNamePattern> getArtifactNamePatterns() {
+ return artifactNamePatterns;
+ }
+
+ public ImmutableList<String> getCxxBuiltinIncludeDirectories() {
+ return cxxBuiltinIncludeDirectories;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public String getMajorVersion() {
+ return majorVersion;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public String getMinorVersion() {
+ return minorVersion;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public String getToolchainIdentifier() {
+ return toolchainIdentifier;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public String getHostSystemName() {
+ return hostSystemName;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public String getTargetSystemName() {
+ return targetSystemName;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public String getTargetCpu() {
+ return targetCpu;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public String getTargetLibc() {
+ return targetLibc;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public String getCompiler() {
+ return compiler;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public String getAbiVersion() {
+ return abiVersion;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public String getAbiLibcVersion() {
+ return abiLibcVersion;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public boolean supportsGoldLinker() {
+ return supportsGoldLinker;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public boolean supportsStartEndLib() {
+ return supportsStartEndLib;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public boolean supportsInterfaceSharedObjects() {
+ return supportsInterfaceSharedObjects;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public boolean supportsEmbeddedRuntimes() {
+ return supportsEmbeddedRuntimes;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public String getStaticRuntimesFilegroup() {
+ return staticRuntimesFilegroup;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public String getDynamicRuntimesFilegroup() {
+ return dynamicRuntimesFilegroup;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public boolean supportsFission() {
+ return supportsFission;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public boolean supportsDsym() {
+ return supportsDsym;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public boolean needsPic() {
+ return needsPic;
+ }
+
+ /** Returns a list of paths of the tools in the form Pair<toolName, path>. */
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<Pair<String, String>> getToolPaths() {
+ return toolPaths;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<String> getCompilerFlags() {
+ return compilerFlags;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<String> getCxxFlags() {
+ return cxxFlags;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<String> getUnfilteredCxxFlags() {
+ return unfilteredCxxFlags;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<String> getLinkerFlags() {
+ return linkerFlags;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<String> getDynamicLibraryLinkerFlags() {
+ return dynamicLibraryLinkerFlags;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<String> getTestOnlyLinkerFlags() {
+ return testOnlyLinkerFlags;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<String> getObjcopyEmbedFlags() {
+ return objcopyEmbedFlags;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<String> getLdEmbedFlags() {
+ return ldEmbedFlags;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<String> getMostlyStaticLinkingModeFlags() {
+ return mostlyStaticLinkingModeFlags;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<String> getDynamicLinkingModeFlags() {
+ return dynamicLinkingModeFlags;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<String> getFullyStaticLinkingModeFlags() {
+ return fullyStaticLinkingModeFlags;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<String> getMostlyStaticLibrariesLinkingModeFlags() {
+ return mostlyStaticLibrariesLinkingModeFlags;
+ }
+
+ /** Returns a list of make variables that have the form Pair<name, value>. */
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<Pair<String, String>> getMakeVariables() {
+ return makeVariables;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public String getBuiltinSysroot() {
+ return builtinSysroot;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public String getDefaultGrteTop() {
+ return defaultGrteTop;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<String> getDebianExtraRequires() {
+ return debianExtraRequires;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<String> getOptCompilationModeCompilerFlags() {
+ return optCompilationModeCompilerFlags;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<String> getOptCompilationModeCxxFlags() {
+ return optCompilationModeCxxFlags;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<String> getOptCompilationModeLinkerFlags() {
+ return optCompilationModeLinkerFlags;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<String> getDbgCompilationModeCompilerFlags() {
+ return dbgCompilationModeCompilerFlags;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<String> getDbgCompilationModeCxxFlags() {
+ return dbgCompilationModeCxxFlags;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<String> getDbgCompilationModeLinkerFlags() {
+ return dbgCompilationModeLinkerFlags;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<String> getFastbuildCompilationModeCompilerFlags() {
+ return fastbuildCompilationModeCompilerFlags;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<String> getFastbuildCompilationModeCxxFlags() {
+ return fastbuildCompilationModeCxxFlags;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public ImmutableList<String> getFastbuildCompilationModeLinkerFlags() {
+ return fastbuildCompilationModeLinkerFlags;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public String getCcTargetOs() {
+ return ccTargetOs;
+ }
+
+ // TODO(b/65151735): Remove once this field is migrated to features.
+ @Deprecated
+ public boolean hasDynamicLinkingModeFlags() {
+ return hasDynamicLinkingModeFlags;
+ }
+}
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java
index a0671e386d..5c94600ad3 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java
@@ -45,6 +45,7 @@ import com.google.devtools.build.lib.testutil.TestUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CToolchain;
+import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CrosstoolRelease;
import com.google.protobuf.TextFormat;
import java.io.IOException;
import java.util.Collection;
@@ -93,7 +94,10 @@ public class CcToolchainFeaturesTest extends FoundationTestCase {
CToolchain.Builder toolchainBuilder = CToolchain.newBuilder();
TextFormat.merge(Joiner.on("").join(toolchain), toolchainBuilder);
return new CcToolchainFeatures(
- toolchainBuilder.buildPartial(), PathFragment.create("crosstool/"));
+ CrosstoolInfo.fromToolchain(
+ CrosstoolRelease.getDefaultInstance(),
+ toolchainBuilder.buildPartial(),
+ PathFragment.create("crosstool/")));
}
private Set<String> getEnabledFeatures(CcToolchainFeatures features,
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTestCase.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTestCase.java
index f2ba84608d..516b52f042 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTestCase.java
@@ -23,6 +23,7 @@ import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CToolchain;
+import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CrosstoolRelease;
import com.google.protobuf.TextFormat;
import java.util.List;
@@ -72,7 +73,10 @@ public class LinkBuildVariablesTestCase extends BuildViewTestCase {
CToolchain.Builder toolchainBuilder = CToolchain.newBuilder();
TextFormat.merge(Joiner.on("").join(toolchain), toolchainBuilder);
return new CcToolchainFeatures(
- toolchainBuilder.buildPartial(), /* crosstoolTop= */ PathFragment.EMPTY_FRAGMENT);
+ CrosstoolInfo.fromToolchain(
+ CrosstoolRelease.getDefaultInstance(),
+ toolchainBuilder.buildPartial(),
+ /* crosstoolTop= */ PathFragment.EMPTY_FRAGMENT));
}
/** Returns the value of a given sequence variable in context of the given Variables instance. */