Search in sources :

Example 16 with FeatureConfiguration

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

the class CppLinkActionTest method testInterfaceOutputForDynamicLibrary.

@Test
public void testInterfaceOutputForDynamicLibrary() throws Exception {
    FeatureConfiguration featureConfiguration = CcToolchainFeaturesTest.buildFeatures("feature {", "   name: 'build_interface_libraries'", "   flag_set {", "       action: '" + LinkTargetType.DYNAMIC_LIBRARY.getActionName() + "',", "       flag_group {", "           flag: '%{generate_interface_library}'", "           flag: '%{interface_library_builder_path}'", "           flag: '%{interface_library_input_path}'", "           flag: '%{interface_library_output_path}'", "       }", "   }", "}", "feature {", "   name: 'dynamic_library_linker_tool'", "   flag_set {", "       action: 'c++-link-dynamic-library'", "       flag_group {", "           flag: 'dynamic_library_linker_tool'", "       }", "   }", "}", "feature {", "    name: 'has_configured_linker_path'", "}", "action_config {", "   config_name: '" + LinkTargetType.DYNAMIC_LIBRARY.getActionName() + "'", "   action_name: '" + LinkTargetType.DYNAMIC_LIBRARY.getActionName() + "'", "   tool {", "       tool_path: 'custom/crosstool/scripts/link_dynamic_library.sh'", "   }", "   implies: 'has_configured_linker_path'", "   implies: 'build_interface_libraries'", "   implies: 'dynamic_library_linker_tool'", "}").getFeatureConfiguration("build_interface_libraries", "dynamic_library_linker_tool", LinkTargetType.DYNAMIC_LIBRARY.getActionName());
    CppLinkActionBuilder builder = createLinkBuilder(LinkTargetType.DYNAMIC_LIBRARY, "foo.so", ImmutableList.<Artifact>of(), ImmutableList.<LibraryToLink>of(), featureConfiguration).setLibraryIdentifier("foo").setInterfaceOutput(scratchArtifact("FakeInterfaceOutput.ifso"));
    List<String> commandLine = builder.build().getCommandLine();
    assertThat(commandLine).hasSize(6);
    assertThat(commandLine.get(0)).endsWith("custom/crosstool/scripts/link_dynamic_library.sh");
    assertThat(commandLine.get(1)).isEqualTo("yes");
    assertThat(commandLine.get(2)).endsWith("tools/cpp/build_interface_so");
    assertThat(commandLine.get(3)).endsWith("foo.so");
    assertThat(commandLine.get(4)).isEqualTo("FakeInterfaceOutput.ifso");
    assertThat(commandLine.get(5)).isEqualTo("dynamic_library_linker_tool");
}
Also used : FeatureConfiguration(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration) Test(org.junit.Test)

Example 17 with FeatureConfiguration

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

the class CcToolchainFeaturesTest method testErrorForNoMatchingTool.

@Test
public void testErrorForNoMatchingTool() 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: 'feature-a'", "}", "feature {", "  name: 'activates-action-a'", "  implies: 'action-a'", "}");
    PathFragment crosstoolPath = new PathFragment("crosstool/");
    FeatureConfiguration noFeaturesConfiguration = toolchainFeatures.getFeatureConfiguration("activates-action-a");
    try {
        noFeaturesConfiguration.getToolForAction("action-a").getToolPath(crosstoolPath);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage()).contains("Matching tool for action action-a not found for given feature configuration");
    }
}
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 18 with FeatureConfiguration

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

the class CcToolchainFeaturesTest method testActionConfigCanActivateFeature.

@Test
public void testActionConfigCanActivateFeature() 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' }", "  }", "  implies: 'activated-feature'", "}", "feature {", "   name: 'activated-feature'", "}");
    FeatureConfiguration featureConfiguration = toolchainFeatures.getFeatureConfiguration("action-a");
    assertThat(featureConfiguration.isEnabled("activated-feature")).isTrue();
}
Also used : FeatureConfiguration(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration) Test(org.junit.Test)

Example 19 with FeatureConfiguration

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

the class CcToolchainFeaturesTest method testFlagsFromActionConfig.

@Test
public void testFlagsFromActionConfig() throws Exception {
    FeatureConfiguration featureConfiguration = buildFeatures("action_config {", "  config_name: 'c++-compile'", "  action_name: 'c++-compile'", "  flag_set {", "    flag_group {flag: 'foo'}", "  }", "}").getFeatureConfiguration("c++-compile");
    List<String> commandLine = featureConfiguration.getCommandLine("c++-compile", createVariables());
    assertThat(commandLine).contains("foo");
    ;
}
Also used : FeatureConfiguration(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration) Test(org.junit.Test)

Example 20 with FeatureConfiguration

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

the class CcToolchainFeaturesTest method testActivateActionConfigFromFeature.

@Test
public void testActivateActionConfigFromFeature() 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: 'activates-action-a'", "   implies: 'action-a'", "}");
    FeatureConfiguration featureConfiguration = toolchainFeatures.getFeatureConfiguration("activates-action-a");
    assertThat(featureConfiguration.actionIsConfigured("action-a")).isTrue();
}
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