use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class CxxLibraryDescriptionTest method locationMacroExpandedExportedLinkerFlag.
@Test
public void locationMacroExpandedExportedLinkerFlag() throws Exception {
BuildTarget location = BuildTargetFactory.newInstance("//:loc");
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
ProjectFilesystem filesystem = new FakeProjectFilesystem();
ExportFileBuilder locBuilder = ExportFileBuilder.newExportFileBuilder(location);
locBuilder.setOut("somewhere.over.the.rainbow");
CxxLibraryBuilder libBuilder = new CxxLibraryBuilder(target, cxxBuckConfig);
libBuilder.setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new PathSourcePath(filesystem, Paths.get("test.cpp")))));
libBuilder.setExportedLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("-Wl,--version-script=%s", LocationMacro.of(location))));
TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build(), locBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
ExportFile loc = locBuilder.build(resolver, filesystem, targetGraph);
CxxLibrary lib = (CxxLibrary) libBuilder.build(resolver, filesystem, targetGraph);
NativeLinkableInput nativeLinkableInput = lib.getNativeLinkableInput(CxxLibraryBuilder.createDefaultPlatform(), Linker.LinkableDepType.SHARED);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
assertThat(FluentIterable.from(nativeLinkableInput.getArgs()).transformAndConcat(arg -> arg.getDeps(ruleFinder)).toSet(), hasItem(loc));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
assertThat(Arg.stringify(nativeLinkableInput.getArgs(), pathResolver), hasItem(containsString(pathResolver.getRelativePath(Preconditions.checkNotNull(loc.getSourcePathToOutput())).toString())));
}
use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class DirectHeaderMapTest method setUp.
@Before
public void setUp() throws Exception {
projectFilesystem = new FakeProjectFilesystem(tmpDir.getRoot());
// Create a build target to use when building the symlink tree.
buildTarget = BuildTargetFactory.newInstance("//test:test");
// Get the first file we're symlinking
Path link1 = Paths.get("file");
file1 = tmpDir.newFile();
Files.write(file1, "hello world".getBytes(Charsets.UTF_8));
// Get the second file we're symlinking
Path link2 = Paths.get("directory", "then", "file");
file2 = tmpDir.newFile();
Files.write(file2, "hello world".getBytes(Charsets.UTF_8));
// Setup the map representing the link tree.
links = ImmutableMap.of(link1, new PathSourcePath(projectFilesystem, MorePaths.relativize(tmpDir.getRoot(), file1)), link2, new PathSourcePath(projectFilesystem, MorePaths.relativize(tmpDir.getRoot(), file2)));
// The output path used by the buildable for the link tree.
symlinkTreeRoot = BuildTargets.getGenPath(projectFilesystem, buildTarget, "%s/symlink-tree-root");
// Setup the symlink tree buildable.
ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
ruleFinder = new SourcePathRuleFinder(ruleResolver);
pathResolver = new SourcePathResolver(ruleFinder);
buildRule = new DirectHeaderMap(buildTarget, projectFilesystem, symlinkTreeRoot, links, ruleFinder);
ruleResolver.addToIndex(buildRule);
headerMapPath = pathResolver.getRelativePath(buildRule.getSourcePathToOutput());
}
use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class HeaderSymlinkTreeWithHeaderMapTest method testSymlinkTreeRuleKeyChangesIfLinkMapChanges.
@Test
public void testSymlinkTreeRuleKeyChangesIfLinkMapChanges() throws Exception {
Path aFile = tmpDir.newFile();
Files.write(aFile, "hello world".getBytes(Charsets.UTF_8));
HeaderSymlinkTreeWithHeaderMap modifiedSymlinkTreeBuildRule = HeaderSymlinkTreeWithHeaderMap.create(buildTarget, projectFilesystem, symlinkTreeRoot, ImmutableMap.of(Paths.get("different/link"), new PathSourcePath(projectFilesystem, MorePaths.relativize(tmpDir.getRoot(), aFile))), ruleFinder);
// Calculate their rule keys and verify they're different.
DefaultFileHashCache hashCache = DefaultFileHashCache.createDefaultFileHashCache(new ProjectFilesystem(tmpDir.getRoot()));
FileHashLoader hashLoader = new StackedFileHashCache(ImmutableList.of(hashCache));
RuleKey key1 = new DefaultRuleKeyFactory(0, hashLoader, resolver, ruleFinder).build(symlinkTreeBuildRule);
RuleKey key2 = new DefaultRuleKeyFactory(0, hashLoader, resolver, ruleFinder).build(modifiedSymlinkTreeBuildRule);
assertNotEquals(key1, key2);
}
use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class HeaderSymlinkTreeWithHeaderMapTest method setUp.
@Before
public void setUp() throws Exception {
projectFilesystem = new FakeProjectFilesystem(tmpDir.getRoot());
// Create a build target to use when building the symlink tree.
buildTarget = BuildTargetFactory.newInstance("//test:test");
// Get the first file we're symlinking
Path link1 = Paths.get("file");
Path file1 = tmpDir.newFile();
Files.write(file1, "hello world".getBytes(Charsets.UTF_8));
// Get the second file we're symlinking
Path link2 = Paths.get("directory", "then", "file");
Path file2 = tmpDir.newFile();
Files.write(file2, "hello world".getBytes(Charsets.UTF_8));
// Setup the map representing the link tree.
links = ImmutableMap.of(link1, new PathSourcePath(projectFilesystem, MorePaths.relativize(tmpDir.getRoot(), file1)), link2, new PathSourcePath(projectFilesystem, MorePaths.relativize(tmpDir.getRoot(), file2)));
// The output path used by the buildable for the link tree.
symlinkTreeRoot = BuildTargets.getGenPath(projectFilesystem, buildTarget, "%s/symlink-tree-root");
ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
ruleFinder = new SourcePathRuleFinder(ruleResolver);
resolver = new SourcePathResolver(ruleFinder);
// Setup the symlink tree buildable.
symlinkTreeBuildRule = HeaderSymlinkTreeWithHeaderMap.create(buildTarget, projectFilesystem, symlinkTreeRoot, links, ruleFinder);
}
use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class PrebuiltCxxLibraryGroupDescriptionTest method sharedLink.
@Test
public void sharedLink() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
BuildTarget target = BuildTargetFactory.newInstance("//:lib");
SourcePath lib1 = new FakeSourcePath("dir/lib1.so");
PathSourcePath lib2 = new FakeSourcePath("dir/lib2.so");
NativeLinkable lib = (NativeLinkable) new PrebuiltCxxLibraryGroupBuilder(target).setSharedLink(ImmutableList.of("--something", "$(lib lib1.so)", "--something-else", "$(rel-lib lib2.so)")).setSharedLibs(ImmutableMap.of("lib1.so", lib1, "lib2.so", lib2)).build(resolver);
assertThat(lib.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.SHARED), Matchers.equalTo(NativeLinkableInput.builder().addArgs(StringArg.of("--something"), SourcePathArg.of(lib1), StringArg.of("--something-else"), new RelativeLinkArg(lib2)).build()));
}
Aggregations