Search in sources :

Example 11 with SourcePathResolver

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

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

Example 13 with SourcePathResolver

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

the class CxxDescriptionEnhancer method parseOnlyPlatformHeaders.

static ImmutableMap<String, SourcePath> parseOnlyPlatformHeaders(BuildTarget buildTarget, BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder, SourcePathResolver sourcePathResolver, CxxPlatform cxxPlatform, String headersParameterName, SourceList headers, String platformHeadersParameterName, PatternMatchedCollection<SourceList> platformHeaders) throws NoSuchBuildTargetException {
    ImmutableMap.Builder<String, SourcePath> parsed = ImmutableMap.builder();
    java.util.function.Function<SourcePath, SourcePath> fixup = path -> {
        try {
            return CxxGenruleDescription.fixupSourcePath(resolver, ruleFinder, cxxPlatform, path);
        } catch (NoSuchBuildTargetException e) {
            throw new RuntimeException(e);
        }
    };
    // Include all normal exported headers that are generated by `cxx_genrule`.
    parsed.putAll(headers.toNameMap(buildTarget, sourcePathResolver, headersParameterName, path -> CxxGenruleDescription.wrapsCxxGenrule(ruleFinder, path), fixup));
    // Include all platform specific headers.
    for (SourceList sourceList : platformHeaders.getMatchingValues(cxxPlatform.getFlavor().toString())) {
        parsed.putAll(sourceList.toNameMap(buildTarget, sourcePathResolver, platformHeadersParameterName, path -> true, fixup));
    }
    return parsed.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) PatternMatchedCollection(com.facebook.buck.rules.coercer.PatternMatchedCollection) ImmutableCollection(com.google.common.collect.ImmutableCollection) RichStream(com.facebook.buck.util.RichStream) InternalFlavor(com.facebook.buck.model.InternalFlavor) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) SymlinkTree(com.facebook.buck.rules.SymlinkTree) FlavorDomain(com.facebook.buck.model.FlavorDomain) Matcher(java.util.regex.Matcher) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) StringArg(com.facebook.buck.rules.args.StringArg) Map(java.util.Map) SourceList(com.facebook.buck.rules.coercer.SourceList) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) RuleKeyObjectSink(com.facebook.buck.rules.RuleKeyObjectSink) Path(java.nio.file.Path) JsonConcatenate(com.facebook.buck.json.JsonConcatenate) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TargetGraph(com.facebook.buck.rules.TargetGraph) BuildTarget(com.facebook.buck.model.BuildTarget) RuleKeyAppendableFunction(com.facebook.buck.rules.args.RuleKeyAppendableFunction) SourceWithFlags(com.facebook.buck.rules.SourceWithFlags) Predicate(com.google.common.base.Predicate) Optional(java.util.Optional) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Pattern(java.util.regex.Pattern) Joiner(com.google.common.base.Joiner) CellPathResolver(com.facebook.buck.rules.CellPathResolver) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) HashMap(java.util.HashMap) BuildRule(com.facebook.buck.rules.BuildRule) ImmutableList(com.google.common.collect.ImmutableList) Files(com.google.common.io.Files) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) Suppliers(com.google.common.base.Suppliers) StreamSupport(java.util.stream.StreamSupport) StringWithMacros(com.facebook.buck.rules.macros.StringWithMacros) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Logger(com.facebook.buck.log.Logger) Functions(com.google.common.base.Functions) FileListableLinkerInputArg(com.facebook.buck.rules.args.FileListableLinkerInputArg) HumanReadableException(com.facebook.buck.util.HumanReadableException) QueryUtils(com.facebook.buck.rules.query.QueryUtils) Arg(com.facebook.buck.rules.args.Arg) Paths(java.nio.file.Paths) CommandTool(com.facebook.buck.rules.CommandTool) StringWithMacrosArg(com.facebook.buck.rules.args.StringWithMacrosArg) LocationMacroExpander(com.facebook.buck.rules.macros.LocationMacroExpander) Preconditions(com.google.common.base.Preconditions) Flavor(com.facebook.buck.model.Flavor) MacroHandler(com.facebook.buck.rules.macros.MacroHandler) VisibleForTesting(com.google.common.annotations.VisibleForTesting) BuildTargets(com.facebook.buck.model.BuildTargets) SourceList(com.facebook.buck.rules.coercer.SourceList) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 14 with SourcePathResolver

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

the class CxxDescriptionEnhancer method createSandboxTreeBuildRule.

public static SymlinkTree createSandboxTreeBuildRule(BuildRuleResolver resolver, CxxConstructorArg args, CxxPlatform platform, BuildRuleParams params) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
    ImmutableCollection<SourcePath> privateHeaders = parseHeaders(params.getBuildTarget(), resolver, ruleFinder, sourcePathResolver, Optional.of(platform), args).values();
    ImmutableCollection<CxxSource> sources = parseCxxSources(params.getBuildTarget(), resolver, ruleFinder, sourcePathResolver, platform, args).values();
    HashMap<Path, SourcePath> links = new HashMap<>();
    for (SourcePath headerPath : privateHeaders) {
        links.put(Paths.get(sourcePathResolver.getSourcePathName(params.getBuildTarget(), headerPath)), headerPath);
    }
    if (args instanceof CxxLibraryDescription.Arg) {
        ImmutableCollection<SourcePath> publicHeaders = CxxDescriptionEnhancer.parseExportedHeaders(params.getBuildTarget(), resolver, ruleFinder, sourcePathResolver, Optional.of(platform), (CxxLibraryDescription.Arg) args).values();
        for (SourcePath headerPath : publicHeaders) {
            links.put(Paths.get(sourcePathResolver.getSourcePathName(params.getBuildTarget(), headerPath)), headerPath);
        }
    }
    for (CxxSource source : sources) {
        SourcePath sourcePath = source.getPath();
        links.put(Paths.get(sourcePathResolver.getSourcePathName(params.getBuildTarget(), sourcePath)), sourcePath);
    }
    return createSandboxSymlinkTree(params, platform, ImmutableMap.copyOf(links), ruleFinder);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) HashMap(java.util.HashMap) StringArg(com.facebook.buck.rules.args.StringArg) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) FileListableLinkerInputArg(com.facebook.buck.rules.args.FileListableLinkerInputArg) Arg(com.facebook.buck.rules.args.Arg) StringWithMacrosArg(com.facebook.buck.rules.args.StringWithMacrosArg) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 15 with SourcePathResolver

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

the class CxxDescriptionEnhancer method createUberCompilationDatabase.

public static BuildRule createUberCompilationDatabase(BuildRuleParams params, BuildRuleResolver ruleResolver) throws NoSuchBuildTargetException {
    Optional<CxxCompilationDatabaseDependencies> compilationDatabases = ruleResolver.requireMetadata(params.withoutFlavor(CxxCompilationDatabase.UBER_COMPILATION_DATABASE).withAppendedFlavor(CxxCompilationDatabase.COMPILATION_DATABASE).getBuildTarget(), CxxCompilationDatabaseDependencies.class);
    Preconditions.checkState(compilationDatabases.isPresent());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    return new JsonConcatenate(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.copyOf(ruleFinder.filterBuildRuleInputs(compilationDatabases.get().getSourcePaths()))), Suppliers.ofInstance(ImmutableSortedSet.of())), pathResolver.getAllAbsolutePaths(compilationDatabases.get().getSourcePaths()), "compilation-database-concatenate", "Concatenate compilation databases", "uber-compilation-database", "compile_commands.json");
}
Also used : SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) JsonConcatenate(com.facebook.buck.json.JsonConcatenate)

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