From 9ceea1f592a232d91fb0215fa901e168c9620ad7 Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Sat, 14 May 2011 14:29:27 -0700 Subject: [PATCH] hide internals of BuildStatus --- src/build.cc | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/build.cc b/src/build.cc index 3447e0d..7825fbe 100644 --- a/src/build.cc +++ b/src/build.cc @@ -46,13 +46,16 @@ int64_t GetTimeMillis() { /// Tracks the status of a build: completion fraction, printing updates. struct BuildStatus { - BuildStatus(); + BuildStatus(const BuildConfig& config); void PlanHasTotalEdges(int total); void BuildEdgeStarted(Edge* edge); void BuildEdgeFinished(Edge* edge, int* start_time, int* end_time); + private: void PrintStatus(Edge* edge); + const BuildConfig& config_; + /// Time the build started. int64_t start_time_millis_; /// Time we last printed an update. @@ -64,16 +67,15 @@ struct BuildStatus { typedef map RunningEdgeMap; RunningEdgeMap running_edges_; - BuildConfig::Verbosity verbosity_; /// Whether we can do fancy terminal control codes. bool smart_terminal_; }; -BuildStatus::BuildStatus() - : start_time_millis_(GetTimeMillis()), +BuildStatus::BuildStatus(const BuildConfig& config) + : config_(config), + start_time_millis_(GetTimeMillis()), last_update_millis_(start_time_millis_), - finished_edges_(0), total_edges_(0), - verbosity_(BuildConfig::NORMAL) { + finished_edges_(0), total_edges_(0) { #ifndef WIN32 const char* term = getenv("TERM"); smart_terminal_ = isatty(1) && term && string(term) != "dumb"; @@ -99,8 +101,8 @@ void BuildStatus::BuildEdgeFinished(Edge* edge, int64_t now = GetTimeMillis(); ++finished_edges_; - if (verbosity_ != BuildConfig::QUIET) { - if (smart_terminal_ && verbosity_ == BuildConfig::NORMAL) { + if (config_.verbosity != BuildConfig::QUIET) { + if (smart_terminal_ && config_.verbosity == BuildConfig::NORMAL) { PrintStatus(edge); if (finished_edges_ == total_edges_) printf("\n"); @@ -120,7 +122,7 @@ void BuildStatus::BuildEdgeFinished(Edge* edge, } void BuildStatus::PrintStatus(Edge* edge) { - switch (verbosity_) { + switch (config_.verbosity) { case BuildConfig::QUIET: return; @@ -130,7 +132,7 @@ void BuildStatus::PrintStatus(Edge* edge) { default: { string to_print = edge->GetDescription(); - if (to_print.empty() || verbosity_ == BuildConfig::VERBOSE) + if (to_print.empty() || config_.verbosity == BuildConfig::VERBOSE) to_print = edge->EvaluateCommand(); #ifndef WIN32 if (smart_terminal_) { @@ -378,8 +380,7 @@ Builder::Builder(State* state, const BuildConfig& config) command_runner_ = new DryRunCommandRunner; else command_runner_ = new RealCommandRunner(config); - status_ = new BuildStatus; - status_->verbosity_ = config.verbosity; + status_ = new BuildStatus(config); log_ = state->build_log_; } -- 2.34.1