Search in sources :

Example 21 with Tool

use of com.facebook.buck.rules.Tool in project buck by facebook.

the class ReDexStep method createSteps.

public static ImmutableList<Step> createSteps(final ProjectFilesystem filesystem, SourcePathResolver resolver, RedexOptions redexOptions, Path inputApkPath, Path outputApkPath, Supplier<KeystoreProperties> keystorePropertiesSupplier, Path proguardConfigDir, SourcePathResolver pathResolver) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    Tool redexBinary = redexOptions.getRedex();
    ReDexStep redexStep = new ReDexStep(filesystem.getRootPath(), redexBinary.getCommandPrefix(resolver), redexBinary.getEnvironment(resolver), inputApkPath, outputApkPath, keystorePropertiesSupplier, redexOptions.getRedexConfig().map(resolver::getAbsolutePath), redexOptions.getRedexExtraArgs(), proguardConfigDir.resolve("mapping.txt"), proguardConfigDir.resolve("command-line.txt"), proguardConfigDir.resolve("seeds.txt"), pathResolver);
    steps.add(redexStep);
    return steps.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Step(com.facebook.buck.step.Step) ShellStep(com.facebook.buck.shell.ShellStep) Tool(com.facebook.buck.rules.Tool)

Example 22 with Tool

use of com.facebook.buck.rules.Tool in project buck by facebook.

the class HaskellDescriptionUtils method createLinkRule.

/**
   * Create a Haskell link rule that links the given inputs to a executable or shared library and
   * pulls in transitive native linkable deps from the given dep roots.
   */
