Fix for missing "no work to do." message if all build edges are phony rules.
authorRichard Geary <richardg.work@gmail.com>
Sun, 11 Aug 2013 00:14:49 +0000 (20:14 -0400)
committerRichard Geary <richardg.work@gmail.com>
Sun, 11 Aug 2013 00:15:22 +0000 (20:15 -0400)
Added NestedPhonyPrintsDone unit test

src/build.cc
src/build.h
src/graph_test.cc

index 45f6849..6d23f3b 100644 (file)
@@ -362,8 +362,11 @@ void Plan::ResumeDelayedJobs(Edge* edge) {
 void Plan::EdgeFinished(Edge* edge) {
   map<Edge*, bool>::iterator i = want_.find(edge);
   assert(i != want_.end());
-  if (i->second)
+  if (i->second) {
     --wanted_edges_;
+    if (!edge->is_phony())
+      --command_edges_;
+  }
   want_.erase(i);
   edge->outputs_ready_ = true;
 
index 33df7d0..a872f6c 100644 (file)
@@ -51,7 +51,7 @@ struct Plan {
   Edge* FindWork();
 
   /// Returns true if there's more work to be done.
-  bool more_to_do() const { return wanted_edges_; }
+  bool more_to_do() const { return (command_edges_ > 0); }
 
   /// Dumps the current state of the plan.
   void Dump();
index 63d5757..8521216 100644 (file)
@@ -13,6 +13,7 @@
 // limitations under the License.
 
 #include "graph.h"
+#include "build.h"
 
 #include "test.h"
 
@@ -226,3 +227,22 @@ TEST_F(GraphTest, DepfileOverrideParent) {
   Edge* edge = GetNode("out")->in_edge();
   EXPECT_EQ("depfile is y", edge->GetBinding("command"));
 }
+
+// Verify that building a nested phony rule prints "no work to do"
+TEST_F(GraphTest, NestedPhonyPrintsDone) {
+  AssertParse(&state_,
+"build n1: phony \n"
+"build n2: phony n1\n"
+  );
+  string err;
+  Edge* edge = GetNode("n2")->in_edge();
+  EXPECT_TRUE(scan_.RecomputeDirty(edge, &err));
+  ASSERT_EQ("", err);
+
+  Plan plan_;
+  EXPECT_TRUE(plan_.AddTarget(GetNode("n2"), &err));
+  ASSERT_EQ("", err);
+
+  EXPECT_EQ(0, plan_.command_edge_count());
+  ASSERT_FALSE(plan_.more_to_do());
+}