Index: tools/gn/setup.cc |
diff --git a/tools/gn/setup.cc b/tools/gn/setup.cc |
index 8a433bcdbb1cacf67fd0e96bdbaf5f5bee9dc360..ed6ef54d174615bf0e14271814b0751c97fb50b5 100644 |
--- a/tools/gn/setup.cc |
+++ b/tools/gn/setup.cc |
@@ -106,6 +106,15 @@ Variables |
The secondary source root must be inside the main source tree. |
+ default_args [optional] |
+ Scope containing the default overrides for declared arguments. These |
+ overrides take precedence over the default values specified in the |
+ declare_args() block, but can be overriden using --args or the |
+ args.gn file. |
+ |
+ This is intended to be used when subprojects declare arguments with |
+ default values that need to be changed for whatever reason. |
+ |
Example .gn file contents |
buildconfig = "//build/config/BUILDCONFIG.gn" |
@@ -118,6 +127,12 @@ Example .gn file contents |
root = "//:root" |
secondary_source = "//build/config/temporary_buildfiles/" |
+ |
+ default_args = { |
+ # Default to release builds for this project. |
+ is_debug = false |
+ is_component_build = false |
+ } |
)"; |
namespace { |
@@ -257,6 +272,7 @@ Setup::Setup() |
check_public_headers_(false), |
dotfile_settings_(&build_settings_, std::string()), |
dotfile_scope_(&dotfile_settings_), |
+ default_args_(nullptr), |
fill_arguments_(true) { |
dotfile_settings_.set_toolchain_label(Label()); |
@@ -300,6 +316,14 @@ bool Setup::DoSetup(const std::string& build_dir, bool force_create) { |
return false; |
} |
+ // Apply project-specific default (if specified). |
+ // Must happen before FillArguments(). |
+ if (default_args_) { |
+ Scope::KeyValueMap overrides; |
+ default_args_->GetCurrentScopeValues(&overrides); |
+ build_settings_.build_args().AddArgOverrides(overrides); |
+ } |
+ |
if (fill_arguments_) { |
if (!FillArguments(*cmdline)) |
return false; |
@@ -738,5 +762,17 @@ bool Setup::FillOtherConfig(const base::CommandLine& cmdline) { |
build_settings_.set_exec_script_whitelist(std::move(whitelist)); |
} |
+ // Fill optional default_args. |
+ const Value* default_args_value = |
+ dotfile_scope_.GetValue("default_args", true); |
+ if (default_args_value) { |
+ if (!default_args_value->VerifyTypeIs(Value::SCOPE, &err)) { |
+ err.PrintToStdout(); |
+ return false; |
+ } |
+ |
+ default_args_ = default_args_value->scope_value(); |
+ } |
+ |
return true; |
} |