Search in sources :

Example 11 with FeatureConfiguration

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();
}
Also used : FeatureConfiguration(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration) Test(org.junit.Test)

Example 12 with FeatureConfiguration

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;
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) FeatureConfiguration(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration)

Example 13 with FeatureConfiguration

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();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) FeatureConfiguration(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration)

Example 14 with FeatureConfiguration

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");
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment) FeatureConfiguration(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration) Test(org.junit.Test)

Example 15 with FeatureConfiguration

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();
        }
    });
}
Also used : ActionCombinationFactory(com.google.devtools.build.lib.analysis.util.ActionTester.ActionCombinationFactory) Action(com.google.devtools.build.lib.actions.Action) RuleContext(com.google.devtools.build.lib.analysis.RuleContext) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) FeatureConfiguration(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Aggregations

FeatureConfiguration (com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration)23 Test (org.junit.Test)17 Artifact (com.google.devtools.build.lib.actions.Artifact)8 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)8 LibraryToLink (com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink)4 RuleContext (com.google.devtools.build.lib.analysis.RuleContext)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Action (com.google.devtools.build.lib.actions.Action)2 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)2 Runfiles (com.google.devtools.build.lib.analysis.Runfiles)2 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)2 ActionCombinationFactory (com.google.devtools.build.lib.analysis.util.ActionTester.ActionCombinationFactory)2 InstrumentedFilesProvider (com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider)2 Function (com.google.common.base.Function)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 FailAction (com.google.devtools.build.lib.actions.FailAction)1 ResourceSet (com.google.devtools.build.lib.actions.ResourceSet)1 Root (com.google.devtools.build.lib.actions.Root)1 RunfilesSupport (com.google.devtools.build.lib.analysis.RunfilesSupport)1