diff options
author | Evan Martin <martine@danga.com> | 2012-12-29 21:36:00 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2012-12-29 21:47:41 (GMT) |
commit | 2c953d1501de5195e2485185fa24a2ebfd76bbb5 (patch) | |
tree | 2fc88e378a6df571bb125d282b14475f2b9ba05c /src/clean.cc | |
parent | 7096bf1507f98be981aa14ffd9ed5a4a8b1c1494 (diff) | |
parent | 3249938cdf574058a066436aea06b0541ded6958 (diff) | |
download | Ninja-2c953d1501de5195e2485185fa24a2ebfd76bbb5.zip Ninja-2c953d1501de5195e2485185fa24a2ebfd76bbb5.tar.gz Ninja-2c953d1501de5195e2485185fa24a2ebfd76bbb5.tar.bz2 |
version 1.1.0v1.1.0
Diffstat (limited to 'src/clean.cc')
-rw-r--r-- | src/clean.cc | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/src/clean.cc b/src/clean.cc index 3fe23ec..0b8476b 100644 --- a/src/clean.cc +++ b/src/clean.cc @@ -29,6 +29,7 @@ Cleaner::Cleaner(State* state, const BuildConfig& config) : state_(state), config_(config), removed_(), + cleaned_(), cleaned_files_count_(0), disk_interface_(new RealDiskInterface), status_(0) { @@ -40,6 +41,7 @@ Cleaner::Cleaner(State* state, : state_(state), config_(config), removed_(), + cleaned_(), cleaned_files_count_(0), disk_interface_(disk_interface), status_(0) { @@ -80,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; @@ -111,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_; @@ -127,16 +135,20 @@ 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) { - DoCleanTarget(*n); + Node* next = *n; + // call DoCleanTarget recursively if this node has not been visited + if (cleaned_.count(next) == 0) { + DoCleanTarget(next); + } } } + + // mark this target to be cleaned already + cleaned_.insert(target); } int Cleaner::CleanTarget(Node* target) { @@ -191,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); } } } @@ -249,4 +258,5 @@ void Cleaner::Reset() { status_ = 0; cleaned_files_count_ = 0; removed_.clear(); + cleaned_.clear(); } |