Search in sources :

Example 1 with BuildResult

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);
}
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 BuildResult

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();
}
Also used : BuildResult(com.facebook.buck.rules.BuildResult) Optional(java.util.Optional) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) LinkedHashMap(java.util.LinkedHashMap) Before(org.junit.Before)

Example 3 with BuildResult

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;
}
Also used : JavaLibraryDescription(com.facebook.buck.jvm.java.JavaLibraryDescription) BuildResult(com.facebook.buck.rules.BuildResult) BuildTarget(com.facebook.buck.model.BuildTarget) PrebuiltJarDescription(com.facebook.buck.jvm.java.PrebuiltJarDescription)

Example 4 with BuildResult

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);
}
Also used : BuildResult(com.facebook.buck.rules.BuildResult) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) TestCaseSummary(com.facebook.buck.test.TestCaseSummary) CachingBuildEngine(com.facebook.buck.rules.CachingBuildEngine) TestResults(com.facebook.buck.test.TestResults) FakeTestResults(com.facebook.buck.test.FakeTestResults) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) TestResultSummary(com.facebook.buck.test.TestResultSummary) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) FakeTestRule(com.facebook.buck.rules.FakeTestRule) Test(org.junit.Test)

Example 5 with BuildResult

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);
}
Also used : BuildResult(com.facebook.buck.rules.BuildResult) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) CachingBuildEngine(com.facebook.buck.rules.CachingBuildEngine) TestResults(com.facebook.buck.test.TestResults) FakeTestResults(com.facebook.buck.test.FakeTestResults) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) FakeTestRule(com.facebook.buck.rules.FakeTestRule) Test(org.junit.Test)

Aggregations

BuildResult (com.facebook.buck.rules.BuildResult)12 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)8 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)8 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)8 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)7 ExecutionContext (com.facebook.buck.step.ExecutionContext)7 FakeTestRule (com.facebook.buck.rules.FakeTestRule)6 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)6 FakeTestResults (com.facebook.buck.test.FakeTestResults)6 TestResults (com.facebook.buck.test.TestResults)6 Test (org.junit.Test)6 CachingBuildEngine (com.facebook.buck.rules.CachingBuildEngine)5 Optional (java.util.Optional)5 BuildRule (com.facebook.buck.rules.BuildRule)4 LinkedHashMap (java.util.LinkedHashMap)4 BuildTarget (com.facebook.buck.model.BuildTarget)3 Map (java.util.Map)3 BuildRuleSuccessType (com.facebook.buck.rules.BuildRuleSuccessType)2 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)2 AndroidPlatformTarget (com.facebook.buck.android.AndroidPlatformTarget)1