use of com.facebook.buck.rules.BuildRuleResolver 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());
}
use of com.facebook.buck.rules.BuildRuleResolver in project buck by facebook.
the class ProjectGenerator method getPublicCxxHeaders.
private ImmutableSortedMap<Path, SourcePath> getPublicCxxHeaders(TargetNode<? extends CxxLibraryDescription.Arg, ?> targetNode) {
CxxLibraryDescription.Arg arg = targetNode.getConstructorArg();
if (arg instanceof AppleNativeTargetDescriptionArg) {
Path headerPathPrefix = AppleDescriptions.getHeaderPathPrefix((AppleNativeTargetDescriptionArg) arg, targetNode.getBuildTarget());
ImmutableSortedMap<String, SourcePath> cxxHeaders = AppleDescriptions.convertAppleHeadersToPublicCxxHeaders(this::resolveSourcePath, headerPathPrefix, arg);
return convertMapKeysToPaths(cxxHeaders);
} else {
BuildRuleResolver resolver = buildRuleResolverForNode.apply(targetNode);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
try {
return ImmutableSortedMap.copyOf(CxxDescriptionEnhancer.parseExportedHeaders(targetNode.getBuildTarget(), resolver, ruleFinder, pathResolver, Optional.empty(), arg));
} catch (NoSuchBuildTargetException e) {
throw new RuntimeException(e);
}
}
}
use of com.facebook.buck.rules.BuildRuleResolver in project buck by facebook.
the class CxxGenruleDescription method getMacroHandler.
@Override
protected <A extends Arg> MacroHandler getMacroHandler(BuildTarget buildTarget, ProjectFilesystem filesystem, BuildRuleResolver resolver, TargetGraph targetGraph, A args) {
CxxPlatform cxxPlatform = cxxPlatforms.getRequiredValue(buildTarget);
ImmutableMap.Builder<String, MacroExpander> macros = ImmutableMap.builder();
macros.put("exe", new ExecutableMacroExpander());
macros.put("location", new CxxLocationMacroExpander(cxxPlatform));
macros.put("platform-name", new StringExpander(cxxPlatform.getFlavor().toString()));
macros.put("location-platform", new LocationMacroExpander() {
@Override
protected BuildRule resolve(BuildRuleResolver resolver, LocationMacro input) throws MacroException {
try {
return resolver.requireRule(input.getTarget().withAppendedFlavors(cxxPlatform.getFlavor()));
} catch (NoSuchBuildTargetException e) {
throw new MacroException(e.getHumanReadableErrorMessage());
}
}
});
macros.put("cc", new ToolExpander(cxxPlatform.getCc().resolve(resolver)));
macros.put("cxx", new ToolExpander(cxxPlatform.getCxx().resolve(resolver)));
ImmutableList<String> asflags = cxxPlatform.getAsflags();
ImmutableList<String> cflags = cxxPlatform.getCflags();
ImmutableList<String> cxxflags = cxxPlatform.getCxxflags();
macros.put("cflags", new StringExpander(shquoteJoin(Iterables.concat(cflags, asflags))));
macros.put("cxxflags", new StringExpander(shquoteJoin(Iterables.concat(cxxflags, asflags))));
macros.put("cppflags", new CxxPreprocessorFlagsExpander(cxxPlatform, CxxSource.Type.C));
macros.put("cxxppflags", new CxxPreprocessorFlagsExpander(cxxPlatform, CxxSource.Type.CXX));
macros.put("ld", new ToolExpander(cxxPlatform.getLd().resolve(resolver)));
for (Linker.LinkableDepType depType : Linker.LinkableDepType.values()) {
for (Filter filter : Filter.values()) {
macros.put(String.format("ldflags-%s%s", depType.toString().toLowerCase().replace('_', '-'), filter == Filter.PARAM ? "-filter" : ""), new CxxLinkerFlagsExpander(buildTarget, filesystem, cxxPlatform, depType, args.out, filter));
}
}
return new MacroHandler(macros.build());
}
use of com.facebook.buck.rules.BuildRuleResolver 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.BuildRuleResolver 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;
}
Aggregations