Search in sources :

Example 1 with BuildRuleSuccessType

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);
}
Also used : Optional(java.util.Optional) SourcePath(com.facebook.buck.rules.SourcePath) BuildResult(com.facebook.buck.rules.BuildResult) BuildRuleSuccessType(com.facebook.buck.rules.BuildRuleSuccessType) BuildRule(com.facebook.buck.rules.BuildRule) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with BuildRuleSuccessType

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());
}
Also used : Matcher(java.util.regex.Matcher) BuildTarget(com.facebook.buck.model.BuildTarget) Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode) BuildRuleSuccessType(com.facebook.buck.rules.BuildRuleSuccessType) CacheResult(com.facebook.buck.artifact_cache.CacheResult) BuildRuleStatus(com.facebook.buck.rules.BuildRuleStatus) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 3 with BuildRuleSuccessType

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();
}
Also used : Optional(java.util.Optional) SourcePath(com.facebook.buck.rules.SourcePath) BuildResult(com.facebook.buck.rules.BuildResult) BuildRuleSuccessType(com.facebook.buck.rules.BuildRuleSuccessType) BuildRule(com.facebook.buck.rules.BuildRule) Ansi(com.facebook.buck.util.Ansi) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

BuildRuleSuccessType (com.facebook.buck.rules.BuildRuleSuccessType)3 BuildResult (com.facebook.buck.rules.BuildResult)2 BuildRule (com.facebook.buck.rules.BuildRule)2 SourcePath (com.facebook.buck.rules.SourcePath)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Optional (java.util.Optional)2 CacheResult (com.facebook.buck.artifact_cache.CacheResult)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 BuildRuleStatus (com.facebook.buck.rules.BuildRuleStatus)1 Ansi (com.facebook.buck.util.Ansi)1 Sha1HashCode (com.facebook.buck.util.sha1.Sha1HashCode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Matcher (java.util.regex.Matcher)1