#include "eval_env.h"
-struct StatHelper {
+struct DiskInterface {
virtual int Stat(const string& path);
};
#include <stdio.h>
#include <string.h>
-int StatHelper::Stat(const string& path) {
+int DiskInterface::Stat(const string& path) {
struct stat st;
if (stat(path.c_str(), &st) < 0) {
if (errno == ENOENT) {
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(StatHelper* stat_helper);
+ bool Stat(DiskInterface* disk_interface);
// Return true if we needed to stat.
- bool StatIfNecessary(StatHelper* stat_helper) {
+ bool StatIfNecessary(DiskInterface* disk_interface) {
if (status_known())
return false;
- Stat(stat_helper);
+ Stat(disk_interface);
return true;
}
Edge() : rule_(NULL), env_(NULL) {}
void MarkDirty(Node* node);
- void RecomputeDirty(StatHelper* stat_helper);
+ void RecomputeDirty(DiskInterface* disk_interface);
string EvaluateCommand(); // XXX move to env, take env ptr
Rule* rule_;
node_->MarkDirty();
}
-bool FileStat::Stat(StatHelper* stat_helper) {
- mtime_ = stat_helper->Stat(path_);
+bool FileStat::Stat(DiskInterface* disk_interface) {
+ mtime_ = disk_interface->Stat(path_);
return mtime_ > 0;
}
(*i)->MarkDirty(this);
}
-void Edge::RecomputeDirty(StatHelper* stat_helper) {
+void Edge::RecomputeDirty(DiskInterface* disk_interface) {
bool dirty = false;
time_t most_recent_input = 1;
for (vector<Node*>::iterator i = inputs_.begin(); i != inputs_.end(); ++i) {
- if ((*i)->file_->StatIfNecessary(stat_helper)) {
+ if ((*i)->file_->StatIfNecessary(disk_interface)) {
if (Edge* edge = (*i)->in_edge_)
- edge->RecomputeDirty(stat_helper);
+ edge->RecomputeDirty(disk_interface);
else
(*i)->dirty_ = !(*i)->file_->exists();
}
}
struct Builder {
- Builder(State* state) : plan_(state), stat_helper_(&default_stat_helper_) {}
+ Builder(State* state)
+ : plan_(state), disk_interface_(&default_disk_interface_) {}
virtual ~Builder() {}
Node* AddTarget(const string& name, string* err) {
*err = "unknown target: '" + name + "'";
return NULL;
}
- node->file_->StatIfNecessary(stat_helper_);
+ node->file_->StatIfNecessary(disk_interface_);
if (node->in_edge_)
- node->in_edge_->RecomputeDirty(stat_helper_);
+ node->in_edge_->RecomputeDirty(disk_interface_);
if (!node->dirty_) {
*err = "target is clean; nothing to do";
return NULL;
bool Build(Shell* shell, string* err);
Plan plan_;
- StatHelper default_stat_helper_;
- StatHelper* stat_helper_;
+ DiskInterface default_disk_interface_;
+ DiskInterface* disk_interface_;
};
bool Builder::Build(Shell* shell, string* err) {
struct BuildTest : public StateTestWithBuiltinRules,
public Shell,
- public StatHelper {
+ public DiskInterface {
BuildTest() : builder_(&state_), now_(1) {
- builder_.stat_helper_ = this;
+ builder_.disk_interface_ = this;
AssertParse(&state_,
"build cat1: cat in1\n"
"build cat2: cat in1 in2\n"
// shell override
virtual bool RunCommand(Edge* edge);
- // StatHelper
+ // DiskInterface
virtual int Stat(const string& path) {
return now_;
}
}
struct StatTest : public StateTestWithBuiltinRules,
- public StatHelper {
+ public DiskInterface {
+ // DiskInterface implementation.
virtual int Stat(const string& path);
map<string, time_t> mtimes_;