mirror of
https://github.com/ninja-build/ninja.git
synced 2026-06-29 11:19:25 +00:00
refactor repeated code in cleaner
This commit is contained in:
28
src/clean.cc
28
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user