From 3ba052b16265acb6ada689d7e9e517c25a507510 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Mon, 27 Feb 2012 00:35:03 +0000 Subject: Lazily create the CommandRunner in Builder::Build This allows the user to interrupt the build (i.e. using Ctrl-C) while the build plan is being computed. --- src/build.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/build.cc b/src/build.cc index d3e88ee..2b9c657 100644 --- a/src/build.cc +++ b/src/build.cc @@ -479,10 +479,6 @@ struct DryRunCommandRunner : public CommandRunner { Builder::Builder(State* state, const BuildConfig& config) : state_(state), config_(config) { disk_interface_ = new RealDiskInterface; - if (config.dry_run) - command_runner_.reset(new DryRunCommandRunner); - else - command_runner_.reset(new RealCommandRunner(config)); status_ = new BuildStatus(config); log_ = state->build_log_; } @@ -540,6 +536,14 @@ bool Builder::Build(string* err) { int pending_commands = 0; int failures_allowed = config_.failures_allowed; + // Set up the command runner if we haven't done so already. + if (!command_runner_.get()) { + if (config_.dry_run) + command_runner_.reset(new DryRunCommandRunner); + else + command_runner_.reset(new RealCommandRunner(config_)); + } + // This main loop runs the entire build process. // It is structured like this: // First, we attempt to start as many commands as allowed by the -- cgit v0.12