aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/cpp
diff options
context:
space:
mode:
authorGravatar cpeyser <cpeyser@google.com>2017-09-19 18:19:27 +0200
committerGravatar László Csomor <laszlocsomor@google.com>2017-09-20 09:02:42 +0200
commita399b7cb92955897c745a1b813210c6168b80c59 (patch)
tree3f8874275e9f71bfa6c6512fb4a8ecd95c32eb3c /src/main/java/com/google/devtools/build/lib/rules/cpp
parentc034dfd487bdba6b6b2f3f7851415a312ae10f53 (diff)
Introduce --enabled_toolchain_types, which when set to the cpp toolchain causes the cc_toolchain dependency of cc targets to be selected using the platforms/toolchains constraint solving system.
PiperOrigin-RevId: 169250621
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java8
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java31
4 files changed, 44 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java
index 8fc5075c46..74aa13de0b 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java
@@ -124,7 +124,7 @@ public final class CcToolchainProvider extends ToolchainInfo {
ImmutableMap<String, String> environment,
ImmutableList<PathFragment> builtInIncludeDirectories,
@Nullable PathFragment sysroot) {
- super(ImmutableMap.<String, Object>of(), Location.BUILTIN);
+ super(ImmutableMap.of(), Location.BUILTIN);
this.cppConfiguration = cppConfiguration;
this.crosstool = Preconditions.checkNotNull(crosstool);
this.crosstoolMiddleman = Preconditions.checkNotNull(crosstoolMiddleman);
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 4133decc06..fa0f18f287 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
@@ -41,6 +41,7 @@ import com.google.devtools.build.lib.packages.OutputFile;
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.rules.cpp.CppActionConfigs.CppPlatform;
import com.google.devtools.build.lib.rules.cpp.CppConfigurationLoader.CppConfigurationParameters;
+import com.google.devtools.build.lib.rules.cpp.CrosstoolConfigurationLoader.CrosstoolFile;
import com.google.devtools.build.lib.rules.cpp.transitions.ContextCollectorOwnerTransition;
import com.google.devtools.build.lib.rules.cpp.transitions.DisableLipoTransition;
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
@@ -225,6 +226,7 @@ public class CppConfiguration extends BuildConfiguration.Fragment {
}
private final Label crosstoolTop;
+ private final CrosstoolFile crosstoolFile;
private final String hostSystemName;
private final String compiler;
// TODO(lberki): desiredCpu *should* be always the same as targetCpu, except that we don't check
@@ -336,6 +338,7 @@ public class CppConfiguration extends BuildConfiguration.Fragment {
this.targetLibc = toolchain.getTargetLibc();
this.targetOS = toolchain.getCcTargetOs();
this.crosstoolTop = params.crosstoolTop;
+ this.crosstoolFile = params.crosstoolFile;
this.ccToolchainLabel = params.ccToolchainLabel;
this.stlLabel = params.stlLabel;
this.compilationMode = params.commonOptions.compilationMode;
@@ -834,6 +837,11 @@ public class CppConfiguration extends BuildConfiguration.Fragment {
return toolchainIdentifier;
}
+ /** Returns the contents of the CROSSTOOL for this configuration. */
+ public CrosstoolFile getCrosstoolFile() {
+ return crosstoolFile;
+ }
+
/**
* Returns the path of the crosstool.
*/
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 b334b10923..73f3b1b6ea 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
@@ -83,6 +83,7 @@ public class CppConfigurationLoader implements ConfigurationFragmentFactory {
*/
public static class CppConfigurationParameters {
protected final CrosstoolConfig.CToolchain toolchain;
+ protected final CrosstoolConfigurationLoader.CrosstoolFile crosstoolFile;
protected final String cacheKeySuffix;
protected final BuildConfiguration.Options commonOptions;
protected final CppOptions cppOptions;
@@ -94,6 +95,7 @@ public class CppConfigurationLoader implements ConfigurationFragmentFactory {
CppConfigurationParameters(
CrosstoolConfig.CToolchain toolchain,
+ CrosstoolConfigurationLoader.CrosstoolFile crosstoolFile,
String cacheKeySuffix,
BuildOptions buildOptions,
Path fdoZip,
@@ -102,6 +104,7 @@ public class CppConfigurationLoader implements ConfigurationFragmentFactory {
Label stlLabel,
Label sysrootLabel) {
this.toolchain = toolchain;
+ this.crosstoolFile = crosstoolFile;
this.cacheKeySuffix = cacheKeySuffix;
this.commonOptions = buildOptions.get(BuildConfiguration.Options.class);
this.cppOptions = buildOptions.get(CppOptions.class);
@@ -224,6 +227,7 @@ public class CppConfigurationLoader implements ConfigurationFragmentFactory {
return new CppConfigurationParameters(
toolchain,
+ file,
file.getMd5(),
options,
fdoZip,
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 7c48a9ff3a..aff9c39e18 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
@@ -27,9 +27,11 @@ import com.google.devtools.build.lib.actions.MiddlemanFactory;
import com.google.devtools.build.lib.analysis.AnalysisUtils;
import com.google.devtools.build.lib.analysis.FileProvider;
import com.google.devtools.build.lib.analysis.MakeVariableSupplier;
+import com.google.devtools.build.lib.analysis.PlatformConfiguration;
import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.StaticallyLinkedMarkerProvider;
+import com.google.devtools.build.lib.analysis.ToolchainContext.ResolvedToolchainProviders;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
@@ -328,6 +330,35 @@ public class CppHelper {
*/
public static CcToolchainProvider getToolchain(RuleContext ruleContext,
TransitiveInfoCollection dep) {
+ 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)) {
+ toolchainType =
+ ruleContext.attributes().get(CcToolchain.CC_TOOLCHAIN_TYPE_ATTRIBUTE_NAME, LABEL);
+ } else {
+ toolchainType = null;
+ }
+
+ if (toolchainType != null
+ && ruleContext
+ .getFragment(PlatformConfiguration.class)
+ .getEnabledToolchainTypes()
+ .contains(toolchainType)) {
+ return getToolchainFromPlatformConstraints(ruleContext, toolchainType);
+ }
+ return getToolchainFromCrosstoolTop(ruleContext, dep);
+ }
+
+ private static CcToolchainProvider getToolchainFromPlatformConstraints(
+ RuleContext ruleContext, Label toolchainType) {
+ ResolvedToolchainProviders providers =
+ (ResolvedToolchainProviders)
+ ruleContext.getToolchainContext().getResolvedToolchainProviders();
+ return (CcToolchainProvider) providers.getForToolchainType(toolchainType);
+ }
+
+ private static CcToolchainProvider getToolchainFromCrosstoolTop(
+ RuleContext ruleContext, TransitiveInfoCollection dep) {
// TODO(bazel-team): Consider checking this generally at the attribute level.
if ((dep == null) || (dep.get(ToolchainInfo.PROVIDER) == null)) {
ruleContext.ruleError("The selected C++ toolchain is not a cc_toolchain rule");