OLD | NEW |
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 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 Lists all variants of the target //base:base (it may be referenced | 857 Lists all variants of the target //base:base (it may be referenced |
858 in multiple toolchains). | 858 in multiple toolchains). |
859 | 859 |
860 | 860 |
861 ``` | 861 ``` |
862 ## **gn path <out_dir> <target_one> <target_two>** | 862 ## **gn path <out_dir> <target_one> <target_two>** |
863 | 863 |
864 ``` | 864 ``` |
865 Finds paths of dependencies between two targets. Each unique path | 865 Finds paths of dependencies between two targets. Each unique path |
866 will be printed in one group, and groups will be separate by newlines. | 866 will be printed in one group, and groups will be separate by newlines. |
867 The two targets can appear in either order: paths will be found going | 867 The two targets can appear in either order (paths will be found going |
868 in either direction. | 868 in either direction). |
869 | 869 |
870 By default, a single path will be printed. If there is a path with | 870 By default, a single path will be printed. If there is a path with |
871 only public dependencies, the shortest public path will be printed. | 871 only public dependencies, the shortest public path will be printed. |
872 Otherwise, the shortest path using either public or private | 872 Otherwise, the shortest path using either public or private |
873 dependencies will be printed. If --with-data is specified, data deps | 873 dependencies will be printed. If --with-data is specified, data deps |
874 will also be considered. If there are multiple shortest paths, an | 874 will also be considered. If there are multiple shortest paths, an |
875 arbitrary one will be selected. | 875 arbitrary one will be selected. |
876 | 876 |
877 ``` | 877 ``` |
878 | 878 |
| 879 ### **Interesting paths** |
| 880 |
| 881 ``` |
| 882 In a large project, there can be 100's of millions of unique paths |
| 883 between a very high level and a common low-level target. To make the |
| 884 output more useful (and terminate in a reasonable time), GN will not |
| 885 revisit sub-paths previously known to lead to the target. |
| 886 |
| 887 ``` |
| 888 |
879 ### **Options** | 889 ### **Options** |
880 | 890 |
881 ``` | 891 ``` |
882 --all | 892 --all |
883 Prints all paths found rather than just the first one. Public paths | 893 Prints all "interesting" paths found rather than just the first |
884 will be printed first in order of increasing length, followed by | 894 one. Public paths will be printed first in order of increasing |
885 non-public paths in order of increasing length. | 895 length, followed by non-public paths in order of increasing length. |
886 | 896 |
887 --public | 897 --public |
888 Considers only public paths. Can't be used with --with-data. | 898 Considers only public paths. Can't be used with --with-data. |
889 | 899 |
890 --with-data | 900 --with-data |
891 Additionally follows data deps. Without this flag, only public and | 901 Additionally follows data deps. Without this flag, only public and |
892 private linked deps will be followed. Can't be used with --public. | 902 private linked deps will be followed. Can't be used with --public. |
893 | 903 |
894 ``` | 904 ``` |
895 | 905 |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1419 put it behind iOS/Mac conditionals. | 1429 put it behind iOS/Mac conditionals. |
1420 | 1430 |
1421 If a create_bundle is specified as a data_deps for another target, the | 1431 If a create_bundle is specified as a data_deps for another target, the |
1422 bundle is considered a leaf, and its public and private dependencies | 1432 bundle is considered a leaf, and its public and private dependencies |
1423 will not contribute to any data or data_deps. Required runtime | 1433 will not contribute to any data or data_deps. Required runtime |
1424 dependencies should be placed in the bundle. A create_bundle can | 1434 dependencies should be placed in the bundle. A create_bundle can |
1425 declare its own explicit data and data_deps, however. | 1435 declare its own explicit data and data_deps, however. |
1426 | 1436 |
1427 ``` | 1437 ``` |
1428 | 1438 |
| 1439 ### **Code signing** |
| 1440 |
| 1441 ``` |
| 1442 Some bundle needs to be code signed as part of the build (on iOS all |
| 1443 application needs to be code signed to run on a device). The code |
| 1444 signature can be configured via the code_signing_script variable. |
| 1445 |
| 1446 If set, code_signing_script is the path of a script that invoked after |
| 1447 all files have been moved into the bundle. The script must not change |
| 1448 any file in the bundle, but may add new files. |
| 1449 |
| 1450 If code_signing_script is defined, then code_signing_outputs must also |
| 1451 be defined and non-empty to inform when the script needs to be re-run. |
| 1452 The code_signing_args will be passed as is to the script (so path have |
| 1453 to be rebased) and additional inputs may be listed with the variable |
| 1454 code_signing_sources. |
| 1455 |
| 1456 ``` |
| 1457 |
1429 ### **Variables** | 1458 ### **Variables** |
1430 | 1459 |
1431 ``` | 1460 ``` |
1432 bundle_root_dir*, bundle_resources_dir*, bundle_executable_dir*, | 1461 bundle_root_dir*, bundle_resources_dir*, bundle_executable_dir*, |
1433 bundle_plugins_dir*, deps, data_deps, public_deps, visibility, | 1462 bundle_plugins_dir*, deps, data_deps, public_deps, visibility, |
1434 product_type | 1463 product_type, code_signing_args, code_signing_script, |
| 1464 code_signing_sources, code_signing_outputs |
1435 * = required | 1465 * = required |
1436 | 1466 |
1437 ``` | 1467 ``` |
1438 | 1468 |
1439 ### **Example** | 1469 ### **Example** |
1440 | 1470 |
1441 ``` | 1471 ``` |
1442 # Defines a template to create an application. On most platform, this | 1472 # Defines a template to create an application. On most platform, this |
1443 # is just an alias for an "executable" target, but on iOS/OS X, it | 1473 # is just an alias for an "executable" target, but on iOS/OS X, it |
1444 # builds an application bundle. | 1474 # builds an application bundle. |
(...skipping 15 matching lines...) Expand all Loading... |
1460 } | 1490 } |
1461 | 1491 |
1462 bundle_data("${app_name}_bundle_info_plist") { | 1492 bundle_data("${app_name}_bundle_info_plist") { |
1463 deps = [ ":${app_name}_generate_info_plist" ] | 1493 deps = [ ":${app_name}_generate_info_plist" ] |
1464 sources = [ "$gen_path/Info.plist" ] | 1494 sources = [ "$gen_path/Info.plist" ] |
1465 outputs = [ "{{bundle_root_dir}}/Info.plist" ] | 1495 outputs = [ "{{bundle_root_dir}}/Info.plist" ] |
1466 } | 1496 } |
1467 | 1497 |
1468 executable("${app_name}_generate_executable") { | 1498 executable("${app_name}_generate_executable") { |
1469 forward_variables_from(invoker, "*", [ | 1499 forward_variables_from(invoker, "*", [ |
1470 "output_name", | 1500 "output_name", |
1471 "visibility", | 1501 "visibility", |
1472 ]) | 1502 ]) |
1473 output_name = | 1503 output_name = |
1474 rebase_path("$gen_path/$app_name", root_build_dir) | 1504 rebase_path("$gen_path/$app_name", root_build_dir) |
1475 } | 1505 } |
1476 | 1506 |
1477 bundle_data("${app_name}_bundle_executable") { | 1507 code_signing = |
1478 deps = [ ":${app_name}_generate_executable" ] | 1508 defined(invoker.code_signing) && invoker.code_signing |
1479 sources = [ "$gen_path/$app_name" ] | 1509 |
1480 outputs = [ "{{bundle_executable_dir}}/$app_name" ] | 1510 if (is_ios && !code_signing) { |
| 1511 bundle_data("${app_name}_bundle_executable") { |
| 1512 deps = [ ":${app_name}_generate_executable" ] |
| 1513 sources = [ "$gen_path/$app_name" ] |
| 1514 outputs = [ "{{bundle_executable_dir}}/$app_name" ] |
| 1515 } |
1481 } | 1516 } |
1482 | 1517 |
1483 create_bundle("${app_name}.app") { | 1518 create_bundle("${app_name}.app") { |
1484 product_type = "com.apple.product-type.application" | 1519 product_type = "com.apple.product-type.application" |
1485 deps = [ | |
1486 ":${app_name}_bundle_executable", | |
1487 ":${app_name}_bundle_info_plist", | |
1488 ] | |
1489 if (is_ios) { | 1520 if (is_ios) { |
1490 bundle_root_dir = "${root_build_dir}/$target_name" | 1521 bundle_root_dir = "${root_build_dir}/$target_name" |
1491 bundle_resources_dir = bundle_root_dir | 1522 bundle_resources_dir = bundle_root_dir |
1492 bundle_executable_dir = bundle_root_dir | 1523 bundle_executable_dir = bundle_root_dir |
1493 bundle_plugins_dir = bundle_root_dir + "/Plugins" | 1524 bundle_plugins_dir = bundle_root_dir + "/Plugins" |
1494 } else { | 1525 } else { |
1495 bundle_root_dir = "${root_build_dir}/target_name/Contents" | 1526 bundle_root_dir = "${root_build_dir}/target_name/Contents" |
1496 bundle_resources_dir = bundle_root_dir + "/Resources" | 1527 bundle_resources_dir = bundle_root_dir + "/Resources" |
1497 bundle_executable_dir = bundle_root_dir + "/MacOS" | 1528 bundle_executable_dir = bundle_root_dir + "/MacOS" |
1498 bundle_plugins_dir = bundle_root_dir + "/Plugins" | 1529 bundle_plugins_dir = bundle_root_dir + "/Plugins" |
1499 } | 1530 } |
1500 } | 1531 deps = [ ":${app_name}_bundle_info_plist" ] |
1501 | 1532 if (is_ios && code_signing) { |
1502 group(target_name) { | 1533 deps += [ ":${app_name}_generate_executable" ] |
1503 forward_variables_from(invoker, ["visibility"]) | 1534 code_signing_script = "//build/config/ios/codesign.py" |
1504 deps = [ ":${app_name}.app" ] | 1535 code_signing_sources = [ |
| 1536 invoker.entitlements_path, |
| 1537 "$target_gen_dir/$app_name", |
| 1538 ] |
| 1539 code_signing_outputs = [ |
| 1540 "$bundle_root_dir/$app_name", |
| 1541 "$bundle_root_dir/_CodeSignature/CodeResources", |
| 1542 "$bundle_root_dir/embedded.mobileprovision", |
| 1543 "$target_gen_dir/$app_name.xcent", |
| 1544 ] |
| 1545 code_signing_args = [ |
| 1546 "-i=" + ios_code_signing_identity, |
| 1547 "-b=" + rebase_path( |
| 1548 "$target_gen_dir/$app_name", root_build_dir), |
| 1549 "-e=" + rebase_path( |
| 1550 invoker.entitlements_path, root_build_dir), |
| 1551 "-e=" + rebase_path( |
| 1552 "$target_gen_dir/$app_name.xcent", root_build_dir), |
| 1553 rebase_path(bundle_root_dir, root_build_dir), |
| 1554 ] |
| 1555 } else { |
| 1556 deps += [ ":${app_name}_bundle_executable" ] |
| 1557 } |
1505 } | 1558 } |
1506 } | 1559 } |
1507 } | 1560 } |
1508 | 1561 |
1509 | 1562 |
1510 ``` | 1563 ``` |
1511 ## **declare_args**: Declare build arguments. | 1564 ## **declare_args**: Declare build arguments. |
1512 | 1565 |
1513 ``` | 1566 ``` |
1514 Introduces the given arguments into the current scope. If they are | 1567 Introduces the given arguments into the current scope. If they are |
(...skipping 2089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3604 args = [ "-o", rebase_path(root_out_dir, root_build_dir) ] | 3657 args = [ "-o", rebase_path(root_out_dir, root_build_dir) ] |
3605 } | 3658 } |
3606 | 3659 |
3607 | 3660 |
3608 ``` | 3661 ``` |
3609 ## **target_cpu**: The desired cpu architecture for the build. | 3662 ## **target_cpu**: The desired cpu architecture for the build. |
3610 | 3663 |
3611 ``` | 3664 ``` |
3612 This value should be used to indicate the desired architecture for | 3665 This value should be used to indicate the desired architecture for |
3613 the primary objects of the build. It will match the cpu architecture | 3666 the primary objects of the build. It will match the cpu architecture |
3614 of the default toolchain. | 3667 of the default toolchain, but not necessarily the current toolchain. |
3615 | 3668 |
3616 In many cases, this is the same as "host_cpu", but in the case | 3669 In many cases, this is the same as "host_cpu", but in the case |
3617 of cross-compiles, this can be set to something different. This | 3670 of cross-compiles, this can be set to something different. This |
3618 value is different from "current_cpu" in that it can be referenced | 3671 value is different from "current_cpu" in that it does not change |
3619 from inside any toolchain. This value can also be ignored if it is | 3672 based on the current toolchain. When writing rules, "current_cpu" |
3620 not needed or meaningful for a project. | 3673 should be used rather than "target_cpu" most of the time. |
3621 | 3674 |
3622 This value is not used internally by GN for any purpose, so it | 3675 This value is not used internally by GN for any purpose, so it |
3623 may be set to whatever value is needed for the build. | 3676 may be set to whatever value is needed for the build. |
3624 GN defaults this value to the empty string ("") and the | 3677 GN defaults this value to the empty string ("") and the |
3625 configuration files should set it to an appropriate value | 3678 configuration files should set it to an appropriate value |
3626 (e.g., setting it to the value of "host_cpu") if it is not | 3679 (e.g., setting it to the value of "host_cpu") if it is not |
3627 overridden on the command line or in the args.gn file. | 3680 overridden on the command line or in the args.gn file. |
3628 | 3681 |
3629 Where practical, use one of the following list of common values: | 3682 Where practical, use one of the following list of common values: |
3630 | 3683 |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4255 | 4308 |
4256 ``` | 4309 ``` |
4257 source_set("busted_includes") { | 4310 source_set("busted_includes") { |
4258 # This target's includes are messed up, exclude it from checking. | 4311 # This target's includes are messed up, exclude it from checking. |
4259 check_includes = false | 4312 check_includes = false |
4260 ... | 4313 ... |
4261 } | 4314 } |
4262 | 4315 |
4263 | 4316 |
4264 ``` | 4317 ``` |
| 4318 ## **code_signing_args**: [string list] Arguments passed to code signing script. |
| 4319 |
| 4320 ``` |
| 4321 For create_bundle targets, code_signing_args is the list of arguments |
| 4322 to pass to the code signing script. Typically you would use source |
| 4323 expansion (see "gn help source_expansion") to insert the source file |
| 4324 names. |
| 4325 |
| 4326 See also "gn help create_bundle". |
| 4327 |
| 4328 |
| 4329 ``` |
| 4330 ## **code_signing_outputs**: [file list] Output files for code signing step. |
| 4331 |
| 4332 ``` |
| 4333 Outputs from the code signing step of a create_bundle target. Must |
| 4334 refer to files in the build directory. |
| 4335 |
| 4336 See also "gn help create_bundle". |
| 4337 |
| 4338 |
| 4339 ``` |
| 4340 ## **code_signing_script**: [file name] Script for code signing. |
| 4341 ``` |
| 4342 An absolute or buildfile-relative file name of a Python script to run |
| 4343 for a create_bundle target to perform code signing step. |
| 4344 |
| 4345 See also "gn help create_bundle". |
| 4346 |
| 4347 |
| 4348 ``` |
| 4349 ## **code_signing_sources**: [file list] Sources for code signing step. |
| 4350 |
| 4351 ``` |
| 4352 A list of files used as input for code signing script step of a |
| 4353 create_bundle target. Non-absolute paths will be resolved relative to |
| 4354 the current build file. |
| 4355 |
| 4356 See also "gn help create_bundle". |
| 4357 |
| 4358 |
| 4359 ``` |
4265 ## **complete_static_lib**: [boolean] Links all deps into a static library. | 4360 ## **complete_static_lib**: [boolean] Links all deps into a static library. |
4266 | 4361 |
4267 ``` | 4362 ``` |
4268 A static library normally doesn't include code from dependencies, but | 4363 A static library normally doesn't include code from dependencies, but |
4269 instead forwards the static libraries and source sets in its deps up | 4364 instead forwards the static libraries and source sets in its deps up |
4270 the dependency chain until a linkable target (an executable or shared | 4365 the dependency chain until a linkable target (an executable or shared |
4271 library) is reached. The final linkable target only links each static | 4366 library) is reached. The final linkable target only links each static |
4272 library once, even if it appears more than once in its dependency | 4367 library once, even if it appears more than once in its dependency |
4273 graph. | 4368 graph. |
4274 | 4369 |
(...skipping 1667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5942 (possibly on the static library target itself). | 6037 (possibly on the static library target itself). |
5943 | 6038 |
5944 ``` | 6039 ``` |
5945 | 6040 |
5946 ### **Multiple outputs** | 6041 ### **Multiple outputs** |
5947 | 6042 |
5948 ``` | 6043 ``` |
5949 When a tool produces more than one output, only the first output | 6044 When a tool produces more than one output, only the first output |
5950 is considered. For example, a shared library target may produce a | 6045 is considered. For example, a shared library target may produce a |
5951 .dll and a .lib file on Windows. Only the .dll file will be considered | 6046 .dll and a .lib file on Windows. Only the .dll file will be considered |
5952 a runtime dependency. This applies only to linker tools, scripts and | 6047 a runtime dependency. This applies only to linker tools. Scripts and |
5953 copy steps with multiple outputs will also get all outputs listed. | 6048 copy steps with multiple outputs will get all outputs listed. |
5954 | 6049 |
5955 | 6050 |
5956 ``` | 6051 ``` |
5957 ## **How Source Expansion Works** | 6052 ## **How Source Expansion Works** |
5958 | 6053 |
5959 ``` | 6054 ``` |
5960 Source expansion is used for the action_foreach and copy target types | 6055 Source expansion is used for the action_foreach and copy target types |
5961 to map source file names to output file names or arguments. | 6056 to map source file names to output file names or arguments. |
5962 | 6057 |
5963 To perform source expansion in the outputs, GN maps every entry in the | 6058 To perform source expansion in the outputs, GN maps every entry in the |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6091 ** \--root**: Explicitly specify source root. | 6186 ** \--root**: Explicitly specify source root. |
6092 ** \--runtime-deps-list-file**: Save runtime dependencies for targets in file. | 6187 ** \--runtime-deps-list-file**: Save runtime dependencies for targets in file. |
6093 ** \--script-executable**: Set the executable used to execute scripts. | 6188 ** \--script-executable**: Set the executable used to execute scripts. |
6094 ** \--threads**: Specify number of worker threads. | 6189 ** \--threads**: Specify number of worker threads. |
6095 ** \--time**: Outputs a summary of how long everything took. | 6190 ** \--time**: Outputs a summary of how long everything took. |
6096 ** \--tracelog**: Writes a Chrome-compatible trace log to the given file. | 6191 ** \--tracelog**: Writes a Chrome-compatible trace log to the given file. |
6097 ** -v**: Verbose logging. | 6192 ** -v**: Verbose logging. |
6098 ** \--version**: Prints the GN version number and exits. | 6193 ** \--version**: Prints the GN version number and exits. |
6099 | 6194 |
6100 ``` | 6195 ``` |
OLD | NEW |