use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method findDepsFromParamsWithLocation.
@Test
public void findDepsFromParamsWithLocation() throws NoSuchBuildTargetException {
BuildTarget genTarget = BuildTargetFactory.newInstance("//other:gen_lib");
GenruleBuilder genruleBuilder = GenruleBuilder.newGenruleBuilder(genTarget).setOut("lib_dir");
PrebuiltCxxLibraryBuilder builder = new PrebuiltCxxLibraryBuilder(TARGET);
builder.setSoname("test");
builder.setLibDir("$(location //other:gen_lib)");
TargetGraph targetGraph = TargetGraphFactory.newInstance(genruleBuilder.build(), builder.build());
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
BuildRule genrule = genruleBuilder.build(resolver, filesystem, targetGraph);
PrebuiltCxxLibrary lib = (PrebuiltCxxLibrary) builder.build(resolver, filesystem, targetGraph);
Iterable<BuildTarget> implicit = builder.findImplicitDeps();
assertEquals(1, Iterables.size(implicit));
assertTrue(Iterables.contains(implicit, genTarget));
assertThat(lib.getDeps(), Matchers.contains(genrule));
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method includesDirs.
@Test
public void includesDirs() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
PrebuiltCxxLibraryBuilder prebuiltCxxLibraryBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:r")).setIncludeDirs(ImmutableList.of("include"));
TargetGraph targetGraph = TargetGraphFactory.newInstance(prebuiltCxxLibraryBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
PrebuiltCxxLibrary rule = (PrebuiltCxxLibrary) prebuiltCxxLibraryBuilder.build(resolver, filesystem, targetGraph);
assertThat(rule.getCxxPreprocessorInput(CxxPlatformUtils.DEFAULT_PLATFORM, HeaderVisibility.PUBLIC).getIncludes(), Matchers.contains(CxxHeadersDir.of(CxxPreprocessables.IncludeType.SYSTEM, new PathSourcePath(filesystem, rule.getBuildTarget().getBasePath().resolve("include")))));
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method nativeLinkTargetDeps.
@Test
public void nativeLinkTargetDeps() throws Exception {
PrebuiltCxxLibraryBuilder depBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep"));
PrebuiltCxxLibraryBuilder exportedDepBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:exported_dep"));
PrebuiltCxxLibraryBuilder ruleBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:rule")).setExportedDeps(ImmutableSortedSet.of(depBuilder.getTarget(), exportedDepBuilder.getTarget()));
TargetGraph targetGraph = TargetGraphFactory.newInstance(depBuilder.build(), exportedDepBuilder.build(), ruleBuilder.build());
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
PrebuiltCxxLibrary dep = (PrebuiltCxxLibrary) depBuilder.build(resolver, filesystem, targetGraph);
PrebuiltCxxLibrary exportedDep = (PrebuiltCxxLibrary) exportedDepBuilder.build(resolver, filesystem, targetGraph);
PrebuiltCxxLibrary rule = (PrebuiltCxxLibrary) ruleBuilder.build(resolver, filesystem, targetGraph);
assertThat(ImmutableList.copyOf(rule.getNativeLinkTarget(CXX_PLATFORM).get().getNativeLinkTargetDeps(CXX_PLATFORM)), Matchers.hasItems(dep, exportedDep));
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method nativeLinkTargetMode.
@Test
public void nativeLinkTargetMode() throws Exception {
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
PrebuiltCxxLibraryBuilder prebuiltCxxLibraryBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:rule")).setSoname("libsoname.so");
TargetGraph targetGraph = TargetGraphFactory.newInstance(prebuiltCxxLibraryBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
PrebuiltCxxLibrary rule = (PrebuiltCxxLibrary) prebuiltCxxLibraryBuilder.build(resolver, filesystem, targetGraph);
assertThat(rule.getNativeLinkTarget(CXX_PLATFORM).get().getNativeLinkTargetMode(CXX_PLATFORM), Matchers.equalTo(NativeLinkTargetMode.library("libsoname.so")));
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method headerOnly.
@Test
public void headerOnly() throws Exception {
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
PrebuiltCxxLibraryBuilder libBuilder = new PrebuiltCxxLibraryBuilder(TARGET).setHeaderOnly(true);
TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
PrebuiltCxxLibrary lib = (PrebuiltCxxLibrary) libBuilder.build(resolver, filesystem, targetGraph);
// Verify static native linkable input.
NativeLinkableInput expectedStaticLinkableInput = NativeLinkableInput.of(ImmutableList.of(), ImmutableSet.of(), ImmutableSet.of());
assertEquals(expectedStaticLinkableInput, lib.getNativeLinkableInput(CXX_PLATFORM, Linker.LinkableDepType.STATIC));
// Verify shared native linkable input.
NativeLinkableInput expectedSharedLinkableInput = NativeLinkableInput.of(ImmutableList.of(), ImmutableSet.of(), ImmutableSet.of());
assertEquals(expectedSharedLinkableInput, lib.getNativeLinkableInput(CXX_PLATFORM, Linker.LinkableDepType.SHARED));
}
Aggregations