diff options
author | Nicolas Despres <nicolas.despres@gmail.com> | 2011-04-10 11:32:24 (GMT) |
---|---|---|
committer | Nicolas Despres <nicolas.despres@gmail.com> | 2011-04-26 11:23:04 (GMT) |
commit | 3ad977241b24ea8077073f1f3feecab7b8dc0b55 (patch) | |
tree | 270bedc93683bb41e97a28b348eb70feafa297ec /src/ninja_jumble.cc | |
parent | f10afb9d402b33710bd0b93f0c9c42f438347171 (diff) | |
download | Ninja-3ad977241b24ea8077073f1f3feecab7b8dc0b55.zip Ninja-3ad977241b24ea8077073f1f3feecab7b8dc0b55.tar.gz Ninja-3ad977241b24ea8077073f1f3feecab7b8dc0b55.tar.bz2 |
Add the 'targets' tool.
This tool list targets by depth or by rule. It can be useful:
- for shell completion script ;
- to know what are the primary targets: ninja -t targets depth 1 ;
- to know targets that are linked: ninja -t rule link ;
- when debugging.
It works by first listing the root nodes and then following the input nodes
of their in edge.
Diffstat (limited to 'src/ninja_jumble.cc')
-rw-r--r-- | src/ninja_jumble.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/ninja_jumble.cc b/src/ninja_jumble.cc index fd2ee18..e6a0de6 100644 --- a/src/ninja_jumble.cc +++ b/src/ninja_jumble.cc @@ -182,3 +182,21 @@ void State::AddOut(Edge* edge, const string& path) { } node->in_edge_ = edge; } + +vector<Node*> State::RootNodes(string* error) +{ + assert(error); + vector<Node*> root_nodes; + // Search for nodes with no output. + for (vector<Edge*>::iterator e = edges_.begin(); e != edges_.end(); ++e) + for (vector<Node*>::iterator outs = (*e)->outputs_.begin(); + outs != (*e)->outputs_.end(); + ++outs) + if ((*outs)->out_edges_.size() == 0) + root_nodes.push_back(*outs); + if (!edges_.empty() && root_nodes.empty()) { + *error = "could not determine root nodes of build graph"; + } + assert(edges_.empty() || !root_nodes.empty()); + return root_nodes; +} |