Chromium Code Reviews| Index: tools/gn/functions.cc |
| diff --git a/tools/gn/functions.cc b/tools/gn/functions.cc |
| index 86043f0a73ab930c5c00fd28832e434b7a208331..7d9e669a3be9be3e608f372a1477466c9d00e7ee 100644 |
| --- a/tools/gn/functions.cc |
| +++ b/tools/gn/functions.cc |
| @@ -344,7 +344,46 @@ const char kDeclareArgs_Help[] = |
| "\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 the executing the block, any variables set within\n" |
|
Bons
2015/10/02 18:55:22
"at the end of the executing the block"...?
|
| + " that scope are saved globally as build arguments, with their\n" |
| + " current values being saved as the \"default value\" for that arg.\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" |