use of com.facebook.buck.testutil.AllExistingProjectFilesystem in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method nativeLinkTargetInput.
@Test
public void nativeLinkTargetInput() throws Exception {
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
PrebuiltCxxLibraryBuilder ruleBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:rule")).setExportedLinkerFlags(ImmutableList.of("--exported-flag"));
TargetGraph targetGraph = TargetGraphFactory.newInstance(ruleBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
PrebuiltCxxLibrary rule = (PrebuiltCxxLibrary) ruleBuilder.build(resolver, filesystem, targetGraph);
NativeLinkableInput input = rule.getNativeLinkTarget(CXX_PLATFORM).get().getNativeLinkTargetInput(CxxPlatformUtils.DEFAULT_PLATFORM);
assertThat(Arg.stringify(input.getArgs(), pathResolver), Matchers.hasItems("--exported-flag"));
}
use of com.facebook.buck.testutil.AllExistingProjectFilesystem in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method locationMacro.
@Test
public void locationMacro() throws NoSuchBuildTargetException {
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
CellPathResolver cellRoots = TestCellBuilder.createCellRoots(filesystem);
Optional<String> libName = Optional.of("test");
Optional<String> libDir = Optional.of("$(location //other:gen_lib)/");
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
BuildTarget genTarget = BuildTargetFactory.newInstance("//other:gen_lib");
GenruleBuilder genruleBuilder = GenruleBuilder.newGenruleBuilder(genTarget).setOut("lib_dir");
BuildRule genRule = genruleBuilder.build(resolver);
CxxPlatform platform = CxxPlatformUtils.DEFAULT_PLATFORM.withFlavor(InternalFlavor.of("PLATFORM1"));
Path path = pathResolver.getAbsolutePath(Preconditions.checkNotNull(genRule.getSourcePathToOutput()));
final SourcePath staticLibraryPath = PrebuiltCxxLibraryDescription.getStaticLibraryPath(TARGET, cellRoots, filesystem, resolver, platform, Optional.empty(), libDir, libName);
assertEquals(TARGET.getBasePath().resolve(String.format("%s/libtest.a", path)), pathResolver.getAbsolutePath(staticLibraryPath));
}
use of com.facebook.buck.testutil.AllExistingProjectFilesystem in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method headerNamespace.
@Test
public void headerNamespace() throws Exception {
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
PrebuiltCxxLibraryBuilder libBuilder = new PrebuiltCxxLibraryBuilder(TARGET).setHeaderNamespace("hello").setExportedHeaders(SourceList.ofUnnamedSources(ImmutableSortedSet.of(new FakeSourcePath("foo.h"))));
TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
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.contains(filesystem.getPath("hello", "foo.h")));
}
use of com.facebook.buck.testutil.AllExistingProjectFilesystem in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method goodPathNoLocation.
@Test
public void goodPathNoLocation() {
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
CxxPlatform platform = CxxPlatformUtils.DEFAULT_PLATFORM.withFlavor(InternalFlavor.of("PLATFORM1"));
final SourcePath staticLibraryPath = PrebuiltCxxLibraryDescription.getStaticLibraryPath(TARGET_TWO, TestCellBuilder.createCellRoots(filesystem), filesystem, resolver, platform, Optional.empty(), Optional.of("lib"), Optional.empty());
assertThat(MorePaths.pathWithUnixSeparators(pathResolver.getAbsolutePath(staticLibraryPath)), Matchers.containsString(String.format("two/%s/libtarget.a", "lib")));
}
use of com.facebook.buck.testutil.AllExistingProjectFilesystem in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method providedLibIsNotANativeLinkTargetSoname.
@Test
public void providedLibIsNotANativeLinkTargetSoname() 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);
assertFalse(rule.getNativeLinkTarget(CXX_PLATFORM).isPresent());
}
Aggregations