Chromium Code Reviews| Index: tools/gn/functions.cc |
| diff --git a/tools/gn/functions.cc b/tools/gn/functions.cc |
| index e01a25c977f7a300ae1048f994c2c6d0b8a33851..9723107a33d790d44ae2974eb1a4dbdecc1c4efa 100644 |
| --- a/tools/gn/functions.cc |
| +++ b/tools/gn/functions.cc |
| @@ -357,8 +357,9 @@ const char kDeclareArgs_Help[] = |
| The precise behavior of declare args is: |
| - 1. The declare_arg block executes. Any variables in the enclosing scope are |
| - available for reading. |
| + 1. The declare_args() block executes. Any variable defined in the enclosing |
| + scope is available for reading, but any variable defined earlier in |
| + the current scope is not (since the overrides haven't been applied yet). |
| 2. At the end of executing the block, any variables set within that scope |
| are saved globally as build arguments, with their current values being |
| @@ -377,12 +378,10 @@ const char kDeclareArgs_Help[] = |
| like [], "", or -1, and after the declare_args block, call exec_script if |
| the value is unset by the user. |
| - - Any code inside of the declare_args block will see the default values of |
| - previous variables defined in the block rather than the user-overridden |
| - value. This can be surprising because you will be used to seeing the |
| - overridden value. If you need to make the default value of one arg |
| - dependent on the possibly-overridden value of another, write two separate |
| - declare_args blocks: |
| + - Because you cannot read the value of a variable defined in the same |
| + block, if you need to make the default value of one arg depend |
| + on the possibly-overridden value of another, write two separate |
| + declare_args() blocks: |
| declare_args() { |
| enable_foo = true |
| @@ -415,6 +414,12 @@ Value RunDeclareArgs(Scope* scope, |
| return Value(); |
| Scope block_scope(scope); |
| + |
| + // Mark that this scope is part of a declare_args() call, in order to |
| + // prevent reads of any variables that are defined earlier in the same call |
| + // (see `gn help declare_args` for more). |
| + block_scope.SetProperty(&kInDeclareArgsKey, (void *)&kInDeclareArgsKey); |
|
brettw
2016/11/18 22:07:43
Are you sure you need the void* cast here? I think
Dirk Pranke
2016/11/18 22:35:39
I thought I didn't need it, either, but the compil
|
| + |
| block->Execute(&block_scope, err); |
| if (err->has_error()) |
| return Value(); |