Commit ddb3babc authored by phosek's avatar phosek Committed by Commit bot

Use $root:default as a "default" rule

When the root build file is changed in .gn file, we should check
$root:default rather than //:default when looking for "default" rule.

Review-Url: https://codereview.chromium.org/2824153002
Cr-Commit-Position: refs/heads/master@{#465758}
parent 8aeea939
...@@ -25,6 +25,10 @@ BuildSettings::BuildSettings(const BuildSettings& other) ...@@ -25,6 +25,10 @@ BuildSettings::BuildSettings(const BuildSettings& other)
BuildSettings::~BuildSettings() { BuildSettings::~BuildSettings() {
} }
void BuildSettings::SetRootTargetLabel(const Label& r) {
root_target_label_ = r;
}
void BuildSettings::SetRootPath(const base::FilePath& r) { void BuildSettings::SetRootPath(const base::FilePath& r) {
DCHECK(r.value()[r.value().size() - 1] != base::FilePath::kSeparators[0]); DCHECK(r.value()[r.value().size() - 1] != base::FilePath::kSeparators[0]);
root_path_ = r.NormalizePathSeparatorsTo('/'); root_path_ = r.NormalizePathSeparatorsTo('/');
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/macros.h" #include "base/macros.h"
#include "tools/gn/args.h" #include "tools/gn/args.h"
#include "tools/gn/label.h"
#include "tools/gn/scope.h" #include "tools/gn/scope.h"
#include "tools/gn/source_dir.h" #include "tools/gn/source_dir.h"
#include "tools/gn/source_file.h" #include "tools/gn/source_file.h"
...@@ -31,6 +32,10 @@ class BuildSettings { ...@@ -31,6 +32,10 @@ class BuildSettings {
BuildSettings(const BuildSettings& other); BuildSettings(const BuildSettings& other);
~BuildSettings(); ~BuildSettings();
// Root target label.
const Label& root_target_label() const { return root_target_label_; }
void SetRootTargetLabel(const Label& r);
// Absolute path of the source root on the local system. Everything is // Absolute path of the source root on the local system. Everything is
// relative to this. Does not end in a [back]slash. // relative to this. Does not end in a [back]slash.
const base::FilePath& root_path() const { return root_path_; } const base::FilePath& root_path() const { return root_path_; }
...@@ -104,6 +109,7 @@ class BuildSettings { ...@@ -104,6 +109,7 @@ class BuildSettings {
} }
private: private:
Label root_target_label_;
base::FilePath root_path_; base::FilePath root_path_;
std::string root_path_utf8_; std::string root_path_utf8_;
base::FilePath secondary_source_path_; base::FilePath secondary_source_path_;
......
...@@ -5861,8 +5861,9 @@ ...@@ -5861,8 +5861,9 @@
All generated targets (see "gn help execution") will be added to an implicit 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 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 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 typing "ninja"). If there is a target named "default" in the root build file,
default build rule, otherwise the implicit "all" rule will be used. it will be the default build rule, otherwise the implicit "all" rule will be
used.
``` ```
#### **Phony rules** #### **Phony rules**
......
...@@ -349,8 +349,9 @@ The "all" and "default" rules ...@@ -349,8 +349,9 @@ The "all" and "default" rules
All generated targets (see "gn help execution") will be added to an implicit 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 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 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 typing "ninja"). If there is a target named "default" in the root build file,
default build rule, otherwise the implicit "all" rule will be used. it will be the default build rule, otherwise the implicit "all" rule will be
used.
Phony rules Phony rules
...@@ -396,7 +397,7 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) { ...@@ -396,7 +397,7 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) {
written_rules.insert("all"); written_rules.insert("all");
// Set if we encounter a target named "//:default". // Set if we encounter a target named "//:default".
bool default_target_exists = false; const Target* default_target = nullptr;
// Targets in the root build file. // Targets in the root build file.
std::vector<const Target*> toplevel_targets; std::vector<const Target*> toplevel_targets;
...@@ -418,8 +419,9 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) { ...@@ -418,8 +419,9 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) {
const Label& label = target->label(); const Label& label = target->label();
const std::string& short_name = label.name(); const std::string& short_name = label.name();
if (label.dir().value() == "//" && label.name() == "default") if (label.dir() == build_settings_->root_target_label().dir() &&
default_target_exists = true; short_name == "default")
default_target = target;
// Count the number of targets with the given short name. // Count the number of targets with the given short name.
Counts& short_names_counts = short_names[short_name]; Counts& short_names_counts = short_names[short_name];
...@@ -537,10 +539,18 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) { ...@@ -537,10 +539,18 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) {
} }
out_ << std::endl; out_ << std::endl;
if (default_target_exists) if (default_target) {
out_ << "\ndefault default" << std::endl; // Use the short name when available
else if (!default_toolchain_targets_.empty()) 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; out_ << "\ndefault all" << std::endl;
}
return true; return true;
} }
......
...@@ -698,6 +698,7 @@ bool Setup::RunConfigFile() { ...@@ -698,6 +698,7 @@ bool Setup::RunConfigFile() {
bool Setup::FillOtherConfig(const base::CommandLine& cmdline) { bool Setup::FillOtherConfig(const base::CommandLine& cmdline) {
Err err; Err err;
SourceDir current_dir("//"); SourceDir current_dir("//");
Label root_target_label(current_dir, "");
// Secondary source path, read from the config file if present. // Secondary source path, read from the config file if present.
// Read from the config file if present. // Read from the config file if present.
...@@ -720,8 +721,7 @@ bool Setup::FillOtherConfig(const base::CommandLine& cmdline) { ...@@ -720,8 +721,7 @@ bool Setup::FillOtherConfig(const base::CommandLine& cmdline) {
return false; return false;
} }
Label root_target_label = root_target_label = Label::Resolve(current_dir, Label(), *root_value, &err);
Label::Resolve(current_dir, Label(), *root_value, &err);
if (err.has_error()) { if (err.has_error()) {
err.PrintToStdout(); err.PrintToStdout();
return false; return false;
...@@ -729,6 +729,7 @@ bool Setup::FillOtherConfig(const base::CommandLine& cmdline) { ...@@ -729,6 +729,7 @@ bool Setup::FillOtherConfig(const base::CommandLine& cmdline) {
root_build_file_ = Loader::BuildFileForLabel(root_target_label); root_build_file_ = Loader::BuildFileForLabel(root_target_label);
} }
build_settings_.SetRootTargetLabel(root_target_label);
// Build config file. // Build config file.
const Value* build_config_value = const Value* build_config_value =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment