Search in sources :

Example 1 with CachingBuildEngine

use of com.facebook.buck.rules.CachingBuildEngine in project buck by facebook.

the class FetchCommand method runWithoutHelp.

@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
    if (getArguments().isEmpty()) {
        params.getBuckEventBus().post(ConsoleEvent.severe("Must specify at least one build target to fetch."));
        return 1;
    }
    // Post the build started event, setting it to the Parser recorded start time if appropriate.
    BuildEvent.Started started = BuildEvent.started(getArguments());
    if (params.getParser().getParseStartTime().isPresent()) {
        params.getBuckEventBus().post(started, params.getParser().getParseStartTime().get());
    } else {
        params.getBuckEventBus().post(started);
    }
    FetchTargetNodeToBuildRuleTransformer ruleGenerator = createFetchTransformer(params);
    int exitCode;
    try (CommandThreadManager pool = new CommandThreadManager("Fetch", getConcurrencyLimit(params.getBuckConfig()))) {
        ActionGraphAndResolver actionGraphAndResolver;
        ImmutableSet<BuildTarget> buildTargets;
        try {
            ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
            TargetGraphAndBuildTargets result = params.getParser().buildTargetGraphForTargetNodeSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), pool.getExecutor(), parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), getArguments()), /* ignoreBuckAutodepsFiles */
            false, parserConfig.getDefaultFlavorsMode());
            if (params.getBuckConfig().getBuildVersions()) {
                result = toVersionedTargetGraph(params, result);
            }
            actionGraphAndResolver = Preconditions.checkNotNull(ActionGraphCache.getFreshActionGraph(params.getBuckEventBus(), ruleGenerator, result.getTargetGraph()));
            buildTargets = ruleGenerator.getDownloadableTargets();
        } catch (BuildTargetException | BuildFileParseException | VersionException e) {
            params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
            return 1;
        }
        CachingBuildEngineBuckConfig cachingBuildEngineBuckConfig = params.getBuckConfig().getView(CachingBuildEngineBuckConfig.class);
        LocalCachingBuildEngineDelegate localCachingBuildEngineDelegate = new LocalCachingBuildEngineDelegate(params.getFileHashCache());
        try (RuleKeyCacheScope<RuleKey> ruleKeyCacheScope = getDefaultRuleKeyCacheScope(params, new RuleKeyCacheRecycler.SettingsAffectingCache(params.getBuckConfig().getKeySeed(), actionGraphAndResolver.getActionGraph()));
            Build build = createBuild(params.getBuckConfig(), actionGraphAndResolver.getActionGraph(), actionGraphAndResolver.getResolver(), params.getCell(), params.getAndroidPlatformTargetSupplier(), new CachingBuildEngine(localCachingBuildEngineDelegate, pool.getExecutor(), pool.getExecutor(), new DefaultStepRunner(), getBuildEngineMode().orElse(cachingBuildEngineBuckConfig.getBuildEngineMode()), cachingBuildEngineBuckConfig.getBuildDepFiles(), cachingBuildEngineBuckConfig.getBuildMaxDepFileCacheEntries(), cachingBuildEngineBuckConfig.getBuildArtifactCacheSizeLimit(), params.getObjectMapper(), actionGraphAndResolver.getResolver(), cachingBuildEngineBuckConfig.getResourceAwareSchedulingInfo(), new RuleKeyFactoryManager(params.getBuckConfig().getKeySeed(), fs -> localCachingBuildEngineDelegate.getFileHashCache(), actionGraphAndResolver.getResolver(), cachingBuildEngineBuckConfig.getBuildInputRuleKeyFileSizeLimit(), ruleKeyCacheScope.getCache())), params.getArtifactCacheFactory().newInstance(), params.getConsole(), params.getBuckEventBus(), Optional.empty(), params.getPersistentWorkerPools(), params.getPlatform(), params.getEnvironment(), params.getObjectMapper(), params.getClock(), Optional.empty(), Optional.empty(), params.getExecutors())) {
            exitCode = build.executeAndPrintFailuresToEventBus(buildTargets, isKeepGoing(), params.getBuckEventBus(), params.getConsole(), getPathToBuildReport(params.getBuckConfig()));
        }
    }
    params.getBuckEventBus().post(BuildEvent.finished(started, exitCode));
    return exitCode;
}
Also used : BuildTargetException(com.facebook.buck.model.BuildTargetException) LocalCachingBuildEngineDelegate(com.facebook.buck.rules.LocalCachingBuildEngineDelegate) RuleKey(com.facebook.buck.rules.RuleKey) CachingBuildEngine(com.facebook.buck.rules.CachingBuildEngine) RuleKeyFactoryManager(com.facebook.buck.rules.keys.RuleKeyFactoryManager) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) BuildEvent(com.facebook.buck.rules.BuildEvent) BuildTarget(com.facebook.buck.model.BuildTarget) Build(com.facebook.buck.command.Build) DefaultStepRunner(com.facebook.buck.step.DefaultStepRunner) ActionGraphAndResolver(com.facebook.buck.rules.ActionGraphAndResolver) RuleKeyCacheRecycler(com.facebook.buck.rules.keys.RuleKeyCacheRecycler) ParserConfig(com.facebook.buck.parser.ParserConfig) TargetGraphAndBuildTargets(com.facebook.buck.rules.TargetGraphAndBuildTargets) VersionException(com.facebook.buck.versions.VersionException) CachingBuildEngineBuckConfig(com.facebook.buck.rules.CachingBuildEngineBuckConfig)

