use of com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration in project bazel by bazelbuild.
the class CcToolchainFeaturesTest method testUnsupportedAction.
@Test
public void testUnsupportedAction() throws Exception {
FeatureConfiguration configuration = buildFeatures("").getFeatureConfiguration();
assertThat(configuration.getCommandLine("invalid-action", createVariables())).isEmpty();
}
use of com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration in project bazel by bazelbuild.
the class CcCommon method configureFeatures.
/**
* Creates the feature configuration for a given rule.
*
* @param ruleContext the context of the rule we want the feature configuration for.
* @param ruleSpecificRequestedFeatures features that will be requested, and thus be always
* enabled if the toolchain supports them.
* @param ruleSpecificUnsupportedFeatures features that are not supported in the current context.
* @param sourceCategory the source category for this build.
* @return the feature configuration for the given {@code ruleContext}.
*/
public static FeatureConfiguration configureFeatures(RuleContext ruleContext, Set<String> ruleSpecificRequestedFeatures, Set<String> ruleSpecificUnsupportedFeatures, SourceCategory sourceCategory, CcToolchainProvider toolchain) {
ImmutableSet.Builder<String> unsupportedFeaturesBuilder = ImmutableSet.builder();
unsupportedFeaturesBuilder.addAll(ruleSpecificUnsupportedFeatures);
if (!toolchain.supportsHeaderParsing()) {
// TODO(bazel-team): Remove once supports_header_parsing has been removed from the
// cc_toolchain rule.
unsupportedFeaturesBuilder.add(CppRuleClasses.PARSE_HEADERS);
unsupportedFeaturesBuilder.add(CppRuleClasses.PREPROCESS_HEADERS);
}
if (toolchain.getCppCompilationContext().getCppModuleMap() == null) {
unsupportedFeaturesBuilder.add(CppRuleClasses.MODULE_MAPS);
}
Set<String> unsupportedFeatures = unsupportedFeaturesBuilder.build();
ImmutableSet.Builder<String> requestedFeatures = ImmutableSet.builder();
for (String feature : Iterables.concat(ImmutableSet.of(toolchain.getCompilationMode().toString(), getHostOrNonHostFeature(ruleContext)), DEFAULT_FEATURES, toolchain.getFeatures().getDefaultFeatures(), ruleContext.getFeatures())) {
if (!unsupportedFeatures.contains(feature)) {
requestedFeatures.add(feature);
}
}
requestedFeatures.addAll(ruleSpecificRequestedFeatures);
requestedFeatures.addAll(sourceCategory.getActionConfigSet());
FeatureConfiguration configuration = toolchain.getFeatures().getFeatureConfiguration(requestedFeatures.build());
for (String feature : unsupportedFeatures) {
if (configuration.isEnabled(feature)) {
ruleContext.ruleError("The C++ toolchain '" + ruleContext.getPrerequisite(":cc_toolchain", Mode.TARGET).getLabel() + "' unconditionally implies feature '" + feature + "', which is unsupported by this rule. " + "This is most likely a misconfiguration in the C++ toolchain.");
}
}
return configuration;
}
use of com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration in project bazel by bazelbuild.
the class CcToolchainFeaturesTest method getEnabledFeatures.
private Set<String> getEnabledFeatures(CcToolchainFeatures features, String... requestedFeatures) throws Exception {
FeatureConfiguration configuration = features.getFeatureConfiguration(Arrays.asList(requestedFeatures));
ImmutableSet.Builder<String> enabledFeatures = ImmutableSet.builder();
for (String feature : features.getActivatableNames()) {
if (configuration.isEnabled(feature)) {
enabledFeatures.add(feature);
}
}
return enabledFeatures.build();
}
use of com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration in project bazel by bazelbuild.
the class CcToolchainFeaturesTest method testSimpleActionTool.
@Test
public void testSimpleActionTool() throws Exception {
FeatureConfiguration configuration = buildFeatures("action_config {", " config_name: 'action-a'", " action_name: 'action-a'", " tool {", " tool_path: 'toolchain/a'", " }", "}", "feature {", " name: 'activates-action-a'", " implies: 'action-a'", "}").getFeatureConfiguration("activates-action-a");
PathFragment crosstoolPath = new PathFragment("crosstool/");
PathFragment toolPath = configuration.getToolForAction("action-a").getToolPath(crosstoolPath);
assertThat(toolPath.toString()).isEqualTo("crosstool/toolchain/a");
}
use of com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration in project bazel by bazelbuild.
the class CppLinkActionTest method testComputeKeyNonStatic.
/**
* This mainly checks that non-static links don't have identical keys. Many options are only
* allowed on non-static links, and we test several of them here.
*/
@Test
public void testComputeKeyNonStatic() throws Exception {
final RuleContext ruleContext = createDummyRuleContext();
final PathFragment exeOutputPath = new PathFragment("dummyRuleContext/output/path");
final PathFragment dynamicOutputPath = new PathFragment("dummyRuleContext/output/path.so");
final Artifact staticOutputFile = getBinArtifactWithNoOwner(exeOutputPath.getPathString());
final Artifact dynamicOutputFile = getBinArtifactWithNoOwner(dynamicOutputPath.getPathString());
final Artifact oFile = getSourceArtifact("cc/a.o");
final Artifact oFile2 = getSourceArtifact("cc/a2.o");
final FeatureConfiguration featureConfiguration = getMockFeatureConfiguration();
ActionTester.runTest(64, new ActionCombinationFactory() {
@Override
public Action generate(int i) throws InterruptedException {
CppLinkActionBuilder builder = new CppLinkActionBuilder(ruleContext, (i & 2) == 0 ? dynamicOutputFile : staticOutputFile, CppHelper.getToolchain(ruleContext, ":cc_toolchain"), CppHelper.getFdoSupport(ruleContext, ":cc_toolchain")) {
};
builder.addCompilationInputs((i & 1) == 0 ? ImmutableList.of(oFile) : ImmutableList.of(oFile2));
if ((i & 2) == 0) {
builder.setLinkType(LinkTargetType.DYNAMIC_LIBRARY);
builder.setLibraryIdentifier("foo");
} else {
builder.setLinkType(LinkTargetType.EXECUTABLE);
}
builder.setLinkStaticness(LinkStaticness.DYNAMIC);
builder.setNativeDeps((i & 4) == 0);
builder.setUseTestOnlyFlags((i & 8) == 0);
builder.setFake((i & 16) == 0);
builder.setRuntimeSolibDir((i & 32) == 0 ? null : new PathFragment("so1"));
builder.setFeatureConfiguration(featureConfiguration);
return builder.build();
}
});
}
Aggregations