use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class BuildReport method generateJsonBuildReport.
public String generateJsonBuildReport() throws IOException {
Map<BuildRule, Optional<BuildResult>> ruleToResult = buildExecutionResult.getResults();
LinkedHashMap<String, Object> results = Maps.newLinkedHashMap();
LinkedHashMap<String, Object> failures = Maps.newLinkedHashMap();
boolean isOverallSuccess = true;
for (Map.Entry<BuildRule, Optional<BuildResult>> entry : ruleToResult.entrySet()) {
BuildRule rule = entry.getKey();
Optional<BuildRuleSuccessType> success = Optional.empty();
Optional<BuildResult> result = entry.getValue();
if (result.isPresent()) {
success = Optional.ofNullable(result.get().getSuccess());
}
Map<String, Object> value = Maps.newLinkedHashMap();
boolean isSuccess = success.isPresent();
value.put("success", isSuccess);
if (!isSuccess) {
isOverallSuccess = false;
}
if (isSuccess) {
value.put("type", success.get().name());
SourcePath outputFile = rule.getSourcePathToOutput();
value.put("output", outputFile != null ? pathResolver.getRelativePath(outputFile).toString() : null);
}
results.put(rule.getFullyQualifiedName(), value);
}
for (BuildResult failureResult : buildExecutionResult.getFailures()) {
Throwable failure = Preconditions.checkNotNull(failureResult.getFailure());
failures.put(failureResult.getRule().getFullyQualifiedName(), failure.getMessage());
}
Map<String, Object> report = Maps.newLinkedHashMap();
report.put("success", isOverallSuccess);
report.put("results", results);
report.put("failures", failures);
ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
return objectMapper.writeValueAsString(report);
}
use of com.facebook.buck.rules.SourcePath 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.SourcePath 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.SourcePath in project buck by facebook.
the class CxxDescriptionEnhancer method createCompilationDatabaseDependencies.
public static Optional<CxxCompilationDatabaseDependencies> createCompilationDatabaseDependencies(BuildTarget buildTarget, FlavorDomain<CxxPlatform> platforms, BuildRuleResolver resolver, CxxConstructorArg args) throws NoSuchBuildTargetException {
Preconditions.checkState(buildTarget.getFlavors().contains(CxxCompilationDatabase.COMPILATION_DATABASE));
Optional<Flavor> cxxPlatformFlavor = platforms.getFlavor(buildTarget);
Preconditions.checkState(cxxPlatformFlavor.isPresent(), "Could not find cxx platform in:\n%s", Joiner.on(", ").join(buildTarget.getFlavors()));
ImmutableSet.Builder<SourcePath> sourcePaths = ImmutableSet.builder();
for (BuildTarget dep : args.deps) {
Optional<CxxCompilationDatabaseDependencies> compilationDatabases = resolver.requireMetadata(BuildTarget.builder(dep).addFlavors(CxxCompilationDatabase.COMPILATION_DATABASE).addFlavors(cxxPlatformFlavor.get()).build(), CxxCompilationDatabaseDependencies.class);
if (compilationDatabases.isPresent()) {
sourcePaths.addAll(compilationDatabases.get().getSourcePaths());
}
}
// Not all parts of Buck use require yet, so require the rule here so it's available in the
// resolver for the parts that don't.
BuildRule buildRule = resolver.requireRule(buildTarget);
sourcePaths.add(buildRule.getSourcePathToOutput());
return Optional.of(CxxCompilationDatabaseDependencies.of(sourcePaths.build()));
}
use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class CxxDescriptionEnhancer method createSandboxSymlinkTree.
public static SymlinkTree createSandboxSymlinkTree(BuildRuleParams params, CxxPlatform cxxPlatform, ImmutableMap<Path, SourcePath> map, SourcePathRuleFinder ruleFinder) {
BuildTarget sandboxSymlinkTreeTarget = CxxDescriptionEnhancer.createSandboxSymlinkTreeTarget(params.getBuildTarget(), cxxPlatform.getFlavor());
Path sandboxSymlinkTreeRoot = CxxDescriptionEnhancer.getSandboxSymlinkTreePath(params.getProjectFilesystem(), sandboxSymlinkTreeTarget);
return new SymlinkTree(sandboxSymlinkTreeTarget, params.getProjectFilesystem(), sandboxSymlinkTreeRoot, map, ruleFinder);
}
Aggregations