use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer in project buck by facebook.
the class CxxTestDescriptionTest method testArgsArePropagated.
@Test
public void testArgsArePropagated() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
addFramework(resolver, filesystem);
BuildRule someRule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:some_rule")).setOut("someRule").build(resolver);
CxxTestBuilder builder = createTestBuilder().setArgs(ImmutableList.of("value $(location //:some_rule)"));
addSandbox(resolver, filesystem, builder.getTarget());
CxxTest cxxTest = builder.build(resolver);
TestRunningOptions testOptions = TestRunningOptions.builder().setShufflingTests(false).setTestSelectorList(TestSelectorList.empty()).build();
ImmutableList<Step> steps = cxxTest.runTests(TestExecutionContext.newInstance(), testOptions, pathResolver, TestRule.NOOP_REPORTING_CALLBACK);
CxxTestStep testStep = (CxxTestStep) Iterables.getLast(steps);
assertThat(testStep.getCommand(), Matchers.hasItem("value " + pathResolver.getAbsolutePath(Preconditions.checkNotNull(someRule.getSourcePathToOutput()))));
}
use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer in project buck by facebook.
the class CxxTestDescriptionTest method locationMacro.
@Test
public void locationMacro() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
Genrule dep = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out").build(resolver);
CxxTestBuilder builder = createTestBuilder().setLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("--linker-script=%s", LocationMacro.of(dep.getBuildTarget()))));
addFramework(resolver, filesystem);
addSandbox(resolver, filesystem, builder.getTarget());
assertThat(builder.build().getExtraDeps(), Matchers.hasItem(dep.getBuildTarget()));
CxxTest test = builder.build(resolver);
CxxLink binary = (CxxLink) resolver.getRule(CxxDescriptionEnhancer.createCxxLinkTarget(test.getBuildTarget(), Optional.empty()));
assertThat(Arg.stringify(binary.getArgs(), pathResolver), Matchers.hasItem(String.format("--linker-script=%s", dep.getAbsoluteOutputFilePath(pathResolver))));
assertThat(binary.getDeps(), Matchers.hasItem(dep));
}
use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer in project buck by facebook.
the class CxxCompileStepIntegrationTest method assertCompDir.
private void assertCompDir(Path compDir, Optional<String> failure) throws Exception {
ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot());
CxxPlatform platform = CxxPlatformUtils.build(new CxxBuckConfig(FakeBuckConfig.builder().build()));
// Build up the paths to various files the archive step will use.
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
Compiler compiler = platform.getCc().resolve(resolver);
ImmutableList<String> compilerCommandPrefix = compiler.getCommandPrefix(pathResolver);
Path output = filesystem.resolve(Paths.get("output.o"));
Path depFile = filesystem.resolve(Paths.get("output.dep"));
Path relativeInput = Paths.get("input.c");
Path input = filesystem.resolve(relativeInput);
filesystem.writeContentsToPath("int main() {}", relativeInput);
Path scratchDir = filesystem.getPath("scratchDir");
filesystem.mkdirs(scratchDir);
ImmutableList.Builder<String> preprocessorArguments = ImmutableList.builder();
ImmutableList.Builder<String> compilerArguments = ImmutableList.builder();
compilerArguments.add("-g");
DebugPathSanitizer sanitizer = new MungingDebugPathSanitizer(200, File.separatorChar, compDir, ImmutableBiMap.of());
// Build an archive step.
CxxPreprocessAndCompileStep step = new CxxPreprocessAndCompileStep(filesystem, CxxPreprocessAndCompileStep.Operation.PREPROCESS_AND_COMPILE, output, depFile, relativeInput, CxxSource.Type.C, Optional.of(new CxxPreprocessAndCompileStep.ToolCommand(compilerCommandPrefix, preprocessorArguments.build(), ImmutableMap.of(), Optional.empty())), Optional.of(new CxxPreprocessAndCompileStep.ToolCommand(compilerCommandPrefix, compilerArguments.build(), ImmutableMap.of(), Optional.empty())), HeaderPathNormalizer.empty(pathResolver), sanitizer, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, scratchDir, true, compiler);
// Execute the archive step and verify it ran successfully.
ExecutionContext executionContext = TestExecutionContext.newInstance();
TestConsole console = (TestConsole) executionContext.getConsole();
int exitCode = step.execute(executionContext).getExitCode();
if (failure.isPresent()) {
assertNotEquals("compile step succeeded", 0, exitCode);
assertThat(console.getTextWrittenToStdErr(), console.getTextWrittenToStdErr(), Matchers.containsString(failure.get()));
} else {
assertEquals("compile step failed: " + console.getTextWrittenToStdErr(), 0, exitCode);
// Verify that we find the expected compilation dir embedded in the file.
String contents = new String(Files.readAllBytes(output));
assertThat(contents, Matchers.containsString(sanitizer.getCompilationDirectory()));
}
// Cleanup.
Files.delete(input);
Files.deleteIfExists(output);
}
use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer in project buck by facebook.
the class CxxDescriptionEnhancerTest method nonTestLibraryDepDoesNotIncludePrivateHeadersOfLibrary.
@Test
public void nonTestLibraryDepDoesNotIncludePrivateHeadersOfLibrary() throws Exception {
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
BuildTarget libTarget = BuildTargetFactory.newInstance("//:lib");
BuildRuleParams libParams = new FakeBuildRuleParamsBuilder(libTarget).build();
FakeCxxLibrary libRule = new FakeCxxLibrary(libParams, BuildTargetFactory.newInstance("//:header"), BuildTargetFactory.newInstance("//:symlink"), BuildTargetFactory.newInstance("//:privateheader"), BuildTargetFactory.newInstance("//:privatesymlink"), new FakeBuildRule("//:archive", pathResolver), new FakeBuildRule("//:shared", pathResolver), Paths.get("output/path/lib.so"), "lib.so", // This library has no tests.
ImmutableSortedSet.of());
BuildTarget otherLibDepTarget = BuildTargetFactory.newInstance("//:other");
BuildRuleParams otherLibDepParams = new FakeBuildRuleParamsBuilder(otherLibDepTarget).setDeclaredDeps(ImmutableSortedSet.of(libRule)).build();
ImmutableList<CxxPreprocessorInput> otherInput = CxxDescriptionEnhancer.collectCxxPreprocessorInput(otherLibDepParams, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableMultimap.of(), ImmutableList.of(), ImmutableSet.of(), CxxPreprocessables.getTransitiveCxxPreprocessorInput(CxxPlatformUtils.DEFAULT_PLATFORM, FluentIterable.from(otherLibDepParams.getDeps()).filter(CxxPreprocessorDep.class::isInstance)), ImmutableList.of(), Optional.empty());
Set<SourcePath> roots = new HashSet<>();
for (CxxHeaders headers : CxxPreprocessorInput.concat(otherInput).getIncludes()) {
roots.add(headers.getRoot());
}
assertThat("Non-test rule with library dep should include public and not private headers", roots, allOf(hasItem(new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//:symlink"))), not(hasItem(new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//:privatesymlink"))))));
}
use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer in project buck by facebook.
the class CxxDescriptionEnhancerTest method libraryTestIncludesPublicHeadersOfDependenciesOfLibraryUnderTest.
@Test
public void libraryTestIncludesPublicHeadersOfDependenciesOfLibraryUnderTest() throws Exception {
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
BuildTarget libTarget = BuildTargetFactory.newInstance("//:lib");
BuildTarget otherlibTarget = BuildTargetFactory.newInstance("//:otherlib");
BuildTarget testTarget = BuildTargetFactory.newInstance("//:test");
BuildRuleParams otherlibParams = new FakeBuildRuleParamsBuilder(otherlibTarget).build();
FakeCxxLibrary otherlibRule = new FakeCxxLibrary(otherlibParams, BuildTargetFactory.newInstance("//:otherheader"), BuildTargetFactory.newInstance("//:othersymlink"), BuildTargetFactory.newInstance("//:otherprivateheader"), BuildTargetFactory.newInstance("//:otherprivatesymlink"), new FakeBuildRule("//:archive", pathResolver), new FakeBuildRule("//:shared", pathResolver), Paths.get("output/path/lib.so"), "lib.so", // This library has no tests.
ImmutableSortedSet.of());
BuildRuleParams libParams = new FakeBuildRuleParamsBuilder(libTarget).setDeclaredDeps(ImmutableSortedSet.of(otherlibRule)).build();
FakeCxxLibrary libRule = new FakeCxxLibrary(libParams, BuildTargetFactory.newInstance("//:header"), BuildTargetFactory.newInstance("//:symlink"), BuildTargetFactory.newInstance("//:privateheader"), BuildTargetFactory.newInstance("//:privatesymlink"), new FakeBuildRule("//:archive", pathResolver), new FakeBuildRule("//:shared", pathResolver), Paths.get("output/path/lib.so"), "lib.so", // Ensure the test is listed as a dep of the lib.
ImmutableSortedSet.of(testTarget));
BuildRuleParams testParams = new FakeBuildRuleParamsBuilder(testTarget).setDeclaredDeps(ImmutableSortedSet.of(libRule)).build();
ImmutableList<CxxPreprocessorInput> combinedInput = CxxDescriptionEnhancer.collectCxxPreprocessorInput(testParams, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableMultimap.of(), ImmutableList.of(), ImmutableSet.of(), CxxPreprocessables.getTransitiveCxxPreprocessorInput(CxxPlatformUtils.DEFAULT_PLATFORM, FluentIterable.from(testParams.getDeps()).filter(CxxPreprocessorDep.class::isInstance)), ImmutableList.of(), Optional.empty());
Set<SourcePath> roots = new HashSet<>();
for (CxxHeaders headers : CxxPreprocessorInput.concat(combinedInput).getIncludes()) {
roots.add(headers.getRoot());
}
assertThat("Test of library should include public dependency headers", Iterables.transform(CxxPreprocessorInput.concat(combinedInput).getIncludes(), CxxHeaders::getRoot), allOf(hasItem(new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//:othersymlink"))), not(hasItem(new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//:otherprivatesymlink"))))));
}
Aggregations