Search in sources :

Example 11 with SourcePath

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());
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) TargetNode(com.facebook.buck.rules.TargetNode) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) ExportFileDescription(com.facebook.buck.shell.ExportFileDescription)

Example 12 with SourcePath

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);
    }
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) GroupedSource(com.facebook.buck.apple.GroupedSource) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) NSString(com.dd.plist.NSString) SourceWithFlags(com.facebook.buck.rules.SourceWithFlags)

Example 13 with SourcePath

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);
                }
            }
        }
    }
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) CxxBinary(com.facebook.buck.cxx.CxxBinary) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) BuildRule(com.facebook.buck.rules.BuildRule) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) CxxLink(com.facebook.buck.cxx.CxxLink)

Example 14 with SourcePath

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())));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) DefaultShellStep(com.facebook.buck.shell.DefaultShellStep) ImmutableList(com.google.common.collect.ImmutableList)

Example 15 with SourcePath

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;
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) BuildRule(com.facebook.buck.rules.BuildRule) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder)

Aggregations

SourcePath (com.facebook.buck.rules.SourcePath)285 Path (java.nio.file.Path)151 BuildTarget (com.facebook.buck.model.BuildTarget)111 Test (org.junit.Test)105 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)102 PathSourcePath (com.facebook.buck.rules.PathSourcePath)100 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)96 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)90 BuildRule (com.facebook.buck.rules.BuildRule)79 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)69 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)69 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)64 ImmutableList (com.google.common.collect.ImmutableList)64 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)53 ImmutableMap (com.google.common.collect.ImmutableMap)48 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)43 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)42 HumanReadableException (com.facebook.buck.util.HumanReadableException)39 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)37 ImmutableSet (com.google.common.collect.ImmutableSet)34