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 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 | 439 |
440 ``` | 440 ``` |
441 ## **gn clean <out_dir>** | 441 ## **gn clean <out_dir>** |
442 | 442 |
443 ``` | 443 ``` |
444 Deletes the contents of the output directory except for args.gn and | 444 Deletes the contents of the output directory except for args.gn and |
445 creates a Ninja build environment sufficient to regenerate the build. | 445 creates a Ninja build environment sufficient to regenerate the build. |
446 | 446 |
447 | 447 |
448 ``` | 448 ``` |
449 ## **gn desc <out_dir> <label or pattern> [<what to show>] [\--blame]** | 449 ## **gn desc <out_dir> <label or pattern> [<what to show>] [\--blame] [\--format
=json]** |
450 | 450 |
451 ``` | 451 ``` |
452 Displays information about a given target or config. The build | 452 Displays information about a given target or config. The build |
453 build parameters will be taken for the build in the given <out_dir>. | 453 build parameters will be taken for the build in the given <out_dir>. |
454 | 454 |
455 The <label or pattern> can be a target label, a config label, or a | 455 The <label or pattern> can be a target label, a config label, or a |
456 label pattern (see "gn help label_pattern"). A label pattern will | 456 label pattern (see "gn help label_pattern"). A label pattern will |
457 only match targets. | 457 only match targets. |
458 | 458 |
459 ``` | 459 ``` |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 ``` | 505 ``` |
506 --all-toolchains | 506 --all-toolchains |
507 Normally only inputs in the default toolchain will be included. | 507 Normally only inputs in the default toolchain will be included. |
508 This switch will turn on matching all toolchains. | 508 This switch will turn on matching all toolchains. |
509 | 509 |
510 For example, a file is in a target might be compiled twice: | 510 For example, a file is in a target might be compiled twice: |
511 once in the default toolchain and once in a secondary one. Without | 511 once in the default toolchain and once in a secondary one. Without |
512 this flag, only the default toolchain one will be matched by | 512 this flag, only the default toolchain one will be matched by |
513 wildcards. With this flag, both will be matched. | 513 wildcards. With this flag, both will be matched. |
514 | 514 |
| 515 --format=json |
| 516 Format the output as JSON instead of text. |
| 517 |
515 ``` | 518 ``` |
516 | 519 |
517 ### **Target flags** | 520 ### **Target flags** |
518 | 521 |
519 ``` | 522 ``` |
520 --blame | 523 --blame |
521 Used with any value specified on a config, this will name | 524 Used with any value specified on a config, this will name |
522 the config that cause that target to get the flag. This doesn't | 525 the config that cause that target to get the flag. This doesn't |
523 currently work for libs and lib_dirs because those are inherited | 526 currently work for libs and lib_dirs because those are inherited |
524 and are more complicated to figure out the blame (patches | 527 and are more complicated to figure out the blame (patches |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 | 698 |
696 --ide=<ide_name> | 699 --ide=<ide_name> |
697 Generate files for an IDE. Currently supported values: | 700 Generate files for an IDE. Currently supported values: |
698 "eclipse" - Eclipse CDT settings file. | 701 "eclipse" - Eclipse CDT settings file. |
699 "vs" - Visual Studio project/solution files. | 702 "vs" - Visual Studio project/solution files. |
700 (default Visual Studio version: 2015) | 703 (default Visual Studio version: 2015) |
701 "vs2013" - Visual Studio 2013 project/solution files. | 704 "vs2013" - Visual Studio 2013 project/solution files. |
702 "vs2015" - Visual Studio 2015 project/solution files. | 705 "vs2015" - Visual Studio 2015 project/solution files. |
703 "xcode" - Xcode workspace/solution files. | 706 "xcode" - Xcode workspace/solution files. |
704 "qtcreator" - QtCreator project files. | 707 "qtcreator" - QtCreator project files. |
| 708 "json" - JSON file containing target information |
705 | 709 |
706 --filters=<path_prefixes> | 710 --filters=<path_prefixes> |
707 Semicolon-separated list of label patterns used to limit the set | 711 Semicolon-separated list of label patterns used to limit the set |
708 of generated projects (see "gn help label_pattern"). Only | 712 of generated projects (see "gn help label_pattern"). Only |
709 matching targets and their dependencies will be included in the | 713 matching targets and their dependencies will be included in the |
710 solution. Only used for Visual Studio and Xcode. | 714 solution. Only used for Visual Studio, Xcode and JSON. |
711 | 715 |
712 ``` | 716 ``` |
713 | 717 |
714 ### **Visual Studio Flags** | 718 ### **Visual Studio Flags** |
715 | 719 |
716 ``` | 720 ``` |
717 --sln=<file_name> | 721 --sln=<file_name> |
718 Override default sln file name ("all"). Solution file is written | 722 Override default sln file name ("all"). Solution file is written |
719 to the root build directory. | 723 to the root build directory. |
720 | 724 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 ``` | 759 ``` |
756 GN DOES NOT generate Eclipse CDT projects. Instead, it generates a | 760 GN DOES NOT generate Eclipse CDT projects. Instead, it generates a |
757 settings file which can be imported into an Eclipse CDT project. The | 761 settings file which can be imported into an Eclipse CDT project. The |
758 XML file contains a list of include paths and defines. Because GN does | 762 XML file contains a list of include paths and defines. Because GN does |
759 not generate a full .cproject definition, it is not possible to | 763 not generate a full .cproject definition, it is not possible to |
760 properly define includes/defines for each file individually. | 764 properly define includes/defines for each file individually. |
761 Instead, one set of includes/defines is generated for the entire | 765 Instead, one set of includes/defines is generated for the entire |
762 project. This works fairly well but may still result in a few indexer | 766 project. This works fairly well but may still result in a few indexer |
763 issues here and there. | 767 issues here and there. |
764 | 768 |
| 769 ``` |
| 770 |
| 771 ### **Generic JSON Output** |
| 772 |
| 773 ``` |
| 774 Dumps target information to JSON file and optionally invokes python |
| 775 script on generated file. |
| 776 |
| 777 See comments at the beginning of json_project_writer.cc and |
| 778 desc_builder.cc for overview of JSON file format. |
| 779 |
| 780 --json-file-name=<json_file_name> |
| 781 Overrides default file name (project.json) of generated JSON file. |
| 782 |
| 783 --json-ide-script=<path_to_python_script> |
| 784 Executes python script after the JSON file is generated. |
| 785 Path can be project absolute (//), system absolute (/) or |
| 786 relative, in which case the output directory will be base. |
| 787 Path to generated JSON file will be first argument when invoking |
| 788 script. |
| 789 |
| 790 --json-ide-script-args=<argument> |
| 791 Optional second argument that will passed to executed script. |
| 792 |
765 | 793 |
766 ``` | 794 ``` |
767 ## **gn help <anything>** | 795 ## **gn help <anything>** |
768 | 796 |
769 ``` | 797 ``` |
770 Yo dawg, I heard you like help on your help so I put help on the help | 798 Yo dawg, I heard you like help on your help so I put help on the help |
771 in the help. | 799 in the help. |
772 | 800 |
773 You can also use "all" as the parameter to get all help at once. | 801 You can also use "all" as the parameter to get all help at once. |
774 | 802 |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1295 | 1323 |
1296 ### **Examples** | 1324 ### **Examples** |
1297 | 1325 |
1298 ``` | 1326 ``` |
1299 bundle_data("icudata") { | 1327 bundle_data("icudata") { |
1300 sources = [ "sources/data/in/icudtl.dat" ] | 1328 sources = [ "sources/data/in/icudtl.dat" ] |
1301 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ] | 1329 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ] |
1302 } | 1330 } |
1303 | 1331 |
1304 bundle_data("base_unittests_bundle_data]") { | 1332 bundle_data("base_unittests_bundle_data]") { |
1305 sources = [ "test/data" ] | 1333 sources = [ "test/data" ] |
1306 outputs = [ | 1334 outputs = [ |
1307 "{{bundle_resources_dir}}/{{source_root_relative_dir}}/" + | 1335 "{{bundle_resources_dir}}/{{source_root_relative_dir}}/" + |
1308 "{{source_file_part}}" | 1336 "{{source_file_part}}" |
1309 ] | 1337 ] |
1310 } | 1338 } |
1311 | 1339 |
1312 bundle_data("material_typography_bundle_data") { | 1340 bundle_data("material_typography_bundle_data") { |
1313 sources = [ | 1341 sources = [ |
1314 "src/MaterialTypography.bundle/Roboto-Bold.ttf", | 1342 "src/MaterialTypography.bundle/Roboto-Bold.ttf", |
1315 "src/MaterialTypography.bundle/Roboto-Italic.ttf", | 1343 "src/MaterialTypography.bundle/Roboto-Italic.ttf", |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1461 The code_signing_args will be passed as is to the script (so path have | 1489 The code_signing_args will be passed as is to the script (so path have |
1462 to be rebased) and additional inputs may be listed with the variable | 1490 to be rebased) and additional inputs may be listed with the variable |
1463 code_signing_sources. | 1491 code_signing_sources. |
1464 | 1492 |
1465 ``` | 1493 ``` |
1466 | 1494 |
1467 ### **Variables** | 1495 ### **Variables** |
1468 | 1496 |
1469 ``` | 1497 ``` |
1470 bundle_root_dir*, bundle_resources_dir*, bundle_executable_dir*, | 1498 bundle_root_dir*, bundle_resources_dir*, bundle_executable_dir*, |
1471 bundle_plugins_dir*, deps, data_deps, public_deps, visibility, | 1499 bundle_plugins_dir*, bundle_deps_filter, deps, data_deps, public_deps, |
1472 product_type, code_signing_args, code_signing_script, | 1500 visibility, product_type, code_signing_args, code_signing_script, |
1473 code_signing_sources, code_signing_outputs | 1501 code_signing_sources, code_signing_outputs |
1474 * = required | 1502 * = required |
1475 | 1503 |
1476 ``` | 1504 ``` |
1477 | 1505 |
1478 ### **Example** | 1506 ### **Example** |
1479 | 1507 |
1480 ``` | 1508 ``` |
1481 # Defines a template to create an application. On most platform, this | 1509 # Defines a template to create an application. On most platform, this |
1482 # is just an alias for an "executable" target, but on iOS/OS X, it | 1510 # is just an alias for an "executable" target, but on iOS/OS X, it |
(...skipping 1541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3024 at least one output file. There can be more than one output (a | 3052 at least one output file. There can be more than one output (a |
3025 linker might produce a library and an import library, for | 3053 linker might produce a library and an import library, for |
3026 example). | 3054 example). |
3027 | 3055 |
3028 This array just declares to GN what files the tool will | 3056 This array just declares to GN what files the tool will |
3029 produce. It is your responsibility to specify the tool command | 3057 produce. It is your responsibility to specify the tool command |
3030 that actually produces these files. | 3058 that actually produces these files. |
3031 | 3059 |
3032 If you specify more than one output for shared library links, | 3060 If you specify more than one output for shared library links, |
3033 you should consider setting link_output, depend_output, and | 3061 you should consider setting link_output, depend_output, and |
3034 runtime_link_output. Otherwise, the first entry in the | 3062 runtime_outputs. |
3035 outputs list should always be the main output which will be | |
3036 linked to. | |
3037 | 3063 |
3038 Example for a compiler tool that produces .obj files: | 3064 Example for a compiler tool that produces .obj files: |
3039 outputs = [ | 3065 outputs = [ |
3040 "{{source_out_dir}}/{{source_name_part}}.obj" | 3066 "{{source_out_dir}}/{{source_name_part}}.obj" |
3041 ] | 3067 ] |
3042 | 3068 |
3043 Example for a linker tool that produces a .dll and a .lib. The | 3069 Example for a linker tool that produces a .dll and a .lib. The |
3044 use of {{target_output_name}}, {{output_extension}} and | 3070 use of {{target_output_name}}, {{output_extension}} and |
3045 {{output_dir}} allows the target to override these values. | 3071 {{output_dir}} allows the target to override these values. |
3046 outputs = [ | 3072 outputs = [ |
3047 "{{output_dir}}/{{target_output_name}}{{output_extension}}", | 3073 "{{output_dir}}/{{target_output_name}}{{output_extension}}", |
3048 "{{output_dir}}/{{target_output_name}}.lib", | 3074 "{{output_dir}}/{{target_output_name}}.lib", |
3049 ] | 3075 ] |
3050 | 3076 |
3051 pool [label, optional] | 3077 pool [label, optional] |
3052 | 3078 |
3053 Label of the pool to use for the tool. Pools are used to limit | 3079 Label of the pool to use for the tool. Pools are used to limit |
3054 the number of tasks that can execute concurrently during the | 3080 the number of tasks that can execute concurrently during the |
3055 build. | 3081 build. |
3056 | 3082 |
3057 See also "gn help pool". | 3083 See also "gn help pool". |
3058 | 3084 |
3059 link_output [string with substitutions] | 3085 link_output [string with substitutions] |
3060 depend_output [string with substitutions] | 3086 depend_output [string with substitutions] |
3061 runtime_link_output [string with substitutions] | |
3062 Valid for: "solink" only (optional) | 3087 Valid for: "solink" only (optional) |
3063 | 3088 |
3064 These three files specify which of the outputs from the solink | 3089 These two files specify which of the outputs from the solink |
3065 tool should be used for linking and dependency tracking. These | 3090 tool should be used for linking and dependency tracking. These |
3066 should match entries in the "outputs". If unspecified, the | 3091 should match entries in the "outputs". If unspecified, the |
3067 first item in the "outputs" array will be used for all. See | 3092 first item in the "outputs" array will be used for all. See |
3068 "Separate linking and dependencies for shared libraries" | 3093 "Separate linking and dependencies for shared libraries" |
3069 below for more. If link_output is set but runtime_link_output | 3094 below for more. |
3070 is not set, runtime_link_output defaults to link_output. | |
3071 | 3095 |
3072 On Windows, where the tools produce a .dll shared library and | 3096 On Windows, where the tools produce a .dll shared library and |
3073 a .lib import library, you will want the first two to be the | 3097 a .lib import library, you will want the first two to be the |
3074 import library and the third one to be the .dll file. | 3098 import library and the third one to be the .dll file. |
3075 On Linux, if you're not doing the separate linking/dependency | 3099 On Linux, if you're not doing the separate linking/dependency |
3076 optimization, all of these should be the .so output. | 3100 optimization, all of these should be the .so output. |
3077 | 3101 |
3078 output_prefix [string] | 3102 output_prefix [string] |
3079 Valid for: Linker tools (optional) | 3103 Valid for: Linker tools (optional) |
3080 | 3104 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3137 allows you to get around OS command-line length limits. | 3161 allows you to get around OS command-line length limits. |
3138 | 3162 |
3139 This example adds the inputs and libraries to a response file, | 3163 This example adds the inputs and libraries to a response file, |
3140 but passes the linker flags directly on the command line: | 3164 but passes the linker flags directly on the command line: |
3141 tool("link") { | 3165 tool("link") { |
3142 command = "link -o {{output}} {{ldflags}} @{{output}}.rsp" | 3166 command = "link -o {{output}} {{ldflags}} @{{output}}.rsp" |
3143 rspfile = "{{output}}.rsp" | 3167 rspfile = "{{output}}.rsp" |
3144 rspfile_content = "{{inputs}} {{solibs}} {{libs}}" | 3168 rspfile_content = "{{inputs}} {{solibs}} {{libs}}" |
3145 } | 3169 } |
3146 | 3170 |
| 3171 runtime_outputs [string list with substitutions] |
| 3172 Valid for: linker tools |
| 3173 |
| 3174 If specified, this list is the subset of the outputs that should |
| 3175 be added to runtime deps (see "gn help runtime_deps"). By |
| 3176 default (if runtime_outputs is empty or unspecified), it will be |
| 3177 the link_output. |
| 3178 |
3147 ``` | 3179 ``` |
3148 | 3180 |
3149 ### **Expansions for tool variables** | 3181 ### **Expansions for tool variables** |
3150 | 3182 |
3151 ``` | 3183 ``` |
3152 All paths are relative to the root build directory, which is the | 3184 All paths are relative to the root build directory, which is the |
3153 current directory for running all tools. These expansions are | 3185 current directory for running all tools. These expansions are |
3154 available to all tools: | 3186 available to all tools: |
3155 | 3187 |
3156 {{label}} | 3188 {{label}} |
(...skipping 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4802 propagated across all types of targets, and public_configs | 4834 propagated across all types of targets, and public_configs |
4803 are always propagated across public deps of all types of targets. | 4835 are always propagated across public deps of all types of targets. |
4804 | 4836 |
4805 Data dependencies are propagated differently. See | 4837 Data dependencies are propagated differently. See |
4806 "gn help data_deps" and "gn help runtime_deps". | 4838 "gn help data_deps" and "gn help runtime_deps". |
4807 | 4839 |
4808 See also "public_deps". | 4840 See also "public_deps". |
4809 | 4841 |
4810 | 4842 |
4811 ``` | 4843 ``` |
| 4844 ## **bundle_deps_filter**: [label list] A list of labels that are filtered out. |
| 4845 |
| 4846 ``` |
| 4847 A list of target labels. |
| 4848 |
| 4849 This list contains target label patterns that should be filtered out |
| 4850 when creating the bundle. Any target matching one of those label will |
| 4851 be removed from the dependencies of the create_bundle target. |
| 4852 |
| 4853 This is mostly useful when creating application extension bundle as |
| 4854 the application extension has access to runtime resources from the |
| 4855 application bundle and thus do not require a second copy. |
| 4856 |
| 4857 See "gn help create_bundle" for more information. |
| 4858 |
| 4859 ``` |
| 4860 |
| 4861 ### **Example** |
| 4862 |
| 4863 ``` |
| 4864 create_bundle("today_extension") { |
| 4865 deps = [ |
| 4866 "//base" |
| 4867 ] |
| 4868 bundle_root_dir = "$root_out_dir/today_extension.appex" |
| 4869 bundle_deps_filter = [ |
| 4870 # The extension uses //base but does not use any function calling |
| 4871 # into third_party/icu and thus does not need the icudtl.dat file. |
| 4872 "//third_party/icu:icudata", |
| 4873 ] |
| 4874 } |
| 4875 |
| 4876 |
| 4877 ``` |
4812 ## **include_dirs**: Additional include directories. | 4878 ## **include_dirs**: Additional include directories. |
4813 | 4879 |
4814 ``` | 4880 ``` |
4815 A list of source directories. | 4881 A list of source directories. |
4816 | 4882 |
4817 The directories in this list will be added to the include path for | 4883 The directories in this list will be added to the include path for |
4818 the files in the affected target. | 4884 the files in the affected target. |
4819 | 4885 |
4820 ``` | 4886 ``` |
4821 | 4887 |
(...skipping 1328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6150 targets only. If you need to list a static library as a runtime | 6216 targets only. If you need to list a static library as a runtime |
6151 dependency, you can manually compute the .a/.lib file name for the | 6217 dependency, you can manually compute the .a/.lib file name for the |
6152 current platform and list it in the "data" list of a target | 6218 current platform and list it in the "data" list of a target |
6153 (possibly on the static library target itself). | 6219 (possibly on the static library target itself). |
6154 | 6220 |
6155 ``` | 6221 ``` |
6156 | 6222 |
6157 ### **Multiple outputs** | 6223 ### **Multiple outputs** |
6158 | 6224 |
6159 ``` | 6225 ``` |
6160 When a tool produces more than one output, only the first output | 6226 Linker tools can specify which of their outputs should be considered |
6161 is considered. For example, a shared library target may produce a | 6227 when computing the runtime deps by setting runtime_outputs. If this |
6162 .dll and a .lib file on Windows. Only the .dll file will be considered | 6228 is unset on the tool, the default will be the first output only. |
6163 a runtime dependency. This applies only to linker tools. Scripts and | |
6164 copy steps with multiple outputs will get all outputs listed. | |
6165 | 6229 |
6166 | 6230 |
6167 ``` | 6231 ``` |
6168 ## **How Source Expansion Works** | 6232 ## **How Source Expansion Works** |
6169 | 6233 |
6170 ``` | 6234 ``` |
6171 Source expansion is used for the action_foreach and copy target types | 6235 Source expansion is used for the action_foreach and copy target types |
6172 to map source file names to output file names or arguments. | 6236 to map source file names to output file names or arguments. |
6173 | 6237 |
6174 To perform source expansion in the outputs, GN maps every entry in the | 6238 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... |
6302 ** \--root**: Explicitly specify source root. | 6366 ** \--root**: Explicitly specify source root. |
6303 ** \--runtime-deps-list-file**: Save runtime dependencies for targets in file. | 6367 ** \--runtime-deps-list-file**: Save runtime dependencies for targets in file. |
6304 ** \--script-executable**: Set the executable used to execute scripts. | 6368 ** \--script-executable**: Set the executable used to execute scripts. |
6305 ** \--threads**: Specify number of worker threads. | 6369 ** \--threads**: Specify number of worker threads. |
6306 ** \--time**: Outputs a summary of how long everything took. | 6370 ** \--time**: Outputs a summary of how long everything took. |
6307 ** \--tracelog**: Writes a Chrome-compatible trace log to the given file. | 6371 ** \--tracelog**: Writes a Chrome-compatible trace log to the given file. |
6308 ** -v**: Verbose logging. | 6372 ** -v**: Verbose logging. |
6309 ** \--version**: Prints the GN version number and exits. | 6373 ** \--version**: Prints the GN version number and exits. |
6310 | 6374 |
6311 ``` | 6375 ``` |
OLD | NEW |