aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dep.cc3
-rw-r--r--main.cc2
-rw-r--r--ninja.cc27
-rw-r--r--ninja.h4
-rw-r--r--symtab.cc2
-rw-r--r--symtab.h1
6 files changed, 27 insertions, 12 deletions
diff --git a/dep.cc b/dep.cc
index 647ba20..ab7204e 100644
--- a/dep.cc
+++ b/dep.cc
@@ -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?
diff --git a/main.cc b/main.cc
index c293b55..ce9ee09 100644
--- a/main.cc
+++ b/main.cc
@@ -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;
}
diff --git a/ninja.cc b/ninja.cc
index 49687ef..7ef2bd6 100644
--- a/ninja.cc
+++ b/ninja.cc
@@ -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);
}
diff --git a/ninja.h b/ninja.h
index e87deaa..0973119 100644
--- a/ninja.h
+++ b/ninja.h
@@ -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);
diff --git a/symtab.cc b/symtab.cc
index cb12b2c..dd4b405 100644
--- a/symtab.cc
+++ b/symtab.cc
@@ -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");
}
diff --git a/symtab.h b/symtab.h
index 907a6eb..b2e772e 100644
--- a/symtab.h
+++ b/symtab.h
@@ -72,6 +72,7 @@ template<> struct hash<Symbol> {
};
}
+extern Symbol kEmptySym;
extern Symbol kShellSym;
void InitSymtab();