use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.
the class TargetsCommandTest method testDetectTestChanges.
@Test
public void testDetectTestChanges() throws CmdLineException, IOException {
BuildTarget libraryTarget = BuildTargetFactory.newInstance("//foo:lib");
BuildTarget libraryTestTarget1 = BuildTargetFactory.newInstance("//foo:xctest1");
BuildTarget libraryTestTarget2 = BuildTargetFactory.newInstance("//foo:xctest2");
BuildTarget testLibraryTarget = BuildTargetFactory.newInstance("//testlib:testlib");
BuildTarget testLibraryTestTarget = BuildTargetFactory.newInstance("//testlib:testlib-xctest");
TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo/foo.m")))).setTests(ImmutableSortedSet.of(libraryTestTarget1, libraryTestTarget2)).build();
TargetNode<?, ?> libraryTestNode1 = AppleTestBuilder.createBuilder(libraryTestTarget1).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo/testfoo1.m")))).setDeps(ImmutableSortedSet.of(libraryTarget)).build();
TargetNode<?, ?> libraryTestNode2 = AppleTestBuilder.createBuilder(libraryTestTarget2).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo/testfoo2.m")))).setDeps(ImmutableSortedSet.of(testLibraryTarget)).build();
TargetNode<?, ?> testLibraryNode = AppleLibraryBuilder.createBuilder(testLibraryTarget).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("testlib/testlib.m")))).setTests(ImmutableSortedSet.of(testLibraryTestTarget)).build();
TargetNode<?, ?> testLibraryTestNode = AppleTestBuilder.createBuilder(testLibraryTestTarget).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("testlib/testlib-test.m")))).setDeps(ImmutableSortedSet.of(testLibraryTarget)).build();
ImmutableSet<TargetNode<?, ?>> nodes = ImmutableSet.of(libraryNode, libraryTestNode1, libraryTestNode2, testLibraryNode, testLibraryTestNode);
TargetGraph targetGraph = TargetGraphFactory.newInstance(nodes);
// No target depends on the referenced file.
SortedMap<String, TargetNode<?, ?>> matchingBuildRules = targetsCommand.getMatchingNodes(targetGraph, Optional.of(ImmutableSet.of(Paths.get("foo/bar.m"))), Optional.empty(), Optional.empty(), true, "BUCK");
assertTrue(matchingBuildRules.isEmpty());
// Test1, test2 and the library depend on the referenced file.
matchingBuildRules = targetsCommand.getMatchingNodes(targetGraph, Optional.of(ImmutableSet.of(Paths.get("foo/testfoo1.m"))), Optional.empty(), Optional.empty(), true, "BUCK");
assertEquals(ImmutableSet.of("//foo:lib", "//foo:xctest1"), matchingBuildRules.keySet());
// Test1, test2 and the library depend on the referenced file.
matchingBuildRules = targetsCommand.getMatchingNodes(targetGraph, Optional.of(ImmutableSet.of(Paths.get("foo/testfoo2.m"))), Optional.empty(), Optional.empty(), true, "BUCK");
assertEquals(ImmutableSet.of("//foo:lib", "//foo:xctest1", "//foo:xctest2"), matchingBuildRules.keySet());
// Library, test1, test2, test library and its test depend on the referenced file.
matchingBuildRules = targetsCommand.getMatchingNodes(targetGraph, Optional.of(ImmutableSet.of(Paths.get("testlib/testlib.m"))), Optional.empty(), Optional.empty(), true, "BUCK");
assertEquals(ImmutableSet.of("//foo:lib", "//foo:xctest1", "//foo:xctest2", "//testlib:testlib", "//testlib:testlib-xctest"), matchingBuildRules.keySet());
// Library, test1, test2, test library and its test depend on the referenced file.
matchingBuildRules = targetsCommand.getMatchingNodes(targetGraph, Optional.of(ImmutableSet.of(Paths.get("testlib/testlib-test.m"))), Optional.empty(), Optional.empty(), true, "BUCK");
assertEquals(ImmutableSet.of("//foo:lib", "//foo:xctest1", "//foo:xctest2", "//testlib:testlib", "//testlib:testlib-xctest"), matchingBuildRules.keySet());
}
use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.
the class CxxCollectAndLogInferDependenciesStepTest method createCaptureRule.
private CxxInferCapture createCaptureRule(BuildRuleParams buildRuleParams, SourcePathResolver sourcePathResolver, ProjectFilesystem filesystem, InferBuckConfig inferBuckConfig) throws Exception {
RuleKeyAppendableFunction<FrameworkPath, Path> defaultFrameworkPathSearchPathFunction = new RuleKeyAppendableFunction<FrameworkPath, Path>() {
@Override
public void appendToRuleKey(RuleKeyObjectSink sink) {
// Do nothing.
}
@Override
public Path apply(FrameworkPath input) {
return Paths.get("test", "framework", "path", input.toString());
}
};
SourcePath preprocessor = new PathSourcePath(filesystem, Paths.get("preprocessor"));
Tool preprocessorTool = new CommandTool.Builder().addInput(preprocessor).build();
PreprocessorDelegate preprocessorDelegate = new PreprocessorDelegate(sourcePathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_PLATFORM.getHeaderVerification(), Paths.get("whatever"), new GccPreprocessor(preprocessorTool), PreprocessorFlags.builder().build(), defaultFrameworkPathSearchPathFunction, Optional.empty(), /* leadingIncludePaths */
Optional.empty());
return new CxxInferCapture(buildRuleParams, CxxToolFlags.of(), CxxToolFlags.of(), new FakeSourcePath("src.c"), AbstractCxxSource.Type.C, Paths.get("src.o"), preprocessorDelegate, inferBuckConfig, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER);
}
use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.
the class CxxCompilationDatabaseTest method testCompilationDatabase.
@Test
public void testCompilationDatabase() throws Exception {
BuildTarget testBuildTarget = BuildTarget.builder(BuildTargetFactory.newInstance("//foo:baz")).addAllFlavors(ImmutableSet.of(CxxCompilationDatabase.COMPILATION_DATABASE)).build();
final String root = "/Users/user/src";
final Path fakeRoot = Paths.get(root);
ProjectFilesystem filesystem = new FakeProjectFilesystem(fakeRoot);
BuildRuleParams testBuildRuleParams = new FakeBuildRuleParamsBuilder(testBuildTarget).setProjectFilesystem(filesystem).build();
BuildRuleResolver testBuildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver testSourcePathResolver = new SourcePathResolver(new SourcePathRuleFinder(testBuildRuleResolver));
HeaderSymlinkTree privateSymlinkTree = CxxDescriptionEnhancer.createHeaderSymlinkTree(testBuildRuleParams, testBuildRuleResolver, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableMap.of(), HeaderVisibility.PRIVATE, true);
testBuildRuleResolver.addToIndex(privateSymlinkTree);
HeaderSymlinkTree exportedSymlinkTree = CxxDescriptionEnhancer.createHeaderSymlinkTree(testBuildRuleParams, testBuildRuleResolver, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableMap.of(), HeaderVisibility.PUBLIC, true);
testBuildRuleResolver.addToIndex(exportedSymlinkTree);
BuildTarget compileTarget = BuildTarget.builder(testBuildRuleParams.getBuildTarget().getUnflavoredBuildTarget()).addFlavors(InternalFlavor.of("compile-test.cpp")).build();
PreprocessorFlags preprocessorFlags = PreprocessorFlags.builder().addIncludes(CxxHeadersDir.of(CxxPreprocessables.IncludeType.SYSTEM, new FakeSourcePath("/foo/bar")), CxxHeadersDir.of(CxxPreprocessables.IncludeType.SYSTEM, new FakeSourcePath("/test"))).build();
ImmutableSortedSet.Builder<CxxPreprocessAndCompile> rules = ImmutableSortedSet.naturalOrder();
BuildRuleParams compileBuildRuleParams = new FakeBuildRuleParamsBuilder(compileTarget).setProjectFilesystem(filesystem).setDeclaredDeps(ImmutableSortedSet.of(privateSymlinkTree, exportedSymlinkTree)).build();
rules.add(testBuildRuleResolver.addToIndex(CxxPreprocessAndCompile.preprocessAndCompile(compileBuildRuleParams, new PreprocessorDelegate(testSourcePathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_PLATFORM.getHeaderVerification(), filesystem.getRootPath(), new GccPreprocessor(new HashedFileTool(Paths.get("preprocessor"))), preprocessorFlags, new RuleKeyAppendableFunction<FrameworkPath, Path>() {
@Override
public void appendToRuleKey(RuleKeyObjectSink sink) {
// Do nothing.
}
@Override
public Path apply(FrameworkPath input) {
throw new UnsupportedOperationException("should not be called");
}
}, Optional.empty(), /* leadingIncludePaths */
Optional.empty()), new CompilerDelegate(testSourcePathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, new GccCompiler(new HashedFileTool(Paths.get("compiler"))), CxxToolFlags.of()), Paths.get("test.o"), new FakeSourcePath(filesystem, "test.cpp"), CxxSource.Type.CXX, Optional.empty(), CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, Optional.empty())));
CxxCompilationDatabase compilationDatabase = CxxCompilationDatabase.createCompilationDatabase(testBuildRuleParams, rules.build());
testBuildRuleResolver.addToIndex(compilationDatabase);
assertThat(compilationDatabase.getRuntimeDeps().collect(MoreCollectors.toImmutableSet()), Matchers.contains(exportedSymlinkTree.getBuildTarget(), privateSymlinkTree.getBuildTarget()));
assertEquals("getPathToOutput() should be a function of the build target.", BuildTargets.getGenPath(filesystem, testBuildTarget, "__%s.json"), testSourcePathResolver.getRelativePath(compilationDatabase.getSourcePathToOutput()));
List<Step> buildSteps = compilationDatabase.getBuildSteps(FakeBuildContext.withSourcePathResolver(testSourcePathResolver), new FakeBuildableContext());
assertEquals(2, buildSteps.size());
assertTrue(buildSteps.get(0) instanceof MkdirStep);
assertTrue(buildSteps.get(1) instanceof CxxCompilationDatabase.GenerateCompilationCommandsJson);
CxxCompilationDatabase.GenerateCompilationCommandsJson step = (CxxCompilationDatabase.GenerateCompilationCommandsJson) buildSteps.get(1);
Iterable<CxxCompilationDatabaseEntry> observedEntries = step.createEntries();
Iterable<CxxCompilationDatabaseEntry> expectedEntries = ImmutableList.of(CxxCompilationDatabaseEntry.of(root, root + "/test.cpp", ImmutableList.of("compiler", "-isystem", "/foo/bar", "-isystem", "/test", "-x", "c++", "-c", "-MD", "-MF", "test.o.dep", "test.cpp", "-o", "test.o")));
MoreAsserts.assertIterablesEquals(expectedEntries, observedEntries);
}
use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.
the class ArchiveTest method testThatBuildTargetSourcePathDepsAndPathsArePropagated.
@Test
public void testThatBuildTargetSourcePathDepsAndPathsArePropagated() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
// Create a couple of genrules to generate inputs for an archive rule.
Genrule genrule1 = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule")).setOut("foo/bar.o").build(resolver);
Genrule genrule2 = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule2")).setOut("foo/test.o").build(resolver);
// Build the archive using a normal input the outputs of the genrules above.
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
Archive archive = Archive.from(target, params, ruleFinder, DEFAULT_ARCHIVER, ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, ImmutableList.of(new FakeSourcePath("simple.o"), genrule1.getSourcePathToOutput(), genrule2.getSourcePathToOutput()));
// Verify that the archive dependencies include the genrules providing the
// SourcePath inputs.
assertEquals(ImmutableSortedSet.<BuildRule>of(genrule1, genrule2), archive.getDeps());
}
use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.
the class ArchiveTest method testThatInputChangesCauseRuleKeyChanges.
@Test
public void testThatInputChangesCauseRuleKeyChanges() {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
FakeFileHashCache hashCache = FakeFileHashCache.createFromStrings(ImmutableMap.<String, String>builder().put(AR.toString(), Strings.repeat("0", 40)).put(RANLIB.toString(), Strings.repeat("1", 40)).put("a.o", Strings.repeat("a", 40)).put("b.o", Strings.repeat("b", 40)).put("c.o", Strings.repeat("c", 40)).put(Paths.get("different").toString(), Strings.repeat("d", 40)).build());
// Generate a rule key for the defaults.
RuleKey defaultRuleKey = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(Archive.from(target, params, ruleFinder, DEFAULT_ARCHIVER, ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, DEFAULT_INPUTS));
// Verify that changing the archiver causes a rulekey change.
RuleKey archiverChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(Archive.from(target, params, ruleFinder, new GnuArchiver(new HashedFileTool(Paths.get("different"))), ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, DEFAULT_INPUTS));
assertNotEquals(defaultRuleKey, archiverChange);
// Verify that changing the output path causes a rulekey change.
RuleKey outputChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(Archive.from(target, params, ruleFinder, DEFAULT_ARCHIVER, ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, Paths.get("different"), DEFAULT_INPUTS));
assertNotEquals(defaultRuleKey, outputChange);
// Verify that changing the inputs causes a rulekey change.
RuleKey inputChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(Archive.from(target, params, ruleFinder, DEFAULT_ARCHIVER, ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, ImmutableList.of(new FakeSourcePath("different"))));
assertNotEquals(defaultRuleKey, inputChange);
// Verify that changing the type of archiver causes a rulekey change.
RuleKey archiverTypeChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(Archive.from(target, params, ruleFinder, new BsdArchiver(new HashedFileTool(AR)), ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, DEFAULT_INPUTS));
assertNotEquals(defaultRuleKey, archiverTypeChange);
}
Aggregations