diff options
author | 2015-09-16 10:01:38 +0000 | |
---|---|---|
committer | 2015-09-16 10:19:10 +0000 | |
commit | 86bd4fdc16e0e71504dfe0428c188fdb9efab77f (patch) | |
tree | 24d079a3fd40b85ff4dc6d86be22987b70b86e1c /src/main/java/com/google/devtools/build/lib/pkgcache | |
parent | 806130233d4d190dbfaf6a28feb84eb5a010f1c7 (diff) |
Add experimental flag, that partially disables loading phase (pattern evaluation, test_suite expansion and configuration creation is still there). Also remove some unused code.
--
MOS_MIGRATED_REVID=103177839
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/pkgcache')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunner.java | 102 |
1 files changed, 69 insertions, 33 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunner.java b/src/main/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunner.java index 97f336f09d..8006899a3b 100644 --- a/src/main/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunner.java +++ b/src/main/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunner.java @@ -290,7 +290,7 @@ public class LoadingPhaseRunner { public LoadingResult execute(EventHandler eventHandler, EventBus eventBus, List<String> targetPatterns, Options options, ListMultimap<String, Label> labelsToLoadUnconditionally, boolean keepGoing, - boolean determineTests, @Nullable Callback callback) + boolean enableLoading, boolean determineTests, @Nullable Callback callback) throws TargetParsingException, LoadingFailedException, InterruptedException { LOG.info("Starting pattern evaluation"); Stopwatch timer = Stopwatch.createStarted(); @@ -371,14 +371,20 @@ public class LoadingPhaseRunner { callback.notifyTargets(targets.getTargets()); } maybeReportDeprecation(eventHandler, targets.getTargets()); - - BaseLoadingResult result = doLoadingPhase(eventHandler, eventBus, targets.getTargets(), - labelsToLoadUnconditionally, keepGoing, options.loadingPhaseThreads); - LoadingResult loadingResult = new LoadingResult(targets.hasError(), !result.isSuccesful(), - result.getTargets(), testsToRun, - collectPackageRoots(pkgLoader.getErrorFreeVisitedPackages())); - freeMemoryAfterLoading(callback, pkgLoader.getVisitedPackageNames()); - return loadingResult; + BaseLoadingResult result; + if (enableLoading) { + result = doLoadingPhase(eventHandler, eventBus, targets.getTargets(), + labelsToLoadUnconditionally, keepGoing, options.loadingPhaseThreads); + LoadingResult loadingResult = new LoadingResult(targets.hasError(), !result.isSuccesful(), + result.getTargets(), testsToRun, + collectPackageRoots(pkgLoader.getErrorFreeVisitedPackages())); + freeMemoryAfterLoading(callback, pkgLoader.getVisitedPackageNames()); + return loadingResult; + } else { + result = doSimpleLoadingPhase(eventHandler, eventBus, targets.getTargets(), keepGoing); + return new LoadingResult(targets.hasError(), !result.isSuccesful(), result.getTargets(), + testsToRun, collectPackageRoots(new ArrayList<Package>())); + } } private void freeMemoryAfterLoading(Callback callback, Set<PackageIdentifier> visitedPackages) { @@ -389,6 +395,27 @@ public class LoadingPhaseRunner { packageManager.partiallyClear(); } + /** + * Simplified version of {@code doLoadingPhase} method. This method does not load targets. + * It only does test_suite expansion and emits necessary events and logging messages for legacy + * support. + */ + private BaseLoadingResult doSimpleLoadingPhase(EventHandler eventHandler, EventBus eventBus, + ImmutableSet<Target> targetsToLoad, boolean keepGoing) + throws LoadingFailedException { + Stopwatch timer = preLoadingLogging(eventHandler); + + BaseLoadingResult expandedResult; + try { + expandedResult = expandTestSuites(eventHandler, targetsToLoad, keepGoing); + } catch (TargetParsingException e) { + throw new LoadingFailedException("Loading failed; build aborted", e); + } + + postLoadingLogging(eventBus, targetsToLoad, expandedResult.getTargets(), timer); + return new BaseLoadingResult(expandedResult.getTargets(), expandedResult.isSuccesful()); + } + /** * Visit the transitive closure of the targets, populating the package cache * and ensuring that all labels can be resolved and all rules were free from @@ -404,25 +431,38 @@ public class LoadingPhaseRunner { ImmutableSet<Target> targetsToLoad, ListMultimap<String, Label> labelsToLoadUnconditionally, boolean keepGoing, int loadingPhaseThreads) throws InterruptedException, LoadingFailedException { - eventHandler.handle(Event.progress("Loading...")); - Stopwatch timer = Stopwatch.createStarted(); - LOG.info("Starting loading phase"); + Stopwatch timer = preLoadingLogging(eventHandler); BaseLoadingResult baseResult = performLoadingOfTargets(eventHandler, eventBus, targetsToLoad, labelsToLoadUnconditionally, keepGoing, loadingPhaseThreads); - BaseLoadingResult expandedResult = expandTestSuites(eventHandler, baseResult.getTargets(), - keepGoing); - - Set<Target> testSuiteTargets = Sets.difference(baseResult.getTargets(), - expandedResult.getTargets()); - eventBus.post(new LoadingPhaseCompleteEvent(expandedResult.getTargets(), testSuiteTargets, - packageManager.getStatistics(), timer.stop().elapsed(TimeUnit.MILLISECONDS))); - LOG.info("Loading phase finished"); + BaseLoadingResult expandedResult; + try { + expandedResult = expandTestSuites(eventHandler, baseResult.getTargets(), + keepGoing); + } catch (TargetParsingException e) { + // This shouldn't happen, because we've already loaded the targets successfully. + throw (AssertionError) (new AssertionError("Unexpected target failure").initCause(e)); + } + postLoadingLogging(eventBus, baseResult.getTargets(), expandedResult.getTargets(), timer); return new BaseLoadingResult(expandedResult.getTargets(), baseResult.isSuccesful() && expandedResult.isSuccesful()); } + private Stopwatch preLoadingLogging(EventHandler eventHandler) { + eventHandler.handle(Event.progress("Loading...")); + LOG.info("Starting loading phase"); + return Stopwatch.createStarted(); + } + + private void postLoadingLogging(EventBus eventBus, ImmutableSet<Target> originalTargetsToLoad, + ImmutableSet<Target> expandedTargetsToLoad, Stopwatch timer) { + Set<Target> testSuiteTargets = Sets.difference(originalTargetsToLoad, expandedTargetsToLoad); + eventBus.post(new LoadingPhaseCompleteEvent(expandedTargetsToLoad, testSuiteTargets, + packageManager.getStatistics(), timer.stop().elapsed(TimeUnit.MILLISECONDS))); + LOG.info("Loading phase finished"); + } + private BaseLoadingResult performLoadingOfTargets(EventHandler eventHandler, EventBus eventBus, ImmutableSet<Target> targetsToLoad, ListMultimap<String, Label> labelsToLoadUnconditionally, boolean keepGoing, int loadingPhaseThreads) throws InterruptedException, @@ -468,19 +508,15 @@ public class LoadingPhaseRunner { } private BaseLoadingResult expandTestSuites(EventHandler eventHandler, - ImmutableSet<Target> targets, boolean keepGoing) throws LoadingFailedException { - try { - // We use strict test_suite expansion here to match the analysis-time checks. - ResolvedTargets<Target> expandedResult = TestTargetUtils.expandTestSuites( - packageManager, eventHandler, targets, /*strict=*/true, /*keepGoing=*/true); - if (expandedResult.hasError() && !keepGoing) { - throw new LoadingFailedException("Could not expand test suite target"); - } - return new BaseLoadingResult(expandedResult.getTargets(), !expandedResult.hasError()); - } catch (TargetParsingException e) { - // This shouldn't happen, because we've already loaded the targets successfully. - throw (AssertionError) (new AssertionError("Unexpected target failure").initCause(e)); + ImmutableSet<Target> targets, boolean keepGoing) + throws LoadingFailedException, TargetParsingException { + // We use strict test_suite expansion here to match the analysis-time checks. + ResolvedTargets<Target> expandedResult = TestTargetUtils.expandTestSuites( + packageManager, eventHandler, targets, /*strict=*/true, /*keepGoing=*/true); + if (expandedResult.hasError() && !keepGoing) { + throw new LoadingFailedException("Could not expand test suite target"); } + return new BaseLoadingResult(expandedResult.getTargets(), !expandedResult.hasError()); } private static class BaseLoadingResult { @@ -543,7 +579,7 @@ public class LoadingPhaseRunner { /** * Returns a map of collected package names to root paths. */ - private static ImmutableMap<PackageIdentifier, Path> collectPackageRoots( + public static ImmutableMap<PackageIdentifier, Path> collectPackageRoots( Collection<Package> packages) { // Make a map of the package names to their root paths. ImmutableMap.Builder<PackageIdentifier, Path> packageRoots = ImmutableMap.builder(); |