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();
}
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()));
}
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;
}
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);
}
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);
}
};
}
Aggregations