Search in sources :

Example 11 with SourcePathRuleFinder

use of com.facebook.buck.rules.SourcePathRuleFinder 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 12 with SourcePathRuleFinder

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

the class CxxBinaryDescription method createBuildRule.

@SuppressWarnings("PMD.PrematureDeclaration")
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    // We explicitly remove some flavors below from params to make sure rule
    // has the same output regardless if we will strip or not.
    Optional<StripStyle> flavoredStripStyle = StripStyle.FLAVOR_DOMAIN.getValue(params.getBuildTarget());
    Optional<LinkerMapMode> flavoredLinkerMapMode = LinkerMapMode.FLAVOR_DOMAIN.getValue(params.getBuildTarget());
    params = CxxStrip.removeStripStyleFlavorInParams(params, flavoredStripStyle);
    params = LinkerMapMode.removeLinkerMapModeFlavorInParams(params, flavoredLinkerMapMode);
    // Extract the platform from the flavor, falling back to the default platform if none are
    // found.
    ImmutableSet<Flavor> flavors = ImmutableSet.copyOf(params.getBuildTarget().getFlavors());
    CxxPlatform cxxPlatform = cxxPlatforms.getValue(flavors).orElse(defaultCxxPlatform);
    if (flavors.contains(CxxDescriptionEnhancer.HEADER_SYMLINK_TREE_FLAVOR)) {
        flavors = ImmutableSet.copyOf(Sets.difference(flavors, ImmutableSet.of(CxxDescriptionEnhancer.HEADER_SYMLINK_TREE_FLAVOR)));
        BuildTarget target = BuildTarget.builder(params.getBuildTarget().getUnflavoredBuildTarget()).addAllFlavors(flavors).build();
        BuildRuleParams typeParams = params.withBuildTarget(target);
        return createHeaderSymlinkTreeBuildRule(typeParams, resolver, cxxPlatform, args);
    }
    if (flavors.contains(CxxCompilationDatabase.COMPILATION_DATABASE)) {
        BuildRuleParams paramsWithoutFlavor = params.withoutFlavor(CxxCompilationDatabase.COMPILATION_DATABASE);
        CxxLinkAndCompileRules cxxLinkAndCompileRules = CxxDescriptionEnhancer.createBuildRulesForCxxBinaryDescriptionArg(targetGraph, paramsWithoutFlavor, resolver, cxxBuckConfig, cxxPlatform, args, flavoredStripStyle, flavoredLinkerMapMode);
        return CxxCompilationDatabase.createCompilationDatabase(params, cxxLinkAndCompileRules.compileRules);
    }
    if (flavors.contains(CxxCompilationDatabase.UBER_COMPILATION_DATABASE)) {
        return CxxDescriptionEnhancer.createUberCompilationDatabase(cxxPlatforms.getValue(flavors).isPresent() ? params : params.withAppendedFlavor(defaultCxxPlatform.getFlavor()), resolver);
    }
    if (flavors.contains(CxxInferEnhancer.InferFlavors.INFER.get())) {
        return CxxInferEnhancer.requireInferAnalyzeAndReportBuildRuleForCxxDescriptionArg(params, resolver, cxxBuckConfig, cxxPlatform, args, inferBuckConfig, new CxxInferSourceFilter(inferBuckConfig));
    }
    if (flavors.contains(CxxInferEnhancer.InferFlavors.INFER_ANALYZE.get())) {
        return CxxInferEnhancer.requireInferAnalyzeBuildRuleForCxxDescriptionArg(params, resolver, cxxBuckConfig, cxxPlatform, args, inferBuckConfig, new CxxInferSourceFilter(inferBuckConfig));
    }
    if (flavors.contains(CxxInferEnhancer.InferFlavors.INFER_CAPTURE_ALL.get())) {
        return CxxInferEnhancer.requireAllTransitiveCaptureBuildRules(params, resolver, cxxBuckConfig, cxxPlatform, inferBuckConfig, new CxxInferSourceFilter(inferBuckConfig), args);
    }
    if (flavors.contains(CxxInferEnhancer.InferFlavors.INFER_CAPTURE_ONLY.get())) {
        return CxxInferEnhancer.requireInferCaptureAggregatorBuildRuleForCxxDescriptionArg(params, resolver, cxxBuckConfig, cxxPlatform, args, inferBuckConfig, new CxxInferSourceFilter(inferBuckConfig));
    }
    if (flavors.contains(CxxDescriptionEnhancer.SANDBOX_TREE_FLAVOR)) {
        return CxxDescriptionEnhancer.createSandboxTreeBuildRule(resolver, args, cxxPlatform, params);
    }
    CxxLinkAndCompileRules cxxLinkAndCompileRules = CxxDescriptionEnhancer.createBuildRulesForCxxBinaryDescriptionArg(targetGraph, params, resolver, cxxBuckConfig, cxxPlatform, args, flavoredStripStyle, flavoredLinkerMapMode);
    // Return a CxxBinary rule as our representative in the action graph, rather than the CxxLink
    // rule above for a couple reasons:
    //  1) CxxBinary extends BinaryBuildRule whereas CxxLink does not, so the former can be used
    //     as executables for genrules.
    //  2) In some cases, users add dependencies from some rules onto other binary rules, typically
    //     if the binary is executed by some test or library code at test time.  These target graph
    //     deps should *not* become build time dependencies on the CxxLink step, otherwise we'd
    //     have to wait for the dependency binary to link before we could link the dependent binary.
    //     By using another BuildRule, we can keep the original target graph dependency tree while
    //     preventing it from affecting link parallelism.
    params = CxxStrip.restoreStripStyleFlavorInParams(params, flavoredStripStyle);
    params = LinkerMapMode.restoreLinkerMapModeFlavorInParams(params, flavoredLinkerMapMode);
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    CxxBinary cxxBinary = new CxxBinary(params.copyReplacingDeclaredAndExtraDeps(() -> cxxLinkAndCompileRules.deps, params.getExtraDeps()).copyAppendingExtraDeps(cxxLinkAndCompileRules.executable.getDeps(ruleFinder)), resolver, ruleFinder, cxxLinkAndCompileRules.getBinaryRule(), cxxLinkAndCompileRules.executable, args.frameworks, args.tests, params.getBuildTarget().withoutFlavors(cxxPlatforms.getFlavors()));
    resolver.addToIndex(cxxBinary);
    return cxxBinary;
}
Also used : Flavor(com.facebook.buck.model.Flavor) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget)

