use of com.facebook.buck.rules.SymlinkTree in project buck by facebook.
the class AndroidResourceDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, final BuildRuleResolver resolver, A args) {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
if (params.getBuildTarget().getFlavors().contains(RESOURCES_SYMLINK_TREE_FLAVOR)) {
return createSymlinkTree(ruleFinder, params, args.res, "res");
} else if (params.getBuildTarget().getFlavors().contains(ASSETS_SYMLINK_TREE_FLAVOR)) {
return createSymlinkTree(ruleFinder, params, args.assets, "assets");
}
// Only allow android resource and library rules as dependencies.
Optional<BuildRule> invalidDep = params.getDeclaredDeps().get().stream().filter(rule -> !(rule instanceof AndroidResource || rule instanceof AndroidLibrary)).findFirst();
if (invalidDep.isPresent()) {
throw new HumanReadableException(params.getBuildTarget() + " (android_resource): dependency " + invalidDep.get().getBuildTarget() + " (" + invalidDep.get().getType() + ") is not of type android_resource or android_library.");
}
// We don't handle the resources parameter well in `AndroidResource` rules, as instead of
// hashing the contents of the entire resources directory, we try to filter out anything that
// doesn't look like a resource. This means when our resources are supplied from another rule,
// we have to resort to some hackery to make sure things work correctly.
Pair<Optional<SymlinkTree>, Optional<SourcePath>> resInputs = collectInputSourcePaths(resolver, params.getBuildTarget(), RESOURCES_SYMLINK_TREE_FLAVOR, args.res);
Pair<Optional<SymlinkTree>, Optional<SourcePath>> assetsInputs = collectInputSourcePaths(resolver, params.getBuildTarget(), ASSETS_SYMLINK_TREE_FLAVOR, args.assets);
params = params.copyAppendingExtraDeps(Iterables.concat(resInputs.getSecond().map(ruleFinder::filterBuildRuleInputs).orElse(ImmutableSet.of()), assetsInputs.getSecond().map(ruleFinder::filterBuildRuleInputs).orElse(ImmutableSet.of())));
return new AndroidResource(// step.
params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(AndroidResourceHelper.androidResOnly(params.getDeclaredDeps().get())), params.getExtraDeps()), ruleFinder, resolver.getAllRules(args.deps), resInputs.getSecond().orElse(null), resInputs.getFirst().map(SymlinkTree::getLinks).orElse(ImmutableSortedMap.of()), args.rDotJavaPackage.orElse(null), assetsInputs.getSecond().orElse(null), assetsInputs.getFirst().map(SymlinkTree::getLinks).orElse(ImmutableSortedMap.of()), args.manifest.orElse(null), args.hasWhitelistedStrings.orElse(false), args.resourceUnion.orElse(false), isGrayscaleImageProcessingEnabled);
}
use of com.facebook.buck.rules.SymlinkTree in project buck by facebook.
the class HaskellBinaryDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
CxxPlatform cxxPlatform = cxxPlatforms.getValue(params.getBuildTarget()).orElse(defaultCxxPlatform);
Linker.LinkableDepType depType = getLinkStyle(params.getBuildTarget(), args);
// The target to use for the link rule.
BuildTarget binaryTarget = params.getBuildTarget().withFlavors(InternalFlavor.of("binary"));
// Maintain backwards compatibility to ease upgrade flows.
if (haskellConfig.shouldUsedOldBinaryOutputLocation().orElse(true)) {
binaryTarget = binaryTarget.withAppendedFlavors(cxxPlatform.getFlavor());
}
ImmutableSet.Builder<BuildRule> depsBuilder = ImmutableSet.builder();
params.getDeclaredDeps().get().stream().filter(NativeLinkable.class::isInstance).forEach(depsBuilder::add);
args.depsQuery.ifPresent(depsQuery -> QueryUtils.resolveDepQuery(params, depsQuery, resolver, targetGraph).filter(NativeLinkable.class::isInstance).forEach(depsBuilder::add));
ImmutableSet<BuildRule> deps = depsBuilder.build();
ImmutableList.Builder<String> linkFlagsBuilder = ImmutableList.builder();
ImmutableList.Builder<com.facebook.buck.rules.args.Arg> linkArgsBuilder = ImmutableList.builder();
CommandTool.Builder executableBuilder = new CommandTool.Builder();
// Add the binary as the first argument.
executableBuilder.addArg(SourcePathArg.of(new DefaultBuildTargetSourcePath(binaryTarget)));
// Special handling for dynamically linked binaries.
if (depType == Linker.LinkableDepType.SHARED) {
// Create a symlink tree with for all shared libraries needed by this binary.
SymlinkTree sharedLibraries = resolver.addToIndex(CxxDescriptionEnhancer.createSharedLibrarySymlinkTree(ruleFinder, params.getBuildTarget(), params.getProjectFilesystem(), cxxPlatform, deps, NativeLinkable.class::isInstance));
// Embed a origin-relative library path into the binary so it can find the shared libraries.
// The shared libraries root is absolute. Also need an absolute path to the linkOutput
Path absBinaryDir = params.getBuildTarget().getCellPath().resolve(HaskellLinkRule.getOutputDir(binaryTarget, params.getProjectFilesystem()));
linkFlagsBuilder.addAll(MoreIterables.zipAndConcat(Iterables.cycle("-optl"), Linkers.iXlinker("-rpath", String.format("%s/%s", cxxPlatform.getLd().resolve(resolver).origin(), absBinaryDir.relativize(sharedLibraries.getRoot()).toString()))));
// Add all the shared libraries and the symlink tree as inputs to the tool that represents
// this binary, so that users can attach the proper deps.
executableBuilder.addDep(sharedLibraries);
executableBuilder.addInputs(sharedLibraries.getLinks().values());
}
// Generate the compile rule and add its objects to the link.
HaskellCompileRule compileRule = resolver.addToIndex(HaskellDescriptionUtils.requireCompileRule(params, resolver, ruleFinder, deps, cxxPlatform, haskellConfig, depType, args.main, Optional.empty(), args.compilerFlags, HaskellSources.from(params.getBuildTarget(), resolver, pathResolver, ruleFinder, cxxPlatform, "srcs", args.srcs)));
linkArgsBuilder.addAll(SourcePathArg.from(compileRule.getObjects()));
ImmutableList<String> linkFlags = linkFlagsBuilder.build();
ImmutableList<com.facebook.buck.rules.args.Arg> linkArgs = linkArgsBuilder.build();
final CommandTool executable = executableBuilder.build();
final HaskellLinkRule linkRule = HaskellDescriptionUtils.createLinkRule(binaryTarget, params, resolver, ruleFinder, cxxPlatform, haskellConfig, Linker.LinkType.EXECUTABLE, linkFlags, linkArgs, RichStream.from(deps).filter(NativeLinkable.class).toImmutableList(), depType);
return new HaskellBinary(params.copyAppendingExtraDeps(linkRule), ruleFinder, deps, executable, linkRule.getSourcePathToOutput());
}
use of com.facebook.buck.rules.SymlinkTree in project buck by facebook.
the class GoDescriptors method createGoCompileRule.
static GoCompile createGoCompileRule(BuildRuleParams params, BuildRuleResolver resolver, GoBuckConfig goBuckConfig, Path packageName, ImmutableSet<SourcePath> srcs, List<String> compilerFlags, List<String> assemblerFlags, GoPlatform platform, Iterable<BuildTarget> deps) throws NoSuchBuildTargetException {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
Preconditions.checkState(params.getBuildTarget().getFlavors().contains(platform.getFlavor()));
ImmutableSet<GoLinkable> linkables = requireGoLinkables(params.getBuildTarget(), resolver, platform, deps);
ImmutableList.Builder<BuildRule> linkableDepsBuilder = ImmutableList.builder();
for (GoLinkable linkable : linkables) {
linkableDepsBuilder.addAll(linkable.getDeps(ruleFinder));
}
ImmutableList<BuildRule> linkableDeps = linkableDepsBuilder.build();
BuildTarget target = createSymlinkTreeTarget(params.getBuildTarget());
SymlinkTree symlinkTree = makeSymlinkTree(params.withBuildTarget(target), pathResolver, ruleFinder, linkables);
resolver.addToIndex(symlinkTree);
LOG.verbose("Symlink tree for compiling %s: %s", params.getBuildTarget(), symlinkTree.getLinks());
return new GoCompile(params.copyAppendingExtraDeps(linkableDeps).copyAppendingExtraDeps(ImmutableList.of(symlinkTree)), symlinkTree, packageName, getPackageImportMap(goBuckConfig.getVendorPaths(), params.getBuildTarget().getBasePath(), FluentIterable.from(linkables).transformAndConcat(new Function<GoLinkable, ImmutableSet<Path>>() {
@Override
public ImmutableSet<Path> apply(GoLinkable input) {
return input.getGoLinkInput().keySet();
}
})), ImmutableSet.copyOf(srcs), ImmutableList.copyOf(compilerFlags), goBuckConfig.getCompiler(), ImmutableList.copyOf(assemblerFlags), goBuckConfig.getAssemblerIncludeDirs(), goBuckConfig.getAssembler(), goBuckConfig.getPacker(), platform);
}
use of com.facebook.buck.rules.SymlinkTree in project buck by facebook.
the class GoDescriptors method createGoBinaryRule.
static GoBinary createGoBinaryRule(BuildRuleParams params, final BuildRuleResolver resolver, GoBuckConfig goBuckConfig, ImmutableSet<SourcePath> srcs, List<String> compilerFlags, List<String> assemblerFlags, List<String> linkerFlags, GoPlatform platform) throws NoSuchBuildTargetException {
BuildTarget libraryTarget = params.getBuildTarget().withAppendedFlavors(InternalFlavor.of("compile"), platform.getFlavor());
GoCompile library = GoDescriptors.createGoCompileRule(params.withBuildTarget(libraryTarget), resolver, goBuckConfig, Paths.get("main"), srcs, compilerFlags, assemblerFlags, platform, FluentIterable.from(params.getDeclaredDeps().get()).transform(BuildRule::getBuildTarget));
resolver.addToIndex(library);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildTarget target = createTransitiveSymlinkTreeTarget(params.getBuildTarget());
SymlinkTree symlinkTree = makeSymlinkTree(params.withBuildTarget(target), pathResolver, ruleFinder, requireTransitiveGoLinkables(params.getBuildTarget(), resolver, platform, FluentIterable.from(params.getDeclaredDeps().get()).transform(BuildRule::getBuildTarget), /* includeSelf */
false));
resolver.addToIndex(symlinkTree);
LOG.verbose("Symlink tree for linking of %s: %s", params.getBuildTarget(), symlinkTree);
return new GoBinary(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(ruleFinder.filterBuildRuleInputs(symlinkTree.getLinks().values())).add(symlinkTree).add(library).build()), Suppliers.ofInstance(ImmutableSortedSet.of())), platform.getCxxPlatform().map(input -> input.getLd().resolve(resolver)), symlinkTree, library, goBuckConfig.getLinker(), ImmutableList.copyOf(linkerFlags), platform);
}
use of com.facebook.buck.rules.SymlinkTree 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