Example 2 with CachingBuildEngine

use of com.facebook.buck.rules.CachingBuildEngine in project buck by facebook.

the class JavaBuildGraphProcessor method run.

/**
   * Creates the appropriate target graph and other resources needed for the {@link Processor} and
   * runs it. This method will take responsibility for cleaning up the executor service after it
   * runs.
   */
static void run(final CommandRunnerParams params, final AbstractCommand command, final Processor processor) throws ExitCodeException, InterruptedException, IOException {
    final ConcurrencyLimit concurrencyLimit = command.getConcurrencyLimit(params.getBuckConfig());
    try (CommandThreadManager pool = new CommandThreadManager(command.getClass().getName(), concurrencyLimit)) {
        Cell cell = params.getCell();
        WeightedListeningExecutorService executorService = pool.getExecutor();
        // Ideally, we should be able to construct the TargetGraph quickly assuming most of it is
        // already in memory courtesy of buckd. Though we could make a performance optimization where
        // we pass an option to buck.py that tells it to ignore reading the BUCK.autodeps files when
        // parsing the BUCK files because we never need to consider the existing auto-generated deps
        // when creating the new auto-generated deps. If we did so, we would have to make sure to keep
        // the nodes for that version of the graph separate from the ones that are actually used for
        // building.
        TargetGraph graph;
        try {
            graph = params.getParser().buildTargetGraphForTargetNodeSpecs(params.getBuckEventBus(), cell, command.getEnableParserProfiling(), executorService, ImmutableList.of(TargetNodePredicateSpec.of(x -> true, BuildFileSpec.fromRecursivePath(Paths.get(""), cell.getRoot()))), /* ignoreBuckAutodepsFiles */
            true).getTargetGraph();
        } catch (BuildTargetException | BuildFileParseException e) {
            params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
            throw new ExitCodeException(1);
        }
        BuildRuleResolver buildRuleResolver = new BuildRuleResolver(graph, new DefaultTargetNodeToBuildRuleTransformer());
        CachingBuildEngineBuckConfig cachingBuildEngineBuckConfig = params.getBuckConfig().getView(CachingBuildEngineBuckConfig.class);
        LocalCachingBuildEngineDelegate cachingBuildEngineDelegate = new LocalCachingBuildEngineDelegate(params.getFileHashCache());
        BuildEngine buildEngine = new CachingBuildEngine(cachingBuildEngineDelegate, executorService, executorService, new DefaultStepRunner(), CachingBuildEngine.BuildMode.SHALLOW, cachingBuildEngineBuckConfig.getBuildDepFiles(), cachingBuildEngineBuckConfig.getBuildMaxDepFileCacheEntries(), cachingBuildEngineBuckConfig.getBuildArtifactCacheSizeLimit(), params.getObjectMapper(), buildRuleResolver, cachingBuildEngineBuckConfig.getResourceAwareSchedulingInfo(), new RuleKeyFactoryManager(params.getBuckConfig().getKeySeed(), fs -> cachingBuildEngineDelegate.getFileHashCache(), buildRuleResolver, cachingBuildEngineBuckConfig.getBuildInputRuleKeyFileSizeLimit(), new DefaultRuleKeyCache<>()));
        // Create a BuildEngine because we store symbol information as build artifacts.
        BuckEventBus eventBus = params.getBuckEventBus();
        ExecutionContext executionContext = ExecutionContext.builder().setConsole(params.getConsole()).setConcurrencyLimit(concurrencyLimit).setBuckEventBus(eventBus).setEnvironment(/* environment */
        ImmutableMap.of()).setExecutors(ImmutableMap.<ExecutorPool, ListeningExecutorService>of(ExecutorPool.CPU, executorService)).setJavaPackageFinder(params.getJavaPackageFinder()).setObjectMapper(params.getObjectMapper()).setPlatform(params.getPlatform()).setCellPathResolver(params.getCell().getCellPathResolver()).build();
        SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(buildRuleResolver));
        BuildEngineBuildContext buildContext = BuildEngineBuildContext.builder().setBuildContext(BuildContext.builder().setActionGraph(new ActionGraph(ImmutableList.of())).setSourcePathResolver(pathResolver).setJavaPackageFinder(executionContext.getJavaPackageFinder()).setEventBus(eventBus).build()).setClock(params.getClock()).setArtifactCache(params.getArtifactCacheFactory().newInstance()).setBuildId(eventBus.getBuildId()).setObjectMapper(params.getObjectMapper()).setEnvironment(executionContext.getEnvironment()).setKeepGoing(false).build();
        // Traverse the TargetGraph to find all of the auto-generated dependencies.
        JavaDepsFinder javaDepsFinder = JavaDepsFinder.createJavaDepsFinder(params.getBuckConfig(), params.getCell().getCellPathResolver(), params.getObjectMapper(), buildContext, executionContext, buildEngine);
        processor.process(graph, javaDepsFinder, executorService);
    }
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) ActionGraph(com.facebook.buck.rules.ActionGraph) TargetNodePredicateSpec(com.facebook.buck.parser.TargetNodePredicateSpec) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) MoreExceptions(com.facebook.buck.util.MoreExceptions) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) ExecutionContext(com.facebook.buck.step.ExecutionContext) ImmutableList(com.google.common.collect.ImmutableList) LocalCachingBuildEngineDelegate(com.facebook.buck.rules.LocalCachingBuildEngineDelegate) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) DefaultStepRunner(com.facebook.buck.step.DefaultStepRunner) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) ConcurrencyLimit(com.facebook.buck.util.concurrent.ConcurrencyLimit) CachingBuildEngineBuckConfig(com.facebook.buck.rules.CachingBuildEngineBuckConfig) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) Cell(com.facebook.buck.rules.Cell) WeightedListeningExecutorService(com.facebook.buck.util.concurrent.WeightedListeningExecutorService) BuildFileSpec(com.facebook.buck.parser.BuildFileSpec) DefaultRuleKeyCache(com.facebook.buck.rules.keys.DefaultRuleKeyCache) ImmutableMap(com.google.common.collect.ImmutableMap) TargetGraph(com.facebook.buck.rules.TargetGraph) BuildTargetException(com.facebook.buck.model.BuildTargetException) IOException(java.io.IOException) CachingBuildEngine(com.facebook.buck.rules.CachingBuildEngine) JavaDepsFinder(com.facebook.buck.jvm.java.autodeps.JavaDepsFinder) BuildEngineBuildContext(com.facebook.buck.rules.BuildEngineBuildContext) Paths(java.nio.file.Paths) ExecutorPool(com.facebook.buck.step.ExecutorPool) BuildEngine(com.facebook.buck.rules.BuildEngine) BuildContext(com.facebook.buck.rules.BuildContext) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) RuleKeyFactoryManager(com.facebook.buck.rules.keys.RuleKeyFactoryManager) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) BuckEventBus(com.facebook.buck.event.BuckEventBus) JavaDepsFinder(com.facebook.buck.jvm.java.autodeps.JavaDepsFinder) DefaultRuleKeyCache(com.facebook.buck.rules.keys.DefaultRuleKeyCache) TargetGraph(com.facebook.buck.rules.TargetGraph) RuleKeyFactoryManager(com.facebook.buck.rules.keys.RuleKeyFactoryManager) WeightedListeningExecutorService(com.facebook.buck.util.concurrent.WeightedListeningExecutorService) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) DefaultStepRunner(com.facebook.buck.step.DefaultStepRunner) BuildEngineBuildContext(com.facebook.buck.rules.BuildEngineBuildContext) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Cell(com.facebook.buck.rules.Cell) BuildTargetException(com.facebook.buck.model.BuildTargetException) ConcurrencyLimit(com.facebook.buck.util.concurrent.ConcurrencyLimit) LocalCachingBuildEngineDelegate(com.facebook.buck.rules.LocalCachingBuildEngineDelegate) ActionGraph(com.facebook.buck.rules.ActionGraph) CachingBuildEngine(com.facebook.buck.rules.CachingBuildEngine) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) CachingBuildEngine(com.facebook.buck.rules.CachingBuildEngine) BuildEngine(com.facebook.buck.rules.BuildEngine) ExecutionContext(com.facebook.buck.step.ExecutionContext) ExecutorPool(com.facebook.buck.step.ExecutorPool) WeightedListeningExecutorService(com.facebook.buck.util.concurrent.WeightedListeningExecutorService) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) CachingBuildEngineBuckConfig(com.facebook.buck.rules.CachingBuildEngineBuckConfig)

