diff options
author | Nico Weber <nicolasweber@gmx.de> | 2014-01-02 04:31:34 (GMT) |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2014-01-02 04:31:34 (GMT) |
commit | b2e6fcf7031cfaf995c65820d14d4aa390daf9fb (patch) | |
tree | febb947ed184e0bff21fa0556adc941c2dca4c82 /src/build_log.cc | |
parent | 38db96cba7886aeaec7f9af7f5f2eb960d3e1175 (diff) | |
download | Ninja-b2e6fcf7031cfaf995c65820d14d4aa390daf9fb.zip Ninja-b2e6fcf7031cfaf995c65820d14d4aa390daf9fb.tar.gz Ninja-b2e6fcf7031cfaf995c65820d14d4aa390daf9fb.tar.bz2 |
Remove dead entries in .ninja_log and .ninja_deps while recompacting.
For .ninja_deps, remove objects that have no in-edges or whose in-edges
do not have a "deps" attribute. (This matches the behaviour of `-t
deps`).
BuildLog doesn't know about state, so let its recompact method take
delegate that decides is a path is life or not, and implement it in
NinjaMain.
Diffstat (limited to 'src/build_log.cc')
-rw-r--r-- | src/build_log.cc | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/build_log.cc b/src/build_log.cc index b92a06f..825a8f5 100644 --- a/src/build_log.cc +++ b/src/build_log.cc @@ -108,9 +108,9 @@ BuildLog::~BuildLog() { Close(); } -bool BuildLog::OpenForWrite(const string& path, string* err) { +bool BuildLog::OpenForWrite(const string& path, IsDead* is_dead, string* err) { if (needs_recompaction_) { - if (!Recompact(path, err)) + if (!Recompact(path, is_dead, err)) return false; } @@ -350,7 +350,7 @@ bool BuildLog::WriteEntry(FILE* f, const LogEntry& entry) { entry.output.c_str(), entry.command_hash) > 0; } -bool BuildLog::Recompact(const string& path, string* err) { +bool BuildLog::Recompact(const string& path, IsDead* is_dead, string* err) { METRIC_RECORD(".ninja_log recompact"); printf("Recompacting log...\n"); @@ -368,7 +368,13 @@ bool BuildLog::Recompact(const string& path, string* err) { return false; } + vector<StringPiece> dead_outputs; for (Entries::iterator i = entries_.begin(); i != entries_.end(); ++i) { + if (is_dead->IsPathDead(i->first)) { + dead_outputs.push_back(i->first); + continue; + } + if (!WriteEntry(f, *i->second)) { *err = strerror(errno); fclose(f); @@ -376,6 +382,9 @@ bool BuildLog::Recompact(const string& path, string* err) { } } + for (size_t i = 0; i < dead_outputs.size(); ++i) + entries_.erase(dead_outputs[i]); + fclose(f); if (unlink(path.c_str()) < 0) { *err = strerror(errno); |