Search in sources :

Example 6 with SourcePathResolver

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

Example 7 with SourcePathResolver

use of com.facebook.buck.rules.SourcePathResolver 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);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePath(com.facebook.buck.rules.SourcePath) SymlinkTree(com.facebook.buck.rules.SymlinkTree)

Example 8 with SourcePathResolver

use of com.facebook.buck.rules.SourcePathResolver in project buck by facebook.

the class Archive method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    // Cache the archive we built.
    buildableContext.recordArtifact(output);
    SourcePathResolver resolver = context.getSourcePathResolver();
    // paths.
    for (SourcePath input : inputs) {
        Preconditions.checkState(resolver.getFilesystem(input).getRootPath().equals(getProjectFilesystem().getRootPath()));
    }
    ImmutableList.Builder<Step> builder = ImmutableList.builder();
    builder.add(new MkdirStep(getProjectFilesystem(), output.getParent()), new RmStep(getProjectFilesystem(), output), new ArchiveStep(getProjectFilesystem(), archiver.getEnvironment(resolver), archiver.getCommandPrefix(resolver), archiverFlags, archiver.getArchiveOptions(contents == Contents.THIN), output, inputs.stream().map(resolver::getRelativePath).collect(MoreCollectors.toImmutableList()), archiver));
    if (archiver.isRanLibStepRequired()) {
        builder.add(new RanlibStep(getProjectFilesystem(), ranlib.getEnvironment(resolver), ranlib.getCommandPrefix(resolver), ranlibFlags, output));
    }
    if (!archiver.getScrubbers().isEmpty()) {
        builder.add(new FileScrubberStep(getProjectFilesystem(), output, archiver.getScrubbers()));
    }
    return builder.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) RmStep(com.facebook.buck.step.fs.RmStep) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) RmStep(com.facebook.buck.step.fs.RmStep) Step(com.facebook.buck.step.Step) MkdirStep(com.facebook.buck.step.fs.MkdirStep) FileScrubberStep(com.facebook.buck.step.fs.FileScrubberStep) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) FileScrubberStep(com.facebook.buck.step.fs.FileScrubberStep)

Example 9 with SourcePathResolver

use of com.facebook.buck.rules.SourcePathResolver in project buck by facebook.

the class CxxBinaryDescription method createHeaderSymlinkTreeBuildRule.

/**
   * @return a {@link com.facebook.buck.cxx.HeaderSymlinkTree} for the headers of this C/C++ binary.
   */
public static <A extends Arg> HeaderSymlinkTree createHeaderSymlinkTreeBuildRule(BuildRuleParams params, BuildRuleResolver resolver, CxxPlatform cxxPlatform, A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    return CxxDescriptionEnhancer.createHeaderSymlinkTree(params, resolver, cxxPlatform, CxxDescriptionEnhancer.parseHeaders(params.getBuildTarget(), resolver, ruleFinder, pathResolver, Optional.of(cxxPlatform), args), HeaderVisibility.PRIVATE, true);
}
Also used : SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 10 with SourcePathResolver

use of com.facebook.buck.rules.SourcePathResolver in project buck by facebook.

the class ProjectCommand method runDeprecatedIntellijProjectGenerator.

