use of com.facebook.buck.testutil.AllExistingProjectFilesystem 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.testutil.AllExistingProjectFilesystem 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.testutil.AllExistingProjectFilesystem 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.testutil.AllExistingProjectFilesystem in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method providedDoNotReturnSharedLibs.
@Test
public void providedDoNotReturnSharedLibs() throws Exception {
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
PrebuiltCxxLibraryBuilder prebuiltCxxLibraryBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:rule")).setProvided(true);
TargetGraph targetGraph = TargetGraphFactory.newInstance(prebuiltCxxLibraryBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
PrebuiltCxxLibrary rule = (PrebuiltCxxLibrary) prebuiltCxxLibraryBuilder.build(resolver, filesystem, targetGraph);
assertThat(rule.getSharedLibraries(CXX_PLATFORM).entrySet(), empty());
}
use of com.facebook.buck.testutil.AllExistingProjectFilesystem 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));
}
Aggregations