Make GN use_custom_libcxx work properly with sanitizers.
Its default value depended on a previous flag, but the value of that flag wasn't getting set until the end of the declare_args block. The solution is to add a new declare_args block.
Added documentation for this since it can be surprising.
Review URL: https://codereview.chromium.org/1386713002
Cr-Original-Commit-Position: refs/heads/master@{#352109}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: cc637eee86e6041ac9df3ad7d3160ceb2a88cddd
diff --git a/tools/gn/functions.cc b/tools/gn/functions.cc
index 86043f0..01d0aeb 100644
--- a/tools/gn/functions.cc
+++ b/tools/gn/functions.cc
@@ -344,7 +344,46 @@
"\n"
" See also \"gn help buildargs\" for an overview.\n"
"\n"
- "Example:\n"
+ " The precise behavior of declare args is:\n"
+ "\n"
+ " 1. The declare_arg block executes. Any variables in the enclosing\n"
+ " scope are available for reading.\n"
+ "\n"
+ " 2. At the end of executing the block, any variables set within that\n"
+ " scope are saved globally as build arguments, with their current\n"
+ " values being saved as the \"default value\" for that argument.\n"
+ "\n"
+ " 3. User-defined overrides are applied. Anything set in \"gn args\"\n"
+ " now overrides any default values. The resulting set of variables\n"
+ " is promoted to be readable from the following code in the file.\n"
+ "\n"
+ " This has some ramifications that may not be obvious:\n"
+ "\n"
+ " - You should not perform difficult work inside a declare_args block\n"
+ " since this only sets a default value that may be discarded. In\n"
+ " particular, don't use the result of exec_script() to set the\n"
+ " default value. If you want to have a script-defined default, set\n"
+ " some default \"undefined\" value like [], \"\", or -1, and after\n"
+ " the declare_args block, call exec_script if the value is unset by\n"
+ " the user.\n"
+ "\n"
+ " - Any code inside of the declare_args block will see the default\n"
+ " values of previous variables defined in the block rather than\n"
+ " the user-overridden value. This can be surprising because you will\n"
+ " be used to seeing the overridden value. If you need to make the\n"
+ " default value of one arg dependent on the possibly-overridden\n"
+ " value of another, write two separate declare_args blocks:\n"
+ "\n"
+ " declare_args() {\n"
+ " enable_foo = true\n"
+ " }\n"
+ " declare_args() {\n"
+ " # Bar defaults to same user-overridden state as foo.\n"
+ " enable_bar = enable_foo\n"
+ " }\n"
+ "\n"
+ "Example\n"
+ "\n"
" declare_args() {\n"
" enable_teleporter = true\n"
" enable_doom_melon = false\n"