Skip to content

Commit

Permalink
Merge pull request #1730 from naarcini/master
Browse files Browse the repository at this point in the history
Add 'inputs' tool to print out all inputs for a set of targets
  • Loading branch information
jhasse authored Feb 2, 2022
2 parents 6ed7d54 + 4a13d59 commit f404f00
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
4 changes: 4 additions & 0 deletions doc/manual.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 33 additions & 1 deletion src/ninja.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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[]);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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".
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit f404f00

Please sign in to comment.