use of com.facebook.buck.rules.BuildRuleSuccessType 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.BuildRuleSuccessType in project buck by facebook.
the class BuckBuildLog method fromLogContents.
public static BuckBuildLog fromLogContents(Path root, List<String> logContents) {
ImmutableMap.Builder<BuildTarget, BuildLogEntry> builder = ImmutableMap.builder();
for (String line : logContents) {
Matcher matcher = BUILD_LOG_FINISHED_RULE_REGEX.matcher(line);
if (!matcher.matches()) {
continue;
}
String buildTargetRaw = matcher.group("BuildTarget");
BuildTarget buildTarget = BuildTargetFactory.newInstance(root, buildTargetRaw);
String statusRaw = matcher.group("Status");
BuildRuleStatus status = BuildRuleStatus.valueOf(statusRaw);
String ruleKeyRaw = matcher.group("RuleKey");
Sha1HashCode ruleKey = Sha1HashCode.of(ruleKeyRaw);
CacheResult cacheResult = null;
BuildRuleSuccessType successType = null;
if (status == BuildRuleStatus.SUCCESS) {
String cacheResultRaw = matcher.group("CacheResult");
cacheResult = CacheResult.valueOf(cacheResultRaw);
String successTypeRaw = matcher.group("SuccessType");
successType = BuildRuleSuccessType.valueOf(successTypeRaw);
}
builder.put(buildTarget, new BuildLogEntry(status, Optional.ofNullable(successType), Optional.ofNullable(cacheResult), ruleKey));
}
return new BuckBuildLog(root, builder.build());
}
use of com.facebook.buck.rules.BuildRuleSuccessType in project buck by facebook.
the class BuildReport method generateForConsole.
public String generateForConsole(Console console) {
Ansi ansi = console.getAnsi();
Map<BuildRule, Optional<BuildResult>> ruleToResult = buildExecutionResult.getResults();
StringBuilder report = new StringBuilder();
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());
}
String successIndicator;
String successType;
SourcePath outputFile;
if (success.isPresent()) {
successIndicator = ansi.asHighlightedSuccessText("OK ");
successType = success.get().name();
outputFile = rule.getSourcePathToOutput();
} else {
successIndicator = ansi.asHighlightedFailureText("FAIL");
successType = null;
outputFile = null;
}
report.append(String.format("%s %s%s%s\n", successIndicator, rule.getBuildTarget(), successType != null ? " " + successType : "", outputFile != null ? " " + pathResolver.getRelativePath(outputFile) : ""));
}
if (!buildExecutionResult.getFailures().isEmpty() && console.getVerbosity().shouldPrintCommand()) {
report.append("\n ** Summary of failures encountered during the build **\n");
for (BuildResult failureResult : buildExecutionResult.getFailures()) {
Throwable failure = Preconditions.checkNotNull(failureResult.getFailure());
report.append(String.format("Rule %s FAILED because %s.\n", failureResult.getRule().getFullyQualifiedName(), failure.getMessage()));
}
}
return report.toString();
}
Aggregations