diff options
author | Evan Martin <martine@danga.com> | 2011-11-02 06:26:33 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2011-11-02 06:26:33 (GMT) |
commit | 801377e0651d35a8f006ea3722a44f52cfe787bf (patch) | |
tree | bdd46e03aed72e964d30f66238f860b00038e545 /src/build_log.cc | |
parent | bb52198d196ba294908abad00960783456e40f8b (diff) | |
parent | 0efbbbf67a94452919084765e87106e7748274cb (diff) | |
download | Ninja-801377e0651d35a8f006ea3722a44f52cfe787bf.zip Ninja-801377e0651d35a8f006ea3722a44f52cfe787bf.tar.gz Ninja-801377e0651d35a8f006ea3722a44f52cfe787bf.tar.bz2 |
Merge pull request #125 from pcc/outputs-ready
CMake requirements: Make-style order-only dependencies, restat rules
Diffstat (limited to 'src/build_log.cc')
-rw-r--r-- | src/build_log.cc | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/src/build_log.cc b/src/build_log.cc index 43d5f01..7fd9ca1 100644 --- a/src/build_log.cc +++ b/src/build_log.cc @@ -32,8 +32,8 @@ namespace { -const char kFileSignature[] = "# ninja log v2\n"; -const int kCurrentVersion = 2; +const char kFileSignature[] = "# ninja log v%d\n"; +const int kCurrentVersion = 3; } @@ -59,7 +59,7 @@ bool BuildLog::OpenForWrite(const string& path, string* err) { SetCloseOnExec(fileno(log_file_)); if (ftell(log_file_) == 0) { - if (fwrite(kFileSignature, sizeof(kFileSignature) - 1, 1, log_file_) < 1) { + if (fprintf(log_file_, kFileSignature, kCurrentVersion) < 0) { *err = strerror(errno); return false; } @@ -68,10 +68,8 @@ bool BuildLog::OpenForWrite(const string& path, string* err) { return true; } -void BuildLog::RecordCommand(Edge* edge, int start_time, int end_time) { - if (!log_file_) - return; - +void BuildLog::RecordCommand(Edge* edge, int start_time, int end_time, + time_t restat_mtime) { const string command = edge->EvaluateCommand(); for (vector<Node*>::iterator out = edge->outputs_.begin(); out != edge->outputs_.end(); ++out) { @@ -88,8 +86,10 @@ void BuildLog::RecordCommand(Edge* edge, int start_time, int end_time) { log_entry->command = command; log_entry->start_time = start_time; log_entry->end_time = end_time; + log_entry->restat_mtime = restat_mtime; - WriteEntry(log_file_, *log_entry); + if (log_file_) + WriteEntry(log_file_, *log_entry); } } @@ -116,10 +116,8 @@ bool BuildLog::Load(const string& path, string* err) { while (fgets(buf, sizeof(buf), file)) { if (!log_version) { log_version = 1; // Assume by default. - if (strcmp(buf, kFileSignature) == 0) { - log_version = 2; + if (sscanf(buf, kFileSignature, &log_version) > 0) continue; - } } char* start = buf; char* end = strchr(start, ' '); @@ -128,6 +126,8 @@ bool BuildLog::Load(const string& path, string* err) { *end = 0; int start_time = 0, end_time = 0; + time_t restat_mtime = 0; + if (log_version == 1) { // In v1 we logged how long the command took; we don't use this info. // int time_ms = atoi(start); @@ -144,6 +144,16 @@ bool BuildLog::Load(const string& path, string* err) { end_time = atoi(start); start = end + 1; } + + if (log_version >= 3) { + // In v3 we log the restat mtime. + char* end = strchr(start, ' '); + if (!end) + continue; + *end = 0; + restat_mtime = atol(start); + start = end + 1; + } end = strchr(start, ' '); if (!end) @@ -169,6 +179,7 @@ bool BuildLog::Load(const string& path, string* err) { entry->start_time = start_time; entry->end_time = end_time; + entry->restat_mtime = restat_mtime; entry->command = string(start, end - start); } @@ -197,8 +208,8 @@ BuildLog::LogEntry* BuildLog::LookupByOutput(const string& path) { } void BuildLog::WriteEntry(FILE* f, const LogEntry& entry) { - fprintf(f, "%d %d %s %s\n", - entry.start_time, entry.end_time, + fprintf(f, "%d %d %ld %s %s\n", + entry.start_time, entry.end_time, (long) entry.restat_mtime, entry.output.c_str(), entry.command.c_str()); } @@ -212,7 +223,7 @@ bool BuildLog::Recompact(const string& path, string* err) { return false; } - if (fwrite(kFileSignature, sizeof(kFileSignature) - 1, 1, f) < 1) { + if (fprintf(f, kFileSignature, kCurrentVersion) < 0) { *err = strerror(errno); return false; } |