summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Niklas Hasse <jhasse@bixense.com>2022-02-02 18:49:17 (GMT)
committerGitHub <noreply@github.com>2022-02-02 18:49:17 (GMT)
commitf404f0059d71c8c86da7b56c48794266b5befd10 (patch)
tree701f9f03cdbc0603795a1022c055ab14a2b37419
parent6ed7d54d2ef30a3f55db0e274cf3c4f4dd36fd8d (diff)
parent4a13d59820bf215232c12a34c1e0bef9e31fb04d (diff)
downloadNinja-f404f0059d71c8c86da7b56c48794266b5befd10.zip
Ninja-f404f0059d71c8c86da7b56c48794266b5befd10.tar.gz
Ninja-f404f0059d71c8c86da7b56c48794266b5befd10.tar.bz2
Merge pull request #1730 from naarcini/master
Add 'inputs' tool to print out all inputs for a set of targets
-rw-r--r--doc/manual.asciidoc4
-rw-r--r--src/ninja.cc34
2 files changed, 37 insertions, 1 deletions
diff --git a/doc/manual.asciidoc b/doc/manual.asciidoc
index 2066340..9e2bec5 100644
--- a/doc/manual.asciidoc
+++ b/doc/manual.asciidoc
@@ -257,6 +257,10 @@ than the _depth_ mode.
executed in order, may be used to rebuild those targets, assuming that all
output files are out of date.
+`inputs`:: given a list of targets, print a list of all inputs which are used
+to rebuild those targets.
+_Available since Ninja 1.11._
+
`clean`:: remove built files. By default it removes all built files
except for those created by the generator. Adding the `-g` flag also
removes built files created by the generator (see <<ref_rule,the rule
diff --git a/src/ninja.cc b/src/ninja.cc
index 06be1da..df39ba9 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -127,6 +127,7 @@ struct NinjaMain : public BuildLogUser {
int ToolMSVC(const Options* options, int argc, char* argv[]);
int ToolTargets(const Options* options, int argc, char* argv[]);
int ToolCommands(const Options* options, int argc, char* argv[]);
+ int ToolInputs(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[]);
@@ -702,7 +703,7 @@ void PrintCommands(Edge* edge, EdgeSet* seen, PrintCommandMode mode) {
}
int NinjaMain::ToolCommands(const Options* options, int argc, char* argv[]) {
- // The clean tool uses getopt, and expects argv[0] to contain the name of
+ // The commands tool uses getopt, and expects argv[0] to contain the name of
// the tool, i.e. "commands".
++argc;
--argv;
@@ -743,6 +744,35 @@ int NinjaMain::ToolCommands(const Options* options, int argc, char* argv[]) {
return 0;
}
+void PrintInputs(Edge* edge, set<Edge*>* seen) {
+ if (!edge)
+ return;
+ if (!seen->insert(edge).second)
+ return;
+
+ for (vector<Node*>::iterator in = edge->inputs_.begin();
+ in != edge->inputs_.end(); ++in)
+ PrintInputs((*in)->in_edge(), seen);
+
+ if (!edge->is_phony())
+ puts(edge->GetBinding("in_newline").c_str());
+}
+
+int NinjaMain::ToolInputs(const Options* options, int argc, char* argv[]) {
+ vector<Node*> nodes;
+ string err;
+ if (!CollectTargetsFromArgs(argc, argv, &nodes, &err)) {
+ Error("%s", err.c_str());
+ return 1;
+ }
+
+ set<Edge*> seen;
+ for (vector<Node*>::iterator in = nodes.begin(); in != nodes.end(); ++in)
+ PrintInputs((*in)->in_edge(), &seen);
+
+ return 0;
+}
+
int NinjaMain::ToolClean(const Options* options, int argc, char* argv[]) {
// The clean tool uses getopt, and expects argv[0] to contain the name of
// the tool, i.e. "clean".
@@ -1021,6 +1051,8 @@ const Tool* ChooseTool(const string& tool_name) {
Tool::RUN_AFTER_LOAD, &NinjaMain::ToolClean },
{ "commands", "list all commands required to rebuild given targets",
Tool::RUN_AFTER_LOAD, &NinjaMain::ToolCommands },
+ { "inputs", "list all inputs required to rebuild given targets",
+ Tool::RUN_AFTER_LOAD, &NinjaMain::ToolInputs},
{ "deps", "show dependencies stored in the deps log",
Tool::RUN_AFTER_LOGS, &NinjaMain::ToolDeps },
{ "missingdeps", "check deps log dependencies on generated files",