From 699598d53b38a657a0dd0d220beecad26b00fbe5 Mon Sep 17 00:00:00 2001 From: jcater Date: Thu, 4 Feb 2021 08:45:56 -0800 Subject: [PATCH] CcToolchainAttributesProvider is never actually used as a ToolchainInfo provider. Tested with Bazel downstream: https://buildkite.com/bazel/bazel-at-head-plus-downstream/builds/1894 (only failures also happen in the nightly). PiperOrigin-RevId: 355635392 --- .../build/lib/rules/cpp/CcToolchain.java | 7 +++++-- .../rules/cpp/CcToolchainAttributesProvider.java | 16 ++++++++++------ .../build/lib/rules/cpp/CcToolchainSuite.java | 9 ++++++++- 3 files changed, 23 insertions(+), 9 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 110fb5b1d86a99..ded613f3a3f346 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 @@ -25,6 +25,7 @@ import com.google.devtools.build.lib.analysis.RunfilesProvider; import com.google.devtools.build.lib.analysis.TemplateVariableInfo; import com.google.devtools.build.lib.analysis.config.BuildOptions; +import com.google.devtools.build.lib.analysis.platform.ToolchainInfo; import com.google.devtools.build.lib.cmdline.Label; import java.io.Serializable; import java.util.HashMap; @@ -81,8 +82,10 @@ public ConfiguredTarget create(RuleContext ruleContext) if (!CppHelper.useToolchainResolution(ruleContext)) { // This is not a platforms-backed build, let's provide CcToolchainAttributesProvider // and have cc_toolchain_suite select one of its toolchains and create CcToolchainProvider - // from its attributes. - return ruleConfiguredTargetBuilder.build(); + // from its attributes. We also need to provide a do-nothing ToolchainInfo. + return ruleConfiguredTargetBuilder + .addNativeDeclaredProvider(new ToolchainInfo(ImmutableMap.of("cc", "dummy cc toolchain"))) + .build(); } // This is a platforms-backed build, we will not analyze cc_toolchain_suite at all, and we are diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainAttributesProvider.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainAttributesProvider.java index b09a7bfae7e992..6755048265cbf9 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainAttributesProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainAttributesProvider.java @@ -18,7 +18,6 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.actions.Actions; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.Allowlist; @@ -30,24 +29,24 @@ import com.google.devtools.build.lib.analysis.PackageSpecificationProvider; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; -import com.google.devtools.build.lib.analysis.platform.ToolchainInfo; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.BuiltinProvider; +import com.google.devtools.build.lib.packages.Info; import com.google.devtools.build.lib.packages.License; +import com.google.devtools.build.lib.packages.NativeInfo; import com.google.devtools.build.lib.packages.Type; import com.google.devtools.build.lib.rules.cpp.CcToolchain.AdditionalBuildVariablesComputer; -import net.starlark.java.syntax.Location; /** * Provider encapsulating all the information from the cc_toolchain rule that affects creation of * {@link CcToolchainProvider} */ // TODO(adonovan): rename s/Provider/Info/. -public class CcToolchainAttributesProvider extends ToolchainInfo implements HasCcToolchainLabel { +public class CcToolchainAttributesProvider extends NativeInfo implements HasCcToolchainLabel { public static final BuiltinProvider PROVIDER = new BuiltinProvider( @@ -106,7 +105,7 @@ public CcToolchainAttributesProvider( RuleContext ruleContext, boolean isAppleToolchain, AdditionalBuildVariablesComputer additionalBuildVariablesComputer) { - super(ImmutableMap.of(), Location.BUILTIN); + super(); this.ccToolchainLabel = ruleContext.getLabel(); this.toolchainIdentifier = ruleContext.attributes().get("toolchain_identifier", Type.STRING); if (ruleContext.getFragment(CppConfiguration.class).removeCpuCompilerCcToolchainAttributes() @@ -221,6 +220,11 @@ public CcToolchainAttributesProvider( ruleContext, CcToolchain.LOOSE_HEADER_CHECK_ALLOWLIST); } + @Override + public BuiltinProvider getProvider() { + return PROVIDER; + } + public String getCpu() { return cpu; } @@ -468,6 +472,6 @@ private static NestedSet fullInputsForLink( * CcToolchainProvider}. */ // TODO(b/113849758): Remove once behavior is migrated. -interface HasCcToolchainLabel { +interface HasCcToolchainLabel extends Info { Label getCcToolchainLabel(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuite.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuite.java index 4053977b40e848..e65ed56e020e89 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuite.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuite.java @@ -28,6 +28,7 @@ import com.google.devtools.build.lib.analysis.platform.ToolchainInfo; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.packages.BuildType; +import com.google.devtools.build.lib.packages.BuiltinProvider; import java.util.Map; /** @@ -60,6 +61,9 @@ public ConfiguredTarget create(RuleContext ruleContext) ccToolchainProvider = selectCcToolchain( CcToolchainProvider.class, + // TOOD(b/17906781): Change this to CcToolchainProvider when CcToolchainProvider isn't + // a subclass of ToolchainInfo. + ToolchainInfo.PROVIDER, ruleContext, transformedCpu, compiler, @@ -70,6 +74,7 @@ public ConfiguredTarget create(RuleContext ruleContext) CcToolchainAttributesProvider selectedAttributes = selectCcToolchain( CcToolchainAttributesProvider.class, + CcToolchainAttributesProvider.PROVIDER, ruleContext, transformedCpu, compiler, @@ -107,6 +112,8 @@ public ConfiguredTarget create(RuleContext ruleContext) private T selectCcToolchain( Class clazz, + // TOOD(b/17906781): Change the type to T when CcToolchainprovider has its own provider type. + BuiltinProvider providerType, RuleContext ruleContext, String cpu, String compiler, @@ -114,7 +121,7 @@ private T selectCcToolchain( throws RuleErrorException { T selectedAttributes = null; for (TransitiveInfoCollection dep : ruleContext.getPrerequisiteMap("toolchains").values()) { - T attributes = clazz.cast(dep.get(ToolchainInfo.PROVIDER)); + T attributes = clazz.cast(dep.get(providerType)); if (attributes != null && attributes.getCcToolchainLabel().equals(selectedCcToolchain)) { selectedAttributes = attributes; break;