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

Unified Diff: tools/gn/setup.cc

Issue 2581193003: GN: Add optional default_args variable to .gn. (Closed)
Patch Set: Address comment. Created 3 years, 11 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/setup.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « tools/gn/setup.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698