use of com.facebook.buck.cxx.CxxLink in project buck by facebook.
the class AppleBinaryDescriptionTest method linkerFlagsLocationMacro.
@Test
public void linkerFlagsLocationMacro() throws Exception {
assumeThat(Platform.detect(), is(Platform.MACOS));
BuildTarget sandboxTarget = BuildTargetFactory.newInstance("//:rule#sandbox," + FakeAppleRuleDescriptions.DEFAULT_IPHONEOS_I386_PLATFORM.getFlavor());
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(new AppleBinaryBuilder(sandboxTarget).build()), new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
Genrule dep = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out").build(resolver);
AppleBinaryBuilder builder = new AppleBinaryBuilder(BuildTargetFactory.newInstance("//:rule")).setLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("--linker-script=%s", LocationMacro.of(dep.getBuildTarget()))));
assertThat(builder.build().getExtraDeps(), Matchers.hasItem(dep.getBuildTarget()));
BuildRule binary = ((CxxBinary) builder.build(resolver)).getLinkRule();
assertThat(binary, Matchers.instanceOf(CxxLink.class));
assertThat(Arg.stringify(((CxxLink) binary).getArgs(), pathResolver), Matchers.hasItem(String.format("--linker-script=%s", dep.getAbsoluteOutputFilePath(pathResolver))));
assertThat(binary.getDeps(), Matchers.hasItem(dep));
}
use of com.facebook.buck.cxx.CxxLink in project buck by facebook.
the class SwiftLibraryIntegrationTest method testSwiftCompileAndLinkArgs.
@Test
public void testSwiftCompileAndLinkArgs() throws NoSuchBuildTargetException {
BuildTarget buildTarget = BuildTargetFactory.newInstance("//foo:bar#iphoneos-x86_64");
BuildTarget swiftCompileTarget = buildTarget.withAppendedFlavors(SwiftLibraryDescription.SWIFT_COMPILE_FLAVOR);
BuildRuleParams params = new FakeBuildRuleParamsBuilder(swiftCompileTarget).build();
SwiftLibraryDescription.Arg args = createDummySwiftArg();
SwiftCompile buildRule = (SwiftCompile) FakeAppleRuleDescriptions.SWIFT_LIBRARY_DESCRIPTION.createBuildRule(TargetGraph.EMPTY, params, resolver, args);
resolver.addToIndex(buildRule);
ImmutableList<Arg> astArgs = buildRule.getAstLinkArgs();
assertThat(astArgs, Matchers.hasSize(3));
assertThat(astArgs.get(0), Matchers.equalTo(StringArg.of("-Xlinker")));
assertThat(astArgs.get(1), Matchers.equalTo(StringArg.of("-add_ast_path")));
assertThat(astArgs.get(2), Matchers.instanceOf(SourcePathArg.class));
SourcePathArg sourcePathArg = (SourcePathArg) astArgs.get(2);
assertThat(sourcePathArg.getPath(), Matchers.equalTo(new ExplicitBuildTargetSourcePath(swiftCompileTarget, pathResolver.getRelativePath(buildRule.getSourcePathToOutput()).resolve("bar.swiftmodule"))));
Arg objArg = buildRule.getFileListLinkArg();
assertThat(objArg, Matchers.instanceOf(FileListableLinkerInputArg.class));
FileListableLinkerInputArg fileListArg = (FileListableLinkerInputArg) objArg;
ExplicitBuildTargetSourcePath fileListSourcePath = new ExplicitBuildTargetSourcePath(swiftCompileTarget, pathResolver.getRelativePath(buildRule.getSourcePathToOutput()).resolve("bar.o"));
assertThat(fileListArg.getPath(), Matchers.equalTo(fileListSourcePath));
BuildTarget linkTarget = buildTarget.withAppendedFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR);
CxxLink linkRule = (CxxLink) FakeAppleRuleDescriptions.SWIFT_LIBRARY_DESCRIPTION.createBuildRule(TargetGraphFactory.newInstance(FakeTargetNodeBuilder.build(buildRule)), params.withBuildTarget(linkTarget), resolver, args);
assertThat(linkRule.getArgs(), Matchers.hasItem(objArg));
assertThat(linkRule.getArgs(), Matchers.not(Matchers.hasItem(SourcePathArg.of(fileListSourcePath))));
}
use of com.facebook.buck.cxx.CxxLink in project buck by facebook.
the class AppleLibraryDescriptionTest method linkerFlagsLocationMacro.
@Test
public void linkerFlagsLocationMacro() throws Exception {
assumeThat(Platform.detect(), is(Platform.MACOS));
BuildTarget sandboxTarget = BuildTargetFactory.newInstance("//:rule").withFlavors(CxxDescriptionEnhancer.SANDBOX_TREE_FLAVOR, DefaultCxxPlatforms.FLAVOR);
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(new AppleLibraryBuilder(sandboxTarget).build()), new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
BuildTarget target = BuildTargetFactory.newInstance("//:rule").withFlavors(DefaultCxxPlatforms.FLAVOR, CxxDescriptionEnhancer.SHARED_FLAVOR);
Genrule dep = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out").build(resolver);
AppleLibraryBuilder builder = new AppleLibraryBuilder(target).setLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("--linker-script=%s", LocationMacro.of(dep.getBuildTarget())))).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.c"))));
assertThat(builder.build().getExtraDeps(), Matchers.hasItem(dep.getBuildTarget()));
BuildRule binary = builder.build(resolver);
assertThat(binary, Matchers.instanceOf(CxxLink.class));
assertThat(Arg.stringify(((CxxLink) binary).getArgs(), pathResolver), Matchers.hasItem(String.format("--linker-script=%s", dep.getAbsoluteOutputFilePath(pathResolver))));
assertThat(binary.getDeps(), Matchers.hasItem(dep));
}
use of com.facebook.buck.cxx.CxxLink in project buck by facebook.
the class AppleTestDescriptionTest method linkerFlagsLocationMacro.
@Test
public void linkerFlagsLocationMacro() throws Exception {
assumeThat(Platform.detect(), is(Platform.MACOS));
GenruleBuilder depBuilder = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out");
AppleTestBuilder builder = new AppleTestBuilder(BuildTargetFactory.newInstance("//:rule#macosx-x86_64")).setLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("--linker-script=%s", LocationMacro.of(depBuilder.getTarget())))).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.c"))));
TargetGraph targetGraph = TargetGraphFactory.newInstance(builder.build(), depBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
Genrule dep = depBuilder.build(resolver, targetGraph);
assertThat(builder.build().getExtraDeps(), Matchers.hasItem(dep.getBuildTarget()));
AppleTest test = builder.build(resolver, targetGraph);
CxxStrip strip = (CxxStrip) RichStream.from(test.getDeps()).filter(AppleBundle.class).findFirst().get().getBinary().get();
BuildRule binary = strip.getDeps().first();
assertThat(binary, Matchers.instanceOf(CxxLink.class));
assertThat(Arg.stringify(((CxxLink) binary).getArgs(), pathResolver), Matchers.hasItem(String.format("--linker-script=%s", dep.getAbsoluteOutputFilePath(pathResolver))));
assertThat(binary.getDeps(), Matchers.hasItem(dep));
}
use of com.facebook.buck.cxx.CxxLink in project buck by facebook.
the class RelinkerRule method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
final ImmutableList.Builder<Step> relinkerSteps = ImmutableList.builder();
if (linker != null) {
ImmutableList<Arg> args = ImmutableList.<Arg>builder().addAll(linkerArgs).add(StringArg.of("-Wl,--version-script=" + getRelativeVersionFilePath().toString())).build();
relinkerSteps.addAll(new CxxLink(buildRuleParams.withAppendedFlavor(InternalFlavor.of("cxx-link")).withoutFlavor(LinkerMapMode.NO_LINKER_MAP.getFlavor()), linker, getLibFilePath(), args, cxxBuckConfig.getLinkScheduleInfo(), cxxBuckConfig.shouldCacheLinks()).getBuildSteps(context, buildableContext));
buildableContext.recordArtifact(getRelativeVersionFilePath());
}
buildableContext.recordArtifact(getSymbolsNeededOutPath());
return ImmutableList.of(new MakeCleanDirectoryStep(getProjectFilesystem(), getScratchDirPath()), new AbstractExecutionStep("xdso-dce relinker") {
@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException, InterruptedException {
ImmutableSet<String> symbolsNeeded = readSymbolsNeeded();
if (linker == null) {
getProjectFilesystem().copyFile(getBaseLibPath(), getLibFilePath());
buildableContext.recordArtifact(getLibFilePath());
} else {
writeVersionScript(context.getProcessExecutor(), symbolsNeeded);
for (Step s : relinkerSteps.build()) {
StepExecutionResult executionResult = s.execute(context);
if (!executionResult.isSuccess()) {
return StepExecutionResult.ERROR;
}
}
}
writeSymbols(getSymbolsNeededOutPath(), Sets.union(symbolsNeeded, getSymbols(context.getProcessExecutor(), getLibFilePath()).undefined));
return StepExecutionResult.SUCCESS;
}
});
}
Aggregations