Skip to content

Commit

Permalink
Add helper to centrally define the CC toolchain type requirement.
Browse files Browse the repository at this point in the history
Everything that gets a CC toolchain via CppHelper.getToolchain should use this helper.

Part of #14727.

PiperOrigin-RevId: 449233884
  • Loading branch information
katre authored and Copybara-Service committed May 17, 2022
1 parent 11dda14 commit c1009c2
Showing 1 changed file with 11 additions and 0 deletions.
Expand Up @@ -36,6 +36,7 @@
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;
Expand Down Expand Up @@ -76,6 +77,16 @@ public static Label ccToolchainTypeAttribute(RuleDefinitionEnvironment env) {
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(
Expand Down

0 comments on commit c1009c2

Please sign in to comment.