Search in sources :

Example 1 with Arg

use of com.facebook.buck.rules.args.Arg in project buck by facebook.

the class AbstractPrebuiltCxxLibraryGroupDescription method getSharedLinkArgs.

/**
   * @return the link args formed from the user-provided shared link line after resolving library
   *         macro references.
   */
private Iterable<Arg> getSharedLinkArgs(BuildTarget target, ImmutableMap<String, SourcePath> libs, ImmutableList<String> args) {
    ImmutableList.Builder<Arg> builder = ImmutableList.builder();
    for (String arg : args) {
        Optional<Pair<String, String>> libRef = getLibRef(ImmutableSet.of(LIB_MACRO, REL_LIB_MACRO), arg);
        if (libRef.isPresent()) {
            SourcePath lib = libs.get(libRef.get().getSecond());
            if (lib == null) {
                throw new HumanReadableException("%s: library \"%s\" (in \"%s\") must refer to keys in the `sharedLibs` parameter", target, libRef.get().getSecond(), arg);
            }
            Arg libArg;
            if (libRef.get().getFirst().equals(LIB_MACRO)) {
                libArg = SourcePathArg.of(lib);
            } else if (libRef.get().getFirst().equals(REL_LIB_MACRO)) {
                if (!(lib instanceof PathSourcePath)) {
                    throw new HumanReadableException("%s: can only link prebuilt DSOs without sonames", target);
                }
                libArg = new RelativeLinkArg((PathSourcePath) lib);
            } else {
                throw new IllegalStateException();
            }
            builder.add(libArg);
        } else {
            builder.add(StringArg.of(arg));
        }
    }
    return builder.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) ImmutableList(com.google.common.collect.ImmutableList) HumanReadableException(com.facebook.buck.util.HumanReadableException) 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) Pair(com.facebook.buck.model.Pair)

Example 2 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 3 with Arg

use of com.facebook.buck.rules.args.Arg in project buck by facebook.

the class AbstractPrebuiltCxxLibraryGroupDescription method getStaticLinkArgs.

/**
   * @return the link args formed from the user-provided static link line after resolving library
   *         macro references.
   */
private Iterable<Arg> getStaticLinkArgs(BuildTarget target, ImmutableList<SourcePath> libs, ImmutableList<String> args) {
    ImmutableList.Builder<Arg> builder = ImmutableList.builder();
    for (String arg : args) {
        Optional<Pair<String, String>> libRef = getLibRef(ImmutableSet.of(LIB_MACRO), arg);
        if (libRef.isPresent()) {
            int index;
            try {
                index = Integer.parseInt(libRef.get().getSecond());
            } catch (NumberFormatException e) {
                throw new HumanReadableException("%s: ", target);
            }
            if (index < 0 || index >= libs.size()) {
                throw new HumanReadableException("%s: ", target);
            }
            builder.add(SourcePathArg.of(libs.get(index)));
        } else {
            builder.add(StringArg.of(arg));
        }
    }
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) HumanReadableException(com.facebook.buck.util.HumanReadableException) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) StringArg(com.facebook.buck.rules.args.StringArg) Arg(com.facebook.buck.rules.args.Arg) Pair(com.facebook.buck.model.Pair)

Example 4 with Arg

use of com.facebook.buck.rules.args.Arg in project buck by facebook.

the class OcamlBuildRulesGenerator method generateSingleMLBytecodeCompilation.

/**
   * Compiles a single .ml file to a .cmo
   */
