use of com.facebook.buck.cxx.NativeLinkableInput in project buck by facebook.
the class HalideLibraryDescriptionTest method testCreateBuildRule.
@Test
public void testCreateBuildRule() throws Exception {
// Set up a #halide-compiler rule, then set up a halide_library rule, and
// check that the library rule depends on the compiler rule.
BuildTarget compilerTarget = BuildTargetFactory.newInstance("//:rule").withFlavors(HalideLibraryDescription.HALIDE_COMPILER_FLAVOR);
BuildTarget libTarget = BuildTargetFactory.newInstance("//:rule");
ProjectFilesystem filesystem = new FakeProjectFilesystem();
HalideLibraryBuilder compilerBuilder = new HalideLibraryBuilder(compilerTarget);
compilerBuilder.setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("main.cpp"))));
HalideLibraryBuilder libBuilder = new HalideLibraryBuilder(libTarget);
TargetGraph targetGraph = TargetGraphFactory.newInstance(compilerBuilder.build(), libBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
HalideLibrary lib = (HalideLibrary) libBuilder.build(resolver, filesystem, targetGraph);
// Check that the library rule has the correct preprocessor input.
CxxPlatform cxxPlatform = CxxLibraryBuilder.createDefaultPlatform();
String headerName = "rule.h";
BuildTarget flavoredLibTarget = libTarget.withFlavors(HalideLibraryDescription.HALIDE_COMPILE_FLAVOR, cxxPlatform.getFlavor());
Path headerPath = HalideCompile.headerOutputPath(flavoredLibTarget, lib.getProjectFilesystem(), Optional.empty());
CxxSymlinkTreeHeaders publicHeaders = (CxxSymlinkTreeHeaders) lib.getCxxPreprocessorInput(cxxPlatform, HeaderVisibility.PUBLIC).getIncludes().get(0);
assertThat(publicHeaders.getIncludeType(), Matchers.equalTo(CxxPreprocessables.IncludeType.SYSTEM));
assertThat(publicHeaders.getNameToPathMap(), Matchers.equalTo(ImmutableMap.<Path, SourcePath>of(Paths.get(headerName), new ExplicitBuildTargetSourcePath(flavoredLibTarget, headerPath))));
// Check that the library rule has the correct native linkable input.
NativeLinkableInput input = lib.getNativeLinkableInput(cxxPlatform, Linker.LinkableDepType.STATIC);
BuildRule buildRule = FluentIterable.from(input.getArgs()).transformAndConcat(arg -> arg.getDeps(new SourcePathRuleFinder(resolver))).get(0);
assertThat(buildRule, is(instanceOf(Archive.class)));
}
use of com.facebook.buck.cxx.NativeLinkableInput in project buck by facebook.
the class HaskellLibraryDescriptionTest method thinArchivesPropagatesDepFromObjects.
@Test
public void thinArchivesPropagatesDepFromObjects() throws Exception {
BuildTarget target = BuildTargetFactory.newInstance("//:rule");
CxxBuckConfig cxxBuckConfig = new CxxBuckConfig(FakeBuckConfig.builder().setSections("[cxx]", "archive_contents=thin").build());
HaskellLibraryBuilder builder = new HaskellLibraryBuilder(target, FakeHaskellConfig.DEFAULT, cxxBuckConfig, CxxPlatformUtils.DEFAULT_PLATFORMS).setSrcs(SourceList.ofUnnamedSources(ImmutableSortedSet.of(new FakeSourcePath("Test.hs")))).setLinkWhole(true);
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(builder.build()), new DefaultTargetNodeToBuildRuleTransformer());
HaskellLibrary library = builder.build(resolver);
// Test static dep type.
NativeLinkableInput staticInput = library.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.STATIC);
assertThat(FluentIterable.from(staticInput.getArgs()).transformAndConcat(arg -> arg.getDeps(new SourcePathRuleFinder(resolver))).transform(BuildRule::getBuildTarget).toList(), Matchers.hasItem(HaskellDescriptionUtils.getCompileBuildTarget(library.getBuildTarget(), CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.STATIC)));
}
use of com.facebook.buck.cxx.NativeLinkableInput in project buck by facebook.
the class HaskellPrebuiltLibraryDescriptionTest method staticLibraries.
@Test
public void staticLibraries() throws Exception {
PathSourcePath lib = new FakeSourcePath("libfoo.a");
BuildTarget target = BuildTargetFactory.newInstance("//:rule");
PrebuiltHaskellLibraryBuilder builder = new PrebuiltHaskellLibraryBuilder(target).setVersion("1.0.0").setDb(new FakeSourcePath("package.conf.d")).setStaticLibs(ImmutableList.of(lib));
TargetGraph targetGraph = TargetGraphFactory.newInstance(builder.build());
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
PrebuiltHaskellLibrary library = builder.build(resolver, filesystem, targetGraph);
NativeLinkableInput input = library.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.STATIC);
assertThat(RichStream.from(input.getArgs()).flatMap(a -> a.getInputs().stream()).toImmutableSet(), Matchers.contains(lib));
}
use of com.facebook.buck.cxx.NativeLinkableInput in project buck by facebook.
the class HaskellPrebuiltLibraryDescriptionTest method exportedLinkerFlags.
@Test
public void exportedLinkerFlags() throws Exception {
BuildTarget target = BuildTargetFactory.newInstance("//:rule");
String flag = "-exported-linker-flags";
PrebuiltHaskellLibraryBuilder builder = new PrebuiltHaskellLibraryBuilder(target).setVersion("1.0.0").setDb(new FakeSourcePath("package.conf.d")).setExportedLinkerFlags(ImmutableList.of(flag));
TargetGraph targetGraph = TargetGraphFactory.newInstance(builder.build());
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
PrebuiltHaskellLibrary library = builder.build(resolver, filesystem, targetGraph);
NativeLinkableInput staticInput = library.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.STATIC);
assertThat(Arg.stringify(staticInput.getArgs(), pathResolver), Matchers.contains(flag));
NativeLinkableInput sharedInput = library.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.SHARED);
assertThat(Arg.stringify(sharedInput.getArgs(), pathResolver), Matchers.contains(flag));
}
use of com.facebook.buck.cxx.NativeLinkableInput in project buck by facebook.
the class CxxPythonExtensionDescriptionTest method nativeLinkTargetInput.
@Test
public void nativeLinkTargetInput() throws Exception {
CxxPythonExtensionBuilder builder = new CxxPythonExtensionBuilder(BuildTargetFactory.newInstance("//:rule"), FlavorDomain.of("Python Platform", PY2, PY3), new CxxBuckConfig(FakeBuckConfig.builder().build()), CxxTestBuilder.createDefaultPlatforms());
builder.setLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("--flag")));
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(builder.build()), new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
CxxPythonExtension rule = builder.build(resolver);
NativeLinkTarget nativeLinkTarget = rule.getNativeLinkTarget(PY2);
NativeLinkableInput input = nativeLinkTarget.getNativeLinkTargetInput(CxxPlatformUtils.DEFAULT_PLATFORM);
assertThat(Arg.stringify(input.getArgs(), pathResolver), Matchers.hasItems("--flag"));
}
Aggregations