From 344867f979cde222106b0280bd3f1eca970d5dee Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Thu, 28 Oct 2010 09:40:54 -0700 Subject: [PATCH] track implicit deps separately so they don't add to command line --- ninja.h | 10 +++++++--- ninja_test.cc | 6 +++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ninja.h b/ninja.h index 3658455..d0d12e0 100644 --- 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 inputs_; vector 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::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_; } } diff --git a/ninja_test.cc b/ninja_test.cc index c83f3ac..ba93f4e 100644 --- a/ninja_test.cc +++ b/ninja_test.cc @@ -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) { -- 2.7.4