use of com.google.devtools.build.lib.analysis.RuleContext in project bazel by bazelbuild.
the class CppLinkActionTest method testCommandLineSplitting.
@Test
public void testCommandLineSplitting() throws Exception {
RuleContext ruleContext = createDummyRuleContext();
Artifact output = getDerivedArtifact(new PathFragment("output/path.xyz"), getTargetConfiguration().getBinDirectory(RepositoryName.MAIN), ActionsTestUtil.NULL_ARTIFACT_OWNER);
final Artifact outputIfso = getDerivedArtifact(new PathFragment("output/path.ifso"), getTargetConfiguration().getBinDirectory(RepositoryName.MAIN), ActionsTestUtil.NULL_ARTIFACT_OWNER);
CppLinkActionBuilder builder = new CppLinkActionBuilder(ruleContext, output, CppHelper.getToolchain(ruleContext, ":cc_toolchain"), CppHelper.getFdoSupport(ruleContext, ":cc_toolchain"));
builder.setLinkType(LinkTargetType.STATIC_LIBRARY);
assertTrue(builder.canSplitCommandLine());
builder.setLinkType(LinkTargetType.DYNAMIC_LIBRARY);
assertTrue(builder.canSplitCommandLine());
builder.setInterfaceOutput(outputIfso);
assertFalse(builder.canSplitCommandLine());
builder.setInterfaceOutput(null);
builder.setLinkType(LinkTargetType.INTERFACE_DYNAMIC_LIBRARY);
assertFalse(builder.canSplitCommandLine());
}
use of com.google.devtools.build.lib.analysis.RuleContext in project bazel by bazelbuild.
the class FileWriteActionTest method testTransparentCompressionFlagOn.
@Test
public void testTransparentCompressionFlagOn() throws Exception {
Artifact outputArtifact = getBinArtifactWithNoOwner("destination.txt");
String contents = generateLongRandomString();
useConfiguration("--experimental_transparent_compression=true");
ConfiguredTarget target = scratchConfiguredTarget("a", "a", "filegroup(name='a', srcs=[])");
RuleContext context = getRuleContext(target);
FileWriteAction action = FileWriteAction.create(context, outputArtifact, contents, /*makeExecutable=*/
false);
assertThat(action.usesCompression()).isTrue();
}
use of com.google.devtools.build.lib.analysis.RuleContext 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();
}
});
}
Aggregations