Add helper to centrally define the CC toolchain type requirement.
Everything that gets a CC toolchain via CppHelper.getToolchain should use this helper.
Part of
@@ -36,6 +36,7 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.analysis.config.ExecutionTransitionFactory;
+import com.google.devtools.build.lib.analysis.config.ToolchainTypeRequirement;
import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector.InstrumentationSpec;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.packages.Attribute.LabelLateBoundDefault;
@@ -76,6 +77,16 @@ public class CppRuleClasses {
return env.getToolsLabel(CppHelper.TOOLCHAIN_TYPE_LABEL);
}
+ public static ToolchainTypeRequirement ccToolchainTypeRequirement(Label ccToolchainType) {
+ // TODO(https://github.com/bazelbuild/bazel/issues/14727): Evaluate whether this can be
+ // optional.
+ return ToolchainTypeRequirement.builder(ccToolchainType).mandatory(true).build();
+ }
+
+ public static ToolchainTypeRequirement ccToolchainTypeRequirement(RuleDefinitionEnvironment env) {
+ return ccToolchainTypeRequirement(CppRuleClasses.ccToolchainTypeAttribute(env));
+ }
+
// Artifacts of these types are discarded from the 'hdrs' attribute in cc rules
static final FileTypeSet DISALLOWED_HDRS_FILES =
FileTypeSet.of(
