diff options
author | Evan Martin <martine@danga.com> | 2010-10-20 07:08:08 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2010-10-20 07:08:08 (GMT) |
commit | 1998243378fa61c0a24417d5d0751a8be1a90d7e (patch) | |
tree | aa36ee4d3002c3397b51ef0382de8790ede386bb | |
parent | ac1b574e38a8cb77b73c5a3db1e8ccfddd0ce9e3 (diff) | |
download | Ninja-1998243378fa61c0a24417d5d0751a8be1a90d7e.zip Ninja-1998243378fa61c0a24417d5d0751a8be1a90d7e.tar.gz Ninja-1998243378fa61c0a24417d5d0751a8be1a90d7e.tar.bz2 |
dependency inject stat() calls
-rw-r--r-- | ninja.h | 51 |
1 files changed, 30 insertions, 21 deletions
@@ -11,12 +11,36 @@ using namespace std; #include "eval_env.h" +struct StatHelper { + virtual int Stat(const string& path); +}; + +#include <errno.h> +#include <sys/stat.h> +#include <stdio.h> +#include <string.h> + +int StatHelper::Stat(const string& path) { + struct stat st; + if (stat(path.c_str(), &st) < 0) { + if (errno == ENOENT) { + return 0; + } else { + fprintf(stderr, "stat(%s): %s\n", path.c_str(), strerror(errno)); + return -1; + } + } + + return st.st_mtime; + return true; +} + struct Node; struct FileStat { FileStat(const string& path) : path_(path), mtime_(-1), node_(NULL) {} void Touch(int mtime); // Return true if the file exists (mtime_ got a value). - bool Stat(); + bool Stat(StatHelper* stat_helper); string path_; // Possible values of mtime_: @@ -68,25 +92,9 @@ void FileStat::Touch(int mtime) { node_->MarkDirty(); } -#include <errno.h> -#include <sys/stat.h> -#include <stdio.h> -#include <string.h> - -bool FileStat::Stat() { - struct stat st; - 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; - } - } - - mtime_ = st.st_mtime; - return true; +bool FileStat::Stat(StatHelper* stat_helper) { + mtime_ = stat_helper->Stat(path_); + return mtime_ > 0; } void Node::MarkDirty() { @@ -176,9 +184,10 @@ void StatCache::Dump() { } void StatCache::Reload() { + StatHelper stat_helper; set<Edge*> leaf_edges; for (Paths::iterator i = paths_.begin(); i != paths_.end(); ++i) { - bool exists = i->second->Stat(); + bool exists = i->second->Stat(&stat_helper); Node* node = i->second->node_; node->dirty_ = !exists; if (!node->in_edge_) { |