diff options
author | Evan Martin <martine@danga.com> | 2011-01-08 00:35:47 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2011-01-08 00:35:47 (GMT) |
commit | d4efbf34a3dd58551b4819612d0355396e0e6301 (patch) | |
tree | d276f1d491258670a0bda0393cea1603f1e16bca /src | |
parent | 08a5452d05eae55bec40cd351718d62fd767227c (diff) | |
download | Ninja-d4efbf34a3dd58551b4819612d0355396e0e6301.zip Ninja-d4efbf34a3dd58551b4819612d0355396e0e6301.tar.gz Ninja-d4efbf34a3dd58551b4819612d0355396e0e6301.tar.bz2 |
catch ourselves when we're stuck
Diffstat (limited to 'src')
-rw-r--r-- | src/build.cc | 18 | ||||
-rw-r--r-- | src/build.h | 4 | ||||
-rw-r--r-- | src/build_test.cc | 5 |
3 files changed, 19 insertions, 8 deletions
diff --git a/src/build.cc b/src/build.cc index d02027d..8ffbc7c 100644 --- a/src/build.cc +++ b/src/build.cc @@ -165,7 +165,7 @@ struct RealCommandRunner : public CommandRunner { virtual ~RealCommandRunner() {} virtual bool CanRunMore(); virtual bool StartCommand(Edge* edge); - virtual void WaitForCommands(); + virtual bool WaitForCommands(); virtual Edge* NextFinishedCommand(bool* success); SubprocessSet subprocs_; @@ -188,10 +188,14 @@ bool RealCommandRunner::StartCommand(Edge* edge) { return true; } -void RealCommandRunner::WaitForCommands() { - while (subprocs_.finished_.empty() && !subprocs_.running_.empty()) { +bool RealCommandRunner::WaitForCommands() { + if (subprocs_.running_.empty()) + return false; + + while (subprocs_.finished_.empty()) { subprocs_.DoWork(); } + return true; } Edge* RealCommandRunner::NextFinishedCommand(bool* success) { @@ -225,7 +229,8 @@ struct DryRunCommandRunner : public CommandRunner { finished_.push(edge); return true; } - virtual void WaitForCommands() { + virtual bool WaitForCommands() { + return true; } virtual Edge* NextFinishedCommand(bool* success) { if (finished_.empty()) @@ -300,7 +305,10 @@ bool Builder::Build(string* err) { } FinishEdge(edge); } else { - command_runner_->WaitForCommands(); + if (!command_runner_->WaitForCommands()) { + *err = "stuck [this is a bug]"; + return false; + } } } diff --git a/src/build.h b/src/build.h index f4b8d0c..843e907 100644 --- a/src/build.h +++ b/src/build.h @@ -53,7 +53,9 @@ struct CommandRunner { virtual ~CommandRunner() {} virtual bool CanRunMore() = 0; virtual bool StartCommand(Edge* edge) = 0; - virtual void WaitForCommands() = 0; + // Wait for commands to make progress; return false if there is no + // progress to be made. + virtual bool WaitForCommands() = 0; virtual Edge* NextFinishedCommand(bool* success) = 0; }; diff --git a/src/build_test.cc b/src/build_test.cc index b2c4d76..a430801 100644 --- a/src/build_test.cc +++ b/src/build_test.cc @@ -178,7 +178,7 @@ struct BuildTest : public StateTestWithBuiltinRules, // CommandRunner impl virtual bool CanRunMore(); virtual bool StartCommand(Edge* edge); - virtual void WaitForCommands(); + virtual bool WaitForCommands(); virtual Edge* NextFinishedCommand(bool* success); // DiskInterface @@ -251,7 +251,8 @@ bool BuildTest::StartCommand(Edge* edge) { return false; } -void BuildTest::WaitForCommands() { +bool BuildTest::WaitForCommands() { + return true; } Edge* BuildTest::NextFinishedCommand(bool* success) { |