Example 3 with CachingBuildEngine

use of com.facebook.buck.rules.CachingBuildEngine 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 4 with CachingBuildEngine

use of com.facebook.buck.rules.CachingBuildEngine 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)

Example 5 with CachingBuildEngine

use of com.facebook.buck.rules.CachingBuildEngine in project buck by facebook.

the class TestCommand method runWithoutHelp.

@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
    LOG.debug("Running with arguments %s", getArguments());
    try (CommandThreadManager pool = new CommandThreadManager("Test", getConcurrencyLimit(params.getBuckConfig()))) {
        // Post the build started event, setting it to the Parser recorded start time if appropriate.
        BuildEvent.Started started = BuildEvent.started(getArguments());
        if (params.getParser().getParseStartTime().isPresent()) {
            params.getBuckEventBus().post(started, params.getParser().getParseStartTime().get());
        } else {
            params.getBuckEventBus().post(started);
        }
        // The first step is to parse all of the build files. This will populate the parser and find
        // all of the test rules.
        TargetGraphAndBuildTargets targetGraphAndBuildTargets;
        ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
        try {
            // If the user asked to run all of the tests, parse all of the build files looking for any
            // test rules.
            boolean ignoreBuckAutodepsFiles = false;
            if (isRunAllTests()) {
                targetGraphAndBuildTargets = params.getParser().buildTargetGraphForTargetNodeSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), pool.getExecutor(), ImmutableList.of(TargetNodePredicateSpec.of(input -> Description.getBuildRuleType(input.getDescription()).isTestRule(), BuildFileSpec.fromRecursivePath(Paths.get(""), params.getCell().getRoot()))), ignoreBuckAutodepsFiles, parserConfig.getDefaultFlavorsMode());
                targetGraphAndBuildTargets = targetGraphAndBuildTargets.withBuildTargets(ImmutableSet.of());
            // Otherwise, the user specified specific test targets to build and run, so build a graph
            // around these.
            } else {
                LOG.debug("Parsing graph for arguments %s", getArguments());
                targetGraphAndBuildTargets = params.getParser().buildTargetGraphForTargetNodeSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), pool.getExecutor(), parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), getArguments()), ignoreBuckAutodepsFiles, parserConfig.getDefaultFlavorsMode());
                LOG.debug("Got explicit build targets %s", targetGraphAndBuildTargets.getBuildTargets());
                ImmutableSet.Builder<BuildTarget> testTargetsBuilder = ImmutableSet.builder();
                for (TargetNode<?, ?> node : targetGraphAndBuildTargets.getTargetGraph().getAll(targetGraphAndBuildTargets.getBuildTargets())) {
                    ImmutableSortedSet<BuildTarget> nodeTests = TargetNodes.getTestTargetsForNode(node);
                    if (!nodeTests.isEmpty()) {
                        LOG.debug("Got tests for target %s: %s", node.getBuildTarget(), nodeTests);
                        testTargetsBuilder.addAll(nodeTests);
                    }
                }
                ImmutableSet<BuildTarget> testTargets = testTargetsBuilder.build();
                if (!testTargets.isEmpty()) {
                    LOG.debug("Got related test targets %s, building new target graph...", testTargets);
                    TargetGraph targetGraph = params.getParser().buildTargetGraph(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), pool.getExecutor(), Iterables.concat(targetGraphAndBuildTargets.getBuildTargets(), testTargets));
                    LOG.debug("Finished building new target graph with tests.");
                    targetGraphAndBuildTargets = targetGraphAndBuildTargets.withTargetGraph(targetGraph);
                }
            }
            if (params.getBuckConfig().getBuildVersions()) {
                targetGraphAndBuildTargets = toVersionedTargetGraph(params, targetGraphAndBuildTargets);
            }
        } catch (BuildTargetException | BuildFileParseException | VersionException e) {
            params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
            return 1;
        }
        ActionGraphAndResolver actionGraphAndResolver = Preconditions.checkNotNull(params.getActionGraphCache().getActionGraph(params.getBuckEventBus(), params.getBuckConfig().isActionGraphCheckingEnabled(), params.getBuckConfig().isSkipActionGraphCache(), targetGraphAndBuildTargets.getTargetGraph(), params.getBuckConfig().getKeySeed()));
        // Look up all of the test rules in the action graph.
        Iterable<TestRule> testRules = Iterables.filter(actionGraphAndResolver.getActionGraph().getNodes(), TestRule.class);
        // the build.
        if (!isBuildFiltered(params.getBuckConfig())) {
            testRules = filterTestRules(params.getBuckConfig(), targetGraphAndBuildTargets.getBuildTargets(), testRules);
        }
        CachingBuildEngineBuckConfig cachingBuildEngineBuckConfig = params.getBuckConfig().getView(CachingBuildEngineBuckConfig.class);
        try (CommandThreadManager artifactFetchService = getArtifactFetchService(params.getBuckConfig(), pool.getExecutor());
            RuleKeyCacheScope<RuleKey> ruleKeyCacheScope = getDefaultRuleKeyCacheScope(params, new RuleKeyCacheRecycler.SettingsAffectingCache(params.getBuckConfig().getKeySeed(), actionGraphAndResolver.getActionGraph()))) {
            LocalCachingBuildEngineDelegate localCachingBuildEngineDelegate = new LocalCachingBuildEngineDelegate(params.getFileHashCache());
            CachingBuildEngine cachingBuildEngine = new CachingBuildEngine(new LocalCachingBuildEngineDelegate(params.getFileHashCache()), pool.getExecutor(), artifactFetchService == null ? pool.getExecutor() : artifactFetchService.getExecutor(), new DefaultStepRunner(), getBuildEngineMode().orElse(cachingBuildEngineBuckConfig.getBuildEngineMode()), cachingBuildEngineBuckConfig.getBuildDepFiles(), cachingBuildEngineBuckConfig.getBuildMaxDepFileCacheEntries(), cachingBuildEngineBuckConfig.getBuildArtifactCacheSizeLimit(), params.getObjectMapper(), actionGraphAndResolver.getResolver(), cachingBuildEngineBuckConfig.getResourceAwareSchedulingInfo(), new RuleKeyFactoryManager(params.getBuckConfig().getKeySeed(), fs -> localCachingBuildEngineDelegate.getFileHashCache(), actionGraphAndResolver.getResolver(), cachingBuildEngineBuckConfig.getBuildInputRuleKeyFileSizeLimit(), ruleKeyCacheScope.getCache()));
            try (Build build = createBuild(params.getBuckConfig(), actionGraphAndResolver.getActionGraph(), actionGraphAndResolver.getResolver(), params.getCell(), params.getAndroidPlatformTargetSupplier(), cachingBuildEngine, params.getArtifactCacheFactory().newInstance(), params.getConsole(), params.getBuckEventBus(), getTargetDeviceOptional(), params.getPersistentWorkerPools(), params.getPlatform(), params.getEnvironment(), params.getObjectMapper(), params.getClock(), Optional.of(getAdbOptions(params.getBuckConfig())), Optional.of(getTargetDeviceOptions()), params.getExecutors())) {
                // Build all of the test rules.
                int exitCode = build.executeAndPrintFailuresToEventBus(RichStream.from(testRules).map(TestRule::getBuildTarget).collect(MoreCollectors.toImmutableList()), isKeepGoing(), params.getBuckEventBus(), params.getConsole(), getPathToBuildReport(params.getBuckConfig()));
                params.getBuckEventBus().post(BuildEvent.finished(started, exitCode));
                if (exitCode != 0) {
                    return exitCode;
                }
                // the filtering here, after we've done the build but before we run the tests.
                if (isBuildFiltered(params.getBuckConfig())) {
                    testRules = filterTestRules(params.getBuckConfig(), targetGraphAndBuildTargets.getBuildTargets(), testRules);
                }
                // Once all of the rules are built, then run the tests.
                Optional<ImmutableList<String>> externalTestRunner = params.getBuckConfig().getExternalTestRunner();
                if (externalTestRunner.isPresent()) {
                    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(actionGraphAndResolver.getResolver()));
                    return runTestsExternal(params, build, externalTestRunner.get(), testRules, pathResolver);
                }
                return runTestsInternal(params, cachingBuildEngine, build, testRules);
            }
        }
    }
}
Also used : TargetNodePredicateSpec(com.facebook.buck.parser.TargetNodePredicateSpec) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) RichStream(com.facebook.buck.util.RichStream) AdbOptions(com.facebook.buck.step.AdbOptions) TestRunningOptions(com.facebook.buck.test.TestRunningOptions) RuleKey(com.facebook.buck.rules.RuleKey) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) DefaultStepRunner(com.facebook.buck.step.DefaultStepRunner) Map(java.util.Map) ConcurrencyLimit(com.facebook.buck.util.concurrent.ConcurrencyLimit) TestRule(com.facebook.buck.rules.TestRule) Path(java.nio.file.Path) ImmutableSet(com.google.common.collect.ImmutableSet) TargetGraph(com.facebook.buck.rules.TargetGraph) BuildTargetException(com.facebook.buck.model.BuildTargetException) Set(java.util.Set) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) Option(org.kohsuke.args4j.Option) BuildTarget(com.facebook.buck.model.BuildTarget) SuppressFieldNotInitialized(com.facebook.infer.annotation.SuppressFieldNotInitialized) Collectors(java.util.stream.Collectors) ActionGraphAndResolver(com.facebook.buck.rules.ActionGraphAndResolver) CachingBuildEngine(com.facebook.buck.rules.CachingBuildEngine) List(java.util.List) ForwardingProcessListener(com.facebook.buck.util.ForwardingProcessListener) ExternalTestRunnerTestSpec(com.facebook.buck.rules.ExternalTestRunnerTestSpec) Optional(java.util.Optional) Description(com.facebook.buck.rules.Description) RuleKeyFactoryManager(com.facebook.buck.rules.keys.RuleKeyFactoryManager) ExternalTestRunnerRule(com.facebook.buck.rules.ExternalTestRunnerRule) Iterables(com.google.common.collect.Iterables) TargetGraphAndBuildTargets(com.facebook.buck.rules.TargetGraphAndBuildTargets) Build(com.facebook.buck.command.Build) VersionException(com.facebook.buck.versions.VersionException) RuleKeyCacheRecycler(com.facebook.buck.rules.keys.RuleKeyCacheRecycler) MoreExceptions(com.facebook.buck.util.MoreExceptions) HashMap(java.util.HashMap) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) Lists(com.google.common.collect.Lists) ParserConfig(com.facebook.buck.parser.ParserConfig) Label(com.facebook.buck.rules.Label) ImmutableList(com.google.common.collect.ImmutableList) LocalCachingBuildEngineDelegate(com.facebook.buck.rules.LocalCachingBuildEngineDelegate) CachingBuildEngineBuckConfig(com.facebook.buck.rules.CachingBuildEngineBuckConfig) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) Nullable(javax.annotation.Nullable) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) PrintStream(java.io.PrintStream) Logger(com.facebook.buck.log.Logger) RuleKeyCacheScope(com.facebook.buck.rules.keys.RuleKeyCacheScope) BuildFileSpec(com.facebook.buck.parser.BuildFileSpec) Files(java.nio.file.Files) TargetNode(com.facebook.buck.rules.TargetNode) Channels(java.nio.channels.Channels) TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) IOException(java.io.IOException) TargetDevice(com.facebook.buck.step.TargetDevice) ExecutionException(java.util.concurrent.ExecutionException) BuildEvent(com.facebook.buck.rules.BuildEvent) CoverageReportFormat(com.facebook.buck.test.CoverageReportFormat) Paths(java.nio.file.Paths) BuildEngine(com.facebook.buck.rules.BuildEngine) Preconditions(com.google.common.base.Preconditions) TargetNodes(com.facebook.buck.rules.TargetNodes) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ListeningProcessExecutor(com.facebook.buck.util.ListeningProcessExecutor) Comparator(java.util.Comparator) ImmutableList(com.google.common.collect.ImmutableList) TargetGraph(com.facebook.buck.rules.TargetGraph) RuleKeyFactoryManager(com.facebook.buck.rules.keys.RuleKeyFactoryManager) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) Build(com.facebook.buck.command.Build) DefaultStepRunner(com.facebook.buck.step.DefaultStepRunner) ActionGraphAndResolver(com.facebook.buck.rules.ActionGraphAndResolver) BuildTargetException(com.facebook.buck.model.BuildTargetException) LocalCachingBuildEngineDelegate(com.facebook.buck.rules.LocalCachingBuildEngineDelegate) RuleKey(com.facebook.buck.rules.RuleKey) CachingBuildEngine(com.facebook.buck.rules.CachingBuildEngine) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) TestRule(com.facebook.buck.rules.TestRule) BuildEvent(com.facebook.buck.rules.BuildEvent) RuleKeyCacheRecycler(com.facebook.buck.rules.keys.RuleKeyCacheRecycler) TargetGraphAndBuildTargets(com.facebook.buck.rules.TargetGraphAndBuildTargets) ParserConfig(com.facebook.buck.parser.ParserConfig) VersionException(com.facebook.buck.versions.VersionException) CachingBuildEngineBuckConfig(com.facebook.buck.rules.CachingBuildEngineBuckConfig)

Aggregations

CachingBuildEngine (com.facebook.buck.rules.CachingBuildEngine)8 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)7 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)7 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)6 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)6 ExecutionContext (com.facebook.buck.step.ExecutionContext)6 BuildResult (com.facebook.buck.rules.BuildResult)5 FakeTestRule (com.facebook.buck.rules.FakeTestRule)5 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)5 FakeTestResults (com.facebook.buck.test.FakeTestResults)5 TestResults (com.facebook.buck.test.TestResults)5 Test (org.junit.Test)5 BuildFileParseException (com.facebook.buck.json.BuildFileParseException)3 BuildTargetException (com.facebook.buck.model.BuildTargetException)3 CachingBuildEngineBuckConfig (com.facebook.buck.rules.CachingBuildEngineBuckConfig)3 LocalCachingBuildEngineDelegate (com.facebook.buck.rules.LocalCachingBuildEngineDelegate)3 RuleKeyFactoryManager (com.facebook.buck.rules.keys.RuleKeyFactoryManager)3 Build (com.facebook.buck.command.Build)2 ConsoleEvent (com.facebook.buck.event.ConsoleEvent)2 BuildTarget (com.facebook.buck.model.BuildTarget)2