use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class CxxLibraryDescriptionTest method overrideSoname.
@Test
public void overrideSoname() throws Exception {
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
CxxPlatform cxxPlatform = CxxLibraryBuilder.createDefaultPlatform();
String soname = "test_soname";
// Generate the C++ library rules.
BuildTarget target = BuildTargetFactory.newInstance("//:rule").withFlavors(CxxPlatformUtils.DEFAULT_PLATFORM.getFlavor(), CxxDescriptionEnhancer.SHARED_FLAVOR, LinkerMapMode.NO_LINKER_MAP.getFlavor());
CxxLibraryBuilder ruleBuilder = new CxxLibraryBuilder(target, cxxBuckConfig).setSoname(soname).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.cpp"))));
TargetGraph targetGraph = TargetGraphFactory.newInstance(ruleBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
CxxLink rule = (CxxLink) ruleBuilder.build(resolver, filesystem, targetGraph);
Linker linker = cxxPlatform.getLd().resolve(resolver);
ImmutableList<String> sonameArgs = ImmutableList.copyOf(linker.soname(soname));
assertThat(Arg.stringify(rule.getArgs(), pathResolver), hasItems(sonameArgs.toArray(new String[sonameArgs.size()])));
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class CxxLocationMacroExpanderTest method expandCxxGenrule.
@Test
public void expandCxxGenrule() throws Exception {
CxxGenruleBuilder builder = new CxxGenruleBuilder(BuildTargetFactory.newInstance("//:rule")).setOut("out.txt");
TargetNode<?, ?> node = builder.build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(node);
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
CxxGenrule cxxGenrule = (CxxGenrule) resolver.requireRule(node.getBuildTarget());
CxxLocationMacroExpander expander = new CxxLocationMacroExpander(CxxPlatformUtils.DEFAULT_PLATFORM);
String expanded = expander.expandFrom(node.getBuildTarget(), node.getCellNames(), resolver, LocationMacro.of(node.getBuildTarget()));
assertThat(expanded, Matchers.equalTo(pathResolver.getAbsolutePath(cxxGenrule.getGenrule(CxxPlatformUtils.DEFAULT_PLATFORM)).toString()));
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class CxxLibraryDescriptionTest method sharedLibraryShouldLinkOwnRequiredLibraries.
@Test
public void sharedLibraryShouldLinkOwnRequiredLibraries() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
CxxPlatform platform = CxxLibraryBuilder.createDefaultPlatform();
CxxLibraryBuilder libraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:foo").withFlavors(platform.getFlavor(), CxxDescriptionEnhancer.SHARED_FLAVOR), cxxBuckConfig);
libraryBuilder.setLibraries(ImmutableSortedSet.of(FrameworkPath.ofSourceTreePath(new SourceTreePath(PBXReference.SourceTree.SDKROOT, Paths.get("/usr/lib/libz.dylib"), Optional.empty())), FrameworkPath.ofSourcePath(new FakeSourcePath("/another/path/liba.dylib")))).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.c"))));
TargetGraph targetGraph = TargetGraphFactory.newInstance(libraryBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
CxxLink library = (CxxLink) libraryBuilder.build(resolver, filesystem, targetGraph);
assertThat(Arg.stringify(library.getArgs(), pathResolver), hasItems("-L", "/another/path", "$SDKROOT/usr/lib", "-la", "-lz"));
}
use of com.facebook.buck.rules.TargetGraph 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.TargetGraph in project buck by facebook.
the class PrebuiltCxxLibraryTest method testGetNativeLinkWithDep.
@Test
public void testGetNativeLinkWithDep() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
CxxPlatform platform = CxxLibraryBuilder.createDefaultPlatform();
GenruleBuilder genSrcBuilder = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:gen_libx")).setOut("gen_libx").setCmd("something");
BuildTarget target = BuildTargetFactory.newInstance("//:x");
PrebuiltCxxLibraryBuilder builder = new PrebuiltCxxLibraryBuilder(target).setLibName("x").setLibDir("$(location //:gen_libx)");
TargetGraph targetGraph = TargetGraphFactory.newInstance(genSrcBuilder.build(), builder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildRule genSrc = genSrcBuilder.build(resolver, filesystem, targetGraph);
filesystem.writeContentsToPath("class Test {}", pathResolver.getAbsolutePath(genSrc.getSourcePathToOutput()).resolve("libx.a"));
PrebuiltCxxLibrary lib = (PrebuiltCxxLibrary) builder.build(resolver, filesystem, targetGraph);
lib.getNativeLinkableInput(platform, Linker.LinkableDepType.STATIC);
FileHashCache originalHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
DefaultRuleKeyFactory factory = new DefaultRuleKeyFactory(0, originalHashCache, pathResolver, ruleFinder);
RuleKey ruleKey = factory.build(lib);
assertNotNull(ruleKey);
}
Aggregations