private int runDeprecatedIntellijProjectGenerator(CommandRunnerParams params, TargetGraph projectGraph, TargetGraphAndTargets targetGraphAndTargets, ImmutableSet<BuildTarget> passedInTargetsSet) throws IOException, InterruptedException {
    // Create an ActionGraph that only contains targets that can be represented as IDE
    // configuration files.
    ActionGraphAndResolver result = Preconditions.checkNotNull(ActionGraphCache.getFreshActionGraph(params.getBuckEventBus(), targetGraphAndTargets.getTargetGraph()));
    try (ExecutionContext executionContext = createExecutionContext(params)) {
        Project project = new Project(new SourcePathResolver(new SourcePathRuleFinder(result.getResolver())), FluentIterable.from(result.getActionGraph().getNodes()).filter(ProjectConfig.class).toSortedSet(Ordering.natural()), getBasePathToAliasMap(params.getBuckConfig()), getJavaPackageFinder(params.getBuckConfig()), executionContext, new FilesystemBackedBuildFileTree(params.getCell().getFilesystem(), params.getBuckConfig().getView(ParserConfig.class).getBuildFileName()), params.getCell().getFilesystem(), getPathToDefaultAndroidManifest(params.getBuckConfig()), new IntellijConfig(params.getBuckConfig()), getPathToPostProcessScript(params.getBuckConfig()), new PythonBuckConfig(params.getBuckConfig(), new ExecutableFinder()).getPythonInterpreter(), params.getObjectMapper(), isAndroidAutoGenerateDisabled(params.getBuckConfig()));
        File tempDir = Files.createTempDir();
        File tempFile = new File(tempDir, "project.json");
        int exitCode;
        try {
            exitCode = project.createIntellijProject(tempFile, executionContext.getProcessExecutor(), !passedInTargetsSet.isEmpty(), params.getConsole().getStdOut(), params.getConsole().getStdErr());
            if (exitCode != 0) {
                return exitCode;
            }
            List<String> additionalInitialTargets = ImmutableList.of();
            if (shouldProcessAnnotations()) {
                additionalInitialTargets = getAnnotationProcessingTargets(projectGraph, passedInTargetsSet);
            }
            // Build initial targets.
            if (hasInitialTargets(params.getBuckConfig()) || !additionalInitialTargets.isEmpty()) {
                BuildCommand buildCommand = createBuildCommandOptionsWithInitialTargets(params.getBuckConfig(), additionalInitialTargets);
                buildCommand.setArtifactCacheDisabled(true);
                exitCode = buildCommand.runWithoutHelp(params);
                if (exitCode != 0) {
                    return exitCode;
                }
            }
        } finally {
            // Either leave project.json around for debugging or delete it on exit.
            if (params.getConsole().getVerbosity().shouldPrintOutput()) {
                params.getConsole().getStdErr().printf("project.json was written to %s", tempFile.getAbsolutePath());
            } else {
                tempFile.delete();
                tempDir.delete();
            }
        }
        if (passedInTargetsSet.isEmpty()) {
            String greenStar = params.getConsole().getAnsi().asHighlightedSuccessText(" * ");
            params.getConsole().getStdErr().printf(params.getConsole().getAnsi().asHighlightedSuccessText("=== Did you know ===") + "\n" + greenStar + "You can run `buck project <target>` to generate a minimal project " + "just for that target.\n" + greenStar + "This will make your IDE faster when working on large projects.\n" + greenStar + "See buck project --help for more info.\n" + params.getConsole().getAnsi().asHighlightedSuccessText("--=* Knowing is half the battle!") + "\n");
        }
        return 0;
    }
}
Also used : PythonBuckConfig(com.facebook.buck.python.PythonBuckConfig) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) IntellijConfig(com.facebook.buck.jvm.java.intellij.IntellijConfig) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) IjProject(com.facebook.buck.jvm.java.intellij.IjProject) Project(com.facebook.buck.jvm.java.intellij.Project) FilesystemBackedBuildFileTree(com.facebook.buck.model.FilesystemBackedBuildFileTree) ExecutionContext(com.facebook.buck.step.ExecutionContext) ActionGraphAndResolver(com.facebook.buck.rules.ActionGraphAndResolver) File(java.io.File) ParserConfig(com.facebook.buck.parser.ParserConfig)

Aggregations

SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)486 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)468 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)376 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)350 Test (org.junit.Test)330 BuildTarget (com.facebook.buck.model.BuildTarget)228 BuildRule (com.facebook.buck.rules.BuildRule)161 Path (java.nio.file.Path)154 SourcePath (com.facebook.buck.rules.SourcePath)148 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)138 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)126 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)119 PathSourcePath (com.facebook.buck.rules.PathSourcePath)86 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)82 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)79 TargetGraph (com.facebook.buck.rules.TargetGraph)76 RuleKey (com.facebook.buck.rules.RuleKey)72 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)70 ExecutionContext (com.facebook.buck.step.ExecutionContext)57 ImmutableList (com.google.common.collect.ImmutableList)55