use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method createBuildRuleDefault.
@Test
public void createBuildRuleDefault() throws Exception {
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
PrebuiltCxxLibraryBuilder libBuilder = new PrebuiltCxxLibraryBuilder(TARGET);
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 static native linkable input.
NativeLinkableInput expectedStaticLinkableInput = NativeLinkableInput.of(ImmutableList.of(FileListableLinkerInputArg.withSourcePathArg(SourcePathArg.of(new PathSourcePath(filesystem, getStaticLibraryPath(arg))))), ImmutableSet.of(), ImmutableSet.of());
assertEquals(expectedStaticLinkableInput, lib.getNativeLinkableInput(CXX_PLATFORM, Linker.LinkableDepType.STATIC));
// 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 exportedPlatformHeaders.
@Test
public void exportedPlatformHeaders() throws Exception {
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
PrebuiltCxxLibraryBuilder libBuilder = new PrebuiltCxxLibraryBuilder(TARGET).setExportedPlatformHeaders(PatternMatchedCollection.<SourceList>builder().add(Pattern.compile(CXX_PLATFORM.getFlavor().toString()), SourceList.ofNamedSources(ImmutableSortedMap.of("foo.h", new FakeSourcePath("foo.h")))).add(Pattern.compile("DO NOT MATCH ANYTNING"), SourceList.ofNamedSources(ImmutableSortedMap.of("bar.h", new FakeSourcePath("bar.h")))).build());
TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
PrebuiltCxxLibrary lib = (PrebuiltCxxLibrary) libBuilder.build(resolver, filesystem, targetGraph);
// Verify the preprocessable input is as expected.
CxxPreprocessorInput input = lib.getCxxPreprocessorInput(CXX_PLATFORM, HeaderVisibility.PUBLIC);
assertThat(getHeaderNames(input.getIncludes()), Matchers.hasItem(filesystem.getPath("foo.h")));
assertThat(getHeaderNames(input.getIncludes()), Matchers.not(Matchers.hasItem(filesystem.getPath("bar.h"))));
assertThat(ImmutableSortedSet.copyOf(input.getDeps(resolver, ruleFinder)), Matchers.equalTo(resolver.getAllRules(getInputRules(lib))));
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method versionSubDir.
@Test
public void versionSubDir() throws Exception {
BuildTarget dep = BuildTargetFactory.newInstance("//:dep");
PrebuiltCxxLibraryBuilder depBuilder = new PrebuiltCxxLibraryBuilder(dep);
PrebuiltCxxLibraryBuilder builder = new PrebuiltCxxLibraryBuilder(TARGET);
builder.setSelectedVersions(ImmutableMap.of(dep, Version.of("1.0")));
builder.setVersionedSubDir(VersionMatchedCollection.<String>builder().add(ImmutableMap.of(dep, Version.of("1.0")), "sub-dir").build());
TargetGraph graph = TargetGraphFactory.newInstance(depBuilder.build(), builder.build());
BuildRuleResolver resolver = new BuildRuleResolver(graph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
depBuilder.build(resolver, filesystem, graph);
PrebuiltCxxLibrary lib = (PrebuiltCxxLibrary) builder.build(resolver, filesystem, graph);
NativeLinkableInput nativeLinkableInput = lib.getNativeLinkableInput(CXX_PLATFORM, Linker.LinkableDepType.STATIC);
assertThat(Arg.stringify(nativeLinkableInput.getArgs(), pathResolver).get(0), Matchers.equalTo(filesystem.resolve("sub-dir").resolve(getStaticLibraryPath(builder.build().getConstructorArg())).toString()));
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method forceStatic.
@Test
public void forceStatic() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
PrebuiltCxxLibraryBuilder builder = new PrebuiltCxxLibraryBuilder(TARGET).setForceStatic(true);
TargetGraph targetGraph = TargetGraphFactory.newInstance(builder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
PrebuiltCxxLibrary prebuiltCxxLibrary = (PrebuiltCxxLibrary) builder.build(resolver, filesystem, targetGraph);
assertThat(prebuiltCxxLibrary.getPreferredLinkage(CxxPlatformUtils.DEFAULT_PLATFORM), Matchers.equalTo(NativeLinkable.Linkage.STATIC));
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method nativeLinkableDeps.
@Test
public void nativeLinkableDeps() throws Exception {
PrebuiltCxxLibraryBuilder depBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep"));
PrebuiltCxxLibraryBuilder ruleBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:r")).setDeps(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(rule.getNativeLinkableDepsForPlatform(CxxLibraryBuilder.createDefaultPlatform()), Matchers.contains(dep));
assertThat(ImmutableList.copyOf(rule.getNativeLinkableExportedDepsForPlatform(CxxLibraryBuilder.createDefaultPlatform())), empty());
}
Aggregations