successfully build ourselves

This commit is contained in:
Evan Martin 2010-10-19 20:15:05 -07:00
parent 5ce0da16ca
commit 7c9ae6677f
2 changed files with 13 additions and 10 deletions

View File

@ -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;
}

14
ninja.h
View File

@ -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<Node*>::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<Edge*> 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<Edge*>::iterator j = node->out_edges_.begin();
j != node->out_edges_.end(); ++j) {