use of com.facebook.buck.cxx.CxxLink in project buck by facebook.
the class CxxPythonExtensionDescriptionTest method py2AndPy3PropagateToLinkRules.
@Test
public void py2AndPy3PropagateToLinkRules() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
PrebuiltCxxLibraryBuilder python2Builder = new PrebuiltCxxLibraryBuilder(PYTHON2_DEP_TARGET).setHeaderOnly(true).setExportedLinkerFlags(ImmutableList.of("-lpython2"));
PrebuiltCxxLibraryBuilder python3Builder = new PrebuiltCxxLibraryBuilder(PYTHON3_DEP_TARGET).setHeaderOnly(true).setExportedLinkerFlags(ImmutableList.of("-lpython3"));
PythonPlatform py2 = PY2.withCxxLibrary(PYTHON2_DEP_TARGET);
PythonPlatform py3 = PY3.withCxxLibrary(PYTHON3_DEP_TARGET);
BuildTarget target = BuildTargetFactory.newInstance("//:target");
CxxPythonExtensionBuilder builder = new CxxPythonExtensionBuilder(target, FlavorDomain.of("Python Platform", py2, py3), new CxxBuckConfig(FakeBuckConfig.builder().build()), CxxTestBuilder.createDefaultPlatforms());
TargetGraph targetGraph = TargetGraphFactory.newInstance(python2Builder.build(), python3Builder.build(), builder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
python2Builder.build(resolver, filesystem, targetGraph);
python3Builder.build(resolver, filesystem, targetGraph);
CxxPythonExtension extension = builder.build(resolver, filesystem, targetGraph);
// Get the py2 extension, and verify it pulled in the py2 lib but not the py3 lib.
CxxLink py2Ext = (CxxLink) extension.getExtension(py2, CxxPlatformUtils.DEFAULT_PLATFORM);
assertThat(Arg.stringify(py2Ext.getArgs(), pathResolver), Matchers.allOf(Matchers.hasItem("-lpython2"), Matchers.not(Matchers.hasItem("-lpython3"))));
// Get the py3 extension, and verify it pulled in the py3 lib but not the py2 lib.
CxxLink py3Ext = (CxxLink) extension.getExtension(py3, CxxPlatformUtils.DEFAULT_PLATFORM);
assertThat(Arg.stringify(py3Ext.getArgs(), pathResolver), Matchers.allOf(Matchers.hasItem("-lpython3"), Matchers.not(Matchers.hasItem("-lpython2"))));
}
use of com.facebook.buck.cxx.CxxLink in project buck by facebook.
the class PythonBinaryDescriptionTest method linkerFlagsUsingMergedNativeLinkStrategy.
@Test
public void linkerFlagsUsingMergedNativeLinkStrategy() throws Exception {
CxxLibraryBuilder cxxDepBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("dep.c"))));
CxxLibraryBuilder cxxBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:cxx")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("cxx.c")))).setDeps(ImmutableSortedSet.of(cxxDepBuilder.getTarget()));
PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().build(), new AlwaysFoundExecutableFinder()) {
@Override
public NativeLinkStrategy getNativeLinkStrategy() {
return NativeLinkStrategy.MERGED;
}
};
PythonBinaryBuilder binaryBuilder = new PythonBinaryBuilder(BuildTargetFactory.newInstance("//:bin"), config, PythonTestUtils.PYTHON_PLATFORMS, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS);
binaryBuilder.setLinkerFlags(ImmutableList.of("-flag"));
binaryBuilder.setMainModule("main");
binaryBuilder.setDeps(ImmutableSortedSet.of(cxxBuilder.getTarget()));
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(cxxDepBuilder.build(), cxxBuilder.build(), binaryBuilder.build()), new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
cxxDepBuilder.build(resolver);
cxxBuilder.build(resolver);
PythonBinary binary = binaryBuilder.build(resolver);
for (SourcePath path : binary.getComponents().getNativeLibraries().values()) {
CxxLink link = resolver.getRuleOptionalWithType(((BuildTargetSourcePath<?>) path).getTarget(), CxxLink.class).get();
assertThat(Arg.stringify(link.getArgs(), pathResolver), Matchers.hasItem("-flag"));
}
}
use of com.facebook.buck.cxx.CxxLink in project buck by facebook.
the class SwiftLibrary method requireSwiftLinkRule.
private CxxLink requireSwiftLinkRule(Flavor... flavors) throws NoSuchBuildTargetException {
BuildTarget requiredBuildTarget = getBuildTarget().withoutFlavors(SWIFT_COMPANION_FLAVOR).withAppendedFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR).withAppendedFlavors(flavors);
BuildRule rule = ruleResolver.requireRule(requiredBuildTarget);
if (!(rule instanceof CxxLink)) {
throw new RuntimeException(String.format("Could not find CxxLink with target %s", requiredBuildTarget));
}
return (CxxLink) rule;
}
Aggregations