diff options
author | 2015-09-16 13:00:45 +0000 | |
---|---|---|
committer | 2015-09-16 15:15:50 +0000 | |
commit | ca2d8d2748c1b419bde4926a69100f81399c182d (patch) | |
tree | 6788653c706fceb5e6d1894bf142a7f8d89b8836 /src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java | |
parent | c52eb9c5543f23edd8d91087e33194137e5ccca2 (diff) |
Move several parts of BlazeRuntime to CommandEnvironment.
The main piece is the blaze module environment, which is only valid during
command execution. Also configuration creation and precompleteCommand.
--
MOS_MIGRATED_REVID=103186467
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java | 93 |
1 files changed, 3 insertions, 90 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java index 40d4e889d5..9d77e80fd8 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java @@ -46,21 +46,16 @@ import com.google.devtools.build.lib.analysis.SkyframePackageRootResolver; import com.google.devtools.build.lib.analysis.WorkspaceStatusAction; import com.google.devtools.build.lib.analysis.config.BinTools; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; -import com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection; import com.google.devtools.build.lib.analysis.config.BuildOptions; import com.google.devtools.build.lib.analysis.config.ConfigurationFactory; import com.google.devtools.build.lib.analysis.config.DefaultsPackage; -import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.OutputFilter; import com.google.devtools.build.lib.events.Reporter; import com.google.devtools.build.lib.exec.OutputService; -import com.google.devtools.build.lib.packages.NoSuchThingException; import com.google.devtools.build.lib.packages.PackageFactory; import com.google.devtools.build.lib.packages.Preprocessor; import com.google.devtools.build.lib.packages.RuleClassProvider; -import com.google.devtools.build.lib.packages.Target; -import com.google.devtools.build.lib.pkgcache.LoadedPackageProvider; import com.google.devtools.build.lib.pkgcache.LoadingPhaseRunner; import com.google.devtools.build.lib.pkgcache.PackageCacheOptions; import com.google.devtools.build.lib.pkgcache.PackageManager; @@ -95,7 +90,6 @@ import com.google.devtools.build.lib.skyframe.SequencedSkyframeExecutorFactory; import com.google.devtools.build.lib.skyframe.SkyValueDirtinessChecker; import com.google.devtools.build.lib.skyframe.SkyframeExecutor; import com.google.devtools.build.lib.skyframe.SkyframeExecutorFactory; -import com.google.devtools.build.lib.syntax.Label; import com.google.devtools.build.lib.util.AbruptExitException; import com.google.devtools.build.lib.util.BlazeClock; import com.google.devtools.build.lib.util.Clock; @@ -176,6 +170,7 @@ public final class BlazeRuntime { private final SkyframeExecutor skyframeExecutor; + // Always null in production! Only non-null when tests inject a custom reporter. private final Reporter reporter; private final LoadingPhaseRunner loadingPhaseRunner; private final PackageFactory packageFactory; @@ -190,7 +185,6 @@ public final class BlazeRuntime { private OutputService outputService; private final Iterable<BlazeModule> blazeModules; - private final BlazeModule.ModuleEnvironment blazeModuleEnvironment; private UUID commandId; // Unique identifier for the command being run @@ -204,8 +198,6 @@ public final class BlazeRuntime { private String outputFileSystem; private Map<String, BlazeCommand> commandMap; - private AbruptExitException pendingException; - private final SubscriberExceptionHandler eventBusExceptionHandler; private final BinTools binTools; @@ -214,23 +206,6 @@ public final class BlazeRuntime { private final ProjectFile.Provider projectFileProvider; - private class BlazeModuleEnvironment implements BlazeModule.ModuleEnvironment { - @Override - public Path getFileFromDepot(Label label) - throws NoSuchThingException, InterruptedException, IOException { - Target target = getPackageManager().getTarget(reporter, label); - return (outputService != null) - ? outputService.stageTool(target) - : target.getPackage().getPackageDirectory().getRelative(target.getName()); - } - - @Override - public void exit(AbruptExitException exception) { - Preconditions.checkState(pendingException == null); - pendingException = exception; - } - } - private BlazeRuntime(BlazeDirectories directories, Reporter reporter, WorkspaceStatusAction.Factory workspaceStatusActionFactory, final SkyframeExecutor skyframeExecutor, @@ -267,7 +242,6 @@ public final class BlazeRuntime { this.startupOptionsProvider = startupOptionsProvider; this.eventBusExceptionHandler = eventBusExceptionHandler; - this.blazeModuleEnvironment = new BlazeModuleEnvironment(); if (inWorkspace()) { writeOutputBaseReadmeFile(); @@ -310,7 +284,7 @@ public final class BlazeRuntime { public CommandEnvironment initCommand() { EventBus eventBus = new EventBus(eventBusExceptionHandler); skyframeExecutor.setEventBus(eventBus); - return new CommandEnvironment(this, eventBus); + return new CommandEnvironment(this, reporter, eventBus); } private void clearEventBus() { @@ -502,13 +476,6 @@ public final class BlazeRuntime { return directories.getExecRoot(); } - /** - * Returns the reporter for events. - */ - public Reporter getReporter() { - return reporter; - } - public BinTools getBinTools() { return binTools; } @@ -552,10 +519,6 @@ public final class BlazeRuntime { return workspaceStatusActionFactory; } - public BlazeModule.ModuleEnvironment getBlazeModuleEnvironment() { - return blazeModuleEnvironment; - } - /** * Returns the rule class provider. */ @@ -687,7 +650,7 @@ public final class BlazeRuntime { env.getEventBus().post(new GotOptionsEvent(startupOptionsProvider, optionsParser)); - throwPendingException(); + env.throwPendingException(); outputService = null; BlazeModule outputModule = null; @@ -788,21 +751,6 @@ public final class BlazeRuntime { } /** - * Hook method called by the BlazeCommandDispatcher right before the dispatch - * of each command ends (while its outcome can still be modified). - */ - ExitCode precompleteCommand(CommandEnvironment env, ExitCode originalExit) { - env.getEventBus().post(new CommandPrecompleteEvent(originalExit)); - // If Blaze did not suffer an infrastructure failure, check for errors in modules. - ExitCode exitCode = originalExit; - if (!originalExit.isInfrastructureFailure() && pendingException != null) { - exitCode = pendingException.getExitCode(); - } - pendingException = null; - return exitCode; - } - - /** * Posts the {@link CommandCompleteEvent}, so that listeners can tidy up. Called by {@link * #afterCommand}, and by BugReport when crashing from an exception in an async thread. */ @@ -954,26 +902,6 @@ public final class BlazeRuntime { } /** - * This method only exists for the benefit of InfoCommand, which needs to construct a {@link - * BuildConfigurationCollection} without running a full loading phase. Don't add any more clients; - * instead, we should change info so that it doesn't need the configuration. - */ - public BuildConfigurationCollection getConfigurations(OptionsProvider optionsProvider) - throws InvalidConfigurationException, InterruptedException { - BuildOptions buildOptions = createBuildOptions(optionsProvider); - boolean keepGoing = optionsProvider.getOptions(BuildView.Options.class).keepGoing; - LoadedPackageProvider loadedPackageProvider = - loadingPhaseRunner.loadForConfigurations(reporter, - ImmutableSet.copyOf(buildOptions.getAllLabels().values()), - keepGoing); - if (loadedPackageProvider == null) { - throw new InvalidConfigurationException("Configuration creation failed"); - } - return skyframeExecutor.createConfigurations(configurationFactory, - buildOptions, directories, ImmutableSet.<String>of(), keepGoing); - } - - /** * Initializes the package cache using the given options, and syncs the package cache. Also * injects a defaults package using the options for the {@link BuildConfiguration}. * @@ -995,21 +923,6 @@ public final class BlazeRuntime { } /** - * Throws the exception currently queued by a Blaze module. - * - * <p>This should be called as often as is practical so that errors are reported as soon as - * possible. Ideally, we'd not need this, but the event bus swallows exceptions so we raise - * the exception this way. - */ - public void throwPendingException() throws AbruptExitException { - if (pendingException != null) { - AbruptExitException exception = pendingException; - pendingException = null; - throw exception; - } - } - - /** * Returns the defaults package for the default settings. Should only be called by commands that * do <i>not</i> process {@link BuildOptions}, since build options can alter the contents of the * defaults package, which will not be reflected here. |