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

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

Issue 2239943002: Forward bundle product_type to the compile_xcassets tool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add documentation for new substitution and regenerate reference documentation. Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | tools/gn/function_toolchain.cc » ('j') | tools/gn/function_toolchain.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 10 Most operations take a build directory. The build arguments are taken
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 gn desc out/Foo :base_unittests deps --tree 617 gn desc out/Foo :base_unittests deps --tree
618 Shows a dependency tree of the "base_unittests" project in 618 Shows a dependency tree of the "base_unittests" project in
619 the current directory. 619 the current directory.
620 620
621 gn desc out/Debug //base defines --blame 621 gn desc out/Debug //base defines --blame
622 Shows defines set for the //base:base target, annotated by where 622 Shows defines set for the //base:base target, annotated by where
623 each one was set from. 623 each one was set from.
624 624
625 625
626 ``` 626 ```
627 ## **gn format [\--dump-tree] [\--in-place] [\--stdin] BUILD.gn** 627 ## **gn format [\--dump-tree] (\--stdin | <build_file>)**
628 628
629 ``` 629 ```
630 Formats .gn file to a standard format. 630 Formats .gn file to a standard format.
631 631
632 The contents of some lists ('sources', 'deps', etc.) will be sorted to 632 The contents of some lists ('sources', 'deps', etc.) will be sorted to
633 a canonical order. To suppress this, you can add a comment of the form 633 a canonical order. To suppress this, you can add a comment of the form
634 "# NOSORT" immediately preceeding the assignment. e.g. 634 "# NOSORT" immediately preceeding the assignment. e.g.
635 635
636 # NOSORT 636 # NOSORT
637 sources = [ 637 sources = [
638 "z.cc", 638 "z.cc",
639 "a.cc", 639 "a.cc",
640 ] 640 ]
641 641
642 ``` 642 ```
643 643
644 ### **Arguments** 644 ### **Arguments**
645
645 ``` 646 ```
646 --dry-run 647 --dry-run
647 Does not change or output anything, but sets the process exit code 648 Does not change or output anything, but sets the process exit code
648 based on whether output would be different than what's on disk. 649 based on whether output would be different than what's on disk.
649 This is useful for presubmit/lint-type checks. 650 This is useful for presubmit/lint-type checks.
650 - Exit code 0: successful format, matches on disk. 651 - Exit code 0: successful format, matches on disk.
651 - Exit code 1: general failure (parse error, etc.) 652 - Exit code 1: general failure (parse error, etc.)
652 - Exit code 2: successful format, but differs from on disk. 653 - Exit code 2: successful format, but differs from on disk.
653 654
654 --dump-tree 655 --dump-tree
655 For debugging only, dumps the parse tree. 656 For debugging, dumps the parse tree to stdout and does not update
656 657 the file or print formatted output.
657 --in-place
658 Instead of writing the formatted file to stdout, replace the input
659 file with the formatted output. If no reformatting is required,
660 the input file will not be touched, and nothing printed.
661 658
662 --stdin 659 --stdin
663 Read input from stdin (and write to stdout). Not compatible with 660 Read input from stdin and write to stdout rather than update
664 --in-place of course. 661 a file in-place.
665 662
666 ``` 663 ```
667 664
668 ### **Examples** 665 ### **Examples**
669 ``` 666 ```
670 gn format //some/BUILD.gn 667 gn format //some/BUILD.gn
671 gn format some\BUILD.gn 668 gn format some\BUILD.gn
672 gn format /abspath/some/BUILD.gn 669 gn format /abspath/some/BUILD.gn
673 gn format --stdin 670 gn format --stdin
674 671
(...skipping 1881 matching lines...) Expand 10 before | Expand all | Expand 10 after
2556 configs -= "//tools/mything:settings" 2553 configs -= "//tools/mything:settings"
2557 } 2554 }
2558 2555
2559 2556
2560 ``` 2557 ```
2561 ## **set_sources_assignment_filter**: Set a pattern to filter source files. 2558 ## **set_sources_assignment_filter**: Set a pattern to filter source files.
2562 2559
2563 ``` 2560 ```
2564 The sources assignment filter is a list of patterns that remove files 2561 The sources assignment filter is a list of patterns that remove files
2565 from the list implicitly whenever the "sources" variable is 2562 from the list implicitly whenever the "sources" variable is
2566 assigned to. This is intended to be used to globally filter out files 2563 assigned to. This will do nothing for non-lists.
2567 with platform-specific naming schemes when they don't apply, for 2564
2568 example, you may want to filter out all "*_win.cc" files on non- 2565 This is intended to be used to globally filter out files with
2569 Windows platforms. 2566 platform-specific naming schemes when they don't apply, for example
2567 you may want to filter out all "*_win.cc" files on non-Windows
2568 platforms.
2570 2569
2571 Typically this will be called once in the master build config script 2570 Typically this will be called once in the master build config script
2572 to set up the filter for the current platform. Subsequent calls will 2571 to set up the filter for the current platform. Subsequent calls will
2573 overwrite the previous values. 2572 overwrite the previous values.
2574 2573
2575 If you want to bypass the filter and add a file even if it might 2574 If you want to bypass the filter and add a file even if it might
2576 be filtered out, call set_sources_assignment_filter([]) to clear the 2575 be filtered out, call set_sources_assignment_filter([]) to clear the
2577 list of filters. This will apply until the current scope exits 2576 list of filters. This will apply until the current scope exits
2578 2577
2579 ``` 2578 ```
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
3413 3412
3414 ``` 3413 ```
3415 3414
3416 ### **Functions and variables** 3415 ### **Functions and variables**
3417 3416
3418 ``` 3417 ```
3419 tool() 3418 tool()
3420 The tool() function call specifies the commands commands to run for 3419 The tool() function call specifies the commands commands to run for
3421 a given step. See "gn help tool". 3420 a given step. See "gn help tool".
3422 3421
3423 toolchain_args() 3422 toolchain_args
3424 List of arguments to pass to the toolchain when invoking this 3423 Overrides for build arguments to pass to the toolchain when invoking
3425 toolchain. This applies only to non-default toolchains. See 3424 it. This is a variable of type "scope" where the variable names
3426 "gn help toolchain_args" for more. 3425 correspond to varibles in declare_args() blocks.
3426
3427 When you specify a target using an alternate toolchain, the master
3428 build configuration file is re-interpreted in the context of that
3429 toolchain (see "gn help toolchain"). The toolchain_args allows you
3430 to control the arguments passed into this alternate invocation of
3431 the build.
3432
3433 Any default system arguments or arguments passed in via "gn args"
3434 will also be passed to the alternate invocation unless explicitly
3435 overridden by toolchain_args.
3436
3437 The toolchain_args will be ignored when the toolchain being defined
3438 is the default. In this case, it's expected you want the default
3439 argument values.
3440
3441 See also "gn help buildargs" for an overview of these arguments.
3427 3442
3428 deps 3443 deps
3429 Dependencies of this toolchain. These dependencies will be resolved 3444 Dependencies of this toolchain. These dependencies will be resolved
3430 before any target in the toolchain is compiled. To avoid circular 3445 before any target in the toolchain is compiled. To avoid circular
3431 dependencies these must be targets defined in another toolchain. 3446 dependencies these must be targets defined in another toolchain.
3432 3447
3433 This is expressed as a list of targets, and generally these targets 3448 This is expressed as a list of targets, and generally these targets
3434 will always specify a toolchain: 3449 will always specify a toolchain:
3435 deps = [ "//foo/bar:baz(//build/toolchain:bootstrap)" ] 3450 deps = [ "//foo/bar:baz(//build/toolchain:bootstrap)" ]
3436 3451
(...skipping 15 matching lines...) Expand all
3452 data_deps = [ "//plugins:mine(//toolchains:plugin_toolchain)" ] 3467 data_deps = [ "//plugins:mine(//toolchains:plugin_toolchain)" ]
3453 The string "//build/toolchains:plugin_toolchain" is a label that 3468 The string "//build/toolchains:plugin_toolchain" is a label that
3454 identifies the toolchain declaration for compiling the sources. 3469 identifies the toolchain declaration for compiling the sources.
3455 3470
3456 To load a file in an alternate toolchain, GN does the following: 3471 To load a file in an alternate toolchain, GN does the following:
3457 3472
3458 1. Loads the file with the toolchain definition in it (as determined 3473 1. Loads the file with the toolchain definition in it (as determined
3459 by the toolchain label). 3474 by the toolchain label).
3460 2. Re-runs the master build configuration file, applying the 3475 2. Re-runs the master build configuration file, applying the
3461 arguments specified by the toolchain_args section of the toolchain 3476 arguments specified by the toolchain_args section of the toolchain
3462 definition (see "gn help toolchain_args"). 3477 definition.
3463 3. Loads the destination build file in the context of the 3478 3. Loads the destination build file in the context of the
3464 configuration file in the previous step. 3479 configuration file in the previous step.
3465 3480
3466 ``` 3481 ```
3467 3482
3468 ### **Example**: 3483 ### **Example**
3484
3469 ``` 3485 ```
3470 toolchain("plugin_toolchain") { 3486 toolchain("plugin_toolchain") {
3471 tool("cc") { 3487 tool("cc") {
3472 command = "gcc {{source}}" 3488 command = "gcc {{source}}"
3473 ... 3489 ...
3474 } 3490 }
3475 3491
3476 toolchain_args() { 3492 toolchain_args = {
3477 is_plugin = true 3493 is_plugin = true
3478 is_32bit = true 3494 is_32bit = true
3479 is_64bit = false 3495 is_64bit = false
3480 } 3496 }
3481 } 3497 }
3482 3498
3483 3499
3484 ``` 3500 ```
3485 ## **toolchain_args**: Set build arguments for toolchain build setup. 3501 ## **toolchain_args**: Set build arguments for toolchain build setup.
3486 3502
3487 ``` 3503 ```
3488 Used inside a toolchain definition to pass arguments to an alternate 3504 DEPRECATED. Instead use:
3489 toolchain's invocation of the build. 3505 toolchain_args = { ... }
3490 3506
3491 When you specify a target using an alternate toolchain, the master 3507 See "gn help toolchain" for documentation.
3492 build configuration file is re-interpreted in the context of that
3493 toolchain (see "gn help toolchain"). The toolchain_args function
3494 allows you to control the arguments passed into this alternate
3495 invocation of the build.
3496
3497 Any default system arguments or arguments passed in on the command-
3498 line will also be passed to the alternate invocation unless explicitly
3499 overridden by toolchain_args.
3500
3501 The toolchain_args will be ignored when the toolchain being defined
3502 is the default. In this case, it's expected you want the default
3503 argument values.
3504
3505 See also "gn help buildargs" for an overview of these arguments.
3506
3507 ```
3508
3509 ### **Example**:
3510 ```
3511 toolchain("my_weird_toolchain") {
3512 ...
3513 toolchain_args() {
3514 # Override the system values for a generic Posix system.
3515 is_win = false
3516 is_posix = true
3517
3518 # Pass this new value for specific setup for my toolchain.
3519 is_my_weird_system = true
3520 }
3521 }
3522 3508
3523 3509
3524 ``` 3510 ```
3525 ## **write_file**: Write a file to disk. 3511 ## **write_file**: Write a file to disk.
3526 3512
3527 ``` 3513 ```
3528 write_file(filename, data) 3514 write_file(filename, data)
3529 3515
3530 If data is a list, the list will be written one-item-per-line with no 3516 If data is a list, the list will be written one-item-per-line with no
3531 quoting or brackets. 3517 quoting or brackets.
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
4168 deps = [ "//foo:bar" ] 4154 deps = [ "//foo:bar" ]
4169 ... 4155 ...
4170 assert_no_deps = [ 4156 assert_no_deps = [
4171 "//evil/*", # Don't link any code from the evil directory. 4157 "//evil/*", # Don't link any code from the evil directory.
4172 "//foo:test_support", # This target is also disallowed. 4158 "//foo:test_support", # This target is also disallowed.
4173 ] 4159 ]
4174 } 4160 }
4175 4161
4176 4162
4177 ``` 4163 ```
4164 ## **bundle_deps_filter**: [label list] A list of labels that are filtered out.
4165
4166 ```
4167 A list of target labels.
4168
4169 This list contains target label patterns that should be filtered out
4170 when creating the bundle. Any target matching one of those label will
4171 be removed from the dependencies of the create_bundle target.
4172
4173 This is mostly useful when creating application extension bundle as
4174 the application extension has access to runtime resources from the
4175 application bundle and thus do not require a second copy.
4176
4177 See "gn help create_bundle" for more information.
4178
4179 ```
4180
4181 ### **Example**
4182
4183 ```
4184 create_bundle("today_extension") {
4185 deps = [
4186 "//base"
4187 ]
4188 bundle_root_dir = "$root_out_dir/today_extension.appex"
4189 bundle_deps_filter = [
4190 # The extension uses //base but does not use any function calling
4191 # into third_party/icu and thus does not need the icudtl.dat file.
4192 "//third_party/icu:icudata",
4193 ]
4194 }
4195
4196
4197 ```
4178 ## **bundle_executable_dir**: Expansion of {{bundle_executable_dir}} in create_b undle. 4198 ## **bundle_executable_dir**: Expansion of {{bundle_executable_dir}} in create_b undle.
4179 4199
4180 ``` 4200 ```
4181 A string corresponding to a path in $root_build_dir. 4201 A string corresponding to a path in $root_build_dir.
4182 4202
4183 This string is used by the "create_bundle" target to expand the 4203 This string is used by the "create_bundle" target to expand the
4184 {{bundle_executable_dir}} of the "bundle_data" target it depends on. 4204 {{bundle_executable_dir}} of the "bundle_data" target it depends on.
4185 This must correspond to a path under "bundle_root_dir". 4205 This must correspond to a path under "bundle_root_dir".
4186 4206
4187 See "gn help bundle_root_dir" for examples. 4207 See "gn help bundle_root_dir" for examples.
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
4823 propagated across all types of targets, and public_configs 4843 propagated across all types of targets, and public_configs
4824 are always propagated across public deps of all types of targets. 4844 are always propagated across public deps of all types of targets.
4825 4845
4826 Data dependencies are propagated differently. See 4846 Data dependencies are propagated differently. See
4827 "gn help data_deps" and "gn help runtime_deps". 4847 "gn help data_deps" and "gn help runtime_deps".
4828 4848
4829 See also "public_deps". 4849 See also "public_deps".
4830 4850
4831 4851
4832 ``` 4852 ```
4833 ## **bundle_deps_filter**: [label list] A list of labels that are filtered out.
4834
4835 ```
4836 A list of target labels.
4837
4838 This list contains target label patterns that should be filtered out
4839 when creating the bundle. Any target matching one of those label will
4840 be removed from the dependencies of the create_bundle target.
4841
4842 This is mostly useful when creating application extension bundle as
4843 the application extension has access to runtime resources from the
4844 application bundle and thus do not require a second copy.
4845
4846 See "gn help create_bundle" for more information.
4847
4848 ```
4849
4850 ### **Example**
4851
4852 ```
4853 create_bundle("today_extension") {
4854 deps = [
4855 "//base"
4856 ]
4857 bundle_root_dir = "$root_out_dir/today_extension.appex"
4858 bundle_deps_filter = [
4859 # The extension uses //base but does not use any function calling
4860 # into third_party/icu and thus does not need the icudtl.dat file.
4861 "//third_party/icu:icudata",
4862 ]
4863 }
4864
4865
4866 ```
4867 ## **include_dirs**: Additional include directories. 4853 ## **include_dirs**: Additional include directories.
4868 4854
4869 ``` 4855 ```
4870 A list of source directories. 4856 A list of source directories.
4871 4857
4872 The directories in this list will be added to the include path for 4858 The directories in this list will be added to the include path for
4873 the files in the affected target. 4859 the files in the affected target.
4874 4860
4875 ``` 4861 ```
4876 4862
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after
5734 If specified, arguments from the --args command line flag are used. If 5720 If specified, arguments from the --args command line flag are used. If
5735 that flag is not specified, args from previous builds in the build 5721 that flag is not specified, args from previous builds in the build
5736 directory will be used (this is in the file args.gn in the build 5722 directory will be used (this is in the file args.gn in the build
5737 directory). 5723 directory).
5738 5724
5739 Last, for targets being compiled with a non-default toolchain, the 5725 Last, for targets being compiled with a non-default toolchain, the
5740 toolchain overrides are applied. These are specified in the 5726 toolchain overrides are applied. These are specified in the
5741 toolchain_args section of a toolchain definition. The use-case for 5727 toolchain_args section of a toolchain definition. The use-case for
5742 this is that a toolchain may be building code for a different 5728 this is that a toolchain may be building code for a different
5743 platform, and that it may want to always specify Posix, for example. 5729 platform, and that it may want to always specify Posix, for example.
5744 See "gn help toolchain_args" for more. 5730 See "gn help toolchain" for more.
5745 5731
5746 If you specify an override for a build argument that never appears in 5732 If you specify an override for a build argument that never appears in
5747 a "declare_args" call, a nonfatal error will be displayed. 5733 a "declare_args" call, a nonfatal error will be displayed.
5748 5734
5749 ``` 5735 ```
5750 5736
5751 ### **Examples** 5737 ### **Examples**
5752 5738
5753 ``` 5739 ```
5754 gn args out/FooBar 5740 gn args out/FooBar
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
5864 "//doom_melon/*", # Check everything in this subtree. 5850 "//doom_melon/*", # Check everything in this subtree.
5865 "//tools:mind_controlling_ant", # Check this specific target. 5851 "//tools:mind_controlling_ant", # Check this specific target.
5866 ] 5852 ]
5867 5853
5868 root = "//:root" 5854 root = "//:root"
5869 5855
5870 secondary_source = "//build/config/temporary_buildfiles/" 5856 secondary_source = "//build/config/temporary_buildfiles/"
5871 5857
5872 5858
5873 ``` 5859 ```
5874 ## **GN build language grammar** 5860 ## **Language and grammar for GN build files**
5875 5861
5876 ### **Tokens** 5862 ### **Tokens**
5877 5863
5878 ``` 5864 ```
5879 GN build files are read as sequences of tokens. While splitting the 5865 GN build files are read as sequences of tokens. While splitting the
5880 file into tokens, the next token is the longest sequence of characters 5866 file into tokens, the next token is the longest sequence of characters
5881 that form a valid token. 5867 that form a valid token.
5882 5868
5883 ``` 5869 ```
5884 5870
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
5944 5930
5945 \" U+0022 quotation mark 5931 \" U+0022 quotation mark
5946 \$ U+0024 dollar sign 5932 \$ U+0024 dollar sign
5947 \\ U+005C backslash 5933 \\ U+005C backslash
5948 5934
5949 All other backslashes represent themselves. 5935 All other backslashes represent themselves.
5950 5936
5951 To insert an arbitrary byte value, use $0xFF. For example, to 5937 To insert an arbitrary byte value, use $0xFF. For example, to
5952 insert a newline character: "Line one$0x0ALine two". 5938 insert a newline character: "Line one$0x0ALine two".
5953 5939
5940 An expansion will evaluate the variable following the '$' and insert
5941 a stringified version of it into the result. For example, to concat
5942 two path components with a slash separating them:
5943 "$var_one/$var_two"
5944 Use the "${var_one}" format to be explicitly deliniate the variable
5945 for otherwise-ambiguous cases.
5946
5954 ``` 5947 ```
5955 5948
5956 ### **Punctuation** 5949 ### **Punctuation**
5957 5950
5958 ``` 5951 ```
5959 The following character sequences represent punctuation: 5952 The following character sequences represent punctuation:
5960 5953
5961 + += == != ( ) 5954 + += == != ( )
5962 - -= < <= [ ] 5955 - -= < <= [ ]
5963 ! = > >= { } 5956 ! = > >= { }
5964 && || . , 5957 && || . ,
5965 5958
5966 ``` 5959 ```
5967 5960
5968 ### **Grammar** 5961 ### **Grammar**
5969 5962
5970 ``` 5963 ```
5971 The input tokens form a syntax tree following a context-free grammar: 5964 The input tokens form a syntax tree following a context-free grammar:
5972 5965
5973 File = StatementList . 5966 File = StatementList .
5974 5967
5975 Statement = Assignment | Call | Condition . 5968 Statement = Assignment | Call | Condition .
5976 Assignment = identifier AssignOp Expr . 5969 LValue = identifier | ArrayAccess | ScopeAccess .
5970 Assignment = LValue AssignOp Expr .
5977 Call = identifier "(" [ ExprList ] ")" [ Block ] . 5971 Call = identifier "(" [ ExprList ] ")" [ Block ] .
5978 Condition = "if" "(" Expr ")" Block 5972 Condition = "if" "(" Expr ")" Block
5979 [ "else" ( Condition | Block ) ] . 5973 [ "else" ( Condition | Block ) ] .
5980 Block = "{" StatementList "}" . 5974 Block = "{" StatementList "}" .
5981 StatementList = { Statement } . 5975 StatementList = { Statement } .
5982 5976
5983 ArrayAccess = identifier "[" { identifier | integer } "]" . 5977 ArrayAccess = identifier "[" Expr "]" .
5984 ScopeAccess = identifier "." identifier . 5978 ScopeAccess = identifier "." identifier .
5985 Expr = UnaryExpr | Expr BinaryOp Expr . 5979 Expr = UnaryExpr | Expr BinaryOp Expr .
5986 UnaryExpr = PrimaryExpr | UnaryOp UnaryExpr . 5980 UnaryExpr = PrimaryExpr | UnaryOp UnaryExpr .
5987 PrimaryExpr = identifier | integer | string | Call 5981 PrimaryExpr = identifier | integer | string | Call
5988 | ArrayAccess | ScopeAccess 5982 | ArrayAccess | ScopeAccess | Block
5989 | "(" Expr ")" 5983 | "(" Expr ")"
5990 | "[" [ ExprList [ "," ] ] "]" . 5984 | "[" [ ExprList [ "," ] ] "]" .
5991 ExprList = Expr { "," Expr } . 5985 ExprList = Expr { "," Expr } .
5992 5986
5993 AssignOp = "=" | "+=" | "-=" . 5987 AssignOp = "=" | "+=" | "-=" .
5994 UnaryOp = "!" . 5988 UnaryOp = "!" .
5995 BinaryOp = "+" | "-" // highest priority 5989 BinaryOp = "+" | "-" // highest priority
5996 | "<" | "<=" | ">" | ">=" 5990 | "<" | "<=" | ">" | ">="
5997 | "==" | "!=" 5991 | "==" | "!="
5998 | "&&" 5992 | "&&"
5999 | "||" . // lowest priority 5993 | "||" . // lowest priority
6000 5994
6001 All binary operators are left-associative. 5995 All binary operators are left-associative.
6002 5996
5997 ```
5998
5999 ### **Types**
6000
6001 ```
6002 The GN language is dynamically typed. The following types are used:
6003
6004 - Boolean: Uses the keywords "true" and "false". There is no
6005 implicit conversion between booleans and integers.
6006
6007 - Integers: All numbers in GN are signed 64-bit integers.
6008
6009 - Strings: Strings are 8-bit with no enforced encoding. When a string
6010 is used to interact with other systems with particular encodings
6011 (like the Windows and Mac filesystems) it is assumed to be UTF-8.
6012 See "String literals" above for more.
6013
6014 - Lists: Lists are arbitrary-length ordered lists of values. See
6015 "Lists" below for more.
6016
6017 - Scopes: Scopes are like dictionaries that use variable names for
6018 keys. See "Scopes" below for more.
6019
6020 ```
6021
6022 ### **Lists**
6023
6024 ```
6025 Lists are created with [] and using commas to separate items:
6026
6027 mylist = [ 0, 1, 2, "some string" ]
6028
6029 A comma after the last item is optional. Lists are dereferenced using
6030 0-based indexing:
6031
6032 mylist[0] += 1
6033 var = mylist[2]
6034
6035 Lists can be concatenated using the '+' and '+=' operators. Bare
6036 values can not be concatenated with lists, to add a single item,
6037 it must be put into a list of length one.
6038
6039 Items can be removed from lists using the '-' and '-=' operators.
6040 This will remove all occurrences of every item in the right-hand list
6041 from the left-hand list. It is an error to remove an item not in the
6042 list. This is to prevent common typos and to detect dead code that
6043 is removing things that no longer apply.
6044
6045 It is an error to use '=' to replace a nonempty list with another
6046 nonempty list. This is to prevent accidentally overwriting data
6047 when in most cases '+=' was intended. To overwrite a list on purpose,
6048 first assign it to the empty list:
6049
6050 mylist = []
6051 mylist = otherlist
6052
6053 When assigning to a list named 'sources' using '=' or '+=', list
6054 items may be automatically filtered out.
6055 See "gn help set_sources_assignment_filter" for more.
6056
6057 ```
6058
6059 ### **Scopes**
6060
6061 ```
6062 All execution happens in the context of a scope which holds the
6063 current state (like variables). With the exception of loops and
6064 conditions, '{' introduces a new scope that has a parent reference to
6065 the old scope.
6066
6067 Variable reads recursively search all nested scopes until the
6068 variable is found or there are no more scopes. Variable writes always
6069 go into the current scope. This means that after the closing '}'
6070 (again excepting loops and conditions), all local variables will be
6071 restored to the previous values. This also means that "foo = foo"
6072 can do useful work by copying a variable into the current scope that
6073 was defined in a containing scope.
6074
6075 Scopes can also be assigned to variables. Such scopes can be created
6076 by functions like exec_script, when invoking a template (the template
6077 code refers to the variables set by the invoking code by the
6078 implicitly-created "invoker" scope), or explicitly like:
6079
6080 empty_scope = {}
6081 myvalues = {
6082 foo = 21
6083 bar = "something"
6084 }
6085
6086 Inside such a scope definition can be any GN code including
6087 conditionals and function calls. After the close of the scope, it will
6088 contain all variables explicitly set by the code contained inside it.
6089 After this, the values can be read, modified, or added to:
6090
6091 myvalues.foo += 2
6092 empty_scope.new_thing = [ 1, 2, 3 ]
6093
6003 6094
6004 ``` 6095 ```
6005 ## **input_conversion**: Specifies how to transform input to a variable. 6096 ## **input_conversion**: Specifies how to transform input to a variable.
6006 6097
6007 ``` 6098 ```
6008 input_conversion is an argument to read_file and exec_script that 6099 input_conversion is an argument to read_file and exec_script that
6009 specifies how the result of the read operation should be converted 6100 specifies how the result of the read operation should be converted
6010 into a variable. 6101 into a variable.
6011 6102
6012 "" (the default) 6103 "" (the default)
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
6355 ** \--root**: Explicitly specify source root. 6446 ** \--root**: Explicitly specify source root.
6356 ** \--runtime-deps-list-file**: Save runtime dependencies for targets in file. 6447 ** \--runtime-deps-list-file**: Save runtime dependencies for targets in file.
6357 ** \--script-executable**: Set the executable used to execute scripts. 6448 ** \--script-executable**: Set the executable used to execute scripts.
6358 ** \--threads**: Specify number of worker threads. 6449 ** \--threads**: Specify number of worker threads.
6359 ** \--time**: Outputs a summary of how long everything took. 6450 ** \--time**: Outputs a summary of how long everything took.
6360 ** \--tracelog**: Writes a Chrome-compatible trace log to the given file. 6451 ** \--tracelog**: Writes a Chrome-compatible trace log to the given file.
6361 ** -v**: Verbose logging. 6452 ** -v**: Verbose logging.
6362 ** \--version**: Prints the GN version number and exits. 6453 ** \--version**: Prints the GN version number and exits.
6363 6454
6364 ``` 6455 ```
OLDNEW
« no previous file with comments | « no previous file | tools/gn/function_toolchain.cc » ('j') | tools/gn/function_toolchain.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698