diff options
author | Evan Martin <martine@danga.com> | 2012-10-29 16:53:30 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2012-10-31 19:34:07 (GMT) |
commit | 93e509469953a90f31afc838536b82568da397b2 (patch) | |
tree | d009d6ce241e8b048648e74b19b383a9ad86bb12 /src | |
parent | 599d716fc78441436aebcde948886791d1988651 (diff) | |
download | Ninja-93e509469953a90f31afc838536b82568da397b2.zip Ninja-93e509469953a90f31afc838536b82568da397b2.tar.gz Ninja-93e509469953a90f31afc838536b82568da397b2.tar.bz2 |
refactor repeated code in cleaner
Diffstat (limited to 'src')
-rw-r--r-- | src/clean.cc | 28 | ||||
-rw-r--r-- | src/clean.h | 4 |
2 files changed, 18 insertions, 14 deletions
diff --git a/src/clean.cc b/src/clean.cc index c9d4cbd..0b8476b 100644 --- a/src/clean.cc +++ b/src/clean.cc @@ -82,6 +82,16 @@ bool Cleaner::IsAlreadyRemoved(const string& path) { return (i != removed_.end()); } +void Cleaner::RemoveEdgeFiles(Edge* edge) { + string depfile = edge->EvaluateDepFile(); + if (!depfile.empty()) + Remove(depfile); + + string rspfile = edge->GetRspFile(); + if (!rspfile.empty()) + Remove(rspfile); +} + void Cleaner::PrintHeader() { if (config_.verbosity == BuildConfig::QUIET) return; @@ -113,12 +123,8 @@ int Cleaner::CleanAll(bool generator) { out_node != (*e)->outputs_.end(); ++out_node) { Remove((*out_node)->path()); } - // Remove the depfile - if (!(*e)->rule().depfile().empty()) - Remove((*e)->EvaluateDepFile()); - // Remove the response file - if ((*e)->HasRspFile()) - Remove((*e)->GetRspFile()); + + RemoveEdgeFiles(*e); } PrintFooter(); return status_; @@ -129,10 +135,7 @@ void Cleaner::DoCleanTarget(Node* target) { // Do not try to remove phony targets if (!e->is_phony()) { Remove(target->path()); - if (!target->in_edge()->rule().depfile().empty()) - Remove(target->in_edge()->EvaluateDepFile()); - if (e->HasRspFile()) - Remove(e->GetRspFile()); + RemoveEdgeFiles(e); } for (vector<Node*>::iterator n = e->inputs_.begin(); n != e->inputs_.end(); ++n) { @@ -200,10 +203,7 @@ void Cleaner::DoCleanRule(const Rule* rule) { for (vector<Node*>::iterator out_node = (*e)->outputs_.begin(); out_node != (*e)->outputs_.end(); ++out_node) { Remove((*out_node)->path()); - if (!(*e)->rule().depfile().empty()) - Remove((*e)->EvaluateDepFile()); - if ((*e)->HasRspFile()) - Remove((*e)->GetRspFile()); + RemoveEdgeFiles(*e); } } } diff --git a/src/clean.h b/src/clean.h index 8359901..5a23283 100644 --- a/src/clean.h +++ b/src/clean.h @@ -81,10 +81,14 @@ class Cleaner { /// @returns whether the file @a path exists. bool FileExists(const string& path); void Report(const string& path); + /// Remove the given @a path file only if it has not been already removed. void Remove(const string& path); /// @return whether the given @a path has already been removed. bool IsAlreadyRemoved(const string& path); + /// Remove the depfile and rspfile for an Edge. + void RemoveEdgeFiles(Edge* edge); + /// Helper recursive method for CleanTarget(). void DoCleanTarget(Node* target); void PrintHeader(); |