Skip to content

Commit

Permalink
Merge pull request #436 from tfarina/dry-run-unnamed-namespace
Browse files Browse the repository at this point in the history
Move DryRunCommandRunner into a unnamed namespace.
  • Loading branch information
evmar committed Oct 2, 2012
2 parents 733b2bd + 5cd579d commit 8bd8d17
Showing 1 changed file with 39 additions and 24 deletions.
63 changes: 39 additions & 24 deletions src/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,45 @@
#include "subprocess.h"
#include "util.h"

namespace {

/// A CommandRunner that doesn't actually run the commands.
class DryRunCommandRunner : public CommandRunner {
public:
virtual ~DryRunCommandRunner() {}

// Overridden from CommandRunner:
virtual bool CanRunMore();
virtual bool StartCommand(Edge* edge);
virtual Edge* WaitForCommand(ExitStatus* status, string* /* output */);

private:
queue<Edge*> finished_;
};

bool DryRunCommandRunner::CanRunMore() {
return true;
}

bool DryRunCommandRunner::StartCommand(Edge* edge) {
finished_.push(edge);
return true;
}

Edge* DryRunCommandRunner::WaitForCommand(ExitStatus* status,
string* /*output*/) {
if (finished_.empty()) {
*status = ExitFailure;
return NULL;
}
*status = ExitSuccess;
Edge* edge = finished_.front();
finished_.pop();
return edge;
}

} // namespace

BuildStatus::BuildStatus(const BuildConfig& config)
: config_(config),
start_time_millis_(GetTimeMillis()),
Expand Down Expand Up @@ -528,30 +567,6 @@ Edge* RealCommandRunner::WaitForCommand(ExitStatus* status, string* output) {
return edge;
}

/// A CommandRunner that doesn't actually run the commands.
struct DryRunCommandRunner : public CommandRunner {
virtual ~DryRunCommandRunner() {}
virtual bool CanRunMore() {
return true;
}
virtual bool StartCommand(Edge* edge) {
finished_.push(edge);
return true;
}
virtual Edge* WaitForCommand(ExitStatus* status, string* /* output */) {
if (finished_.empty()) {
*status = ExitFailure;
return NULL;
}
*status = ExitSuccess;
Edge* edge = finished_.front();
finished_.pop();
return edge;
}

queue<Edge*> finished_;
};

Builder::Builder(State* state, const BuildConfig& config,
BuildLog* log, DiskInterface* disk_interface)
: state_(state), config_(config), disk_interface_(disk_interface),
Expand Down

0 comments on commit 8bd8d17

Please sign in to comment.