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 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 | 1049 |
1050 ``` | 1050 ``` |
1051 | 1051 |
1052 ### **Examples**: | 1052 ### **Examples**: |
1053 ``` | 1053 ``` |
1054 assert(is_win) | 1054 assert(is_win) |
1055 assert(defined(sources), "Sources must be defined") | 1055 assert(defined(sources), "Sources must be defined") |
1056 | 1056 |
1057 | 1057 |
1058 ``` | 1058 ``` |
| 1059 ## **bundle_data**: [iOS/OS X] Declare a target without output. |
| 1060 |
| 1061 ``` |
| 1062 This target type allows to declare data that is required at runtime. |
| 1063 It is used to inform "create_bundle" targets of the files to copy |
| 1064 into generated bundle, see "gn help create_bundle" for help. |
| 1065 |
| 1066 The target must define a list of files as "sources" and a single |
| 1067 "outputs". If there are multiple files, source expansions must be |
| 1068 used to express the output. The output must reference a file inside |
| 1069 of {{bundle_root_dir}}. |
| 1070 |
| 1071 This target can be used on all platforms though it is designed only to |
| 1072 generate iOS/OS X bundle. In cross-platform projects, it is advised to |
| 1073 put it behind iOS/Mac conditionals. |
| 1074 |
| 1075 See "gn help create_bundle" for more information. |
| 1076 |
| 1077 ``` |
| 1078 |
| 1079 ### **Variables** |
| 1080 |
| 1081 ``` |
| 1082 sources*, outputs*, deps, data_deps, public_deps, visibility |
| 1083 * = required |
| 1084 |
| 1085 ``` |
| 1086 |
| 1087 ### **Examples** |
| 1088 |
| 1089 ``` |
| 1090 bundle_data("icudata") { |
| 1091 sources = [ "sources/data/in/icudtl.dat" ] |
| 1092 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ] |
| 1093 } |
| 1094 |
| 1095 bundle_data("base_unittests_bundle_data]") { |
| 1096 sources = [ "test/data" ] |
| 1097 outputs = [ |
| 1098 "{{bundle_resources_dir}}/{{source_root_relative_dir}}/" + |
| 1099 "{{source_file_part}}" |
| 1100 ] |
| 1101 } |
| 1102 |
| 1103 bundle_data("material_typography_bundle_data") { |
| 1104 sources = [ |
| 1105 "src/MaterialTypography.bundle/Roboto-Bold.ttf", |
| 1106 "src/MaterialTypography.bundle/Roboto-Italic.ttf", |
| 1107 "src/MaterialTypography.bundle/Roboto-Regular.ttf", |
| 1108 "src/MaterialTypography.bundle/Roboto-Thin.ttf", |
| 1109 ] |
| 1110 outputs = [ |
| 1111 "{{bundle_resources_dir}}/MaterialTypography.bundle/" |
| 1112 "{{source_file_part}}" |
| 1113 ] |
| 1114 } |
| 1115 |
| 1116 |
| 1117 ``` |
1059 ## **config**: Defines a configuration object. | 1118 ## **config**: Defines a configuration object. |
1060 | 1119 |
1061 ``` | 1120 ``` |
1062 Configuration objects can be applied to targets and specify sets of | 1121 Configuration objects can be applied to targets and specify sets of |
1063 compiler flags, includes, defines, etc. They provide a way to | 1122 compiler flags, includes, defines, etc. They provide a way to |
1064 conveniently group sets of this configuration information. | 1123 conveniently group sets of this configuration information. |
1065 | 1124 |
1066 A config is referenced by its label just like a target. | 1125 A config is referenced by its label just like a target. |
1067 | 1126 |
1068 The values in a config are additive only. If you want to remove a flag | 1127 The values in a config are additive only. If you want to remove a flag |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 sources = [ "data1.dat", "data2.dat", "data3.dat" ] | 1206 sources = [ "data1.dat", "data2.dat", "data3.dat" ] |
1148 | 1207 |
1149 # Use source expansion to generate output files with the | 1208 # Use source expansion to generate output files with the |
1150 # corresponding file names in the gen dir. This will just copy each | 1209 # corresponding file names in the gen dir. This will just copy each |
1151 # file. | 1210 # file. |
1152 outputs = [ "$target_gen_dir/{{source_file_part}}" ] | 1211 outputs = [ "$target_gen_dir/{{source_file_part}}" ] |
1153 } | 1212 } |
1154 | 1213 |
1155 | 1214 |
1156 ``` | 1215 ``` |
| 1216 ## **create_bundle**: [iOS/OS X] Build an OS X / iOS bundle. |
| 1217 |
| 1218 ``` |
| 1219 This target generates an iOS/OS X bundle (which is a directory with a |
| 1220 well-know structure). This target does not define any sources, instead |
| 1221 they are computed from all "bundle_data" target this one depends on |
| 1222 transitively (the recursion stops at "create_bundle" targets). |
| 1223 |
| 1224 The "bundle_*_dir" properties must be defined. They will be used for |
| 1225 the expansion of {{bundle_*_dir}} rules in "bundle_data" outputs. |
| 1226 |
| 1227 This target can be used on all platforms though it is designed only to |
| 1228 generate iOS/OS X bundle. In cross-platform projects, it is advised to |
| 1229 put it behind iOS/Mac conditionals. |
| 1230 |
| 1231 ``` |
| 1232 |
| 1233 ### **Variables** |
| 1234 |
| 1235 ``` |
| 1236 bundle_root_dir*, bundle_resources_dir*, bundle_executable_dir*, |
| 1237 bundle_plugins_dir*, deps, data_deps, public_deps, visibility |
| 1238 * = required |
| 1239 |
| 1240 ``` |
| 1241 |
| 1242 ### **Example** |
| 1243 |
| 1244 ``` |
| 1245 # Defines a template to create an application. On most platform, this |
| 1246 # is just an alias for an "executable" target, but on iOS/OS X, it |
| 1247 # builds an application bundle. |
| 1248 template("app") { |
| 1249 if (!is_ios && !is_mac) { |
| 1250 executable(target_name) { |
| 1251 forward_variables_from(invoker, "*") |
| 1252 } |
| 1253 } else { |
| 1254 app_name = target_name |
| 1255 gen_path = target_gen_dir |
| 1256 |
| 1257 action("${app_name}_generate_info_plist") { |
| 1258 script = [ "//build/ios/ios_gen_plist.py" ] |
| 1259 sources = [ "templates/Info.plist" ] |
| 1260 outputs = [ "$gen_path/Info.plist" ] |
| 1261 args = rebase_path(sources, root_build_dir) + |
| 1262 rebase_path(outputs, root_build_dir) |
| 1263 } |
| 1264 |
| 1265 bundle_data("${app_name}_bundle_info_plist") { |
| 1266 deps = [ ":${app_name}_generate_info_plist" ] |
| 1267 sources = [ "$gen_path/Info.plist" ] |
| 1268 outputs = [ "{{bundle_root_dir}}/Info.plist" ] |
| 1269 } |
| 1270 |
| 1271 executable("${app_name}_generate_executable") { |
| 1272 forward_variables_from(invoker, "*", [ |
| 1273 "output_name", |
| 1274 "visibility", |
| 1275 ]) |
| 1276 output_name = |
| 1277 rebase_path("$gen_path/$app_name", root_build_dir) |
| 1278 } |
| 1279 |
| 1280 bundle_data("${app_name}_bundle_executable") { |
| 1281 deps = [ ":${app_name}_generate_executable" ] |
| 1282 sources = [ "$gen_path/$app_name" ] |
| 1283 outputs = [ "{{bundle_executable_dir}}/$app_name" ] |
| 1284 } |
| 1285 |
| 1286 create_bundle("${app_name}.app") { |
| 1287 deps = [ |
| 1288 ":${app_name}_bundle_executable", |
| 1289 ":${app_name}_bundle_info_plist", |
| 1290 ] |
| 1291 if (is_ios) { |
| 1292 bundle_root_dir = "${root_build_dir}/$target_name" |
| 1293 bundle_resources_dir = bundle_root_dir |
| 1294 bundle_executable_dir = bundle_root_dir |
| 1295 bundle_plugins_dir = bundle_root_dir + "/Plugins" |
| 1296 } else { |
| 1297 bundle_root_dir = "${root_build_dir}/target_name/Contents" |
| 1298 bundle_resources_dir = bundle_root_dir + "/Resources" |
| 1299 bundle_executable_dir = bundle_root_dir + "/MacOS" |
| 1300 bundle_plugins_dir = bundle_root_dir + "/Plugins" |
| 1301 } |
| 1302 } |
| 1303 |
| 1304 group(target_name) { |
| 1305 forward_variables_from(invoker, ["visibility"]) |
| 1306 deps = [ ":${app_name}.app" ] |
| 1307 } |
| 1308 } |
| 1309 } |
| 1310 |
| 1311 |
| 1312 ``` |
1157 ## **declare_args**: Declare build arguments. | 1313 ## **declare_args**: Declare build arguments. |
1158 | 1314 |
1159 ``` | 1315 ``` |
1160 Introduces the given arguments into the current scope. If they are | 1316 Introduces the given arguments into the current scope. If they are |
1161 not specified on the command line or in a toolchain's arguments, | 1317 not specified on the command line or in a toolchain's arguments, |
1162 the default values given in the declare_args block will be used. | 1318 the default values given in the declare_args block will be used. |
1163 However, these defaults will not override command-line values. | 1319 However, these defaults will not override command-line values. |
1164 | 1320 |
1165 See also "gn help buildargs" for an overview. | 1321 See also "gn help buildargs" for an overview. |
1166 | 1322 |
(...skipping 1270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2437 | 2593 |
2438 Linker tools: | 2594 Linker tools: |
2439 "alink": Linker for static libraries (archives) | 2595 "alink": Linker for static libraries (archives) |
2440 "solink": Linker for shared libraries | 2596 "solink": Linker for shared libraries |
2441 "link": Linker for executables | 2597 "link": Linker for executables |
2442 | 2598 |
2443 Other tools: | 2599 Other tools: |
2444 "stamp": Tool for creating stamp files | 2600 "stamp": Tool for creating stamp files |
2445 "copy": Tool to copy files. | 2601 "copy": Tool to copy files. |
2446 | 2602 |
| 2603 Platform specific tools: |
| 2604 "copy_bundle_data": [iOS, OS X] Tool to copy files in a bundle. |
| 2605 "compile_xcassets": [iOS, OS X] Tool to compile asset catalogs. |
| 2606 |
2447 ``` | 2607 ``` |
2448 | 2608 |
2449 ### **Tool variables** | 2609 ### **Tool variables** |
2450 | 2610 |
2451 ``` | 2611 ``` |
2452 command [string with substitutions] | 2612 command [string with substitutions] |
2453 Valid for: all tools (required) | 2613 Valid for: all tools (required) |
2454 | 2614 |
2455 The command to run. | 2615 The command to run. |
2456 | 2616 |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2752 shared libraries (if the solink tool specifies a "link_output" | 2912 shared libraries (if the solink tool specifies a "link_output" |
2753 variable separate from the "depend_output"). | 2913 variable separate from the "depend_output"). |
2754 | 2914 |
2755 These should generally be treated the same as libs by your tool. | 2915 These should generally be treated the same as libs by your tool. |
2756 Example: "libfoo.so libbar.so" | 2916 Example: "libfoo.so libbar.so" |
2757 | 2917 |
2758 The copy tool allows the common compiler/linker substitutions, plus | 2918 The copy tool allows the common compiler/linker substitutions, plus |
2759 {{source}} which is the source of the copy. The stamp tool allows | 2919 {{source}} which is the source of the copy. The stamp tool allows |
2760 only the common tool substitutions. | 2920 only the common tool substitutions. |
2761 | 2921 |
| 2922 The copy_bundle_data and compile_xcassets tools only allows the common |
| 2923 tool substitutions. Both tools are required to create iOS/OS X bundles |
| 2924 and need only be defined on those platforms. |
| 2925 |
| 2926 The copy_bundle_data tool will be called with one source and needs to |
| 2927 copy (optionally optimizing the data representation) to its output. It |
| 2928 may be called with a directory as input and it needs to be recursively |
| 2929 copied. |
| 2930 |
| 2931 The compile_xcassets tool will be called with one or more source (each |
| 2932 an asset catalog) that needs to be compiled to a single output. |
| 2933 |
2762 ``` | 2934 ``` |
2763 | 2935 |
2764 ### **Separate linking and dependencies for shared libraries** | 2936 ### **Separate linking and dependencies for shared libraries** |
2765 | 2937 |
2766 ``` | 2938 ``` |
2767 Shared libraries are special in that not all changes to them require | 2939 Shared libraries are special in that not all changes to them require |
2768 that dependent targets be re-linked. If the shared library is changed | 2940 that dependent targets be re-linked. If the shared library is changed |
2769 but no imports or exports are different, dependent code needn't be | 2941 but no imports or exports are different, dependent code needn't be |
2770 relinked, which can speed up the build. | 2942 relinked, which can speed up the build. |
2771 | 2943 |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3442 deps = [ "//foo:bar" ] | 3614 deps = [ "//foo:bar" ] |
3443 ... | 3615 ... |
3444 assert_no_deps = [ | 3616 assert_no_deps = [ |
3445 "//evil/*", # Don't link any code from the evil directory. | 3617 "//evil/*", # Don't link any code from the evil directory. |
3446 "//foo:test_support", # This target is also disallowed. | 3618 "//foo:test_support", # This target is also disallowed. |
3447 ] | 3619 ] |
3448 } | 3620 } |
3449 | 3621 |
3450 | 3622 |
3451 ``` | 3623 ``` |
| 3624 ## **bundle_executable_dir**: Expansion of {{bundle_executable_dir}} in create_b
undle. |
| 3625 |
| 3626 ``` |
| 3627 A string corresponding to a path in $root_build_dir. |
| 3628 |
| 3629 This string is used by the "create_bundle" target to expand the |
| 3630 {{bundle_executable_dir}} of the "bundle_data" target it depends on. |
| 3631 This must correspond to a path under "bundle_root_dir". |
| 3632 |
| 3633 See "gn help bundle_root_dir" for examples. |
| 3634 |
| 3635 |
| 3636 ``` |
| 3637 ## **bundle_plugins_dir**: Expansion of {{bundle_plugins_dir}} in create_bundle. |
| 3638 |
| 3639 ``` |
| 3640 A string corresponding to a path in $root_build_dir. |
| 3641 |
| 3642 This string is used by the "create_bundle" target to expand the |
| 3643 {{bundle_plugins_dir}} of the "bundle_data" target it depends on. |
| 3644 This must correspond to a path under "bundle_root_dir". |
| 3645 |
| 3646 See "gn help bundle_root_dir" for examples. |
| 3647 |
| 3648 |
| 3649 ``` |
| 3650 ## **bundle_resources_dir**: Expansion of {{bundle_resources_dir}} in create_bun
dle. |
| 3651 |
| 3652 ``` |
| 3653 A string corresponding to a path in $root_build_dir. |
| 3654 |
| 3655 This string is used by the "create_bundle" target to expand the |
| 3656 {{bundle_resources_dir}} of the "bundle_data" target it depends on. |
| 3657 This must correspond to a path under "bundle_root_dir". |
| 3658 |
| 3659 See "gn help bundle_root_dir" for examples. |
| 3660 |
| 3661 |
| 3662 ``` |
| 3663 ## **bundle_root_dir**: Expansion of {{bundle_root_dir}} in create_bundle. |
| 3664 |
| 3665 ``` |
| 3666 A string corresponding to a path in root_build_dir. |
| 3667 |
| 3668 This string is used by the "create_bundle" target to expand the |
| 3669 {{bundle_root_dir}} of the "bundle_data" target it depends on. |
| 3670 This must correspond to a path under root_build_dir. |
| 3671 |
| 3672 ``` |
| 3673 |
| 3674 ### **Example** |
| 3675 |
| 3676 ``` |
| 3677 bundle_data("info_plist") { |
| 3678 sources = [ "Info.plist" ] |
| 3679 outputs = [ "{{bundle_root_dir}}/Info.plist" ] |
| 3680 } |
| 3681 |
| 3682 create_bundle("doom_melon.app") { |
| 3683 deps = [ ":info_plist" ] |
| 3684 bundle_root_dir = root_build_dir + "/doom_melon.app/Contents" |
| 3685 bundle_resources_dir = bundle_root_dir + "/Resources" |
| 3686 bundle_executable_dir = bundle_root_dir + "/MacOS" |
| 3687 bundle_plugins_dir = bundle_root_dir + "/PlugIns" |
| 3688 } |
| 3689 |
| 3690 |
| 3691 ``` |
3452 ## **cflags***: Flags passed to the C compiler. | 3692 ## **cflags***: Flags passed to the C compiler. |
3453 | 3693 |
3454 ``` | 3694 ``` |
3455 A list of strings. | 3695 A list of strings. |
3456 | 3696 |
3457 "cflags" are passed to all invocations of the C, C++, Objective C, | 3697 "cflags" are passed to all invocations of the C, C++, Objective C, |
3458 and Objective C++ compilers. | 3698 and Objective C++ compilers. |
3459 | 3699 |
3460 To target one of these variants individually, use "cflags_c", | 3700 To target one of these variants individually, use "cflags_c", |
3461 "cflags_cc", "cflags_objc", and "cflags_objcc", | 3701 "cflags_cc", "cflags_objc", and "cflags_objcc", |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4039 | 4279 |
4040 Inputs are typically only used for action and action_foreach targets. | 4280 Inputs are typically only used for action and action_foreach targets. |
4041 | 4281 |
4042 ``` | 4282 ``` |
4043 | 4283 |
4044 ### **Inputs for actions** | 4284 ### **Inputs for actions** |
4045 | 4285 |
4046 ``` | 4286 ``` |
4047 For action and action_foreach targets, inputs should be the inputs to | 4287 For action and action_foreach targets, inputs should be the inputs to |
4048 script that don't vary. These should be all .py files that the script | 4288 script that don't vary. These should be all .py files that the script |
4049 uses via imports (the main script itself will be an implcit dependency | 4289 uses via imports (the main script itself will be an implicit dependency |
4050 of the action so need not be listed). | 4290 of the action so need not be listed). |
4051 | 4291 |
4052 For action targets, inputs and sources are treated the same, but from | 4292 For action targets, inputs and sources are treated the same, but from |
4053 a style perspective, it's recommended to follow the same rule as | 4293 a style perspective, it's recommended to follow the same rule as |
4054 action_foreach and put helper files in the inputs, and the data used | 4294 action_foreach and put helper files in the inputs, and the data used |
4055 by the script (if any) in sources. | 4295 by the script (if any) in sources. |
4056 | 4296 |
4057 Note that another way to declare input dependencies from an action | 4297 Note that another way to declare input dependencies from an action |
4058 is to have the action write a depfile (see "gn help depfile"). This | 4298 is to have the action write a depfile (see "gn help depfile"). This |
4059 allows the script to dynamically write input dependencies, that might | 4299 allows the script to dynamically write input dependencies, that might |
(...skipping 1187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5247 "args" variable. | 5487 "args" variable. |
5248 "//foo/bar/baz.txt" => "../../foo/bar/baz.txt" | 5488 "//foo/bar/baz.txt" => "../../foo/bar/baz.txt" |
5249 | 5489 |
5250 {{source_file_part}} | 5490 {{source_file_part}} |
5251 The file part of the source including the extension. | 5491 The file part of the source including the extension. |
5252 "//foo/bar/baz.txt" => "baz.txt" | 5492 "//foo/bar/baz.txt" => "baz.txt" |
5253 | 5493 |
5254 {{source_name_part}} | 5494 {{source_name_part}} |
5255 The filename part of the source file with no directory or | 5495 The filename part of the source file with no directory or |
5256 extension. This will generally be used for specifying a | 5496 extension. This will generally be used for specifying a |
5257 transformation from a soruce file to a destination file with the | 5497 transformation from a source file to a destination file with the |
5258 same name but different extension. | 5498 same name but different extension. |
5259 "//foo/bar/baz.txt" => "baz" | 5499 "//foo/bar/baz.txt" => "baz" |
5260 | 5500 |
5261 {{source_dir}} | 5501 {{source_dir}} |
5262 The directory (*) containing the source file with no | 5502 The directory (*) containing the source file with no |
5263 trailing slash. | 5503 trailing slash. |
5264 "//foo/bar/baz.txt" => "../../foo/bar" | 5504 "//foo/bar/baz.txt" => "../../foo/bar" |
5265 | 5505 |
5266 {{source_root_relative_dir}} | 5506 {{source_root_relative_dir}} |
5267 The path to the source file's directory relative to the source | 5507 The path to the source file's directory relative to the source |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5346 ** -q**: Quiet mode. Don't print output on success. | 5586 ** -q**: Quiet mode. Don't print output on success. |
5347 ** \--root**: Explicitly specify source root. | 5587 ** \--root**: Explicitly specify source root. |
5348 ** \--runtime-deps-list-file**: Save runtime dependencies for targets in file. | 5588 ** \--runtime-deps-list-file**: Save runtime dependencies for targets in file. |
5349 ** \--threads**: Specify number of worker threads. | 5589 ** \--threads**: Specify number of worker threads. |
5350 ** \--time**: Outputs a summary of how long everything took. | 5590 ** \--time**: Outputs a summary of how long everything took. |
5351 ** \--tracelog**: Writes a Chrome-compatible trace log to the given file. | 5591 ** \--tracelog**: Writes a Chrome-compatible trace log to the given file. |
5352 ** -v**: Verbose logging. | 5592 ** -v**: Verbose logging. |
5353 ** \--version**: Prints the GN version number and exits. | 5593 ** \--version**: Prints the GN version number and exits. |
5354 | 5594 |
5355 ``` | 5595 ``` |
OLD | NEW |