use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.
the class ProjectGenerator method resolveSourcePath.
private Path resolveSourcePath(SourcePath sourcePath) {
if (sourcePath instanceof PathSourcePath) {
return ((PathSourcePath) sourcePath).getRelativePath();
}
Preconditions.checkArgument(sourcePath instanceof BuildTargetSourcePath);
BuildTargetSourcePath<?> buildTargetSourcePath = (BuildTargetSourcePath<?>) sourcePath;
BuildTarget buildTarget = buildTargetSourcePath.getTarget();
TargetNode<?, ?> node = targetGraph.get(buildTarget);
Optional<TargetNode<ExportFileDescription.Arg, ?>> exportFileNode = node.castArg(ExportFileDescription.Arg.class);
if (!exportFileNode.isPresent()) {
BuildRuleResolver resolver = buildRuleResolverForNode.apply(node);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
Path output = pathResolver.getRelativePath(sourcePath);
if (output == null) {
throw new HumanReadableException("The target '%s' does not have an output.", node.getBuildTarget());
}
requiredBuildTargetsBuilder.add(buildTarget);
return output;
}
Optional<SourcePath> src = exportFileNode.get().getConstructorArg().src;
if (!src.isPresent()) {
return buildTarget.getBasePath().resolve(buildTarget.getShortNameAndFlavorPostfix());
}
return resolveSourcePath(src.get());
}
use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.
the class MultiarchFileInfos method requireMultiarchRule.
/**
* Generate a fat rule from thin rules.
*
* Invariant: thinRules contain all the thin rules listed in info.getThinTargets().
*/
public static BuildRule requireMultiarchRule(BuildRuleParams params, BuildRuleResolver resolver, MultiarchFileInfo info, ImmutableSortedSet<BuildRule> thinRules) {
Optional<BuildRule> existingRule = resolver.getRuleOptional(info.getFatTarget());
if (existingRule.isPresent()) {
return existingRule.get();
}
ImmutableSortedSet<SourcePath> inputs = FluentIterable.from(thinRules).transform(BuildRule::getSourcePathToOutput).toSortedSet(Ordering.natural());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
MultiarchFile multiarchFile = new MultiarchFile(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(thinRules)), ruleFinder, info.getRepresentativePlatform().getLipo(), inputs, BuildTargets.getGenPath(params.getProjectFilesystem(), params.getBuildTarget(), "%s"));
resolver.addToIndex(multiarchFile);
return multiarchFile;
}
use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.
the class ProjectGenerator method getPublicCxxHeaders.
private ImmutableSortedMap<Path, SourcePath> getPublicCxxHeaders(TargetNode<? extends CxxLibraryDescription.Arg, ?> targetNode) {
CxxLibraryDescription.Arg arg = targetNode.getConstructorArg();
if (arg instanceof AppleNativeTargetDescriptionArg) {
Path headerPathPrefix = AppleDescriptions.getHeaderPathPrefix((AppleNativeTargetDescriptionArg) arg, targetNode.getBuildTarget());
ImmutableSortedMap<String, SourcePath> cxxHeaders = AppleDescriptions.convertAppleHeadersToPublicCxxHeaders(this::resolveSourcePath, headerPathPrefix, arg);
return convertMapKeysToPaths(cxxHeaders);
} else {
BuildRuleResolver resolver = buildRuleResolverForNode.apply(targetNode);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
try {
return ImmutableSortedMap.copyOf(CxxDescriptionEnhancer.parseExportedHeaders(targetNode.getBuildTarget(), resolver, ruleFinder, pathResolver, Optional.empty(), arg));
} catch (NoSuchBuildTargetException e) {
throw new RuntimeException(e);
}
}
}
use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.
the class CxxInferEnhancer method collectSources.
public static ImmutableMap<String, CxxSource> collectSources(BuildTarget buildTarget, BuildRuleResolver ruleResolver, CxxPlatform cxxPlatform, CxxConstructorArg args) {
InferFlavors.checkNoInferFlavors(buildTarget.getFlavors());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
return CxxDescriptionEnhancer.parseCxxSources(buildTarget, ruleResolver, ruleFinder, pathResolver, cxxPlatform, args);
}
use of com.facebook.buck.rules.SourcePathRuleFinder 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);
}
Aggregations