private void generateSingleMLBytecodeCompilation(Map<Path, ImmutableSortedSet<BuildRule>> sourceToRule, ImmutableList.Builder<SourcePath> cmoFiles, Path mlSource, ImmutableMap<Path, ImmutableList<Path>> sources, ImmutableList<Path> cycleDetector) {
    ImmutableList<Path> newCycleDetector = ImmutableList.<Path>builder().addAll(cycleDetector).add(mlSource).build();
    if (cycleDetector.contains(mlSource)) {
        throw new HumanReadableException("Dependency cycle detected: %s", Joiner.on(" -> ").join(newCycleDetector));
    }
    if (sourceToRule.containsKey(mlSource)) {
        return;
    }
    ImmutableSortedSet.Builder<BuildRule> depsBuilder = ImmutableSortedSet.naturalOrder();
    if (sources.containsKey(mlSource)) {
        for (Path dep : checkNotNull(sources.get(mlSource))) {
            generateSingleMLBytecodeCompilation(sourceToRule, cmoFiles, dep, sources, newCycleDetector);
            depsBuilder.addAll(checkNotNull(sourceToRule.get(dep)));
        }
    }
    ImmutableSortedSet<BuildRule> deps = depsBuilder.build();
    String name = mlSource.toFile().getName();
    BuildTarget buildTarget = createMLBytecodeCompileBuildTarget(params.getBuildTarget(), name);
    BuildRuleParams compileParams = params.withBuildTarget(buildTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().add(this.cleanRule).addAll(params.getDeclaredDeps().get()).addAll(deps).addAll(ocamlContext.getBytecodeCompileDeps()).addAll(cCompiler.getDeps(ruleFinder)).build()), params.getExtraDeps());
    String outputFileName = getMLBytecodeOutputName(name);
    Path outputPath = ocamlContext.getCompileBytecodeOutputDir().resolve(outputFileName);
    final ImmutableList<Arg> compileFlags = getCompileFlags(/* isBytecode */
    true, /* excludeDeps */
    false);
    BuildRule compileBytecode = new OcamlMLCompile(compileParams, new OcamlMLCompileStep.Args(params.getProjectFilesystem()::resolve, cCompiler.getEnvironment(pathResolver), cCompiler.getCommandPrefix(pathResolver), ocamlContext.getOcamlBytecodeCompiler().get(), ocamlContext.getOcamlInteropIncludesDir(), outputPath, mlSource, compileFlags));
    resolver.addToIndex(compileBytecode);
    sourceToRule.put(mlSource, ImmutableSortedSet.<BuildRule>naturalOrder().add(compileBytecode).addAll(deps).build());
    if (!outputFileName.endsWith(OcamlCompilables.OCAML_CMI)) {
        cmoFiles.add(compileBytecode.getSourcePathToOutput());
    }
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) StringArg(com.facebook.buck.rules.args.StringArg) Arg(com.facebook.buck.rules.args.Arg) BuildRule(com.facebook.buck.rules.BuildRule)

Example 5 with Arg

use of com.facebook.buck.rules.args.Arg in project buck by facebook.

the class OcamlBuildRulesGenerator method generateNativeLinking.

/**
   * Links the .cmx files generated by the native compilation
   */
private BuildRule generateNativeLinking(ImmutableList<SourcePath> allInputs) {
    BuildRuleParams linkParams = params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(ruleFinder.filterBuildRuleInputs(allInputs)).addAll(ocamlContext.getNativeLinkableInput().getArgs().stream().flatMap(arg -> arg.getDeps(ruleFinder).stream()).iterator()).addAll(ocamlContext.getCLinkableInput().getArgs().stream().flatMap(arg -> arg.getDeps(ruleFinder).stream()).iterator()).addAll(cxxCompiler.getDeps(ruleFinder)).build()), Suppliers.ofInstance(ImmutableSortedSet.of()));
    ImmutableList.Builder<Arg> flags = ImmutableList.builder();
    flags.addAll(ocamlContext.getFlags());
    flags.addAll(StringArg.from(ocamlContext.getCommonCLinkerFlags()));
    OcamlLink link = new OcamlLink(linkParams, allInputs, cxxCompiler.getEnvironment(pathResolver), cxxCompiler.getCommandPrefix(pathResolver), ocamlContext.getOcamlCompiler().get(), flags.build(), ocamlContext.getOcamlInteropIncludesDir(), ocamlContext.getNativeOutput(), ocamlContext.getNativePluginOutput(), ocamlContext.getNativeLinkableInput().getArgs(), ocamlContext.getCLinkableInput().getArgs(), ocamlContext.isLibrary(), /* isBytecode */
    false, buildNativePlugin);
    resolver.addToIndex(link);
    return link;
}
Also used : Iterables(com.google.common.collect.Iterables) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePath(com.facebook.buck.rules.SourcePath) InternalFlavor(com.facebook.buck.model.InternalFlavor) BuildRule(com.facebook.buck.rules.BuildRule) Compiler(com.facebook.buck.cxx.Compiler) ImmutableList(com.google.common.collect.ImmutableList) Files(com.google.common.io.Files) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) StringArg(com.facebook.buck.rules.args.StringArg) Map(java.util.Map) Suppliers(com.google.common.base.Suppliers) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ImmutableMap(com.google.common.collect.ImmutableMap) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget) Maps(com.google.common.collect.Maps) Arg(com.facebook.buck.rules.args.Arg) Stream(java.util.stream.Stream) CxxPreprocessorInput(com.facebook.buck.cxx.CxxPreprocessorInput) Preconditions(com.google.common.base.Preconditions) Flavor(com.facebook.buck.model.Flavor) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Joiner(com.google.common.base.Joiner) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) ImmutableList(com.google.common.collect.ImmutableList) StringArg(com.facebook.buck.rules.args.StringArg) Arg(com.facebook.buck.rules.args.Arg)

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