use of com.facebook.buck.rules.args.Arg in project buck by facebook.
the class Omnibus method createOmnibus.
// Create a build rule to link the giant merged omnibus library described by the given spec.
protected static OmnibusLibrary createOmnibus(BuildRuleParams params, BuildRuleResolver ruleResolver, SourcePathRuleFinder ruleFinder, CxxBuckConfig cxxBuckConfig, CxxPlatform cxxPlatform, ImmutableList<? extends Arg> extraLdflags, OmnibusSpec spec) throws NoSuchBuildTargetException {
ImmutableList.Builder<Arg> argsBuilder = ImmutableList.builder();
// Add extra ldflags to the beginning of the link.
argsBuilder.addAll(extraLdflags);
// For roots that aren't dependencies of nodes in the body, we extract their undefined symbols
// to add to the link so that required symbols get pulled into the merged library.
List<SourcePath> undefinedSymbolsOnlyRoots = new ArrayList<>();
for (BuildTarget target : Sets.difference(spec.getRoots().keySet(), spec.getGraph().getNodes())) {
NativeLinkTarget linkTarget = Preconditions.checkNotNull(spec.getRoots().get(target));
undefinedSymbolsOnlyRoots.add(ruleResolver.requireRule(getRootTarget(params.getBuildTarget(), shouldCreateDummyRoot(linkTarget, cxxPlatform) ? getDummyRootTarget(target) : target)).getSourcePathToOutput());
}
argsBuilder.addAll(createUndefinedSymbolsArgs(params, ruleResolver, ruleFinder, cxxPlatform, undefinedSymbolsOnlyRoots));
// Walk the graph in topological order, appending each nodes contributions to the link.
ImmutableList<BuildTarget> targets = TopologicalSort.sort(spec.getGraph()).reverse();
for (BuildTarget target : targets) {
// If this is a root, just place the shared library we've linked above onto the link line.
// We need this so that the linker can grab any undefined symbols from it, and therefore
// know which symbols to pull in from the body nodes.
NativeLinkTarget root = spec.getRoots().get(target);
if (root != null) {
argsBuilder.add(SourcePathArg.of(((CxxLink) ruleResolver.requireRule(getRootTarget(params.getBuildTarget(), root.getBuildTarget()))).getSourcePathToOutput()));
continue;
}
// Otherwise, this is a body node, and we need to add its static library to the link line,
// so that the linker can discard unused object files from it.
NativeLinkable nativeLinkable = Preconditions.checkNotNull(spec.getBody().get(target));
NativeLinkableInput input = NativeLinkables.getNativeLinkableInput(cxxPlatform, Linker.LinkableDepType.STATIC_PIC, nativeLinkable);
argsBuilder.addAll(input.getArgs());
}
// We process all excluded omnibus deps last, and just add their components as if this were a
// normal shared link.
ImmutableMap<BuildTarget, NativeLinkable> deps = NativeLinkables.getNativeLinkables(cxxPlatform, spec.getDeps().values(), Linker.LinkableDepType.SHARED);
for (NativeLinkable nativeLinkable : deps.values()) {
NativeLinkableInput input = NativeLinkables.getNativeLinkableInput(cxxPlatform, Linker.LinkableDepType.SHARED, nativeLinkable);
argsBuilder.addAll(input.getArgs());
}
// Create the merged omnibus library using the arguments assembled above.
BuildTarget omnibusTarget = params.getBuildTarget().withAppendedFlavors(OMNIBUS_FLAVOR);
String omnibusSoname = getOmnibusSoname(cxxPlatform);
CxxLink omnibusRule = ruleResolver.addToIndex(CxxLinkableEnhancer.createCxxLinkableSharedBuildRule(cxxBuckConfig, cxxPlatform, params, ruleResolver, ruleFinder, omnibusTarget, BuildTargets.getGenPath(params.getProjectFilesystem(), omnibusTarget, "%s").resolve(omnibusSoname), Optional.of(omnibusSoname), argsBuilder.build()));
return OmnibusLibrary.of(omnibusSoname, omnibusRule.getSourcePathToOutput());
}
use of com.facebook.buck.rules.args.Arg in project buck by facebook.
the class ReDexStepTest method constructorArgsAreUsedToCreateShellCommand.
@Test
public void constructorArgsAreUsedToCreateShellCommand() {
Path workingDirectory = Paths.get("/where/the/code/is");
List<String> redexBinaryArgs = ImmutableList.of("/usr/bin/redex");
Map<String, String> redexEnvironmentVariables = ImmutableMap.of("REDEX_DEBUG", "1");
Path inputApkPath = Paths.get("buck-out/gen/app.apk.zipalign");
Path outputApkPath = Paths.get("buck-out/gen/app.apk");
Path keystorePath = Paths.get("keystores/debug.keystore");
KeystoreProperties keystoreProperties = new KeystoreProperties(keystorePath, "storepass", "keypass", "alias");
Supplier<KeystoreProperties> keystorePropertiesSupplier = Suppliers.ofInstance(keystoreProperties);
Path redexConfigPath = Paths.get("redex/redex-config.json");
Optional<Path> redexConfig = Optional.of(redexConfigPath);
ImmutableList<Arg> redexExtraArgs = ImmutableList.of(StringArg.of("foo"), StringArg.of("bar"));
Path proguardMap = Paths.get("buck-out/gen/app/__proguard__/mapping.txt");
Path proguardConfig = Paths.get("app.proguard.config");
Path seeds = Paths.get("buck-out/gen/app/__proguard__/seeds.txt");
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
ReDexStep redex = new ReDexStep(workingDirectory, redexBinaryArgs, redexEnvironmentVariables, inputApkPath, outputApkPath, keystorePropertiesSupplier, redexConfig, redexExtraArgs, proguardMap, proguardConfig, seeds, pathResolver);
assertEquals("redex", redex.getShortName());
AndroidPlatformTarget androidPlatform = EasyMock.createMock(AndroidPlatformTarget.class);
Path sdkDirectory = Paths.get("/Users/user/android-sdk-macosx");
EasyMock.expect(androidPlatform.getSdkDirectory()).andReturn(Optional.of(sdkDirectory));
EasyMock.replay(androidPlatform);
ExecutionContext context = TestExecutionContext.newBuilder().setAndroidPlatformTargetSupplier(Suppliers.ofInstance(androidPlatform)).build();
assertEquals(ImmutableMap.of("ANDROID_SDK", sdkDirectory.toString(), "REDEX_DEBUG", "1"), redex.getEnvironmentVariables(context));
EasyMock.verify(androidPlatform);
assertEquals(ImmutableList.of("/usr/bin/redex", "--config", redexConfigPath.toString(), "--sign", "--keystore", keystorePath.toString(), "--keyalias", "alias", "--keypass", "keypass", "--proguard-map", proguardMap.toString(), "-P", proguardConfig.toString(), "--keep", seeds.toString(), "--out", outputApkPath.toString(), "foo", "bar", inputApkPath.toString()), redex.getShellCommandInternal(context));
}
use of com.facebook.buck.rules.args.Arg in project buck by facebook.
the class CxxLinkableEnhancerTest method frameworksToLinkerFlagsTransformer.
@Test
public void frameworksToLinkerFlagsTransformer() {
ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
SourcePathResolver resolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
Arg linkerFlags = CxxLinkableEnhancer.frameworksToLinkerArg(ImmutableSortedSet.of(FrameworkPath.ofSourceTreePath(new SourceTreePath(PBXReference.SourceTree.DEVELOPER_DIR, Paths.get("Library/Frameworks/XCTest.framework"), Optional.empty())), FrameworkPath.ofSourcePath(new PathSourcePath(projectFilesystem, Paths.get("Vendor/Bar/Bar.framework")))));
assertEquals(ImmutableList.of("-framework", "XCTest", "-framework", "Bar"), Arg.stringifyList(linkerFlags, resolver));
}
use of com.facebook.buck.rules.args.Arg in project buck by facebook.
the class CxxPrepareForLinkStepTest method testCreateCxxPrepareForLinkStep.
@Test
public void testCreateCxxPrepareForLinkStep() throws Exception {
Path dummyPath = Paths.get("dummy");
BuildRuleResolver buildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(buildRuleResolver));
// Setup some dummy values for inputs to the CxxLinkStep
ImmutableList<Arg> dummyArgs = ImmutableList.of(FileListableLinkerInputArg.withSourcePathArg(SourcePathArg.of(new FakeSourcePath("libb.a"))));
CxxPrepareForLinkStep cxxPrepareForLinkStepSupportFileList = CxxPrepareForLinkStep.create(dummyPath, dummyPath, ImmutableList.of(StringArg.of("-filelist"), StringArg.of(dummyPath.toString())), dummyPath, dummyArgs, CxxPlatformUtils.DEFAULT_PLATFORM.getLd().resolve(buildRuleResolver), dummyPath, pathResolver);
ImmutableList<Step> containingSteps = ImmutableList.copyOf(cxxPrepareForLinkStepSupportFileList.iterator());
assertThat(containingSteps.size(), Matchers.equalTo(2));
Step firstStep = containingSteps.get(0);
Step secondStep = containingSteps.get(1);
assertThat(firstStep, Matchers.instanceOf(CxxWriteArgsToFileStep.class));
assertThat(secondStep, Matchers.instanceOf(CxxWriteArgsToFileStep.class));
assertThat(firstStep, Matchers.not(secondStep));
CxxPrepareForLinkStep cxxPrepareForLinkStepNoSupportFileList = CxxPrepareForLinkStep.create(dummyPath, dummyPath, ImmutableList.of(), dummyPath, dummyArgs, CxxPlatformUtils.DEFAULT_PLATFORM.getLd().resolve(buildRuleResolver), dummyPath, pathResolver);
containingSteps = ImmutableList.copyOf(cxxPrepareForLinkStepNoSupportFileList.iterator());
assertThat(containingSteps.size(), Matchers.equalTo(1));
assertThat(containingSteps.get(0), Matchers.instanceOf(CxxWriteArgsToFileStep.class));
}
use of com.facebook.buck.rules.args.Arg 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)));
}
Aggregations