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());
}
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();
}
});
}
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");
}
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");
}
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();
}
Aggregations