use of com.facebook.buck.rules.BuildResult 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.BuildResult in project buck by facebook.
the class BuildCommandTest method setUp.
@Before
public void setUp() {
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
resolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
LinkedHashMap<BuildRule, Optional<BuildResult>> ruleToResult = new LinkedHashMap<>();
FakeBuildRule rule1 = new FakeBuildRule(BuildTargetFactory.newInstance("//fake:rule1"), resolver);
rule1.setOutputFile("buck-out/gen/fake/rule1.txt");
ruleResolver.addToIndex(rule1);
ruleToResult.put(rule1, Optional.of(BuildResult.success(rule1, BUILT_LOCALLY, CacheResult.miss())));
BuildRule rule2 = new FakeBuildRule(BuildTargetFactory.newInstance("//fake:rule2"), resolver);
BuildResult rule2Failure = BuildResult.failure(rule2, new RuntimeException("some"));
ruleToResult.put(rule2, Optional.of(rule2Failure));
ruleResolver.addToIndex(rule2);
BuildRule rule3 = new FakeBuildRule(BuildTargetFactory.newInstance("//fake:rule3"), resolver);
ruleToResult.put(rule3, Optional.of(BuildResult.success(rule3, FETCHED_FROM_CACHE, CacheResult.hit("dir"))));
ruleResolver.addToIndex(rule3);
BuildRule rule4 = new FakeBuildRule(BuildTargetFactory.newInstance("//fake:rule4"), resolver);
ruleToResult.put(rule4, Optional.empty());
ruleResolver.addToIndex(rule4);
buildExecutionResult = BuildExecutionResult.builder().setResults(ruleToResult).setFailures(ImmutableSet.of(rule2Failure)).build();
}
use of com.facebook.buck.rules.BuildResult in project buck by facebook.
the class JavaDepsFinder method getJavaFileFeatures.
private Symbols getJavaFileFeatures(TargetNode<?, ?> node, boolean shouldRecordRequiredSymbols) {
// Build a JavaLibrarySymbolsFinder to create the JavaFileFeatures. By making use of Buck's
// build cache, we can often avoid running a Java parser.
BuildTarget buildTarget = node.getBuildTarget();
Object argForNode = node.getConstructorArg();
JavaSymbolsRule.SymbolsFinder symbolsFinder;
ImmutableSortedSet<String> generatedSymbols;
if (argForNode instanceof JavaLibraryDescription.Arg) {
JavaLibraryDescription.Arg arg = (JavaLibraryDescription.Arg) argForNode;
// The build target should be recorded as a provider for every symbol in its
// generated_symbols set (if it exists). It is common to use this for symbols that are
// generated via annotation processors.
generatedSymbols = arg.generatedSymbols;
symbolsFinder = new JavaLibrarySymbolsFinder(arg.srcs, javaFileParser, shouldRecordRequiredSymbols);
} else {
PrebuiltJarDescription.Arg arg = (PrebuiltJarDescription.Arg) argForNode;
generatedSymbols = ImmutableSortedSet.of();
symbolsFinder = new PrebuiltJarSymbolsFinder(arg.binaryJar);
}
// Build the rule, leveraging Buck's build cache.
JavaSymbolsRule buildRule = new JavaSymbolsRule(buildTarget, symbolsFinder, generatedSymbols, objectMapper, node.getFilesystem());
ListenableFuture<BuildResult> future = buildEngine.build(buildContext, executionContext, buildRule);
BuildResult result = Futures.getUnchecked(future);
Symbols features;
if (result.getSuccess() != null) {
features = buildRule.getFeatures();
} else {
Throwable failure = result.getFailure();
Preconditions.checkNotNull(failure);
throw new RuntimeException("Failed to extract Java symbols for " + buildTarget, failure);
}
return features;
}
use of com.facebook.buck.rules.BuildResult in project buck by facebook.
the class TestRunningTest method testRunWhenPreviouslyFailed.
@Test
public void testRunWhenPreviouslyFailed() throws Exception {
ExecutionContext executionContext = TestExecutionContext.newBuilder().setDebugEnabled(false).build();
FakeTestRule testRule = new FakeTestRule(ImmutableSet.of(Label.of("windows")), BuildTargetFactory.newInstance("//:lulz"), new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSortedSet.of()) {
@Override
public boolean hasTestResultFiles() {
return true;
}
};
TestRuleKeyFileHelper testRuleKeyFileHelper = createNiceMock(TestRuleKeyFileHelper.class);
expect(testRuleKeyFileHelper.isRuleKeyInDir(testRule)).andReturn(true).times(2);
CachingBuildEngine cachingBuildEngine = createMock(CachingBuildEngine.class);
BuildResult result = BuildResult.success(testRule, MATCHING_RULE_KEY, CacheResult.miss());
expect(cachingBuildEngine.getBuildRuleResult(BuildTargetFactory.newInstance("//:lulz"))).andReturn(result).times(2);
replay(cachingBuildEngine, testRuleKeyFileHelper);
final TestResults failedTestResults = FakeTestResults.of(ImmutableList.of(new TestCaseSummary("TestCase", ImmutableList.of(new TestResultSummary("TestCaseResult", "passTest", ResultType.FAILURE, 5000, null, null, null, null)))));
assertTrue("Test will be rerun if it previously failed", TestRunning.isTestRunRequiredForTest(testRule, cachingBuildEngine, executionContext, testRuleKeyFileHelper, TestRunningOptions.TestResultCacheMode.ENABLED_IF_PASSED, Callables.<TestResults>returning(failedTestResults), /* running with test selectors */
false, /* hasEnvironmentOverrides */
false));
final TestResults passedTestResults = FakeTestResults.of(ImmutableList.of(new TestCaseSummary("TestCase", ImmutableList.of(new TestResultSummary("TestCaseResult", "passTest", ResultType.SUCCESS, 5000, null, null, null, null)))));
assertFalse("Test will be not rerun if it previously passed", TestRunning.isTestRunRequiredForTest(testRule, cachingBuildEngine, executionContext, testRuleKeyFileHelper, TestRunningOptions.TestResultCacheMode.ENABLED_IF_PASSED, Callables.<TestResults>returning(passedTestResults), /* running with test selectors */
false, /* hasEnvironmentOverrides */
false));
verify(cachingBuildEngine, testRuleKeyFileHelper);
}
use of com.facebook.buck.rules.BuildResult in project buck by facebook.
the class TestRunningTest method testIsTestRunRequiredForTestBuiltLocally.
@Test
public void testIsTestRunRequiredForTestBuiltLocally() throws IOException, ExecutionException, InterruptedException {
ExecutionContext executionContext = TestExecutionContext.newInstance();
assertFalse(executionContext.isDebugEnabled());
FakeTestRule testRule = new FakeTestRule(ImmutableSet.of(Label.of("windows")), BuildTargetFactory.newInstance("//:lulz"), new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSortedSet.of());
CachingBuildEngine cachingBuildEngine = createMock(CachingBuildEngine.class);
BuildResult result = BuildResult.success(testRule, BUILT_LOCALLY, CacheResult.miss());
expect(cachingBuildEngine.getBuildRuleResult(BuildTargetFactory.newInstance("//:lulz"))).andReturn(result);
replay(cachingBuildEngine);
assertTrue("A test built locally should always run regardless of any cached result. ", TestRunning.isTestRunRequiredForTest(testRule, cachingBuildEngine, executionContext, createMock(TestRuleKeyFileHelper.class), TestRunningOptions.TestResultCacheMode.ENABLED, Callables.<TestResults>returning(null), /* running with test selectors */
false, /* hasEnvironmentOverrides */
false));
verify(cachingBuildEngine);
}
Aggregations