track implicit deps separately so they don't add to command line
authorEvan Martin <martine@danga.com>
Thu, 28 Oct 2010 16:40:54 +0000 (09:40 -0700)
committerEvan Martin <martine@danga.com>
Thu, 28 Oct 2010 16:40:54 +0000 (09:40 -0700)
ninja.h
ninja_test.cc

diff --git a/ninja.h b/ninja.h
index 3658455..d0d12e0 100644 (file)
--- a/ninja.h
+++ b/ninja.h
@@ -160,18 +160,20 @@ struct Rule {
 
 class State;
 struct Edge {
-  Edge() : rule_(NULL), env_(NULL) {}
+  Edge() : rule_(NULL), env_(NULL), implicit_deps_(0) {}
 
   void MarkDirty(Node* node);
   bool RecomputeDirty(State* state, DiskInterface* disk_interface, string* err);
   string EvaluateCommand();  // XXX move to env, take env ptr
   bool LoadDepFile(State* state, DiskInterface* disk_interface, string* err);
 
-  Rule* rule_;
   enum InOut { IN, OUT };
+
+  Rule* rule_;
   vector<Node*> inputs_;
   vector<Node*> outputs_;
   EvalString::Env* env_;
+  int implicit_deps_;  // Count on the end of the inputs list.
 };
 
 void FileStat::Touch(int mtime) {
@@ -245,8 +247,9 @@ struct EdgeEnv : public EvalString::Env {
   virtual string Evaluate(const string& var) {
     string result;
     if (var == "@in") {
+      int explicit_deps = edge_->inputs_.size() - edge_->implicit_deps_;
       for (vector<Node*>::iterator i = edge_->inputs_.begin();
-           i != edge_->inputs_.end(); ++i) {
+           i != edge_->inputs_.end() && explicit_deps; ++i, --explicit_deps) {
         if (!result.empty())
           result.push_back(' ');
         result.append((*i)->file_->path_);
@@ -356,6 +359,7 @@ bool Edge::LoadDepFile(State* state, DiskInterface* disk_interface, string* err)
     if (node) {
       inputs_.push_back(node);
       node->out_edges_.push_back(this);
+      ++implicit_deps_;
     }
   }
 
index c83f3ac..ba93f4e 100644 (file)
@@ -461,7 +461,11 @@ TEST_F(BuildTest, DepFileOK) {
 
   // Expect our edge to now have three inputs: foo.c and two headers.
   ASSERT_EQ(orig_edges + 1, state_.edges_.size());
-  ASSERT_EQ(3, state_.edges_.back()->inputs_.size());
+  Edge* edge = state_.edges_.back();
+  ASSERT_EQ(3, edge->inputs_.size());
+
+  // Expect the command line we generate to only use the original input.
+  ASSERT_EQ("cc foo.c", edge->EvaluateCommand());
 }
 
 TEST_F(BuildTest, DepFileParseError) {