use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method linkWithoutSoname.
@Test
public void linkWithoutSoname() throws Exception {
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
PrebuiltCxxLibraryBuilder prebuiltCxxLibraryBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:rule")).setLinkWithoutSoname(true);
TargetGraph targetGraph = TargetGraphFactory.newInstance(prebuiltCxxLibraryBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
PrebuiltCxxLibrary rule = (PrebuiltCxxLibrary) prebuiltCxxLibraryBuilder.build(resolver, filesystem, targetGraph);
NativeLinkableInput input = rule.getNativeLinkableInput(CXX_PLATFORM, Linker.LinkableDepType.SHARED);
assertThat(Arg.stringify(input.getArgs(), pathResolver), Matchers.contains("-L" + filesystem.resolve(rule.getBuildTarget().getBasePath()).resolve("lib"), "-lrule"));
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method staticPicLibsUseCorrectPath.
@Test
public void staticPicLibsUseCorrectPath() throws Exception {
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
PrebuiltCxxLibraryBuilder libBuilder = new PrebuiltCxxLibraryBuilder(TARGET);
TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
PrebuiltCxxLibrary lib = (PrebuiltCxxLibrary) libBuilder.build(resolver, filesystem, targetGraph);
NativeLinkableInput nativeLinkableInput = lib.getNativeLinkableInput(CXX_PLATFORM, Linker.LinkableDepType.STATIC_PIC);
assertThat(Arg.stringify(nativeLinkableInput.getArgs(), pathResolver).get(0), Matchers.endsWith(getStaticPicLibraryPath(libBuilder.build().getConstructorArg()).toString()));
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method nativeLinkableExportedDeps.
@Test
public void nativeLinkableExportedDeps() throws Exception {
PrebuiltCxxLibraryBuilder depBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep"));
PrebuiltCxxLibraryBuilder ruleBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:r")).setExportedDeps(ImmutableSortedSet.of(depBuilder.getTarget()));
TargetGraph targetGraph = TargetGraphFactory.newInstance(depBuilder.build(), ruleBuilder.build());
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
PrebuiltCxxLibrary dep = (PrebuiltCxxLibrary) depBuilder.build(resolver, filesystem, targetGraph);
PrebuiltCxxLibrary rule = (PrebuiltCxxLibrary) ruleBuilder.build(resolver, filesystem, targetGraph);
assertThat(ImmutableList.copyOf(rule.getNativeLinkableDepsForPlatform(CxxLibraryBuilder.createDefaultPlatform())), empty());
assertThat(rule.getNativeLinkableExportedDepsForPlatform(CxxLibraryBuilder.createDefaultPlatform()), Matchers.contains(dep));
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method createBuildRuleExternal.
@Test
public void createBuildRuleExternal() throws Exception {
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
PrebuiltCxxLibraryBuilder libBuilder = new PrebuiltCxxLibraryBuilder(TARGET).setProvided(true);
TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
PrebuiltCxxLibrary lib = (PrebuiltCxxLibrary) libBuilder.build(resolver, filesystem, targetGraph);
PrebuiltCxxLibraryDescription.Arg arg = libBuilder.build().getConstructorArg();
// Verify shared native linkable input.
NativeLinkableInput expectedSharedLinkableInput = NativeLinkableInput.of(ImmutableList.of(SourcePathArg.of(new PathSourcePath(filesystem, getSharedLibraryPath(arg)))), ImmutableSet.of(), ImmutableSet.of());
assertEquals(expectedSharedLinkableInput, lib.getNativeLinkableInput(CXX_PLATFORM, Linker.LinkableDepType.SHARED));
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method supportedPlatforms.
@Test
public void supportedPlatforms() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
// First, make sure without any platform regex, we get something back for each of the interface
// methods.
PrebuiltCxxLibraryBuilder prebuiltCxxLibraryBuilder = new PrebuiltCxxLibraryBuilder(target);
TargetGraph targetGraph1 = TargetGraphFactory.newInstance(prebuiltCxxLibraryBuilder.build());
BuildRuleResolver resolver1 = new BuildRuleResolver(targetGraph1, new DefaultTargetNodeToBuildRuleTransformer());
PrebuiltCxxLibrary prebuiltCxxLibrary = (PrebuiltCxxLibrary) prebuiltCxxLibraryBuilder.build(resolver1, filesystem, targetGraph1);
assertThat(prebuiltCxxLibrary.getSharedLibraries(CxxPlatformUtils.DEFAULT_PLATFORM).entrySet(), Matchers.not(empty()));
assertThat(prebuiltCxxLibrary.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.SHARED).getArgs(), Matchers.not(empty()));
// Now, verify we get nothing when the supported platform regex excludes our platform.
prebuiltCxxLibraryBuilder.setSupportedPlatformsRegex(Pattern.compile("nothing"));
TargetGraph targetGraph2 = TargetGraphFactory.newInstance(prebuiltCxxLibraryBuilder.build());
BuildRuleResolver resolver2 = new BuildRuleResolver(targetGraph2, new DefaultTargetNodeToBuildRuleTransformer());
prebuiltCxxLibrary = (PrebuiltCxxLibrary) prebuiltCxxLibraryBuilder.build(resolver2, filesystem, targetGraph2);
assertThat(prebuiltCxxLibrary.getSharedLibraries(CxxPlatformUtils.DEFAULT_PLATFORM).entrySet(), empty());
assertThat(prebuiltCxxLibrary.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.SHARED).getArgs(), empty());
}
Aggregations