public static HaskellLinkRule createLinkRule(BuildTarget target, BuildRuleParams baseParams, BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder, CxxPlatform cxxPlatform, HaskellConfig haskellConfig, Linker.LinkType linkType, ImmutableList<String> extraFlags, Iterable<Arg> linkerInputs, Iterable<? extends NativeLinkable> deps, Linker.LinkableDepType depType) throws NoSuchBuildTargetException {
    Tool linker = haskellConfig.getLinker().resolve(resolver);
    String name = target.getShortName();
    ImmutableList.Builder<Arg> linkerArgsBuilder = ImmutableList.builder();
    ImmutableList.Builder<Arg> argsBuilder = ImmutableList.builder();
    // Add the base flags from the `.buckconfig` first.
    argsBuilder.addAll(StringArg.from(haskellConfig.getLinkerFlags()));
    // Pass in the appropriate flags to link a shared library.
    if (linkType.equals(Linker.LinkType.SHARED)) {
        name = CxxDescriptionEnhancer.getSharedLibrarySoname(Optional.empty(), target.withFlavors(), cxxPlatform);
        argsBuilder.addAll(StringArg.from("-shared", "-dynamic"));
        argsBuilder.addAll(StringArg.from(MoreIterables.zipAndConcat(Iterables.cycle("-optl"), cxxPlatform.getLd().resolve(resolver).soname(name))));
    }
    // Add in extra flags passed into this function.
    argsBuilder.addAll(StringArg.from(extraFlags));
    // We pass in the linker inputs and all native linkable deps by prefixing with `-optl` so that
    // the args go straight to the linker, and preserve their order.
    linkerArgsBuilder.addAll(linkerInputs);
    for (NativeLinkable nativeLinkable : NativeLinkables.getNativeLinkables(cxxPlatform, deps, depType).values()) {
        linkerArgsBuilder.addAll(NativeLinkables.getNativeLinkableInput(cxxPlatform, depType, nativeLinkable).getArgs());
    }
    // Since we use `-optl` to pass all linker inputs directly to the linker, the haskell linker
    // will complain about not having any input files.  So, create a dummy archive with an empty
    // module and pass that in normally to work around this.
    BuildTarget emptyModuleTarget = target.withAppendedFlavors(InternalFlavor.of("empty-module"));
    WriteFile emptyModule = resolver.addToIndex(new WriteFile(baseParams.withBuildTarget(emptyModuleTarget), "module Unused where", BuildTargets.getGenPath(baseParams.getProjectFilesystem(), emptyModuleTarget, "%s/Unused.hs"), /* executable */
    false));
    HaskellCompileRule emptyCompiledModule = resolver.addToIndex(createCompileRule(target.withAppendedFlavors(InternalFlavor.of("empty-compiled-module")), baseParams, resolver, ruleFinder, // Buck dependency.
    baseParams.getDeps(), cxxPlatform, haskellConfig, depType, Optional.empty(), Optional.empty(), ImmutableList.of(), HaskellSources.builder().putModuleMap("Unused", emptyModule.getSourcePathToOutput()).build()));
    BuildTarget emptyArchiveTarget = target.withAppendedFlavors(InternalFlavor.of("empty-archive"));
    Archive emptyArchive = resolver.addToIndex(Archive.from(emptyArchiveTarget, baseParams, ruleFinder, cxxPlatform, Archive.Contents.NORMAL, BuildTargets.getGenPath(baseParams.getProjectFilesystem(), emptyArchiveTarget, "%s/libempty.a"), emptyCompiledModule.getObjects()));
    argsBuilder.add(SourcePathArg.of(emptyArchive.getSourcePathToOutput()));
    ImmutableList<Arg> args = argsBuilder.build();
    ImmutableList<Arg> linkerArgs = linkerArgsBuilder.build();
    return resolver.addToIndex(new HaskellLinkRule(baseParams.withBuildTarget(target).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(linker.getDeps(ruleFinder)).addAll(Stream.of(args, linkerArgs).flatMap(Collection::stream).flatMap(arg -> arg.getDeps(ruleFinder).stream()).iterator()).build()), Suppliers.ofInstance(ImmutableSortedSet.of())), linker, name, args, linkerArgs, haskellConfig.shouldCacheLinks()));
}
Also used : NativeLinkables(com.facebook.buck.cxx.NativeLinkables) Iterables(com.google.common.collect.Iterables) Linker(com.facebook.buck.cxx.Linker) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) Archive(com.facebook.buck.cxx.Archive) SourcePath(com.facebook.buck.rules.SourcePath) InternalFlavor(com.facebook.buck.model.InternalFlavor) ExplicitCxxToolFlags(com.facebook.buck.cxx.ExplicitCxxToolFlags) BuildRule(com.facebook.buck.rules.BuildRule) CxxSourceTypes(com.facebook.buck.cxx.CxxSourceTypes) AbstractBreadthFirstThrowingTraversal(com.facebook.buck.graph.AbstractBreadthFirstThrowingTraversal) Tool(com.facebook.buck.rules.Tool) ImmutableList(com.google.common.collect.ImmutableList) CxxPlatforms(com.facebook.buck.cxx.CxxPlatforms) CxxPreprocessables(com.facebook.buck.cxx.CxxPreprocessables) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) StringArg(com.facebook.buck.rules.args.StringArg) Map(java.util.Map) CxxToolFlags(com.facebook.buck.cxx.CxxToolFlags) WriteFile(com.facebook.buck.file.WriteFile) NativeLinkable(com.facebook.buck.cxx.NativeLinkable) Suppliers(com.google.common.base.Suppliers) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) CxxDescriptionEnhancer(com.facebook.buck.cxx.CxxDescriptionEnhancer) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) CxxSourceRuleFactory(com.facebook.buck.cxx.CxxSourceRuleFactory) ImmutableSet(com.google.common.collect.ImmutableSet) Collection(java.util.Collection) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) CxxSource(com.facebook.buck.cxx.CxxSource) BuildTarget(com.facebook.buck.model.BuildTarget) Arg(com.facebook.buck.rules.args.Arg) Stream(java.util.stream.Stream) TreeMap(java.util.TreeMap) CxxPreprocessorInput(com.facebook.buck.cxx.CxxPreprocessorInput) PreprocessorFlags(com.facebook.buck.cxx.PreprocessorFlags) Optional(java.util.Optional) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTargets(com.facebook.buck.model.BuildTargets) MoreIterables(com.facebook.buck.util.MoreIterables) WriteFile(com.facebook.buck.file.WriteFile) Archive(com.facebook.buck.cxx.Archive) ImmutableList(com.google.common.collect.ImmutableList) NativeLinkable(com.facebook.buck.cxx.NativeLinkable) 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) Collection(java.util.Collection) Tool(com.facebook.buck.rules.Tool)

