use of com.facebook.buck.rules.SourcePath 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.SourcePath in project buck by facebook.
the class NewNativeTargetProjectMutator method traverseGroupsTreeAndHandleSources.
private void traverseGroupsTreeAndHandleSources(final PBXGroup sourcesGroup, final PBXSourcesBuildPhase sourcesBuildPhase, Iterable<GroupedSource> groupedSources) {
GroupedSource.Visitor visitor = new GroupedSource.Visitor() {
@Override
public void visitSourceWithFlags(SourceWithFlags sourceWithFlags) {
addSourcePathToSourcesBuildPhase(sourceWithFlags, sourcesGroup, sourcesBuildPhase);
}
@Override
public void visitPublicHeader(SourcePath publicHeader) {
addSourcePathToHeadersBuildPhase(publicHeader, sourcesGroup, HeaderVisibility.PUBLIC);
}
@Override
public void visitPrivateHeader(SourcePath privateHeader) {
addSourcePathToHeadersBuildPhase(privateHeader, sourcesGroup, HeaderVisibility.PRIVATE);
}
@Override
public void visitSourceGroup(String sourceGroupName, Path sourceGroupPathRelativeToTarget, List<GroupedSource> sourceGroup) {
PBXGroup newSourceGroup = sourcesGroup.getOrCreateChildGroupByName(sourceGroupName);
newSourceGroup.setSourceTree(PBXReference.SourceTree.SOURCE_ROOT);
newSourceGroup.setPath(sourceGroupPathRelativeToTarget.toString());
// Sources groups stay in the order in which they're in the GroupedSource.
newSourceGroup.setSortPolicy(PBXGroup.SortPolicy.UNSORTED);
traverseGroupsTreeAndHandleSources(newSourceGroup, sourcesBuildPhase, sourceGroup);
}
};
for (GroupedSource groupedSource : groupedSources) {
groupedSource.visit(visitor);
}
}
use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class MultiarchFile method copyLinkMaps.
private void copyLinkMaps(BuildableContext buildableContext, ImmutableList.Builder<Step> steps) {
Path linkMapDir = Paths.get(output + "-LinkMap");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), linkMapDir));
for (SourcePath thinBinary : thinBinaries) {
Optional<BuildRule> maybeRule = ruleFinder.getRule(thinBinary);
if (maybeRule.isPresent()) {
BuildRule rule = maybeRule.get();
if (rule instanceof CxxBinary) {
rule = ((CxxBinary) rule).getLinkRule();
}
if (rule instanceof CxxLink && !rule.getBuildTarget().getFlavors().contains(LinkerMapMode.NO_LINKER_MAP.getFlavor())) {
Optional<Path> maybeLinkerMapPath = ((CxxLink) rule).getLinkerMapPath();
if (maybeLinkerMapPath.isPresent()) {
Path source = maybeLinkerMapPath.get();
Path dest = linkMapDir.resolve(source.getFileName());
steps.add(CopyStep.forFile(getProjectFilesystem(), source, dest));
buildableContext.recordArtifact(dest);
}
}
}
}
}
use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class MultiarchFile method lipoBinaries.
private void lipoBinaries(BuildContext context, ImmutableList.Builder<Step> steps) {
ImmutableList.Builder<String> commandBuilder = ImmutableList.builder();
commandBuilder.addAll(lipo.getCommandPrefix(context.getSourcePathResolver()));
commandBuilder.add("-create", "-output", getProjectFilesystem().resolve(output).toString());
for (SourcePath thinBinary : thinBinaries) {
commandBuilder.add(context.getSourcePathResolver().getAbsolutePath(thinBinary).toString());
}
steps.add(new DefaultShellStep(getProjectFilesystem().getRootPath(), commandBuilder.build(), lipo.getEnvironment(context.getSourcePathResolver())));
}
use of com.facebook.buck.rules.SourcePath 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;
}
Aggregations