diff options
author | Evan Martin <martine@danga.com> | 2011-09-22 21:03:07 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2011-09-22 21:03:07 (GMT) |
commit | d342acd8df37e1b3422a73c62d3fb06d95e6cbca (patch) | |
tree | f2874c92196c6ab3011491a6f4dfca58640dc36b /src/ninja.cc | |
parent | c188937f6310d19d0b0c119b85ee67c3500a9941 (diff) | |
download | Ninja-d342acd8df37e1b3422a73c62d3fb06d95e6cbca.zip Ninja-d342acd8df37e1b3422a73c62d3fb06d95e6cbca.tar.gz Ninja-d342acd8df37e1b3422a73c62d3fb06d95e6cbca.tar.bz2 |
add syntax to build output from a given file
e.g. "ninja src/graph.cc^" builds the object file generated from that input
Diffstat (limited to 'src/ninja.cc')
-rw-r--r-- | src/ninja.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/ninja.cc b/src/ninja.cc index 5a549d4..c70aa43 100644 --- a/src/ninja.cc +++ b/src/ninja.cc @@ -50,6 +50,9 @@ void Usage(const BuildConfig& config) { "usage: ninja [options] [targets...]\n" "\n" "if targets are unspecified, builds the 'default' target (see manual).\n" +"targets are paths, with additional special syntax:\n" +" target^ means 'the first output that uses target'.\n" +" example: 'ninja foo.cc^' will likely build foo.o.\n" "\n" "options:\n" " -f FILE specify input build file [default=build.ninja]\n" @@ -137,8 +140,28 @@ bool CollectTargetsFromArgs(State* state, int argc, char* argv[], for (int i = 0; i < argc; ++i) { string path = argv[i]; CanonicalizePath(&path); + + // Special syntax: "foo.cc^" means "the first output of foo.cc". + bool first_dependent = false; + if (!path.empty() && path[path.size() - 1] == '^') { + path.resize(path.size() - 1); + first_dependent = true; + } + Node* node = state->LookupNode(path); if (node) { + if (first_dependent) { + if (node->out_edges_.empty()) { + *err = "'" + path + "' has no out edge"; + return false; + } + Edge* edge = node->out_edges_[0]; + if (edge->outputs_.empty()) { + edge->Dump(); + Fatal("edge has no outputs"); + } + node = edge->outputs_[0]; + } targets->push_back(node); } else { *err = "unknown target '" + path + "'"; |