diff options
-rw-r--r-- | dep.cc | 3 | ||||
-rw-r--r-- | main.cc | 2 | ||||
-rw-r--r-- | ninja.cc | 27 | ||||
-rw-r--r-- | ninja.h | 4 | ||||
-rw-r--r-- | symtab.cc | 2 | ||||
-rw-r--r-- | symtab.h | 1 |
6 files changed, 27 insertions, 12 deletions
@@ -141,7 +141,10 @@ class DepBuilder { ERROR("*** No targets."); } CHECK(!first_rule_->outputs.empty()); + targets.push_back(first_rule_->outputs[0]); + for (Symbol s : phony_) + targets.push_back(s); } // TODO: LogStats? @@ -251,7 +251,7 @@ static int Run(const vector<Symbol>& targets, if (g_generate_ninja) { ScopedTimeReporter tr("generate ninja time"); - GenerateNinja(g_ninja_suffix, nodes, ev); + GenerateNinja(g_ninja_suffix, nodes, ev, !targets.empty()); return 0; } @@ -168,9 +168,9 @@ class NinjaGenerator { ev_->set_avoid_io(false); } - void Generate(const vector<DepNode*>& nodes) { + void Generate(const vector<DepNode*>& nodes, bool build_all_targets) { GenerateShell(); - GenerateNinja(nodes); + GenerateNinja(nodes, build_all_targets); } private: @@ -316,10 +316,10 @@ class NinjaGenerator { StringPiece base = Basename(node->output.str()); if (base != node->output.str()) { - auto p = short_names_.emplace(base, StringPiece(node->output.str())); + auto p = short_names_.emplace(Intern(base), node->output); if (!p.second) { // We generate shortcuts only for targets whose basename are unique. - p.first->second.clear(); + p.first->second = kEmptySym; } } @@ -382,7 +382,7 @@ class NinjaGenerator { return StringPrintf("ninja%s.sh", ninja_suffix_.c_str()); } - void GenerateNinja(const vector<DepNode*>& nodes) { + void GenerateNinja(const vector<DepNode*>& nodes, bool build_all_targets) { fp_ = fopen(GetNinjaFilename().c_str(), "wb"); if (fp_ == NULL) PERROR("fopen(build.ninja) failed"); @@ -408,10 +408,15 @@ class NinjaGenerator { EmitNode(node); } + if (!build_all_targets) { + CHECK(!nodes.empty()); + fprintf(fp_, "\ndefault %s\n", nodes.front()->output.c_str()); + } + fprintf(fp_, "\n# shortcuts:\n"); for (auto p : short_names_) { - if (!p.second.empty()) - fprintf(fp_, "build %.*s: phony %.*s\n", SPF(p.first), SPF(p.second)); + if (!p.second.empty() && !done_.count(p.second)) + fprintf(fp_, "build %s: phony %s\n", p.first.c_str(), p.second.c_str()); } fclose(fp_); @@ -454,11 +459,13 @@ class NinjaGenerator { string cmd_buf_; string gomacc_; string ninja_suffix_; - unordered_map<StringPiece, StringPiece> short_names_; + unordered_map<Symbol, Symbol> short_names_; }; void GenerateNinja(const char* ninja_suffix, - const vector<DepNode*>& nodes, Evaluator* ev) { + const vector<DepNode*>& nodes, + Evaluator* ev, + bool build_all_targets) { NinjaGenerator ng(ninja_suffix, ev); - ng.Generate(nodes); + ng.Generate(nodes, build_all_targets); } @@ -26,7 +26,9 @@ class DepNode; class Evaluator; void GenerateNinja(const char* ninja_suffix, - const vector<DepNode*>& nodes, Evaluator* ev); + const vector<DepNode*>& nodes, + Evaluator* ev, + bool build_all_targets); // Exposed only for test. bool GetDepfileFromCommand(string* cmd, string* out); @@ -25,6 +25,7 @@ vector<string>* g_symbols; +Symbol kEmptySym = Symbol(Symbol::IsUninitialized()); Symbol kShellSym = Symbol(Symbol::IsUninitialized()); Symbol::Symbol(int v) @@ -48,6 +49,7 @@ class Symtab { CHECK(s.val() == i); } + kEmptySym = Intern(""); kShellSym = Intern("SHELL"); } @@ -72,6 +72,7 @@ template<> struct hash<Symbol> { }; } +extern Symbol kEmptySym; extern Symbol kShellSym; void InitSymtab(); |