Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Unified Diff: tools/gn/ninja_build_writer.cc

Issue 2824153002: Use $root:default as a "default" rule (Closed)
Patch Set: Code review feedback Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/docs/reference.md ('k') | tools/gn/setup.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..f3e9aaf59ac6263f573f4c6b904d0c0f97ea2140 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" in the root build file,
+ 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,18 @@ 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 {
+ out_ << "\ndefault ";
+ path_output_.WriteFile(out_, default_target->dependency_output_file());
+ out_ << std::endl;
+ }
+ } else if (!default_toolchain_targets_.empty()) {
out_ << "\ndefault all" << std::endl;
+ }
return true;
}
« no previous file with comments | « tools/gn/docs/reference.md ('k') | tools/gn/setup.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698