Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'dont-clean-phony' of git://github.com/pcc/ninja

Conflicts:
	src/clean.cc
  • Loading branch information...
commit c2098f931b6d93b6eae406598e2b46c175bd969f 2 parents 5d6249f + 3353e55
@martine authored
Showing with 36 additions and 9 deletions.
  1. +11 −9 src/clean.cc
  2. +25 −0 src/clean_test.cc
View
20 src/clean.cc
@@ -102,7 +102,7 @@ int Cleaner::CleanAll(bool generator) {
for (vector<Edge*>::iterator e = state_->edges_.begin();
e != state_->edges_.end(); ++e) {
// Do not try to remove phony targets
- if ((*e)->rule_ == &State::kPhonyRule)
+ if ((*e)->is_phony())
continue;
// Do not remove generator's files unless generator specified.
if (!generator && (*e)->rule().generator())
@@ -123,14 +123,16 @@ int Cleaner::CleanAll(bool generator) {
}
void Cleaner::DoCleanTarget(Node* target) {
- if (target->in_edge()) {
- Remove(target->path());
- if (!target->in_edge()->rule().depfile().empty())
- Remove(target->in_edge()->EvaluateDepFile());
- if (target->in_edge()->HasRspFile())
- Remove(target->in_edge()->GetRspFile());
- for (vector<Node*>::iterator n = target->in_edge()->inputs_.begin();
- n != target->in_edge()->inputs_.end();
+ if (Edge* e = target->in_edge()) {
+ // 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());
+ }
+ for (vector<Node*>::iterator n = e->inputs_.begin(); n != e->inputs_.end();
++n) {
DoCleanTarget(*n);
}
View
25 src/clean_test.cc
@@ -347,3 +347,28 @@ TEST_F(CleanTest, CleanFailure) {
Cleaner cleaner(&state_, config_, &fs_);
EXPECT_NE(0, cleaner.CleanAll());
}
+
+TEST_F(CleanTest, CleanPhony) {
+ ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
+"build phony: phony t1 t2\n"
+"build t1: cat\n"
+"build t2: cat\n"));
+
+ fs_.Create("phony", 1, "");
+ fs_.Create("t1", 1, "");
+ fs_.Create("t2", 1, "");
+
+ // Check that CleanAll does not remove "phony".
+ Cleaner cleaner(&state_, config_, &fs_);
+ EXPECT_EQ(0, cleaner.CleanAll());
+ EXPECT_EQ(2, cleaner.cleaned_files_count());
+ EXPECT_NE(0, fs_.Stat("phony"));
+
+ fs_.Create("t1", 1, "");
+ fs_.Create("t2", 1, "");
+
+ // Check that CleanTarget does not remove "phony".
+ EXPECT_EQ(0, cleaner.CleanTarget("phony"));
+ EXPECT_EQ(2, cleaner.cleaned_files_count());
+ EXPECT_NE(0, fs_.Stat("phony"));
+}
Please sign in to comment.
Something went wrong with that request. Please try again.