verbosity tristate
authorEvan Martin <martine@danga.com>
Tue, 14 Dec 2010 16:37:48 +0000 (08:37 -0800)
committerEvan Martin <martine@danga.com>
Tue, 14 Dec 2010 16:37:48 +0000 (08:37 -0800)
src/build.cc
src/build.h
src/build_test.cc
src/ninja.cc

index c160dc32f7ce32090b3681b0e0902397bc260b53..dc1fcab0c096c6d96f1a27512dca388ec520e6d1 100644 (file)
@@ -13,12 +13,13 @@ struct BuildStatusLog {
 
   time_t last_update_;
   int finished_edges_, total_edges_;
-  bool verbose_;
+
+  BuildConfig::Verbosity verbosity_;
 };
 
 BuildStatusLog::BuildStatusLog()
     : last_update_(time(NULL)), finished_edges_(0), total_edges_(0),
-      verbose_(false) {}
+      verbosity_(BuildConfig::NORMAL) {}
 
 void BuildStatusLog::PlanHasTotalEdges(int total) {
   total_edges_ = total;
@@ -26,10 +27,12 @@ void BuildStatusLog::PlanHasTotalEdges(int total) {
 
 void BuildStatusLog::BuildEdgeStarted(Edge* edge) {
   string desc = edge->GetDescription();
-  if (!verbose_ && !desc.empty())
-    printf("%s\n", desc.c_str());
-  else
-    printf("%s\n", edge->EvaluateCommand().c_str());
+  if (verbosity_ != BuildConfig::QUIET) {
+    if (verbosity_ != BuildConfig::VERBOSE && !desc.empty())
+      printf("%s\n", desc.c_str());
+    else
+      printf("%s\n", edge->EvaluateCommand().c_str());
+  }
 }
 
 void BuildStatusLog::BuildEdgeFinished(Edge* edge) {
@@ -243,7 +246,7 @@ Builder::Builder(State* state, const BuildConfig& config)
   else
     command_runner_ = new RealCommandRunner;
   log_ = new BuildStatusLog;
-  log_->verbose_ = config.verbose;
+  log_->verbosity_ = config.verbosity;
 }
 
 Node* Builder::AddTarget(const string& name, string* err) {
index b79ffae0fae9cdb034602cbf7af092b32941e0bf..4574e2056a5f4c6bccd00c5f34017cfd1ade28b8 100644 (file)
@@ -58,9 +58,14 @@ struct CommandRunner {
 };
 
 struct BuildConfig {
-  BuildConfig() : verbose(false), dry_run(false) {}
-
-  bool verbose;
+  BuildConfig() : verbosity(NORMAL), dry_run(false) {}
+
+  enum Verbosity {
+    NORMAL,
+    QUIET,  // No output -- used when testing.
+    VERBOSE
+  };
+  Verbosity verbosity;
   bool dry_run;
 };
 
index b8f1887ccfc98e79402142e56440a040b0e89973..b2c4d761afd4eca41796e40f374434a9462b5b7c 100644 (file)
@@ -160,7 +160,7 @@ TEST_F(PlanTest, DependencyCycle) {
 struct BuildTest : public StateTestWithBuiltinRules,
                    public CommandRunner,
                    public DiskInterface {
-  BuildTest() : config_(), builder_(&state_, config_), now_(1),
+  BuildTest() : config_(MakeConfig()), builder_(&state_, config_), now_(1),
                 last_command_(NULL) {
     builder_.disk_interface_ = this;
     builder_.command_runner_ = this;
@@ -197,6 +197,12 @@ struct BuildTest : public StateTestWithBuiltinRules,
     return "";
   }
 
+  BuildConfig MakeConfig() {
+    BuildConfig config;
+    config.verbosity = BuildConfig::QUIET;
+    return config;
+  }
+
   BuildConfig config_;
   Builder builder_;
   int now_;
index 3c09bcde1f7c642b721594b20bad5adce777943c..8376d9a16b2fc53bef232194ff2445ef609e1da0 100644 (file)
@@ -49,7 +49,7 @@ int main(int argc, char** argv) {
         config.dry_run = true;
         break;
       case 'v':
-        config.verbose = true;
+        config.verbosity = BuildConfig::VERBOSE;
         break;
       case 'h':
       default: