From 7c9ae6677fc60b5e22dcf919ebf4e7d42266fa87 Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Tue, 19 Oct 2010 20:15:05 -0700 Subject: [PATCH] successfully build ourselves --- ninja.cc | 9 ++++++--- ninja.h | 14 +++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/ninja.cc b/ninja.cc index b5c1a59..48ae0f6 100644 --- a/ninja.cc +++ b/ninja.cc @@ -14,13 +14,16 @@ int main(int argc, char** argv) { return 1; } + state.stat_cache()->Reload(); + state.stat_cache()->Dump(); + Shell shell; Builder builder(&state); builder.AddTarget(argv[1]); - if (!builder.Build(&shell, &err)) { + bool success = builder.Build(&shell, &err); + if (!err.empty()) { printf("%s\n", err.c_str()); - return 1; } - return 0; + return success ? 1 : 0; } diff --git a/ninja.h b/ninja.h index 20a7799..24466b5 100644 --- a/ninja.h +++ b/ninja.h @@ -13,7 +13,7 @@ struct Node; struct FileStat { FileStat(const string& path) : path_(path), mtime_(0), node_(NULL) {} void Touch(int mtime); - // Return true if the mtime changed. + // Return true if the file exists (mtime_ got a value). bool Stat(); string path_; @@ -128,15 +128,13 @@ bool FileStat::Stat() { if (stat(path_.c_str(), &st) < 0) { if (errno == ENOENT) { st.st_mtime = 0; + return false; } else { fprintf(stderr, "stat(%s): %s\n", path_.c_str(), strerror(errno)); return false; } } - if (st.st_mtime == mtime_) - return false; - mtime_ = st.st_mtime; return true; } @@ -152,7 +150,9 @@ void Node::MarkDirty() { } void Edge::RecomputeDirty() { - time_t min_mtime = -1; + assert(!outputs_.empty()); + + time_t min_mtime = outputs_[0]->file_->mtime_; for (vector::iterator i = outputs_.begin(); i != outputs_.end(); ++i) { min_mtime = min(min_mtime, (*i)->file_->mtime_); } @@ -226,9 +226,9 @@ void StatCache::Dump() { void StatCache::Reload() { set leaf_edges; for (Paths::iterator i = paths_.begin(); i != paths_.end(); ++i) { - i->second->Stat(); + bool exists = i->second->Stat(); Node* node = i->second->node_; - node->dirty_ = false; + node->dirty_ = !exists; if (!node->in_edge_) { for (vector::iterator j = node->out_edges_.begin(); j != node->out_edges_.end(); ++j) {