Example 13 with SourcePathRuleFinder

use of com.facebook.buck.rules.SourcePathRuleFinder 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)

Example 14 with SourcePathRuleFinder

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

the class ProjectCommand method writeProjectAndGetRequiredBuildTargets.

private ImmutableSet<BuildTarget> writeProjectAndGetRequiredBuildTargets(CommandRunnerParams params, final TargetGraphAndTargets targetGraphAndTargets) throws IOException {
    ActionGraphAndResolver result = Preconditions.checkNotNull(ActionGraphCache.getFreshActionGraph(params.getBuckEventBus(), targetGraphAndTargets.getTargetGraph()));
    BuckConfig buckConfig = params.getBuckConfig();
    BuildRuleResolver ruleResolver = result.getResolver();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
    JavacOptions javacOptions = buckConfig.getView(JavaBuckConfig.class).getDefaultJavacOptions();
    IjProject project = new IjProject(targetGraphAndTargets, getJavaPackageFinder(buckConfig), JavaFileParser.createJavaFileParser(javacOptions), ruleResolver, sourcePathResolver, ruleFinder, params.getCell().getFilesystem(), getIntellijAggregationMode(buckConfig), buckConfig);
    return project.write(runIjCleaner, getRemoveUnusedLibraries(buckConfig), excludeArtifacts || getExcludeArtifactsFromConfig(buckConfig));
}
Also used : JavacOptions(com.facebook.buck.jvm.java.JavacOptions) IjProject(com.facebook.buck.jvm.java.intellij.IjProject) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) JavaBuckConfig(com.facebook.buck.jvm.java.JavaBuckConfig) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) HalideBuckConfig(com.facebook.buck.halide.HalideBuckConfig) PythonBuckConfig(com.facebook.buck.python.PythonBuckConfig) ActionGraphAndResolver(com.facebook.buck.rules.ActionGraphAndResolver) JavaBuckConfig(com.facebook.buck.jvm.java.JavaBuckConfig) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver)

Example 15 with SourcePathRuleFinder

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

the class VerifyCachesCommand method verifyRuleKeyCache.

private boolean verifyRuleKeyCache(PrintStream stdOut, int ruleKeySeed, FileHashCache fileHashCache, RuleKeyCacheRecycler<RuleKey> recycler) {
    ImmutableList<Map.Entry<BuildRule, RuleKey>> contents = recycler.getCachedBuildRules();
    RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(ruleKeySeed);
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    contents.forEach(e -> resolver.addToIndex(e.getKey()));
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    DefaultRuleKeyFactory defaultRuleKeyFactory = new DefaultRuleKeyFactory(fieldLoader, fileHashCache, pathResolver, ruleFinder);
    stdOut.println(String.format("Examining %d build rule keys.", contents.size()));
    ImmutableList<BuildRule> mismatches = RichStream.from(contents).filter(entry -> !defaultRuleKeyFactory.build(entry.getKey()).equals(entry.getValue())).map(Map.Entry::getKey).toImmutableList();
    if (mismatches.isEmpty()) {
        stdOut.println("No rule key cache errors found.");
    } else {
        stdOut.println("Found rule key cache errors:");
        for (BuildRule rule : mismatches) {
            stdOut.println(String.format("  %s", rule));
        }
    }
    return true;
}
Also used : RuleKeyFieldLoader(com.facebook.buck.rules.keys.RuleKeyFieldLoader) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Map(java.util.Map) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver)

Aggregations

SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)517 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)466 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)405 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)376 Test (org.junit.Test)352 BuildTarget (com.facebook.buck.model.BuildTarget)250 BuildRule (com.facebook.buck.rules.BuildRule)188 SourcePath (com.facebook.buck.rules.SourcePath)151 Path (java.nio.file.Path)151 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)149 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)139 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)131 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)94 PathSourcePath (com.facebook.buck.rules.PathSourcePath)92 TargetGraph (com.facebook.buck.rules.TargetGraph)91 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)87 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)73 RuleKey (com.facebook.buck.rules.RuleKey)72 ImmutableList (com.google.common.collect.ImmutableList)52 ExecutionContext (com.facebook.buck.step.ExecutionContext)50