Example 23 with Tool

use of com.facebook.buck.rules.Tool in project buck by facebook.

the class GoTestDescription method requireTestMainGenRule.

private GoTestMain requireTestMainGenRule(BuildRuleParams params, BuildRuleResolver resolver, ImmutableSet<SourcePath> srcs, Path packageName) throws NoSuchBuildTargetException {
    Tool testMainGenerator = GoDescriptors.getTestMainGenerator(goBuckConfig, params, resolver);
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    GoTestMain generatedTestMain = new GoTestMain(params.withAppendedFlavor(InternalFlavor.of("test-main-src")).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.copyOf(testMainGenerator.getDeps(ruleFinder))), Suppliers.ofInstance(ImmutableSortedSet.of())), testMainGenerator, srcs, packageName);
    resolver.addToIndex(generatedTestMain);
    return generatedTestMain;
}
Also used : SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) Tool(com.facebook.buck.rules.Tool)

Example 24 with Tool

use of com.facebook.buck.rules.Tool in project buck by facebook.

the class LuaBinaryDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, final BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    CxxPlatform cxxPlatform = cxxPlatforms.getValue(params.getBuildTarget()).orElse(defaultCxxPlatform);
    PythonPlatform pythonPlatform = pythonPlatforms.getValue(params.getBuildTarget()).orElse(pythonPlatforms.getValue(args.pythonPlatform.<Flavor>map(InternalFlavor::of).orElse(pythonPlatforms.getFlavors().iterator().next())));
    LuaBinaryPackageComponents components = getPackageComponentsFromDeps(params, resolver, pathResolver, ruleFinder, cxxPlatform, pythonPlatform, args.nativeStarterLibrary.map(Optional::of).orElse(luaConfig.getNativeStarterLibrary()), args.mainModule, args.packageStyle.orElse(luaConfig.getPackageStyle()), params.getDeclaredDeps().get());
    LuaConfig.PackageStyle packageStyle = args.packageStyle.orElse(luaConfig.getPackageStyle());
    Tool binary = getBinary(params, resolver, ruleFinder, cxxPlatform, args.mainModule, components.getStarter(), components.getComponents(), packageStyle);
    return new LuaBinary(params.copyAppendingExtraDeps(binary.getDeps(ruleFinder)), ruleFinder, getOutputPath(params.getBuildTarget(), params.getProjectFilesystem()), binary, args.mainModule, components.getComponents(), luaConfig.getLua(resolver), packageStyle);
}
Also used : PythonPlatform(com.facebook.buck.python.PythonPlatform) Optional(java.util.Optional) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Tool(com.facebook.buck.rules.Tool) CommandTool(com.facebook.buck.rules.CommandTool)

Example 25 with Tool

use of com.facebook.buck.rules.Tool in project buck by facebook.

the class LuaBinaryDescription method getInPlaceBinary.

