Search in sources :

Example 21 with FeatureConfiguration

use of com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration in project bazel by bazelbuild.

the class CcToolchainFeaturesTest method testActionToolFromFeatureSet.

@Test
public void testActionToolFromFeatureSet() throws Exception {
    CcToolchainFeatures toolchainFeatures = buildFeatures("action_config {", "  config_name: 'action-a'", "  action_name: 'action-a'", "  tool {", "    tool_path: 'toolchain/features-a-and-b'", "    with_feature: {", "      feature: 'feature-a'", "      feature: 'feature-b'", "     }", "  }", "  tool {", "    tool_path: 'toolchain/feature-a'", "    with_feature: { feature: 'feature-a' }", "  }", "  tool {", "    tool_path: 'toolchain/feature-b'", "    with_feature: { feature: 'feature-b' }", "  }", "  tool {", "    tool_path: 'toolchain/default'", "  }", "}", "feature {", "  name: 'feature-a'", "}", "feature {", "  name: 'feature-b'", "}", "feature {", "  name: 'activates-action-a'", "  implies: 'action-a'", "}");
    PathFragment crosstoolPath = new PathFragment("crosstool/");
    FeatureConfiguration featureAConfiguration = toolchainFeatures.getFeatureConfiguration("feature-a", "activates-action-a");
    assertThat(featureAConfiguration.getToolForAction("action-a").getToolPath(crosstoolPath).toString()).isEqualTo("crosstool/toolchain/feature-a");
    FeatureConfiguration featureBConfiguration = toolchainFeatures.getFeatureConfiguration("feature-b", "activates-action-a");
    assertThat(featureBConfiguration.getToolForAction("action-a").getToolPath(crosstoolPath).toString()).isEqualTo("crosstool/toolchain/feature-b");
    FeatureConfiguration featureAAndBConfiguration = toolchainFeatures.getFeatureConfiguration("feature-a", "feature-b", "activates-action-a");
    assertThat(featureAAndBConfiguration.getToolForAction("action-a").getToolPath(crosstoolPath).toString()).isEqualTo("crosstool/toolchain/features-a-and-b");
    FeatureConfiguration noFeaturesConfiguration = toolchainFeatures.getFeatureConfiguration("activates-action-a");
    assertThat(noFeaturesConfiguration.getToolForAction("action-a").getToolPath(crosstoolPath).toString()).isEqualTo("crosstool/toolchain/default");
}
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 22 with FeatureConfiguration

use of com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration in project bazel by bazelbuild.

the class CcToolchainFeaturesTest method testFeatureCanRequireActionConfig.

@Test
public void testFeatureCanRequireActionConfig() throws Exception {
    CcToolchainFeatures toolchainFeatures = buildFeatures("action_config {", "  config_name: 'action-a'", "  action_name: 'action-a'", "  tool {", "    tool_path: 'toolchain/feature-a'", "    with_feature: { feature: 'feature-a' }", "  }", "}", "feature {", "   name: 'requires-action-a'", "   requires: { feature: 'action-a' }", "}");
    FeatureConfiguration featureConfigurationWithoutAction = toolchainFeatures.getFeatureConfiguration("requires-action-a");
    assertThat(featureConfigurationWithoutAction.isEnabled("requires-action-a")).isFalse();
    FeatureConfiguration featureConfigurationWithAction = toolchainFeatures.getFeatureConfiguration("action-a", "requires-action-a");
    assertThat(featureConfigurationWithAction.isEnabled("requires-action-a")).isTrue();
}
Also used : FeatureConfiguration(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration) Test(org.junit.Test)

Example 23 with FeatureConfiguration

use of com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration in project bazel by bazelbuild.

the class CcToolchainFeaturesTest method testEnvVars.

@Test
public void testEnvVars() throws Exception {
    FeatureConfiguration configuration = buildFeatures("feature {", "  name: 'a'", "  env_set {", "     action: 'c++-compile'", "     env_entry { key: 'foo', value: 'bar' }", "     env_entry { key: 'cat', value: 'meow' }", "  }", "  flag_set {", "     action: 'c++-compile'", "     flag_group { flag: '-a-c++-compile' }", "  }", "}", "feature {", "  name: 'b'", "  env_set {", "     action: 'c++-compile'", "     env_entry { key: 'dog', value: 'woof' }", "  }", "}", "feature {", "  name: 'c'", "  env_set {", "     action: 'c++-compile'", "     env_entry { key: 'doNotInclude', value: 'doNotIncludePlease' }", "  }", "}").getFeatureConfiguration("a", "b");
    Map<String, String> env = configuration.getEnvironmentVariables(CppCompileAction.CPP_COMPILE, createVariables());
    assertThat(env).containsExactly("foo", "bar", "cat", "meow", "dog", "woof").inOrder();
    assertThat(env).doesNotContainEntry("doNotInclude", "doNotIncludePlease");
}
Also used : FeatureConfiguration(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration) 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