Search in sources :

Example 6 with FeatureConfiguration

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

the class CppLinkActionTest method assertLinkSizeAccuracy.

private void assertLinkSizeAccuracy(int inputs) throws Exception {
    ImmutableList.Builder<Artifact> objects = ImmutableList.builder();
    for (int i = 0; i < inputs; i++) {
        objects.add(getOutputArtifact("object" + i + ".o"));
    }
    CppLinkAction linkAction = createLinkBuilder(Link.LinkTargetType.EXECUTABLE, "dummyRuleContext/binary2", objects.build(), ImmutableList.<LibraryToLink>of(), new FeatureConfiguration()).setFake(true).build();
    // Ensure that minima are enforced.
    ResourceSet resources = linkAction.estimateResourceConsumptionLocal();
    assertTrue(resources.getMemoryMb() >= CppLinkAction.MIN_STATIC_LINK_RESOURCES.getMemoryMb());
    assertTrue(resources.getCpuUsage() >= CppLinkAction.MIN_STATIC_LINK_RESOURCES.getCpuUsage());
    assertTrue(resources.getIoUsage() >= CppLinkAction.MIN_STATIC_LINK_RESOURCES.getIoUsage());
    final int linkSize = Iterables.size(linkAction.getLinkCommandLine().getLinkerInputs());
    ResourceSet scaledSet = ResourceSet.createWithRamCpuIo(CppLinkAction.LINK_RESOURCES_PER_INPUT.getMemoryMb() * linkSize, CppLinkAction.LINK_RESOURCES_PER_INPUT.getCpuUsage() * linkSize, CppLinkAction.LINK_RESOURCES_PER_INPUT.getIoUsage() * linkSize);
    // Ensure that anything above the minimum is properly scaled.
    assertTrue(resources.getMemoryMb() == CppLinkAction.MIN_STATIC_LINK_RESOURCES.getMemoryMb() || resources.getMemoryMb() == scaledSet.getMemoryMb());
    assertTrue(resources.getCpuUsage() == CppLinkAction.MIN_STATIC_LINK_RESOURCES.getCpuUsage() || resources.getCpuUsage() == scaledSet.getCpuUsage());
    assertTrue(resources.getIoUsage() == CppLinkAction.MIN_STATIC_LINK_RESOURCES.getIoUsage() || resources.getIoUsage() == scaledSet.getIoUsage());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) FeatureConfiguration(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration) ResourceSet(com.google.devtools.build.lib.actions.ResourceSet) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 7 with FeatureConfiguration

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

the class CppLinkActionTest method testComputeKeyStatic.

/**
   * This mainly checks that static library links don't have identical keys, and it also compares
   * them with simple dynamic library links.
   */
@Test
public void testComputeKeyStatic() throws Exception {
    final RuleContext ruleContext = createDummyRuleContext();
    final PathFragment staticOutputPath = new PathFragment("dummyRuleContext/output/path.a");
    final PathFragment dynamicOutputPath = new PathFragment("dummyRuleContext/output/path.so");
    final Artifact staticOutputFile = getBinArtifactWithNoOwner(staticOutputPath.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(4, new ActionCombinationFactory() {

        @Override
        public Action generate(int i) throws InterruptedException {
            CppLinkActionBuilder builder = new CppLinkActionBuilder(ruleContext, (i & 2) == 0 ? staticOutputFile : dynamicOutputFile, CppHelper.getToolchain(ruleContext, ":cc_toolchain"), CppHelper.getFdoSupport(ruleContext, ":cc_toolchain")) {
            };
            builder.addCompilationInputs((i & 1) == 0 ? ImmutableList.of(oFile) : ImmutableList.of(oFile2));
            builder.setLinkType((i & 2) == 0 ? LinkTargetType.STATIC_LIBRARY : LinkTargetType.DYNAMIC_LIBRARY);
            builder.setLibraryIdentifier("foo");
            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)

Example 8 with FeatureConfiguration

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

the class CppLinkActionTest method testToolchainFeatureFlags.

@Test
public void testToolchainFeatureFlags() throws Exception {
    FeatureConfiguration featureConfiguration = CcToolchainFeaturesTest.buildFeatures("feature {", "   name: 'a'", "   flag_set {", "      action: '" + Link.LinkTargetType.EXECUTABLE.getActionName() + "'", "      flag_group { flag: 'some_flag' }", "   }", "}", "action_config {", "   config_name: '" + Link.LinkTargetType.EXECUTABLE.getActionName() + "'", "   action_name: '" + Link.LinkTargetType.EXECUTABLE.getActionName() + "'", "   tool {", "      tool_path: 'toolchain/mock_tool'", "   }", "}").getFeatureConfiguration("a", Link.LinkTargetType.EXECUTABLE.getActionName());
    CppLinkAction linkAction = createLinkBuilder(Link.LinkTargetType.EXECUTABLE, "dummyRuleContext/out", ImmutableList.<Artifact>of(), ImmutableList.<LibraryToLink>of(), featureConfiguration).build();
    assertThat(linkAction.getArgv()).contains("some_flag");
}
Also used : LibraryToLink(com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink) FeatureConfiguration(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 9 with FeatureConfiguration

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

the class CppLinkActionTest method testToolchainFeatureEnv.

@Test
public void testToolchainFeatureEnv() throws Exception {
    FeatureConfiguration featureConfiguration = CcToolchainFeaturesTest.buildFeatures("feature {", "   name: 'a'", "   env_set {", "      action: '" + Link.LinkTargetType.EXECUTABLE.getActionName() + "'", "      env_entry { key: 'foo', value: 'bar' }", "   }", "}").getFeatureConfiguration("a");
    CppLinkAction linkAction = createLinkBuilder(Link.LinkTargetType.EXECUTABLE, "dummyRuleContext/out", ImmutableList.<Artifact>of(), ImmutableList.<LibraryToLink>of(), featureConfiguration).build();
    assertThat(linkAction.getEnvironment()).containsEntry("foo", "bar");
}
Also used : LibraryToLink(com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink) FeatureConfiguration(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 10 with FeatureConfiguration

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

the class CcToolchainFeaturesTest method testFlagOrderEqualsSpecOrder.

@Test
public void testFlagOrderEqualsSpecOrder() throws Exception {
    FeatureConfiguration configuration = buildFeatures("feature {", "  name: 'a'", "  flag_set {", "     action: 'c++-compile'", "     flag_group { flag: '-a-c++-compile' }", "  }", "  flag_set {", "     action: 'link'", "     flag_group { flag: '-a-c++-compile' }", "  }", "}", "feature {", "  name: 'b'", "  flag_set {", "     action: 'c++-compile'", "     flag_group { flag: '-b-c++-compile' }", "  }", "  flag_set {", "     action: 'link'", "     flag_group { flag: '-b-link' }", "  }", "}").getFeatureConfiguration("a", "b");
    List<String> commandLine = configuration.getCommandLine(CppCompileAction.CPP_COMPILE, createVariables());
    assertThat(commandLine).containsExactly("-a-c++-compile", "-b-c++-compile").inOrder();
}
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