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

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

Issue 1660213002: GN: Don't write ldflags and libs when unneeded. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update reference Created 4 years, 10 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/ninja_binary_target_writer.cc » ('j') | no next file with comments »
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 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 gn format //some/BUILD.gn 525 gn format //some/BUILD.gn
526 gn format some\BUILD.gn 526 gn format some\BUILD.gn
527 gn format /abspath/some/BUILD.gn 527 gn format /abspath/some/BUILD.gn
528 gn format --stdin 528 gn format --stdin
529 529
530 530
531 ``` 531 ```
532 ## **gn gen**: Generate ninja files. 532 ## **gn gen**: Generate ninja files.
533 533
534 ``` 534 ```
535 gn gen <out_dir> 535 gn gen [--ide=<ide_name>] <out_dir>
536 536
537 Generates ninja files from the current tree and puts them in the given 537 Generates ninja files from the current tree and puts them in the given
538 output directory. 538 output directory.
539 539
540 The output directory can be a source-repo-absolute path name such as: 540 The output directory can be a source-repo-absolute path name such as:
541 //out/foo 541 //out/foo
542 Or it can be a directory relative to the current directory such as: 542 Or it can be a directory relative to the current directory such as:
543 out/foo 543 out/foo
544 544
545 --ide=<ide_name>
546 Also generate files for an IDE. Currently supported values:
547 'vs' - Visual Studio project/solution files.
548
545 See "gn help switches" for the common command-line switches. 549 See "gn help switches" for the common command-line switches.
546 550
547 551
548 ``` 552 ```
549 ## **gn help <anything>** 553 ## **gn help <anything>**
550 ``` 554 ```
551 Yo dawg, I heard you like help on your help so I put help on the help 555 Yo dawg, I heard you like help on your help so I put help on the help
552 in the help. 556 in the help.
553 557
554 558
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 1. The values specified directly on the target (rather than using a 1037 1. The values specified directly on the target (rather than using a
1034 config. 1038 config.
1035 2. The configs specified in the target's "configs" list, in order. 1039 2. The configs specified in the target's "configs" list, in order.
1036 3. Public_configs from a breadth-first traversal of the dependency 1040 3. Public_configs from a breadth-first traversal of the dependency
1037 tree in the order that the targets appear in "deps". 1041 tree in the order that the targets appear in "deps".
1038 4. All dependent configs from a breadth-first traversal of the 1042 4. All dependent configs from a breadth-first traversal of the
1039 dependency tree in the order that the targets appear in "deps". 1043 dependency tree in the order that the targets appear in "deps".
1040 1044
1041 ``` 1045 ```
1042 1046
1043 ### **Variables valid in a config definition**: 1047 ### **Variables valid in a config definition**
1048
1044 ``` 1049 ```
1045 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, 1050 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc,
1046 asmflags, defines, include_dirs, ldflags, lib_dirs, libs, 1051 asmflags, defines, include_dirs, ldflags, lib_dirs, libs,
1047 precompiled_header, precompiled_source 1052 precompiled_header, precompiled_source
1053 Nested configs: configs
1048 1054
1049 ``` 1055 ```
1050 1056
1051 ### **Variables on a target used to apply configs**: 1057 ### **Variables on a target used to apply configs**
1058
1052 ``` 1059 ```
1053 all_dependent_configs, configs, public_configs 1060 all_dependent_configs, configs, public_configs
1054 1061
1055 ``` 1062 ```
1056 1063
1057 ### **Example**: 1064 ### **Example**
1065
1058 ``` 1066 ```
1059 config("myconfig") { 1067 config("myconfig") {
1060 includes = [ "include/common" ] 1068 includes = [ "include/common" ]
1061 defines = [ "ENABLE_DOOM_MELON" ] 1069 defines = [ "ENABLE_DOOM_MELON" ]
1062 } 1070 }
1063 1071
1064 executable("mything") { 1072 executable("mything") {
1065 configs = [ ":myconfig" ] 1073 configs = [ ":myconfig" ]
1066 } 1074 }
1067 1075
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 } 1391 }
1384 1392
1385 # This is a template around either a target whose type depends on a 1393 # This is a template around either a target whose type depends on a
1386 # global variable. It forwards all values from the invoker. 1394 # global variable. It forwards all values from the invoker.
1387 template("my_wrapper") { 1395 template("my_wrapper") {
1388 target(my_wrapper_target_type, target_name) { 1396 target(my_wrapper_target_type, target_name) {
1389 forward_variables_from(invoker, "*") 1397 forward_variables_from(invoker, "*")
1390 } 1398 }
1391 } 1399 }
1392 1400
1393 # A template that wraps another. It adds behavior based on one 1401 # A template that wraps another. It adds behavior based on one
1394 # variable, and forwards all others to the nested target. 1402 # variable, and forwards all others to the nested target.
1395 template("my_ios_test_app") { 1403 template("my_ios_test_app") {
1396 ios_test_app(target_name) { 1404 ios_test_app(target_name) {
1397 forward_variables_from(invoker, "*", ["test_bundle_name"]) 1405 forward_variables_from(invoker, "*", ["test_bundle_name"])
1398 if (!defined(extra_substitutions)) { 1406 if (!defined(extra_substitutions)) {
1399 extra_substitutions = [] 1407 extra_substitutions = []
1400 } 1408 }
1401 extra_substitutions += [ "BUNDLE_ID_TEST_NAME=$test_bundle_name" ] 1409 extra_substitutions += [ "BUNDLE_ID_TEST_NAME=$test_bundle_name" ]
1402 } 1410 }
1403 } 1411 }
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
1868 1876
1869 If you want to convert a file path to be source-absolute (that is, 1877 If you want to convert a file path to be source-absolute (that is,
1870 beginning with a double slash like "//foo/bar"), you should use 1878 beginning with a double slash like "//foo/bar"), you should use
1871 the get_path_info() function. This function won't work because it will 1879 the get_path_info() function. This function won't work because it will
1872 always make relative paths, and it needs to support making paths 1880 always make relative paths, and it needs to support making paths
1873 relative to the source root, so can't also generate source-absolute 1881 relative to the source root, so can't also generate source-absolute
1874 paths without more special-cases. 1882 paths without more special-cases.
1875 1883
1876 ``` 1884 ```
1877 1885
1878 ### **Arguments**: 1886 ### **Arguments**
1879 1887
1880 ``` 1888 ```
1881 input 1889 input
1882 A string or list of strings representing file or directory names 1890 A string or list of strings representing file or directory names
1883 These can be relative paths ("foo/bar.txt"), system absolute 1891 These can be relative paths ("foo/bar.txt"), system absolute
1884 paths ("/foo/bar.txt"), or source absolute paths 1892 paths ("/foo/bar.txt"), or source absolute paths
1885 ("//foo/bar.txt"). 1893 ("//foo/bar.txt").
1886 1894
1887 new_base 1895 new_base
1888 The directory to convert the paths to be relative to. This can be 1896 The directory to convert the paths to be relative to. This can be
(...skipping 14 matching lines...) Expand all
1903 ``` 1911 ```
1904 1912
1905 ### **Return value** 1913 ### **Return value**
1906 1914
1907 ``` 1915 ```
1908 The return value will be the same type as the input value (either a 1916 The return value will be the same type as the input value (either a
1909 string or a list of strings). All relative and source-absolute file 1917 string or a list of strings). All relative and source-absolute file
1910 names will be converted to be relative to the requested output 1918 names will be converted to be relative to the requested output
1911 System-absolute paths will be unchanged. 1919 System-absolute paths will be unchanged.
1912 1920
1921 Whether an output path will end in a slash will match whether the
1922 corresponding input path ends in a slash. It will return "." or
1923 "./" (depending on whether the input ends in a slash) to avoid
1924 returning empty strings. This means if you want a root path
1925 ("//" or "/") not ending in a slash, you can add a dot ("//.").
1926
1913 ``` 1927 ```
1914 1928
1915 ### **Example** 1929 ### **Example**
1916 1930
1917 ``` 1931 ```
1918 # Convert a file in the current directory to be relative to the build 1932 # Convert a file in the current directory to be relative to the build
1919 # directory (the current dir when executing compilers and scripts). 1933 # directory (the current dir when executing compilers and scripts).
1920 foo = rebase_path("myfile.txt", root_build_dir) 1934 foo = rebase_path("myfile.txt", root_build_dir)
1921 # might produce "../../project/myfile.txt". 1935 # might produce "../../project/myfile.txt".
1922 1936
(...skipping 1422 matching lines...) Expand 10 before | Expand all | Expand 10 after
3345 those configs appear in the list. 3359 those configs appear in the list.
3346 5. all_dependent_configs pulled from dependencies, in the order of 3360 5. all_dependent_configs pulled from dependencies, in the order of
3347 the "deps" list. This is done recursively. If a config appears 3361 the "deps" list. This is done recursively. If a config appears
3348 more than once, only the first occurance will be used. 3362 more than once, only the first occurance will be used.
3349 6. public_configs pulled from dependencies, in the order of the 3363 6. public_configs pulled from dependencies, in the order of the
3350 "deps" list. If a dependency is public, they will be applied 3364 "deps" list. If a dependency is public, they will be applied
3351 recursively. 3365 recursively.
3352 3366
3353 3367
3354 ``` 3368 ```
3369 ## **assert_no_deps**: Ensure no deps on these targets.
3370
3371 ```
3372 A list of label patterns.
3373
3374 This list is a list of patterns that must not match any of the
3375 transitive dependencies of the target. These include all public,
3376 private, and data dependencies, and cross shared library boundaries.
3377 This allows you to express that undesirable code isn't accidentally
3378 added to downstream dependencies in a way that might otherwise be
3379 difficult to notice.
3380
3381 Checking does not cross executable boundaries. If a target depends on
3382 an executable, it's assumed that the executable is a tool that is
3383 producing part of the build rather than something that is linked and
3384 distributed. This allows assert_no_deps to express what is distributed
3385 in the final target rather than depend on the internal build steps
3386 (which may include non-distributable code).
3387
3388 See "gn help label_pattern" for the format of the entries in the
3389 list. These patterns allow blacklisting individual targets or whole
3390 directory hierarchies.
3391
3392 Sometimes it is desirable to enforce that many targets have no
3393 dependencies on a target or set of targets. One efficient way to
3394 express this is to create a group with the assert_no_deps rule on
3395 it, and make that group depend on all targets you want to apply that
3396 assertion to.
3397
3398 ```
3399
3400 ### **Example**
3401
3402 ```
3403 executable("doom_melon") {
3404 deps = [ "//foo:bar" ]
3405 ...
3406 assert_no_deps = [
3407 "//evil/*", # Don't link any code from the evil directory.
3408 "//foo:test_support", # This target is also disallowed.
3409 ]
3410 }
3411
3412
3413 ```
3355 ## **cflags***: Flags passed to the C compiler. 3414 ## **cflags***: Flags passed to the C compiler.
3356 3415
3357 ``` 3416 ```
3358 A list of strings. 3417 A list of strings.
3359 3418
3360 "cflags" are passed to all invocations of the C, C++, Objective C, 3419 "cflags" are passed to all invocations of the C, C++, Objective C,
3361 and Objective C++ compilers. 3420 and Objective C++ compilers.
3362 3421
3363 To target one of these variants individually, use "cflags_c", 3422 To target one of these variants individually, use "cflags_c",
3364 "cflags_cc", "cflags_objc", and "cflags_objcc", 3423 "cflags_cc", "cflags_objc", and "cflags_objcc",
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
4076 that the configs appear in the list. 4135 that the configs appear in the list.
4077 4. Those set on the "public_configs" on the target in order that 4136 4. Those set on the "public_configs" on the target in order that
4078 those configs appear in the list. 4137 those configs appear in the list.
4079 5. all_dependent_configs pulled from dependencies, in the order of 4138 5. all_dependent_configs pulled from dependencies, in the order of
4080 the "deps" list. This is done recursively. If a config appears 4139 the "deps" list. This is done recursively. If a config appears
4081 more than once, only the first occurance will be used. 4140 more than once, only the first occurance will be used.
4082 6. public_configs pulled from dependencies, in the order of the 4141 6. public_configs pulled from dependencies, in the order of the
4083 "deps" list. If a dependency is public, they will be applied 4142 "deps" list. If a dependency is public, they will be applied
4084 recursively. 4143 recursively.
4085 4144
4145 For "libs" and "lib_dirs" only, the values propagated from
4146 dependencies (as described above) are applied last assuming they
4147 are not already in the list.
4148
4086 ``` 4149 ```
4087 4150
4088 ### **Example** 4151 ### **Example**
4089 4152
4090 ``` 4153 ```
4091 lib_dirs = [ "/usr/lib/foo", "lib/doom_melon" ] 4154 lib_dirs = [ "/usr/lib/foo", "lib/doom_melon" ]
4092 4155
4093 4156
4094 ``` 4157 ```
4095 ## **libs**: Additional libraries to link. 4158 ## **libs**: Additional libraries to link.
4096 4159
4097 ``` 4160 ```
4098 A list of strings. 4161 A list of library names or library paths.
4099 4162
4100 These files will be passed to the linker, which will generally search 4163 These libraries will be linked into the final binary (executable or
4101 the library include path. Unlike a normal list of files, they will be 4164 shared library) containing the current target.
4102 passed to the linker unmodified rather than being treated as file
4103 names relative to the current build file. Generally you would set
4104 the "lib_dirs" so your library is found. If you need to specify
4105 a path, you can use "rebase_path" to convert a path to be relative
4106 to the build directory.
4107
4108 When constructing the linker command, the "lib_prefix" attribute of
4109 the linker tool in the current toolchain will be prepended to each
4110 library. So your BUILD file should not specify the switch prefix
4111 (like "-l").
4112
4113 Libraries ending in ".framework" will be special-cased: the switch
4114 "-framework" will be prepended instead of the lib_prefix, and the
4115 ".framework" suffix will be trimmed. This is to support the way Mac
4116 links framework dependencies.
4117 4165
4118 libs and lib_dirs work differently than other flags in two respects. 4166 libs and lib_dirs work differently than other flags in two respects.
4119 First, then are inherited across static library boundaries until a 4167 First, then are inherited across static library boundaries until a
4120 shared library or executable target is reached. Second, they are 4168 shared library or executable target is reached. Second, they are
4121 uniquified so each one is only passed once (the first instance of it 4169 uniquified so each one is only passed once (the first instance of it
4122 will be the one used). 4170 will be the one used).
4123 4171
4124 ``` 4172 ```
4125 4173
4174 ### **Types of libs**
4175
4176 ```
4177 There are several different things that can be expressed in libs:
4178
4179 File paths
4180 Values containing '/' will be treated as references to files in
4181 the checkout. They will be rebased to be relative to the build
4182 directory and specified in the "libs" for linker tools. This
4183 facility should be used for libraries that are checked in to the
4184 version control. For libraries that are generated by the build,
4185 use normal GN deps to link them.
4186
4187 System libraries
4188 Values not containing '/' will be treated as system library names.
4189 These will be passed unmodified to the linker and prefixed with
4190 the "lib_prefix" attribute of the linker tool. Generally you
4191 would set the "lib_dirs" so the given library is found. Your
4192 BUILD.gn file should not specify the switch (like "-l"): this
4193 will be encoded in the "lib_prefix" of the tool.
4194
4195 Apple frameworks
4196 System libraries ending in ".framework" will be special-cased:
4197 the switch "-framework" will be prepended instead of the
4198 lib_prefix, and the ".framework" suffix will be trimmed. This is
4199 to support the way Mac links framework dependencies.
4200
4201 ```
4202
4126 ### **Ordering of flags and values** 4203 ### **Ordering of flags and values**
4127 4204
4128 ``` 4205 ```
4129 1. Those set on the current target (not in a config). 4206 1. Those set on the current target (not in a config).
4130 2. Those set on the "configs" on the target in order that the 4207 2. Those set on the "configs" on the target in order that the
4131 configs appear in the list. 4208 configs appear in the list.
4132 3. Those set on the "all_dependent_configs" on the target in order 4209 3. Those set on the "all_dependent_configs" on the target in order
4133 that the configs appear in the list. 4210 that the configs appear in the list.
4134 4. Those set on the "public_configs" on the target in order that 4211 4. Those set on the "public_configs" on the target in order that
4135 those configs appear in the list. 4212 those configs appear in the list.
4136 5. all_dependent_configs pulled from dependencies, in the order of 4213 5. all_dependent_configs pulled from dependencies, in the order of
4137 the "deps" list. This is done recursively. If a config appears 4214 the "deps" list. This is done recursively. If a config appears
4138 more than once, only the first occurance will be used. 4215 more than once, only the first occurance will be used.
4139 6. public_configs pulled from dependencies, in the order of the 4216 6. public_configs pulled from dependencies, in the order of the
4140 "deps" list. If a dependency is public, they will be applied 4217 "deps" list. If a dependency is public, they will be applied
4141 recursively. 4218 recursively.
4142 4219
4220 For "libs" and "lib_dirs" only, the values propagated from
4221 dependencies (as described above) are applied last assuming they
4222 are not already in the list.
4223
4143 ``` 4224 ```
4144 4225
4145 ### **Examples** 4226 ### **Examples**
4146 4227
4147 ``` 4228 ```
4148 On Windows: 4229 On Windows:
4149 libs = [ "ctl3d.lib" ] 4230 libs = [ "ctl3d.lib" ]
4231
4150 On Linux: 4232 On Linux:
4151 libs = [ "ld" ] 4233 libs = [ "ld" ]
4152 4234
4153 4235
4154 ``` 4236 ```
4155 ## **output_extension**: Value to use for the output's file extension. 4237 ## **output_extension**: Value to use for the output's file extension.
4156 4238
4157 ``` 4239 ```
4158 Normally the file extension for a target is based on the target 4240 Normally the file extension for a target is based on the target
4159 type and the operating system, but in rare cases you will need to 4241 type and the operating system, but in rare cases you will need to
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
4845 4927
4846 ### **String literals** 4928 ### **String literals**
4847 4929
4848 ``` 4930 ```
4849 A string literal represents a string value consisting of the quoted 4931 A string literal represents a string value consisting of the quoted
4850 characters with possible escape sequences and variable expansions. 4932 characters with possible escape sequences and variable expansions.
4851 4933
4852 string = `"` { char | escape | expansion } `"` . 4934 string = `"` { char | escape | expansion } `"` .
4853 escape = `\` ( "$" | `"` | char ) . 4935 escape = `\` ( "$" | `"` | char ) .
4854 BracketExpansion = "{" ( identifier | ArrayAccess | ScopeAccess ) "}" . 4936 BracketExpansion = "{" ( identifier | ArrayAccess | ScopeAccess ) "}" .
4855 expansion = "$" ( identifier | BracketExpansion ) . 4937 Hex = "0x" [0-9A-Fa-f][0-9A-Fa-f]
4938 expansion = "$" ( identifier | BracketExpansion | Hex ) .
4856 char = /* any character except "$", `"`, or newline */ . 4939 char = /* any character except "$", `"`, or newline */ .
4857 4940
4858 After a backslash, certain sequences represent special characters: 4941 After a backslash, certain sequences represent special characters:
4859 4942
4860 \" U+0022 quotation mark 4943 \" U+0022 quotation mark
4861 \$ U+0024 dollar sign 4944 \$ U+0024 dollar sign
4862 \\ U+005C backslash 4945 \\ U+005C backslash
4863 4946
4864 All other backslashes represent themselves. 4947 All other backslashes represent themselves.
4865 4948
4949 To insert an arbitrary byte value, use $0xFF. For example, to
4950 insert a newline character: "Line one$0x0ALine two".
4951
4866 ``` 4952 ```
4867 4953
4868 ### **Punctuation** 4954 ### **Punctuation**
4869 4955
4870 ``` 4956 ```
4871 The following character sequences represent punctuation: 4957 The following character sequences represent punctuation:
4872 4958
4873 + += == != ( ) 4959 + += == != ( )
4874 - -= < <= [ ] 4960 - -= < <= [ ]
4875 ! = > >= { } 4961 ! = > >= { }
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
5222 ** -q**: Quiet mode. Don't print output on success. 5308 ** -q**: Quiet mode. Don't print output on success.
5223 ** \--root**: Explicitly specify source root. 5309 ** \--root**: Explicitly specify source root.
5224 ** \--runtime-deps-list-file**: Save runtime dependencies for targets in file. 5310 ** \--runtime-deps-list-file**: Save runtime dependencies for targets in file.
5225 ** \--threads**: Specify number of worker threads. 5311 ** \--threads**: Specify number of worker threads.
5226 ** \--time**: Outputs a summary of how long everything took. 5312 ** \--time**: Outputs a summary of how long everything took.
5227 ** \--tracelog**: Writes a Chrome-compatible trace log to the given file. 5313 ** \--tracelog**: Writes a Chrome-compatible trace log to the given file.
5228 ** -v**: Verbose logging. 5314 ** -v**: Verbose logging.
5229 ** \--version**: Prints the GN version number and exits. 5315 ** \--version**: Prints the GN version number and exits.
5230 5316
5231 ``` 5317 ```
OLDNEW
« no previous file with comments | « no previous file | tools/gn/ninja_binary_target_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698