summaryrefslogtreecommitdiffstats
path: root/src/ninja.cc
diff options
context:
space:
mode:
authorikifof <ikifof@gmail.com>2018-04-28 01:34:55 (GMT)
committerikifof <ikifof@gmail.com>2019-05-25 18:14:43 (GMT)
commit714621dba1b8b2d8cd6080b7bc82955b44054734 (patch)
treeaaf2e1572decb72ba9cc9b00a909070fce0cfca9 /src/ninja.cc
parent20b30dac6698d119e7797b34d6ed2c4ed8f48417 (diff)
downloadNinja-714621dba1b8b2d8cd6080b7bc82955b44054734.zip
Ninja-714621dba1b8b2d8cd6080b7bc82955b44054734.tar.gz
Ninja-714621dba1b8b2d8cd6080b7bc82955b44054734.tar.bz2
Adding a way to clean dead build artifacts that have an entry in the build log,
but are no longer produced by the current manifest. For now adding a dedicated "-t cleandead" option, since it should be run after reading the log; ideally it should be part of the build config and done before to start looking for dirty targets so that an incremental build would produce the same end result as a clean build from scratch. But since I am not 100% sure to understand the comment in the NinjaMain::isPathDead(), I opted to make it a tool for now to avoid impacting users who want to keep those files. The option name "cleandead" was selected insteadof something like "reap" to keep the "clean" prefix.
Diffstat (limited to 'src/ninja.cc')
-rw-r--r--src/ninja.cc11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/ninja.cc b/src/ninja.cc
index a093cd1..3b9fab5 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -123,6 +123,7 @@ struct NinjaMain : public BuildLogUser {
int ToolTargets(const Options* options, int argc, char* argv[]);
int ToolCommands(const Options* options, int argc, char* argv[]);
int ToolClean(const Options* options, int argc, char* argv[]);
+ int ToolCleanDead(const Options* options, int argc, char* argv[]);
int ToolCompilationDatabase(const Options* options, int argc, char* argv[]);
int ToolRecompact(const Options* options, int argc, char* argv[]);
int ToolUrtle(const Options* options, int argc, char** argv);
@@ -153,9 +154,6 @@ struct NinjaMain : public BuildLogUser {
void DumpMetrics();
virtual bool IsPathDead(StringPiece s) const {
- Node* n = state_.LookupNode(s);
- if (!n || !n->in_edge())
- return false;
// Just checking n isn't enough: If an old output is both in the build log
// and in the deps log, it will have a Node object in state_. (It will also
// have an in edge if one of its inputs is another output that's in the deps
@@ -719,6 +717,11 @@ int NinjaMain::ToolClean(const Options* options, int argc, char* argv[]) {
}
}
+int NinjaMain::ToolCleanDead(const Options* options, int argc, char* argv[]) {
+ Cleaner cleaner(&state_, config_, &disk_interface_);
+ return cleaner.CleanDead(build_log_.entries());
+}
+
void EncodeJSONString(const char *str) {
while (*str) {
if (*str == '"' || *str == '\\')
@@ -893,6 +896,8 @@ const Tool* ChooseTool(const string& tool_name) {
Tool::RUN_AFTER_LOAD, &NinjaMain::ToolRecompact },
{ "rules", "list all rules",
Tool::RUN_AFTER_LOAD, &NinjaMain::ToolRules },
+ { "cleandead", "clean built files that are no longer produced by the manifest",
+ Tool::RUN_AFTER_LOGS, &NinjaMain::ToolCleanDead },
{ "urtle", NULL,
Tool::RUN_AFTER_FLAGS, &NinjaMain::ToolUrtle },
{ NULL, NULL, Tool::RUN_AFTER_FLAGS, NULL }