private Tool getInPlaceBinary(BuildRuleParams params, BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder, CxxPlatform cxxPlatform, final SourcePath starter, final LuaPackageComponents components) {
    final List<SourcePath> extraInputs = new ArrayList<>();
    final SymlinkTree modulesLinkTree = resolver.addToIndex(createSymlinkTree(getModulesSymlinkTreeTarget(params.getBuildTarget()), params.getProjectFilesystem(), resolver, ruleFinder, getModulesSymlinkTreeRoot(params.getBuildTarget(), params.getProjectFilesystem()), components.getModules()));
    final List<SymlinkTree> pythonModulesLinktree = new ArrayList<>();
    if (!components.getPythonModules().isEmpty()) {
        // Add in any missing init modules into the python components.
        SourcePath emptyInit = PythonBinaryDescription.createEmptyInitModule(params, resolver);
        extraInputs.add(emptyInit);
        ImmutableMap<String, SourcePath> pythonModules = MoreMaps.transformKeys(PythonBinaryDescription.addMissingInitModules(MoreMaps.transformKeys(components.getPythonModules(), MorePaths.toPathFn(params.getProjectFilesystem().getRootPath().getFileSystem())), emptyInit), Object::toString);
        final SymlinkTree symlinkTree = resolver.addToIndex(createSymlinkTree(getPythonModulesSymlinkTreeTarget(params.getBuildTarget()), params.getProjectFilesystem(), resolver, ruleFinder, getPythonModulesSymlinkTreeRoot(params.getBuildTarget(), params.getProjectFilesystem()), pythonModules));
        pythonModulesLinktree.add(symlinkTree);
    }
    final List<SymlinkTree> nativeLibsLinktree = new ArrayList<>();
    if (!components.getNativeLibraries().isEmpty()) {
        SymlinkTree symlinkTree = resolver.addToIndex(createSymlinkTree(getNativeLibsSymlinkTreeTarget(params.getBuildTarget()), params.getProjectFilesystem(), resolver, ruleFinder, getNativeLibsSymlinkTreeRoot(params.getBuildTarget(), params.getProjectFilesystem()), addVersionLessLibraries(cxxPlatform, components.getNativeLibraries())));
        nativeLibsLinktree.add(symlinkTree);
    }
    return new Tool() {

        @Override
        public ImmutableCollection<BuildRule> getDeps(SourcePathRuleFinder ruleFinder) {
            return ImmutableSortedSet.<BuildRule>naturalOrder().addAll(ruleFinder.filterBuildRuleInputs(starter)).addAll(components.getDeps(ruleFinder)).add(modulesLinkTree).addAll(nativeLibsLinktree).addAll(pythonModulesLinktree).addAll(ruleFinder.filterBuildRuleInputs(extraInputs)).build();
        }

        @Override
        public ImmutableCollection<SourcePath> getInputs() {
            return ImmutableSortedSet.<SourcePath>naturalOrder().add(starter).addAll(components.getInputs()).addAll(extraInputs).build();
        }

        @Override
        public ImmutableList<String> getCommandPrefix(SourcePathResolver resolver) {
            return ImmutableList.of(resolver.getAbsolutePath(starter).toString());
        }

        @Override
        public ImmutableMap<String, String> getEnvironment(SourcePathResolver resolver) {
            return ImmutableMap.of();
        }

        @Override
        public void appendToRuleKey(RuleKeyObjectSink sink) {
            sink.setReflectively("starter", starter).setReflectively("components", components);
        }
    };
}
Also used : ArrayList(java.util.ArrayList) RuleKeyObjectSink(com.facebook.buck.rules.RuleKeyObjectSink) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePath(com.facebook.buck.rules.SourcePath) SymlinkTree(com.facebook.buck.rules.SymlinkTree) BuildRule(com.facebook.buck.rules.BuildRule) Tool(com.facebook.buck.rules.Tool) CommandTool(com.facebook.buck.rules.CommandTool)

Aggregations

Tool (com.facebook.buck.rules.Tool)30 BuildTarget (com.facebook.buck.model.BuildTarget)14 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)12 Test (org.junit.Test)12 CommandTool (com.facebook.buck.rules.CommandTool)11 BuildRule (com.facebook.buck.rules.BuildRule)10 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)9 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)9 SourcePath (com.facebook.buck.rules.SourcePath)8 Path (java.nio.file.Path)8 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)7 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)6 VersionedTool (com.facebook.buck.rules.VersionedTool)5 ImmutableList (com.google.common.collect.ImmutableList)5 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)4 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)4 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)4 HashedFileTool (com.facebook.buck.rules.HashedFileTool)4 HumanReadableException (com.facebook.buck.util.HumanReadableException)4 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)3