use of com.facebook.buck.rules.SymlinkTree in project buck by facebook.
the class AndroidResourceDescription method createSymlinkTree.
private SymlinkTree createSymlinkTree(SourcePathRuleFinder ruleFinder, BuildRuleParams params, Optional<Either<SourcePath, ImmutableSortedMap<String, SourcePath>>> symlinkAttribute, String outputDirName) {
ImmutableMap<Path, SourcePath> links = ImmutableMap.of();
if (symlinkAttribute.isPresent()) {
if (symlinkAttribute.get().isLeft()) {
// If our resources are coming from a `PathSourcePath`, we collect only the inputs we care
// about and pass those in separately, so that that `AndroidResource` rule knows to only
// hash these into it's rule key.
// TODO(k21): This is deprecated and should be disabled or removed.
// Accessing the filesystem during rule creation is problematic because the accesses are
// not cached or tracked in any way.
Preconditions.checkArgument(symlinkAttribute.get().getLeft() instanceof PathSourcePath, "Resource or asset symlink tree can only be built for a PathSourcePath");
PathSourcePath path = (PathSourcePath) symlinkAttribute.get().getLeft();
links = collectInputFiles(path.getFilesystem(), path.getRelativePath());
} else {
links = RichStream.from(symlinkAttribute.get().getRight().entrySet()).map(e -> new AbstractMap.SimpleEntry<>(Paths.get(e.getKey()), e.getValue())).filter(e -> isPossibleResourcePath(e.getKey())).collect(MoreCollectors.toImmutableMap(e -> e.getKey(), e -> e.getValue()));
}
}
Path symlinkTreeRoot = BuildTargets.getGenPath(params.getProjectFilesystem(), params.getBuildTarget(), "%s").resolve(outputDirName);
return new SymlinkTree(params.getBuildTarget(), params.getProjectFilesystem(), symlinkTreeRoot, links, ruleFinder);
}
use of com.facebook.buck.rules.SymlinkTree in project buck by facebook.
the class CxxInferEnhancer method requireInferCaptureBuildRules.
private static ImmutableSet<CxxInferCapture> requireInferCaptureBuildRules(final BuildRuleParams params, final BuildRuleResolver resolver, CxxBuckConfig cxxBuckConfig, CxxPlatform cxxPlatform, ImmutableMap<String, CxxSource> sources, InferBuckConfig inferBuckConfig, CxxInferSourceFilter sourceFilter, CxxConstructorArg args) throws NoSuchBuildTargetException {
InferFlavors.checkNoInferFlavors(params.getBuildTarget().getFlavors());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
ImmutableMap<Path, SourcePath> headers = CxxDescriptionEnhancer.parseHeaders(params.getBuildTarget(), resolver, ruleFinder, pathResolver, Optional.of(cxxPlatform), args);
// Setup the header symlink tree and combine all the preprocessor input from this rule
// and all dependencies.
boolean shouldCreateHeadersSymlinks = true;
if (args instanceof CxxLibraryDescription.Arg) {
shouldCreateHeadersSymlinks = ((CxxLibraryDescription.Arg) args).xcodePrivateHeadersSymlinks.orElse(true);
}
HeaderSymlinkTree headerSymlinkTree = CxxDescriptionEnhancer.requireHeaderSymlinkTree(params, resolver, cxxPlatform, headers, HeaderVisibility.PRIVATE, shouldCreateHeadersSymlinks);
Optional<SymlinkTree> sandboxTree = Optional.empty();
if (cxxBuckConfig.sandboxSources()) {
sandboxTree = CxxDescriptionEnhancer.createSandboxTree(params, resolver, cxxPlatform);
}
ImmutableList<CxxPreprocessorInput> preprocessorInputs;
if (args instanceof CxxBinaryDescription.Arg) {
preprocessorInputs = computePreprocessorInputForCxxBinaryDescriptionArg(params, cxxPlatform, (CxxBinaryDescription.Arg) args, headerSymlinkTree, sandboxTree);
} else if (args instanceof CxxLibraryDescription.Arg) {
preprocessorInputs = computePreprocessorInputForCxxLibraryDescriptionArg(params, resolver, cxxPlatform, (CxxLibraryDescription.Arg) args, headerSymlinkTree, args.includeDirs, sandboxTree);
} else {
throw new IllegalStateException("Only Binary and Library args supported.");
}
CxxSourceRuleFactory factory = CxxSourceRuleFactory.of(params, resolver, pathResolver, ruleFinder, cxxBuckConfig, cxxPlatform, preprocessorInputs, CxxFlags.getLanguageFlags(args.compilerFlags, args.platformCompilerFlags, args.langCompilerFlags, cxxPlatform), args.prefixHeader, args.precompiledHeader, CxxSourceRuleFactory.PicType.PDC, sandboxTree);
return factory.requireInferCaptureBuildRules(sources, inferBuckConfig, sourceFilter);
}
use of com.facebook.buck.rules.SymlinkTree in project buck by facebook.
the class CxxDescriptionEnhancer method requireSharedLibrarySymlinkTree.
public static SymlinkTree requireSharedLibrarySymlinkTree(BuildTarget buildTarget, ProjectFilesystem filesystem, BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder, CxxPlatform cxxPlatform, Iterable<? extends BuildRule> deps, Predicate<Object> traverse) throws NoSuchBuildTargetException {
BuildTarget target = createSharedLibrarySymlinkTreeTarget(buildTarget, cxxPlatform.getFlavor());
SymlinkTree tree = resolver.getRuleOptionalWithType(target, SymlinkTree.class).orElse(null);
if (tree == null) {
tree = resolver.addToIndex(createSharedLibrarySymlinkTree(ruleFinder, buildTarget, filesystem, cxxPlatform, deps, traverse));
}
return tree;
}
use of com.facebook.buck.rules.SymlinkTree in project buck by facebook.
the class CxxDescriptionEnhancer method createSandboxSymlinkTree.
public static SymlinkTree createSandboxSymlinkTree(BuildRuleParams params, CxxPlatform cxxPlatform, ImmutableMap<Path, SourcePath> map, SourcePathRuleFinder ruleFinder) {
BuildTarget sandboxSymlinkTreeTarget = CxxDescriptionEnhancer.createSandboxSymlinkTreeTarget(params.getBuildTarget(), cxxPlatform.getFlavor());
Path sandboxSymlinkTreeRoot = CxxDescriptionEnhancer.getSandboxSymlinkTreePath(params.getProjectFilesystem(), sandboxSymlinkTreeTarget);
return new SymlinkTree(sandboxSymlinkTreeTarget, params.getProjectFilesystem(), sandboxSymlinkTreeRoot, map, ruleFinder);
}
use of com.facebook.buck.rules.SymlinkTree in project buck by facebook.
the class CxxDescriptionEnhancer method requireSandboxSymlinkTree.
private static SymlinkTree requireSandboxSymlinkTree(BuildRuleParams params, BuildRuleResolver ruleResolver, CxxPlatform cxxPlatform) throws NoSuchBuildTargetException {
BuildRuleParams untypedParams = CxxLibraryDescription.getUntypedParams(params);
BuildTarget headerSymlinkTreeTarget = CxxDescriptionEnhancer.createSandboxSymlinkTreeTarget(untypedParams.getBuildTarget(), cxxPlatform.getFlavor());
BuildRule rule = ruleResolver.requireRule(headerSymlinkTreeTarget);
Preconditions.checkState(rule instanceof SymlinkTree, rule.getBuildTarget() + " " + rule.getClass().toString());
return (SymlinkTree) rule;
}
Aggregations