Index: tools/gn/ninja_build_writer.cc |
diff --git a/tools/gn/ninja_build_writer.cc b/tools/gn/ninja_build_writer.cc |
index 2f2336cde034b77baf63cfcc8963f195b51347b5..85e7e617865db27fa5d56f1edc62956684b6e240 100644 |
--- a/tools/gn/ninja_build_writer.cc |
+++ b/tools/gn/ninja_build_writer.cc |
@@ -349,8 +349,9 @@ The "all" and "default" rules |
All generated targets (see "gn help execution") will be added to an implicit |
build rule called "all" so "ninja all" will always compile everything. The |
default rule will be used by Ninja if no specific target is specified (just |
- typing "ninja"). If there is a target named "//:default" it will be the |
- default build rule, otherwise the implicit "all" rule will be used. |
+ typing "ninja"). If there is a target named "//:default" (or $root:default in |
brettw
2017/04/19 19:49:25
Ditto
Petr Hosek
2017/04/19 20:20:26
Done.
|
+ case the non-default root build target is used) it will be the default build |
+ rule, otherwise the implicit "all" rule will be used. |
Phony rules |
@@ -396,7 +397,7 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) { |
written_rules.insert("all"); |
// Set if we encounter a target named "//:default". |
- bool default_target_exists = false; |
+ const Target* default_target = nullptr; |
// Targets in the root build file. |
std::vector<const Target*> toplevel_targets; |
@@ -418,8 +419,9 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) { |
const Label& label = target->label(); |
const std::string& short_name = label.name(); |
- if (label.dir().value() == "//" && label.name() == "default") |
- default_target_exists = true; |
+ if (label.dir() == build_settings_->root_target_label().dir() && |
+ short_name == "default") |
+ default_target = target; |
// Count the number of targets with the given short name. |
Counts& short_names_counts = short_names[short_name]; |
@@ -537,10 +539,21 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) { |
} |
out_ << std::endl; |
- if (default_target_exists) |
- out_ << "\ndefault default" << std::endl; |
- else if (!default_toolchain_targets_.empty()) |
+ if (default_target) { |
+ // Use the short name when available |
+ if (written_rules.find("default") != written_rules.end()) { |
+ out_ << "\ndefault default" << std::endl; |
+ } else { |
+ EscapeOptions ninja_escape; |
+ ninja_escape.mode = ESCAPE_NINJA; |
+ std::string name = default_target->label().GetUserVisibleName(false); |
brettw
2017/04/19 19:49:25
This is making assumptions about the types of rule
Petr Hosek
2017/04/19 20:20:26
Done.
|
+ base::TrimString(name, "/", &name); |
+ std::string escaped = EscapeString(name, ninja_escape, nullptr); |
+ out_ << "\ndefault " << escaped << std::endl; |
+ } |
+ } else if (!default_toolchain_targets_.empty()) { |
out_ << "\ndefault all" << std::endl; |
+ } |
return true; |
} |