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));
}
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;
}
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();
}
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);
}
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");
}
Aggregations