Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit b7a2ef8

Browse files
committed
add cleaner for -cmt-rm hooks & move rescript_mode into state
1 parent 5d08bbd commit b7a2ef8

7 files changed

+26
-18
lines changed

src/clean.cc

+18-13
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "graph.h"
2222
#include "state.h"
2323
#include "util.h"
24+
#include <stdlib.h>
2425

2526
Cleaner::Cleaner(State* state,
2627
const BuildConfig& config,
@@ -133,24 +134,28 @@ void Cleaner::CleanDead(const BuildLog::Entries& entries) {
133134
Node* n = state_->LookupNode(i->first);
134135
if (!n || !n->in_edge()) {
135136
string toDelete = i->first.AsString();
136-
if(StringPiece::getJsSuffix().IsSuffix(toDelete) ||
137-
StringPiece::getMjsSuffix().IsSuffix(toDelete) ||
138-
StringPiece::getCjsSuffix().IsSuffix(toDelete)){
139-
int ret = RemoveFile(toDelete);
140-
if(ret == 0){
141-
staleFiles.insert(toDelete);
142-
}
137+
int ret = RemoveFile(toDelete);
138+
if (ret == 0) {
139+
staleFiles.insert(toDelete);
143140
}
144141
}
145142
}
146143

147-
if(!staleFiles.empty()){
148-
if(config_.verbosity != BuildConfig::QUIET){
149-
printf("Remove staled output\n");
150-
for(set<string>::const_iterator i = staleFiles.begin(); i != staleFiles.end(); ++i){
151-
printf("%s ",i->c_str());
144+
if (!staleFiles.empty()) {
145+
printf("Remove %lu staled output\n", staleFiles.size());
146+
if (!state_->cleaner.empty()) {
147+
vector<string> staled_cm;
148+
for (set<string>::const_iterator i = staleFiles.begin();
149+
i != staleFiles.end(); ++i) {
150+
if (StringPiece::getCmjSuffix().IsSuffix(*i)) {
151+
staled_cm.push_back(*i);
152+
}
153+
}
154+
for (size_t i = 0; i < staled_cm.size(); ++i) {
155+
string command = state_->cleaner + " -cmt-rm " + staled_cm[i];
156+
printf("%s\n", command.c_str());
157+
system(command.c_str());
152158
}
153-
printf("\nRemove staled done\n");
154159
}
155160
}
156161
}

src/debug_flags.cc

-2
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,3 @@ bool g_keep_depfile = false;
1919
bool g_keep_rsp = false;
2020

2121
bool g_experimental_statcache = true;
22-
23-
bool g_rescript = false;

src/debug_flags.h

-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,4 @@ extern bool g_keep_rsp;
3030

3131
extern bool g_experimental_statcache;
3232

33-
extern bool g_rescript;
3433
#endif // NINJA_EXPLAIN_H_

src/manifest_parser.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ bool ManifestParser::Parse(const string& filename, const string& input,
8181
} else if(lexer_.PeekToken(Lexer::EQUALS)){
8282
if(!lexer_.ReadVarValue(&let_value,err)) return false;
8383
if (name == "rescript") {
84-
g_rescript = true;
84+
state_ -> rescript_mode_ = true;
85+
} else if(name == "cleaner") {
86+
state_ -> cleaner = let_value.Evaluate(env_);
8587
} else {
8688
string value = let_value.Evaluate(env_);
8789
env_->AddBinding(name, value);

src/ninja.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@ NORETURN void real_main(int argc, char** argv) {
13721372
if (options.tool && options.tool->when == Tool::RUN_AFTER_LOGS)
13731373
exit((ninja.*options.tool->func)(&options, argc, argv));
13741374

1375-
if (g_rescript) {
1375+
if (ninja.state_.rescript_mode_) {
13761376
ninja.ToolCleanDead(&options, argc, argv);
13771377
}
13781378

src/state.cc

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ State::State() {
7777
bindings_.AddRule(&kPhonyRule);
7878
AddPool(&kDefaultPool);
7979
AddPool(&kConsolePool);
80+
rescript_mode_ = false;
8081
}
8182

8283
void State::AddPool(Pool* pool) {

src/state.h

+3
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ struct State {
126126

127127
BindingEnv bindings_;
128128
vector<Node*> defaults_;
129+
130+
bool rescript_mode_;
131+
string cleaner ;
129132
};
130133

131134
#endif // NINJA_STATE_H_

0 commit comments

Comments
 (0)