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

Side by Side Diff: tools/gn/docs/reference.md

Issue 2509333003: Change GN to disallow reading args defined in the same declare_args() call. (Closed)
Patch Set: update w/ review feedback Created 4 years 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 unified diff | Download patch
OLDNEW
1 # GN Reference 1 # GN Reference
2 2
3 *This page is automatically generated from* `gn help --markdown all`. 3 *This page is automatically generated from* `gn help --markdown all`.
4 4
5 ## **\--args**: Specifies build arguments overrides. 5 ## **\--args**: Specifies build arguments overrides.
6 6
7 ``` 7 ```
8 See "gn help buildargs" for an overview of how build arguments work. 8 See "gn help buildargs" for an overview of how build arguments work.
9 9
10 Most operations take a build directory. The build arguments are taken from 10 Most operations take a build directory. The build arguments are taken from
(...skipping 1623 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 ``` 1634 ```
1635 Introduces the given arguments into the current scope. If they are not 1635 Introduces the given arguments into the current scope. If they are not
1636 specified on the command line or in a toolchain's arguments, the default 1636 specified on the command line or in a toolchain's arguments, the default
1637 values given in the declare_args block will be used. However, these defaults 1637 values given in the declare_args block will be used. However, these defaults
1638 will not override command-line values. 1638 will not override command-line values.
1639 1639
1640 See also "gn help buildargs" for an overview. 1640 See also "gn help buildargs" for an overview.
1641 1641
1642 The precise behavior of declare args is: 1642 The precise behavior of declare args is:
1643 1643
1644 1. The declare_arg block executes. Any variables in the enclosing scope are 1644 1. The declare_args() block executes. Any variable defined in the enclosing
1645 available for reading. 1645 scope is available for reading, but any variable defined earlier in
1646 the current scope is not (since the overrides haven't been applied yet).
1646 1647
1647 2. At the end of executing the block, any variables set within that scope 1648 2. At the end of executing the block, any variables set within that scope
1648 are saved globally as build arguments, with their current values being 1649 are saved globally as build arguments, with their current values being
1649 saved as the "default value" for that argument. 1650 saved as the "default value" for that argument.
1650 1651
1651 3. User-defined overrides are applied. Anything set in "gn args" now 1652 3. User-defined overrides are applied. Anything set in "gn args" now
1652 overrides any default values. The resulting set of variables is promoted 1653 overrides any default values. The resulting set of variables is promoted
1653 to be readable from the following code in the file. 1654 to be readable from the following code in the file.
1654 1655
1655 This has some ramifications that may not be obvious: 1656 This has some ramifications that may not be obvious:
1656 1657
1657 - You should not perform difficult work inside a declare_args block since 1658 - You should not perform difficult work inside a declare_args block since
1658 this only sets a default value that may be discarded. In particular, 1659 this only sets a default value that may be discarded. In particular,
1659 don't use the result of exec_script() to set the default value. If you 1660 don't use the result of exec_script() to set the default value. If you
1660 want to have a script-defined default, set some default "undefined" value 1661 want to have a script-defined default, set some default "undefined" value
1661 like [], "", or -1, and after the declare_args block, call exec_script if 1662 like [], "", or -1, and after the declare_args block, call exec_script if
1662 the value is unset by the user. 1663 the value is unset by the user.
1663 1664
1664 - Any code inside of the declare_args block will see the default values of 1665 - Because you cannot read the value of a variable defined in the same
1665 previous variables defined in the block rather than the user-overridden 1666 block, if you need to make the default value of one arg depend
1666 value. This can be surprising because you will be used to seeing the 1667 on the possibly-overridden value of another, write two separate
1667 overridden value. If you need to make the default value of one arg 1668 declare_args() blocks:
1668 dependent on the possibly-overridden value of another, write two separate
1669 declare_args blocks:
1670 1669
1671 declare_args() { 1670 declare_args() {
1672 enable_foo = true 1671 enable_foo = true
1673 } 1672 }
1674 declare_args() { 1673 declare_args() {
1675 # Bar defaults to same user-overridden state as foo. 1674 # Bar defaults to same user-overridden state as foo.
1676 enable_bar = enable_foo 1675 enable_bar = enable_foo
1677 } 1676 }
1678 1677
1679 ``` 1678 ```
(...skipping 4965 matching lines...) Expand 10 before | Expand all | Expand 10 after
6645 ** \--root**: Explicitly specify source root. 6644 ** \--root**: Explicitly specify source root.
6646 ** \--runtime-deps-list-file**: Save runtime dependencies for targets in file. 6645 ** \--runtime-deps-list-file**: Save runtime dependencies for targets in file.
6647 ** \--script-executable**: Set the executable used to execute scripts. 6646 ** \--script-executable**: Set the executable used to execute scripts.
6648 ** \--threads**: Specify number of worker threads. 6647 ** \--threads**: Specify number of worker threads.
6649 ** \--time**: Outputs a summary of how long everything took. 6648 ** \--time**: Outputs a summary of how long everything took.
6650 ** \--tracelog**: Writes a Chrome-compatible trace log to the given file. 6649 ** \--tracelog**: Writes a Chrome-compatible trace log to the given file.
6651 ** -v**: Verbose logging. 6650 ** -v**: Verbose logging.
6652 ** \--version**: Prints the GN version number and exits. 6651 ** \--version**: Prints the GN version number and exits.
6653 6652
6654 ``` 6653 ```
OLDNEW
« no previous file with comments | « build/config/ui.gni ('k') | tools/gn/functions.h » ('j') | tools/gn/functions.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698