Search in sources :

Example 11 with Arg

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());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) SourcePath(com.facebook.buck.rules.SourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) StringArg(com.facebook.buck.rules.args.StringArg) Arg(com.facebook.buck.rules.args.Arg)

Example 12 with Arg

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));
}
Also used : Path(java.nio.file.Path) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AndroidPlatformTarget(com.facebook.buck.android.AndroidPlatformTarget) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) Arg(com.facebook.buck.rules.args.Arg) StringArg(com.facebook.buck.rules.args.StringArg) KeystoreProperties(com.facebook.buck.android.KeystoreProperties) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 13 with Arg

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));
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) StringArg(com.facebook.buck.rules.args.StringArg) Arg(com.facebook.buck.rules.args.Arg) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 14 with Arg

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));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) StringArg(com.facebook.buck.rules.args.StringArg) FileListableLinkerInputArg(com.facebook.buck.rules.args.FileListableLinkerInputArg) Arg(com.facebook.buck.rules.args.Arg) Step(com.facebook.buck.step.Step) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 15 with Arg

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)));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) Linker(com.facebook.buck.cxx.Linker) Matchers.not(org.hamcrest.Matchers.not) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) Matchers.hasItems(org.hamcrest.Matchers.hasItems) Assert.assertThat(org.junit.Assert.assertThat) BuildRule(com.facebook.buck.rules.BuildRule) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) CxxPlatformUtils(com.facebook.buck.cxx.CxxPlatformUtils) ImmutableList(com.google.common.collect.ImmutableList) FluentIterable(com.google.common.collect.FluentIterable) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) StringArg(com.facebook.buck.rules.args.StringArg) BuildTargetFactory(com.facebook.buck.model.BuildTargetFactory) NativeLinkable(com.facebook.buck.cxx.NativeLinkable) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Predicates(com.google.common.base.Predicates) SourceList(com.facebook.buck.rules.coercer.SourceList) Path(java.nio.file.Path) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ImmutableSet(com.google.common.collect.ImmutableSet) NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) Arg(com.facebook.buck.rules.args.Arg) TargetGraphFactory(com.facebook.buck.testutil.TargetGraphFactory) Preconditions(com.google.common.base.Preconditions) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Aggregations

Arg (com.facebook.buck.rules.args.Arg)28 StringArg (com.facebook.buck.rules.args.StringArg)21 BuildTarget (com.facebook.buck.model.BuildTarget)14 ImmutableList (com.google.common.collect.ImmutableList)14 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)13 SourcePath (com.facebook.buck.rules.SourcePath)13 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)13 BuildRule (com.facebook.buck.rules.BuildRule)12 SourcePathArg (com.facebook.buck.rules.args.SourcePathArg)12 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)11 Path (java.nio.file.Path)11 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)10 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)10 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)8 Test (org.junit.Test)8 HumanReadableException (com.facebook.buck.util.HumanReadableException)7 Linker (com.facebook.buck.cxx.Linker)6 InternalFlavor (com.facebook.buck.model.InternalFlavor)6 ImmutableMap (com.google.common.collect.ImmutableMap)6 CxxPreprocessorInput (com.facebook.buck.cxx.CxxPreprocessorInput)5