| 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 ## Contents | 5 ## Contents |
| 6 | 6 |
| 7 * [Commands](#commands) | 7 * [Commands](#commands) |
| 8 * [analyze: Analyze which targets are affected by a list of files.](#analy
ze) | 8 * [analyze: Analyze which targets are affected by a list of files.](#analy
ze) |
| 9 * [args: Display or configure arguments declared by the build.](#args) | 9 * [args: Display or configure arguments declared by the build.](#args) |
| 10 * [check: Check header dependencies.](#check) | 10 * [check: Check header dependencies.](#check) |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 - "error": This will only be present if an error occurred, and will contain | 204 - "error": This will only be present if an error occurred, and will contain |
| 205 a string describing the error. This includes cases where the input file is | 205 a string describing the error. This includes cases where the input file is |
| 206 not in the right format, or contains invalid targets. | 206 not in the right format, or contains invalid targets. |
| 207 | 207 |
| 208 The command returns 1 if it is unable to read the input file or write the | 208 The command returns 1 if it is unable to read the input file or write the |
| 209 output file, or if there is something wrong with the build such that gen | 209 output file, or if there is something wrong with the build such that gen |
| 210 would also fail, and 0 otherwise. In particular, it returns 0 even if the | 210 would also fail, and 0 otherwise. In particular, it returns 0 even if the |
| 211 "error" key is non-empty and a non-fatal error occurred. In other words, it | 211 "error" key is non-empty and a non-fatal error occurred. In other words, it |
| 212 tries really hard to always write something to the output JSON and convey | 212 tries really hard to always write something to the output JSON and convey |
| 213 errors that way rather than via return codes. | 213 errors that way rather than via return codes. |
| 214 | |
| 215 | |
| 216 ``` | 214 ``` |
| 217 ### <a name="args"></a>**gn args <out_dir> [\--list] [\--short] [\--args]** | 215 ### <a name="args"></a>**gn args <out_dir> [\--list] [\--short] [\--args]** |
| 218 | 216 |
| 219 ``` | 217 ``` |
| 220 See also "gn help buildargs" for a more high-level overview of how | 218 See also "gn help buildargs" for a more high-level overview of how |
| 221 build arguments work. | 219 build arguments work. |
| 222 | |
| 223 ``` | 220 ``` |
| 224 | 221 |
| 225 #### **Usage** | 222 #### **Usage** |
| 226 | 223 |
| 227 ``` | 224 ``` |
| 228 gn args <out_dir> | 225 gn args <out_dir> |
| 229 Open the arguments for the given build directory in an editor. If the | 226 Open the arguments for the given build directory in an editor. If the |
| 230 given build directory doesn't exist, it will be created and an empty args | 227 given build directory doesn't exist, it will be created and an empty args |
| 231 file will be opened in the editor. You would type something like this | 228 file will be opened in the editor. You would type something like this |
| 232 into that file: | 229 into that file: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 244 Lists all build arguments available in the current configuration, or, if | 241 Lists all build arguments available in the current configuration, or, if |
| 245 an exact_arg is specified for the list flag, just that one build | 242 an exact_arg is specified for the list flag, just that one build |
| 246 argument. | 243 argument. |
| 247 | 244 |
| 248 The output will list the declaration location, current value for the | 245 The output will list the declaration location, current value for the |
| 249 build, default value (if different than the current value), and comment | 246 build, default value (if different than the current value), and comment |
| 250 preceeding the declaration. | 247 preceeding the declaration. |
| 251 | 248 |
| 252 If --short is specified, only the names and current values will be | 249 If --short is specified, only the names and current values will be |
| 253 printed. | 250 printed. |
| 254 | |
| 255 ``` | 251 ``` |
| 256 | 252 |
| 257 #### **Examples** | 253 #### **Examples** |
| 258 | 254 |
| 259 ``` | 255 ``` |
| 260 gn args out/Debug | 256 gn args out/Debug |
| 261 Opens an editor with the args for out/Debug. | 257 Opens an editor with the args for out/Debug. |
| 262 | 258 |
| 263 gn args out/Debug --list --short | 259 gn args out/Debug --list --short |
| 264 Prints all arguments with their default values for the out/Debug | 260 Prints all arguments with their default values for the out/Debug |
| 265 build. | 261 build. |
| 266 | 262 |
| 267 gn args out/Debug --list=target_cpu | 263 gn args out/Debug --list=target_cpu |
| 268 Prints information about the "target_cpu" argument for the " | 264 Prints information about the "target_cpu" argument for the " |
| 269 "out/Debug | 265 "out/Debug |
| 270 build. | 266 build. |
| 271 | 267 |
| 272 gn args --list --args="os=\"android\" enable_doom_melon=true" | 268 gn args --list --args="os=\"android\" enable_doom_melon=true" |
| 273 Prints all arguments with the default values for a build with the | 269 Prints all arguments with the default values for a build with the |
| 274 given arguments set (which may affect the values of other | 270 given arguments set (which may affect the values of other |
| 275 arguments). | 271 arguments). |
| 276 | |
| 277 | |
| 278 ``` | 272 ``` |
| 279 ### <a name="check"></a>**gn check <out_dir> [<label_pattern>] [\--force]** | 273 ### <a name="check"></a>**gn check <out_dir> [<label_pattern>] [\--force]** |
| 280 | 274 |
| 281 ``` | 275 ``` |
| 282 GN's include header checker validates that the includes for C-like source | 276 GN's include header checker validates that the includes for C-like source |
| 283 files match the build dependency graph. | 277 files match the build dependency graph. |
| 284 | 278 |
| 285 "gn check" is the same thing as "gn gen" with the "--check" flag except that | 279 "gn check" is the same thing as "gn gen" with the "--check" flag except that |
| 286 this command does not write out any build files. It's intended to be an easy | 280 this command does not write out any build files. It's intended to be an easy |
| 287 way to manually trigger include file checking. | 281 way to manually trigger include file checking. |
| 288 | 282 |
| 289 The <label_pattern> can take exact labels or patterns that match more than | 283 The <label_pattern> can take exact labels or patterns that match more than |
| 290 one (although not general regular expressions). If specified, only those | 284 one (although not general regular expressions). If specified, only those |
| 291 matching targets will be checked. See "gn help label_pattern" for details. | 285 matching targets will be checked. See "gn help label_pattern" for details. |
| 292 | |
| 293 ``` | 286 ``` |
| 294 | 287 |
| 295 #### **Command-specific switches** | 288 #### **Command-specific switches** |
| 296 | 289 |
| 297 ``` | 290 ``` |
| 298 --force | 291 --force |
| 299 Ignores specifications of "check_includes = false" and checks all | 292 Ignores specifications of "check_includes = false" and checks all |
| 300 target's files that match the target label. | 293 target's files that match the target label. |
| 301 | |
| 302 ``` | 294 ``` |
| 303 | 295 |
| 304 #### **What gets checked** | 296 #### **What gets checked** |
| 305 | 297 |
| 306 ``` | 298 ``` |
| 307 The .gn file may specify a list of targets to be checked. Only these targets | 299 The .gn file may specify a list of targets to be checked. Only these targets |
| 308 will be checked if no label_pattern is specified on the command line. | 300 will be checked if no label_pattern is specified on the command line. |
| 309 Otherwise, the command-line list is used instead. See "gn help dotfile". | 301 Otherwise, the command-line list is used instead. See "gn help dotfile". |
| 310 | 302 |
| 311 Targets can opt-out from checking with "check_includes = false" (see | 303 Targets can opt-out from checking with "check_includes = false" (see |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 | 339 |
| 348 - If a target lists files as "public", only those files are able to be | 340 - If a target lists files as "public", only those files are able to be |
| 349 included by other targets. Anything in the sources will be considered | 341 included by other targets. Anything in the sources will be considered |
| 350 private and will not be includable regardless of dependency paths. | 342 private and will not be includable regardless of dependency paths. |
| 351 | 343 |
| 352 - Ouptuts from actions are treated like public sources on that target. | 344 - Ouptuts from actions are treated like public sources on that target. |
| 353 | 345 |
| 354 - A target can include headers from a target that depends on it if the | 346 - A target can include headers from a target that depends on it if the |
| 355 other target is annotated accordingly. See "gn help | 347 other target is annotated accordingly. See "gn help |
| 356 allow_circular_includes_from". | 348 allow_circular_includes_from". |
| 357 | |
| 358 ``` | 349 ``` |
| 359 | 350 |
| 360 #### **Advice on fixing problems** | 351 #### **Advice on fixing problems** |
| 361 | 352 |
| 362 ``` | 353 ``` |
| 363 If you have a third party project that uses relative includes, it's generally | 354 If you have a third party project that uses relative includes, it's generally |
| 364 best to exclude that target from checking altogether via | 355 best to exclude that target from checking altogether via |
| 365 "check_includes = false". | 356 "check_includes = false". |
| 366 | 357 |
| 367 If you have conditional includes, make sure the build conditions and the | 358 If you have conditional includes, make sure the build conditions and the |
| 368 preprocessor conditions match, and annotate the line with "nogncheck" (see | 359 preprocessor conditions match, and annotate the line with "nogncheck" (see |
| 369 "gn help nogncheck" for an example). | 360 "gn help nogncheck" for an example). |
| 370 | 361 |
| 371 If two targets are hopelessly intertwined, use the | 362 If two targets are hopelessly intertwined, use the |
| 372 "allow_circular_includes_from" annotation. Ideally each should have identical | 363 "allow_circular_includes_from" annotation. Ideally each should have identical |
| 373 dependencies so configs inherited from those dependencies are consistent (see | 364 dependencies so configs inherited from those dependencies are consistent (see |
| 374 "gn help allow_circular_includes_from"). | 365 "gn help allow_circular_includes_from"). |
| 375 | 366 |
| 376 If you have a standalone header file or files that need to be shared between | 367 If you have a standalone header file or files that need to be shared between |
| 377 a few targets, you can consider making a source_set listing only those | 368 a few targets, you can consider making a source_set listing only those |
| 378 headers as public sources. With only header files, the source set will be a | 369 headers as public sources. With only header files, the source set will be a |
| 379 no-op from a build perspective, but will give a central place to refer to | 370 no-op from a build perspective, but will give a central place to refer to |
| 380 those headers. That source set's files will still need to pass "gn check" in | 371 those headers. That source set's files will still need to pass "gn check" in |
| 381 isolation. | 372 isolation. |
| 382 | 373 |
| 383 In rare cases it makes sense to list a header in more than one target if it | 374 In rare cases it makes sense to list a header in more than one target if it |
| 384 could be considered conceptually a member of both. | 375 could be considered conceptually a member of both. |
| 385 | |
| 386 ``` | 376 ``` |
| 387 | 377 |
| 388 #### **Examples** | 378 #### **Examples** |
| 389 | 379 |
| 390 ``` | 380 ``` |
| 391 gn check out/Debug | 381 gn check out/Debug |
| 392 Check everything. | 382 Check everything. |
| 393 | 383 |
| 394 gn check out/Default //foo:bar | 384 gn check out/Default //foo:bar |
| 395 Check only the files in the //foo:bar target. | 385 Check only the files in the //foo:bar target. |
| 396 | 386 |
| 397 gn check out/Default "//foo/* | 387 gn check out/Default "//foo/* |
| 398 Check only the files in targets in the //foo directory tree. | 388 Check only the files in targets in the //foo directory tree. |
| 399 | |
| 400 | |
| 401 ``` | 389 ``` |
| 402 ### <a name="clean"></a>**gn clean <out_dir>** | 390 ### <a name="clean"></a>**gn clean <out_dir>** |
| 403 | 391 |
| 404 ``` | 392 ``` |
| 405 Deletes the contents of the output directory except for args.gn and | 393 Deletes the contents of the output directory except for args.gn and |
| 406 creates a Ninja build environment sufficient to regenerate the build. | 394 creates a Ninja build environment sufficient to regenerate the build. |
| 407 | |
| 408 | |
| 409 ``` | 395 ``` |
| 410 ### <a name="desc"></a>**gn desc <out_dir> <label or pattern> [<what to show>] [
\--blame] "** | 396 ### <a name="desc"></a>**gn desc <out_dir> <label or pattern> [<what to show>] [
\--blame] "** |
| 411 #### **[\--format=json]** | 397 #### **[\--format=json]** |
| 412 | 398 |
| 413 ``` | 399 ``` |
| 414 Displays information about a given target or config. The build build | 400 Displays information about a given target or config. The build build |
| 415 parameters will be taken for the build in the given <out_dir>. | 401 parameters will be taken for the build in the given <out_dir>. |
| 416 | 402 |
| 417 The <label or pattern> can be a target label, a config label, or a label | 403 The <label or pattern> can be a target label, a config label, or a label |
| 418 pattern (see "gn help label_pattern"). A label pattern will only match | 404 pattern (see "gn help label_pattern"). A label pattern will only match |
| 419 targets. | 405 targets. |
| 420 | |
| 421 ``` | 406 ``` |
| 422 | 407 |
| 423 #### **Possibilities for <what to show>** | 408 #### **Possibilities for <what to show>** |
| 424 | 409 |
| 425 ``` | 410 ``` |
| 426 (If unspecified an overall summary will be displayed.) | 411 (If unspecified an overall summary will be displayed.) |
| 427 | 412 |
| 428 all_dependent_configs | 413 all_dependent_configs |
| 429 allow_circular_includes_from | 414 allow_circular_includes_from |
| 430 arflags [--blame] | 415 arflags [--blame] |
| (...skipping 20 matching lines...) Expand all Loading... |
| 451 visibility | 436 visibility |
| 452 | 437 |
| 453 runtime_deps | 438 runtime_deps |
| 454 Compute all runtime deps for the given target. This is a computed list | 439 Compute all runtime deps for the given target. This is a computed list |
| 455 and does not correspond to any GN variable, unlike most other values | 440 and does not correspond to any GN variable, unlike most other values |
| 456 here. | 441 here. |
| 457 | 442 |
| 458 The output is a list of file names relative to the build directory. See | 443 The output is a list of file names relative to the build directory. See |
| 459 "gn help runtime_deps" for how this is computed. This also works with | 444 "gn help runtime_deps" for how this is computed. This also works with |
| 460 "--blame" to see the source of the dependency. | 445 "--blame" to see the source of the dependency. |
| 461 | |
| 462 ``` | 446 ``` |
| 463 | 447 |
| 464 #### **Shared flags** | 448 #### **Shared flags** |
| 465 ``` | 449 ``` |
| 466 --all-toolchains | 450 --all-toolchains |
| 467 Normally only inputs in the default toolchain will be included. | 451 Normally only inputs in the default toolchain will be included. |
| 468 This switch will turn on matching all toolchains. | 452 This switch will turn on matching all toolchains. |
| 469 | 453 |
| 470 For example, a file is in a target might be compiled twice: | 454 For example, a file is in a target might be compiled twice: |
| 471 once in the default toolchain and once in a secondary one. Without | 455 once in the default toolchain and once in a secondary one. Without |
| 472 this flag, only the default toolchain one will be matched by | 456 this flag, only the default toolchain one will be matched by |
| 473 wildcards. With this flag, both will be matched. | 457 wildcards. With this flag, both will be matched. |
| 474 | 458 |
| 475 --format=json | 459 --format=json |
| 476 Format the output as JSON instead of text. | 460 Format the output as JSON instead of text. |
| 477 | |
| 478 ``` | 461 ``` |
| 479 | 462 |
| 480 #### **Target flags** | 463 #### **Target flags** |
| 481 | 464 |
| 482 ``` | 465 ``` |
| 483 --blame | 466 --blame |
| 484 Used with any value specified on a config, this will name the config that | 467 Used with any value specified on a config, this will name the config that |
| 485 cause that target to get the flag. This doesn't currently work for libs | 468 cause that target to get the flag. This doesn't currently work for libs |
| 486 and lib_dirs because those are inherited and are more complicated to | 469 and lib_dirs because those are inherited and are more complicated to |
| 487 figure out the blame (patches welcome). | 470 figure out the blame (patches welcome). |
| 488 | |
| 489 ``` | 471 ``` |
| 490 | 472 |
| 491 #### **Configs** | 473 #### **Configs** |
| 492 | 474 |
| 493 ``` | 475 ``` |
| 494 The "configs" section will list all configs that apply. For targets this will | 476 The "configs" section will list all configs that apply. For targets this will |
| 495 include configs specified in the "configs" variable of the target, and also | 477 include configs specified in the "configs" variable of the target, and also |
| 496 configs pushed onto this target via public or "all dependent" configs. | 478 configs pushed onto this target via public or "all dependent" configs. |
| 497 | 479 |
| 498 Configs can have child configs. Specifying --tree will show the hierarchy. | 480 Configs can have child configs. Specifying --tree will show the hierarchy. |
| 499 | |
| 500 ``` | 481 ``` |
| 501 | 482 |
| 502 #### **Printing outputs** | 483 #### **Printing outputs** |
| 503 | 484 |
| 504 ``` | 485 ``` |
| 505 The "outputs" section will list all outputs that apply, including the outputs | 486 The "outputs" section will list all outputs that apply, including the outputs |
| 506 computed from the tool definition (eg for "executable", "static_library", ... | 487 computed from the tool definition (eg for "executable", "static_library", ... |
| 507 targets). | 488 targets). |
| 508 | |
| 509 ``` | 489 ``` |
| 510 | 490 |
| 511 #### **Printing deps** | 491 #### **Printing deps** |
| 512 | 492 |
| 513 ``` | 493 ``` |
| 514 Deps will include all public, private, and data deps (TODO this could be | 494 Deps will include all public, private, and data deps (TODO this could be |
| 515 clarified and enhanced) sorted in order applying. The following may be used: | 495 clarified and enhanced) sorted in order applying. The following may be used: |
| 516 | 496 |
| 517 --all | 497 --all |
| 518 Collects all recursive dependencies and prints a sorted flat list. Also | 498 Collects all recursive dependencies and prints a sorted flat list. Also |
| (...skipping 30 matching lines...) Expand all Loading... |
| 549 unspecified, no filtering will be performed. | 529 unspecified, no filtering will be performed. |
| 550 ``` | 530 ``` |
| 551 | 531 |
| 552 #### **Note** | 532 #### **Note** |
| 553 | 533 |
| 554 ``` | 534 ``` |
| 555 This command will show the full name of directories and source files, but | 535 This command will show the full name of directories and source files, but |
| 556 when directories and source paths are written to the build file, they will be | 536 when directories and source paths are written to the build file, they will be |
| 557 adjusted to be relative to the build directory. So the values for paths | 537 adjusted to be relative to the build directory. So the values for paths |
| 558 displayed by this command won't match (but should mean the same thing). | 538 displayed by this command won't match (but should mean the same thing). |
| 559 | |
| 560 ``` | 539 ``` |
| 561 | 540 |
| 562 #### **Examples** | 541 #### **Examples** |
| 563 | 542 |
| 564 ``` | 543 ``` |
| 565 gn desc out/Debug //base:base | 544 gn desc out/Debug //base:base |
| 566 Summarizes the given target. | 545 Summarizes the given target. |
| 567 | 546 |
| 568 gn desc out/Foo :base_unittests deps --tree | 547 gn desc out/Foo :base_unittests deps --tree |
| 569 Shows a dependency tree of the "base_unittests" project in | 548 Shows a dependency tree of the "base_unittests" project in |
| 570 the current directory. | 549 the current directory. |
| 571 | 550 |
| 572 gn desc out/Debug //base defines --blame | 551 gn desc out/Debug //base defines --blame |
| 573 Shows defines set for the //base:base target, annotated by where | 552 Shows defines set for the //base:base target, annotated by where |
| 574 each one was set from. | 553 each one was set from. |
| 575 | |
| 576 | |
| 577 ``` | 554 ``` |
| 578 ### <a name="format"></a>**gn format [\--dump-tree] (\--stdin | <build_file>)** | 555 ### <a name="format"></a>**gn format [\--dump-tree] (\--stdin | <build_file>)** |
| 579 | 556 |
| 580 ``` | 557 ``` |
| 581 Formats .gn file to a standard format. | 558 Formats .gn file to a standard format. |
| 582 | 559 |
| 583 The contents of some lists ('sources', 'deps', etc.) will be sorted to a | 560 The contents of some lists ('sources', 'deps', etc.) will be sorted to a |
| 584 canonical order. To suppress this, you can add a comment of the form "# | 561 canonical order. To suppress this, you can add a comment of the form "# |
| 585 NOSORT" immediately preceeding the assignment. e.g. | 562 NOSORT" immediately preceeding the assignment. e.g. |
| 586 | 563 |
| 587 # NOSORT | 564 # NOSORT |
| 588 sources = [ | 565 sources = [ |
| 589 "z.cc", | 566 "z.cc", |
| 590 "a.cc", | 567 "a.cc", |
| 591 ] | 568 ] |
| 592 | |
| 593 ``` | 569 ``` |
| 594 | 570 |
| 595 #### **Arguments** | 571 #### **Arguments** |
| 596 | 572 |
| 597 ``` | 573 ``` |
| 598 --dry-run | 574 --dry-run |
| 599 Does not change or output anything, but sets the process exit code based | 575 Does not change or output anything, but sets the process exit code based |
| 600 on whether output would be different than what's on disk. This is useful | 576 on whether output would be different than what's on disk. This is useful |
| 601 for presubmit/lint-type checks. | 577 for presubmit/lint-type checks. |
| 602 - Exit code 0: successful format, matches on disk. | 578 - Exit code 0: successful format, matches on disk. |
| 603 - Exit code 1: general failure (parse error, etc.) | 579 - Exit code 1: general failure (parse error, etc.) |
| 604 - Exit code 2: successful format, but differs from on disk. | 580 - Exit code 2: successful format, but differs from on disk. |
| 605 | 581 |
| 606 --dump-tree | 582 --dump-tree |
| 607 For debugging, dumps the parse tree to stdout and does not update the | 583 For debugging, dumps the parse tree to stdout and does not update the |
| 608 file or print formatted output. | 584 file or print formatted output. |
| 609 | 585 |
| 610 --stdin | 586 --stdin |
| 611 Read input from stdin and write to stdout rather than update a file | 587 Read input from stdin and write to stdout rather than update a file |
| 612 in-place. | 588 in-place. |
| 613 | |
| 614 ``` | 589 ``` |
| 615 | 590 |
| 616 #### **Examples** | 591 #### **Examples** |
| 617 ``` | 592 ``` |
| 618 gn format //some/BUILD.gn | 593 gn format //some/BUILD.gn |
| 619 gn format some\\BUILD.gn | 594 gn format some\\BUILD.gn |
| 620 gn format /abspath/some/BUILD.gn | 595 gn format /abspath/some/BUILD.gn |
| 621 gn format --stdin | 596 gn format --stdin |
| 622 | |
| 623 | |
| 624 ``` | 597 ``` |
| 625 ### <a name="gen:"></a>**gn gen**: Generate ninja files. | 598 ### <a name="gen:"></a>**gn gen**: Generate ninja files. |
| 626 | 599 |
| 627 ``` | 600 ``` |
| 628 gn gen [<ide options>] <out_dir> | 601 gn gen [<ide options>] <out_dir> |
| 629 | 602 |
| 630 Generates ninja files from the current tree and puts them in the given output | 603 Generates ninja files from the current tree and puts them in the given output |
| 631 directory. | 604 directory. |
| 632 | 605 |
| 633 The output directory can be a source-repo-absolute path name such as: | 606 The output directory can be a source-repo-absolute path name such as: |
| 634 //out/foo | 607 //out/foo |
| 635 Or it can be a directory relative to the current directory such as: | 608 Or it can be a directory relative to the current directory such as: |
| 636 out/foo | 609 out/foo |
| 637 | 610 |
| 638 See "gn help switches" for the common command-line switches. | 611 See "gn help switches" for the common command-line switches. |
| 639 | |
| 640 ``` | 612 ``` |
| 641 | 613 |
| 642 #### **IDE options** | 614 #### **IDE options** |
| 643 | 615 |
| 644 ``` | 616 ``` |
| 645 GN optionally generates files for IDE. Possibilities for <ide options> | 617 GN optionally generates files for IDE. Possibilities for <ide options> |
| 646 | 618 |
| 647 --ide=<ide_name> | 619 --ide=<ide_name> |
| 648 Generate files for an IDE. Currently supported values: | 620 Generate files for an IDE. Currently supported values: |
| 649 "eclipse" - Eclipse CDT settings file. | 621 "eclipse" - Eclipse CDT settings file. |
| 650 "vs" - Visual Studio project/solution files. | 622 "vs" - Visual Studio project/solution files. |
| 651 (default Visual Studio version: 2015) | 623 (default Visual Studio version: 2015) |
| 652 "vs2013" - Visual Studio 2013 project/solution files. | 624 "vs2013" - Visual Studio 2013 project/solution files. |
| 653 "vs2015" - Visual Studio 2015 project/solution files. | 625 "vs2015" - Visual Studio 2015 project/solution files. |
| 654 "vs2017" - Visual Studio 2017 project/solution files. | 626 "vs2017" - Visual Studio 2017 project/solution files. |
| 655 "xcode" - Xcode workspace/solution files. | 627 "xcode" - Xcode workspace/solution files. |
| 656 "qtcreator" - QtCreator project files. | 628 "qtcreator" - QtCreator project files. |
| 657 "json" - JSON file containing target information | 629 "json" - JSON file containing target information |
| 658 | 630 |
| 659 --filters=<path_prefixes> | 631 --filters=<path_prefixes> |
| 660 Semicolon-separated list of label patterns used to limit the set of | 632 Semicolon-separated list of label patterns used to limit the set of |
| 661 generated projects (see "gn help label_pattern"). Only matching targets | 633 generated projects (see "gn help label_pattern"). Only matching targets |
| 662 and their dependencies will be included in the solution. Only used for | 634 and their dependencies will be included in the solution. Only used for |
| 663 Visual Studio, Xcode and JSON. | 635 Visual Studio, Xcode and JSON. |
| 664 | |
| 665 ``` | 636 ``` |
| 666 | 637 |
| 667 #### **Visual Studio Flags** | 638 #### **Visual Studio Flags** |
| 668 | 639 |
| 669 ``` | 640 ``` |
| 670 --sln=<file_name> | 641 --sln=<file_name> |
| 671 Override default sln file name ("all"). Solution file is written to the | 642 Override default sln file name ("all"). Solution file is written to the |
| 672 root build directory. | 643 root build directory. |
| 673 | 644 |
| 674 --no-deps | 645 --no-deps |
| 675 Don't include targets dependencies to the solution. Changes the way how | 646 Don't include targets dependencies to the solution. Changes the way how |
| 676 --filters option works. Only directly matching targets are included. | 647 --filters option works. Only directly matching targets are included. |
| 677 | |
| 678 ``` | 648 ``` |
| 679 | 649 |
| 680 #### **Xcode Flags** | 650 #### **Xcode Flags** |
| 681 | 651 |
| 682 ``` | 652 ``` |
| 683 --workspace=<file_name> | 653 --workspace=<file_name> |
| 684 Override defaut workspace file name ("all"). The workspace file is | 654 Override defaut workspace file name ("all"). The workspace file is |
| 685 written to the root build directory. | 655 written to the root build directory. |
| 686 | 656 |
| 687 --ninja-extra-args=<string> | 657 --ninja-extra-args=<string> |
| 688 This string is passed without any quoting to the ninja invocation | 658 This string is passed without any quoting to the ninja invocation |
| 689 command-line. Can be used to configure ninja flags, like "-j" if using | 659 command-line. Can be used to configure ninja flags, like "-j" if using |
| 690 goma for example. | 660 goma for example. |
| 691 | 661 |
| 692 --root-target=<target_name> | 662 --root-target=<target_name> |
| 693 Name of the target corresponding to "All" target in Xcode. If unset, | 663 Name of the target corresponding to "All" target in Xcode. If unset, |
| 694 "All" invokes ninja without any target and builds everything. | 664 "All" invokes ninja without any target and builds everything. |
| 695 | |
| 696 ``` | 665 ``` |
| 697 | 666 |
| 698 #### **QtCreator Flags** | 667 #### **QtCreator Flags** |
| 699 | 668 |
| 700 ``` | 669 ``` |
| 701 --root-target=<target_name> | 670 --root-target=<target_name> |
| 702 Name of the root target for which the QtCreator project will be generated | 671 Name of the root target for which the QtCreator project will be generated |
| 703 to contain files of it and its dependencies. If unset, the whole build | 672 to contain files of it and its dependencies. If unset, the whole build |
| 704 graph will be emitted. | 673 graph will be emitted. |
| 705 | |
| 706 | |
| 707 ``` | 674 ``` |
| 708 | 675 |
| 709 #### **Eclipse IDE Support** | 676 #### **Eclipse IDE Support** |
| 710 | 677 |
| 711 ``` | 678 ``` |
| 712 GN DOES NOT generate Eclipse CDT projects. Instead, it generates a settings | 679 GN DOES NOT generate Eclipse CDT projects. Instead, it generates a settings |
| 713 file which can be imported into an Eclipse CDT project. The XML file contains | 680 file which can be imported into an Eclipse CDT project. The XML file contains |
| 714 a list of include paths and defines. Because GN does not generate a full | 681 a list of include paths and defines. Because GN does not generate a full |
| 715 .cproject definition, it is not possible to properly define includes/defines | 682 .cproject definition, it is not possible to properly define includes/defines |
| 716 for each file individually. Instead, one set of includes/defines is generated | 683 for each file individually. Instead, one set of includes/defines is generated |
| 717 for the entire project. This works fairly well but may still result in a few | 684 for the entire project. This works fairly well but may still result in a few |
| 718 indexer issues here and there. | 685 indexer issues here and there. |
| 719 | |
| 720 ``` | 686 ``` |
| 721 | 687 |
| 722 #### **Generic JSON Output** | 688 #### **Generic JSON Output** |
| 723 | 689 |
| 724 ``` | 690 ``` |
| 725 Dumps target information to JSON file and optionally invokes python script on | 691 Dumps target information to JSON file and optionally invokes python script on |
| 726 generated file. See comments at the beginning of json_project_writer.cc and | 692 generated file. See comments at the beginning of json_project_writer.cc and |
| 727 desc_builder.cc for overview of JSON file format. | 693 desc_builder.cc for overview of JSON file format. |
| 728 | 694 |
| 729 --json-file-name=<json_file_name> | 695 --json-file-name=<json_file_name> |
| 730 Overrides default file name (project.json) of generated JSON file. | 696 Overrides default file name (project.json) of generated JSON file. |
| 731 | 697 |
| 732 --json-ide-script=<path_to_python_script> | 698 --json-ide-script=<path_to_python_script> |
| 733 Executes python script after the JSON file is generated. Path can be | 699 Executes python script after the JSON file is generated. Path can be |
| 734 project absolute (//), system absolute (/) or relative, in which case the | 700 project absolute (//), system absolute (/) or relative, in which case the |
| 735 output directory will be base. Path to generated JSON file will be first | 701 output directory will be base. Path to generated JSON file will be first |
| 736 argument when invoking script. | 702 argument when invoking script. |
| 737 | 703 |
| 738 --json-ide-script-args=<argument> | 704 --json-ide-script-args=<argument> |
| 739 Optional second argument that will passed to executed script. | 705 Optional second argument that will passed to executed script. |
| 740 | |
| 741 | |
| 742 ``` | 706 ``` |
| 743 ### <a name="help"></a>**gn help <anything>** | 707 ### <a name="help"></a>**gn help <anything>** |
| 744 | 708 |
| 745 ``` | 709 ``` |
| 746 Yo dawg, I heard you like help on your help so I put help on the help in the | 710 Yo dawg, I heard you like help on your help so I put help on the help in the |
| 747 help. | 711 help. |
| 748 | 712 |
| 749 You can also use "all" as the parameter to get all help at once. | 713 You can also use "all" as the parameter to get all help at once. |
| 750 | |
| 751 ``` | 714 ``` |
| 752 | 715 |
| 753 #### **Switches** | 716 #### **Switches** |
| 754 | 717 |
| 755 ``` | 718 ``` |
| 756 --markdown | 719 --markdown |
| 757 Format output in markdown syntax. | 720 Format output in markdown syntax. |
| 758 | |
| 759 ``` | 721 ``` |
| 760 | 722 |
| 761 #### **Example** | 723 #### **Example** |
| 762 | 724 |
| 763 ``` | 725 ``` |
| 764 gn help --markdown all | 726 gn help --markdown all |
| 765 Dump all help to stdout in markdown format. | 727 Dump all help to stdout in markdown format. |
| 766 | |
| 767 | |
| 768 ``` | 728 ``` |
| 769 ### <a name="ls"></a>**gn ls <out_dir> [<label_pattern>] [\--all-toolchains] [\-
-as=...]** | 729 ### <a name="ls"></a>**gn ls <out_dir> [<label_pattern>] [\--all-toolchains] [\-
-as=...]** |
| 770 ``` | 730 ``` |
| 771 [--type=...] [--testonly=...] | 731 [--type=...] [--testonly=...] |
| 772 | 732 |
| 773 Lists all targets matching the given pattern for the given build directory. | 733 Lists all targets matching the given pattern for the given build directory. |
| 774 By default, only targets in the default toolchain will be matched unless a | 734 By default, only targets in the default toolchain will be matched unless a |
| 775 toolchain is explicitly supplied. | 735 toolchain is explicitly supplied. |
| 776 | 736 |
| 777 If the label pattern is unspecified, list all targets. The label pattern is | 737 If the label pattern is unspecified, list all targets. The label pattern is |
| 778 not a general regular expression (see "gn help label_pattern"). If you need | 738 not a general regular expression (see "gn help label_pattern"). If you need |
| 779 more complex expressions, pipe the result through grep. | 739 more complex expressions, pipe the result through grep. |
| 780 | |
| 781 ``` | 740 ``` |
| 782 | 741 |
| 783 #### **Options** | 742 #### **Options** |
| 784 | 743 |
| 785 ``` | 744 ``` |
| 786 --as=(buildfile|label|output) | 745 --as=(buildfile|label|output) |
| 787 How to print targets. | 746 How to print targets. |
| 788 | 747 |
| 789 buildfile | 748 buildfile |
| 790 Prints the build files where the given target was declared as | 749 Prints the build files where the given target was declared as |
| (...skipping 15 matching lines...) Expand all Loading... |
| 806 | 765 |
| 807 --testonly=(true|false) | 766 --testonly=(true|false) |
| 808 Restrict outputs to targets with the testonly flag set | 767 Restrict outputs to targets with the testonly flag set |
| 809 accordingly. When unspecified, the target's testonly flags are | 768 accordingly. When unspecified, the target's testonly flags are |
| 810 ignored. | 769 ignored. |
| 811 | 770 |
| 812 --type=(action|copy|executable|group|loadable_module|shared_library| | 771 --type=(action|copy|executable|group|loadable_module|shared_library| |
| 813 source_set|static_library) | 772 source_set|static_library) |
| 814 Restrict outputs to targets matching the given type. If | 773 Restrict outputs to targets matching the given type. If |
| 815 unspecified, no filtering will be performed. | 774 unspecified, no filtering will be performed. |
| 816 | |
| 817 ``` | 775 ``` |
| 818 | 776 |
| 819 #### **Examples** | 777 #### **Examples** |
| 820 | 778 |
| 821 ``` | 779 ``` |
| 822 gn ls out/Debug | 780 gn ls out/Debug |
| 823 Lists all targets in the default toolchain. | 781 Lists all targets in the default toolchain. |
| 824 | 782 |
| 825 gn ls out/Debug "//base/*" | 783 gn ls out/Debug "//base/*" |
| 826 Lists all targets in the directory base and all subdirectories. | 784 Lists all targets in the directory base and all subdirectories. |
| 827 | 785 |
| 828 gn ls out/Debug "//base:*" | 786 gn ls out/Debug "//base:*" |
| 829 Lists all targets defined in //base/BUILD.gn. | 787 Lists all targets defined in //base/BUILD.gn. |
| 830 | 788 |
| 831 gn ls out/Debug //base --as=output | 789 gn ls out/Debug //base --as=output |
| 832 Lists the build output file for //base:base | 790 Lists the build output file for //base:base |
| 833 | 791 |
| 834 gn ls out/Debug --type=executable | 792 gn ls out/Debug --type=executable |
| 835 Lists all executables produced by the build. | 793 Lists all executables produced by the build. |
| 836 | 794 |
| 837 gn ls out/Debug "//base/*" --as=output | xargs ninja -C out/Debug | 795 gn ls out/Debug "//base/*" --as=output | xargs ninja -C out/Debug |
| 838 Builds all targets in //base and all subdirectories. | 796 Builds all targets in //base and all subdirectories. |
| 839 | 797 |
| 840 gn ls out/Debug //base --all-toolchains | 798 gn ls out/Debug //base --all-toolchains |
| 841 Lists all variants of the target //base:base (it may be referenced | 799 Lists all variants of the target //base:base (it may be referenced |
| 842 in multiple toolchains). | 800 in multiple toolchains). |
| 843 | |
| 844 | |
| 845 ``` | 801 ``` |
| 846 ### <a name="path"></a>**gn path <out_dir> <target_one> <target_two>** | 802 ### <a name="path"></a>**gn path <out_dir> <target_one> <target_two>** |
| 847 | 803 |
| 848 ``` | 804 ``` |
| 849 Finds paths of dependencies between two targets. Each unique path will be | 805 Finds paths of dependencies between two targets. Each unique path will be |
| 850 printed in one group, and groups will be separate by newlines. The two | 806 printed in one group, and groups will be separate by newlines. The two |
| 851 targets can appear in either order (paths will be found going in either | 807 targets can appear in either order (paths will be found going in either |
| 852 direction). | 808 direction). |
| 853 | 809 |
| 854 By default, a single path will be printed. If there is a path with only | 810 By default, a single path will be printed. If there is a path with only |
| 855 public dependencies, the shortest public path will be printed. Otherwise, the | 811 public dependencies, the shortest public path will be printed. Otherwise, the |
| 856 shortest path using either public or private dependencies will be printed. If | 812 shortest path using either public or private dependencies will be printed. If |
| 857 --with-data is specified, data deps will also be considered. If there are | 813 --with-data is specified, data deps will also be considered. If there are |
| 858 multiple shortest paths, an arbitrary one will be selected. | 814 multiple shortest paths, an arbitrary one will be selected. |
| 859 | |
| 860 ``` | 815 ``` |
| 861 | 816 |
| 862 #### **Interesting paths** | 817 #### **Interesting paths** |
| 863 | 818 |
| 864 ``` | 819 ``` |
| 865 In a large project, there can be 100's of millions of unique paths between a | 820 In a large project, there can be 100's of millions of unique paths between a |
| 866 very high level and a common low-level target. To make the output more useful | 821 very high level and a common low-level target. To make the output more useful |
| 867 (and terminate in a reasonable time), GN will not revisit sub-paths | 822 (and terminate in a reasonable time), GN will not revisit sub-paths |
| 868 previously known to lead to the target. | 823 previously known to lead to the target. |
| 869 | |
| 870 ``` | 824 ``` |
| 871 | 825 |
| 872 #### **Options** | 826 #### **Options** |
| 873 | 827 |
| 874 ``` | 828 ``` |
| 875 --all | 829 --all |
| 876 Prints all "interesting" paths found rather than just the first one. | 830 Prints all "interesting" paths found rather than just the first one. |
| 877 Public paths will be printed first in order of increasing length, followed | 831 Public paths will be printed first in order of increasing length, followed |
| 878 by non-public paths in order of increasing length. | 832 by non-public paths in order of increasing length. |
| 879 | 833 |
| 880 --public | 834 --public |
| 881 Considers only public paths. Can't be used with --with-data. | 835 Considers only public paths. Can't be used with --with-data. |
| 882 | 836 |
| 883 --with-data | 837 --with-data |
| 884 Additionally follows data deps. Without this flag, only public and private | 838 Additionally follows data deps. Without this flag, only public and private |
| 885 linked deps will be followed. Can't be used with --public. | 839 linked deps will be followed. Can't be used with --public. |
| 886 | |
| 887 ``` | 840 ``` |
| 888 | 841 |
| 889 #### **Example** | 842 #### **Example** |
| 890 | 843 |
| 891 ``` | 844 ``` |
| 892 gn path out/Default //base //tools/gn | 845 gn path out/Default //base //tools/gn |
| 893 | |
| 894 | |
| 895 ``` | 846 ``` |
| 896 ### <a name="refs"></a>**gn refs <out_dir> (<label_pattern>|<label>|<file>|@<res
ponse_file>)*** | 847 ### <a name="refs"></a>**gn refs <out_dir> (<label_pattern>|<label>|<file>|@<res
ponse_file>)*** |
| 897 ``` | 848 ``` |
| 898 [--all] [--all-toolchains] [--as=...] [--testonly=...] [--type=...] | 849 [--all] [--all-toolchains] [--as=...] [--testonly=...] [--type=...] |
| 899 | 850 |
| 900 Finds reverse dependencies (which targets reference something). The input is | 851 Finds reverse dependencies (which targets reference something). The input is |
| 901 a list containing: | 852 a list containing: |
| 902 | 853 |
| 903 - Target label: The result will be which targets depend on it. | 854 - Target label: The result will be which targets depend on it. |
| 904 | 855 |
| 905 - Config label: The result will be which targets list the given config in | 856 - Config label: The result will be which targets list the given config in |
| 906 its "configs" or "public_configs" list. | 857 its "configs" or "public_configs" list. |
| 907 | 858 |
| 908 - Label pattern: The result will be which targets depend on any target | 859 - Label pattern: The result will be which targets depend on any target |
| 909 matching the given pattern. Patterns will not match configs. These are not | 860 matching the given pattern. Patterns will not match configs. These are not |
| 910 general regular expressions, see "gn help label_pattern" for details. | 861 general regular expressions, see "gn help label_pattern" for details. |
| 911 | 862 |
| 912 - File name: The result will be which targets list the given file in its | 863 - File name: The result will be which targets list the given file in its |
| 913 "inputs", "sources", "public", "data", or "outputs". Any input that does | 864 "inputs", "sources", "public", "data", or "outputs". Any input that does |
| 914 not contain wildcards and does not match a target or a config will be | 865 not contain wildcards and does not match a target or a config will be |
| 915 treated as a file. | 866 treated as a file. |
| 916 | 867 |
| 917 - Response file: If the input starts with an "@", it will be interpreted as | 868 - Response file: If the input starts with an "@", it will be interpreted as |
| 918 a path to a file containing a list of labels or file names, one per line. | 869 a path to a file containing a list of labels or file names, one per line. |
| 919 This allows us to handle long lists of inputs without worrying about | 870 This allows us to handle long lists of inputs without worrying about |
| 920 command line limits. | 871 command line limits. |
| 921 | |
| 922 ``` | 872 ``` |
| 923 | 873 |
| 924 #### **Options** | 874 #### **Options** |
| 925 | 875 |
| 926 ``` | 876 ``` |
| 927 --all | 877 --all |
| 928 When used without --tree, will recurse and display all unique | 878 When used without --tree, will recurse and display all unique |
| 929 dependencies of the given targets. For example, if the input is a target, | 879 dependencies of the given targets. For example, if the input is a target, |
| 930 this will output all targets that depend directly or indirectly on the | 880 this will output all targets that depend directly or indirectly on the |
| 931 input. If the input is a file, this will output all targets that depend | 881 input. If the input is a file, this will output all targets that depend |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 --tree | 915 --tree |
| 966 Outputs a reverse dependency tree from the given target. Duplicates will | 916 Outputs a reverse dependency tree from the given target. Duplicates will |
| 967 be elided. Combine with --all to see a full dependency tree. | 917 be elided. Combine with --all to see a full dependency tree. |
| 968 | 918 |
| 969 Tree output can not be used with the filtering or output flags: --as, | 919 Tree output can not be used with the filtering or output flags: --as, |
| 970 --type, --testonly. | 920 --type, --testonly. |
| 971 --type=(action|copy|executable|group|loadable_module|shared_library| | 921 --type=(action|copy|executable|group|loadable_module|shared_library| |
| 972 source_set|static_library) | 922 source_set|static_library) |
| 973 Restrict outputs to targets matching the given type. If | 923 Restrict outputs to targets matching the given type. If |
| 974 unspecified, no filtering will be performed. | 924 unspecified, no filtering will be performed. |
| 975 | |
| 976 | |
| 977 ``` | 925 ``` |
| 978 | 926 |
| 979 #### **Examples (target input)** | 927 #### **Examples (target input)** |
| 980 | 928 |
| 981 ``` | 929 ``` |
| 982 gn refs out/Debug //tools/gn:gn | 930 gn refs out/Debug //tools/gn:gn |
| 983 Find all targets depending on the given exact target name. | 931 Find all targets depending on the given exact target name. |
| 984 | 932 |
| 985 gn refs out/Debug //base:i18n --as=buildfiles | xargs gvim | 933 gn refs out/Debug //base:i18n --as=buildfiles | xargs gvim |
| 986 Edit all .gn files containing references to //base:i18n | 934 Edit all .gn files containing references to //base:i18n |
| 987 | 935 |
| 988 gn refs out/Debug //base --all | 936 gn refs out/Debug //base --all |
| 989 List all targets depending directly or indirectly on //base:base. | 937 List all targets depending directly or indirectly on //base:base. |
| 990 | 938 |
| 991 gn refs out/Debug "//base/*" | 939 gn refs out/Debug "//base/*" |
| 992 List all targets depending directly on any target in //base or | 940 List all targets depending directly on any target in //base or |
| 993 its subdirectories. | 941 its subdirectories. |
| 994 | 942 |
| 995 gn refs out/Debug "//base:*" | 943 gn refs out/Debug "//base:*" |
| 996 List all targets depending directly on any target in | 944 List all targets depending directly on any target in |
| 997 //base/BUILD.gn. | 945 //base/BUILD.gn. |
| 998 | 946 |
| 999 gn refs out/Debug //base --tree | 947 gn refs out/Debug //base --tree |
| 1000 Print a reverse dependency tree of //base:base | 948 Print a reverse dependency tree of //base:base |
| 1001 | |
| 1002 ``` | 949 ``` |
| 1003 | 950 |
| 1004 #### **Examples (file input)** | 951 #### **Examples (file input)** |
| 1005 | 952 |
| 1006 ``` | 953 ``` |
| 1007 gn refs out/Debug //base/macros.h | 954 gn refs out/Debug //base/macros.h |
| 1008 Print target(s) listing //base/macros.h as a source. | 955 Print target(s) listing //base/macros.h as a source. |
| 1009 | 956 |
| 1010 gn refs out/Debug //base/macros.h --tree | 957 gn refs out/Debug //base/macros.h --tree |
| 1011 Display a reverse dependency tree to get to the given file. This | 958 Display a reverse dependency tree to get to the given file. This |
| 1012 will show how dependencies will reference that file. | 959 will show how dependencies will reference that file. |
| 1013 | 960 |
| 1014 gn refs out/Debug //base/macros.h //base/at_exit.h --all | 961 gn refs out/Debug //base/macros.h //base/at_exit.h --all |
| 1015 Display all unique targets with some dependency path to a target | 962 Display all unique targets with some dependency path to a target |
| 1016 containing either of the given files as a source. | 963 containing either of the given files as a source. |
| 1017 | 964 |
| 1018 gn refs out/Debug //base/macros.h --testonly=true --type=executable | 965 gn refs out/Debug //base/macros.h --testonly=true --type=executable |
| 1019 --all --as=output | 966 --all --as=output |
| 1020 Display the executable file names of all test executables | 967 Display the executable file names of all test executables |
| 1021 potentially affected by a change to the given file. | 968 potentially affected by a change to the given file. |
| 1022 | |
| 1023 | |
| 1024 ``` | 969 ``` |
| 1025 ## <a name="targets"></a>Target declarations | 970 ## <a name="targets"></a>Target declarations |
| 1026 | 971 |
| 1027 ### <a name="action"></a>**action**: Declare a target that runs a script a singl
e time. | 972 ### <a name="action"></a>**action**: Declare a target that runs a script a singl
e time. |
| 1028 | 973 |
| 1029 ``` | 974 ``` |
| 1030 This target type allows you to run a script a single time to produce one or | 975 This target type allows you to run a script a single time to produce one or |
| 1031 more output files. If you want to run a script once for each of a set of | 976 more output files. If you want to run a script once for each of a set of |
| 1032 input files, see "gn help action_foreach". | 977 input files, see "gn help action_foreach". |
| 1033 | |
| 1034 ``` | 978 ``` |
| 1035 | 979 |
| 1036 #### **Inputs** | 980 #### **Inputs** |
| 1037 | 981 |
| 1038 ``` | 982 ``` |
| 1039 In an action the "sources" and "inputs" are treated the same: they're both | 983 In an action the "sources" and "inputs" are treated the same: they're both |
| 1040 input dependencies on script execution with no special handling. If you want | 984 input dependencies on script execution with no special handling. If you want |
| 1041 to pass the sources to your script, you must do so explicitly by including | 985 to pass the sources to your script, you must do so explicitly by including |
| 1042 them in the "args". Note also that this means there is no special handling of | 986 them in the "args". Note also that this means there is no special handling of |
| 1043 paths since GN doesn't know which of the args are paths and not. You will | 987 paths since GN doesn't know which of the args are paths and not. You will |
| 1044 want to use rebase_path() to convert paths to be relative to the | 988 want to use rebase_path() to convert paths to be relative to the |
| 1045 root_build_dir. | 989 root_build_dir. |
| 1046 | 990 |
| 1047 You can dynamically write input dependencies (for incremental rebuilds if an | 991 You can dynamically write input dependencies (for incremental rebuilds if an |
| 1048 input file changes) by writing a depfile when the script is run (see "gn help | 992 input file changes) by writing a depfile when the script is run (see "gn help |
| 1049 depfile"). This is more flexible than "inputs". | 993 depfile"). This is more flexible than "inputs". |
| 1050 | 994 |
| 1051 If the command line length is very long, you can use response files to pass | 995 If the command line length is very long, you can use response files to pass |
| 1052 args to your script. See "gn help response_file_contents". | 996 args to your script. See "gn help response_file_contents". |
| 1053 | 997 |
| 1054 It is recommended you put inputs to your script in the "sources" variable, | 998 It is recommended you put inputs to your script in the "sources" variable, |
| 1055 and stuff like other Python files required to run your script in the "inputs" | 999 and stuff like other Python files required to run your script in the "inputs" |
| 1056 variable. | 1000 variable. |
| 1057 The "deps" and "public_deps" for an action will always be | 1001 The "deps" and "public_deps" for an action will always be |
| 1058 completed before any part of the action is run so it can depend on | 1002 completed before any part of the action is run so it can depend on |
| 1059 the output of previous steps. The "data_deps" will be built if the | 1003 the output of previous steps. The "data_deps" will be built if the |
| 1060 action is built, but may not have completed before all steps of the | 1004 action is built, but may not have completed before all steps of the |
| 1061 action are started. This can give additional parallelism in the build | 1005 action are started. This can give additional parallelism in the build |
| 1062 for runtime-only dependencies. | 1006 for runtime-only dependencies. |
| 1063 | |
| 1064 ``` | 1007 ``` |
| 1065 | 1008 |
| 1066 #### **Outputs** | 1009 #### **Outputs** |
| 1067 | 1010 |
| 1068 ``` | 1011 ``` |
| 1069 You should specify files created by your script by specifying them in the | 1012 You should specify files created by your script by specifying them in the |
| 1070 "outputs". | 1013 "outputs". |
| 1071 The script will be executed with the given arguments with the current | 1014 The script will be executed with the given arguments with the current |
| 1072 directory being that of the root build directory. If you pass files | 1015 directory being that of the root build directory. If you pass files |
| 1073 to your script, see "gn help rebase_path" for how to convert | 1016 to your script, see "gn help rebase_path" for how to convert |
| 1074 file names to be relative to the build directory (file names in the | 1017 file names to be relative to the build directory (file names in the |
| 1075 sources, outputs, and inputs will be all treated as relative to the | 1018 sources, outputs, and inputs will be all treated as relative to the |
| 1076 current build file and converted as needed automatically). | 1019 current build file and converted as needed automatically). |
| 1077 | |
| 1078 ``` | 1020 ``` |
| 1079 | 1021 |
| 1080 #### **File name handling** | 1022 #### **File name handling** |
| 1081 ``` | 1023 ``` |
| 1082 All output files must be inside the output directory of the build. | 1024 All output files must be inside the output directory of the build. |
| 1083 You would generally use |$target_out_dir| or |$target_gen_dir| to | 1025 You would generally use |$target_out_dir| or |$target_gen_dir| to |
| 1084 reference the output or generated intermediate file directories, | 1026 reference the output or generated intermediate file directories, |
| 1085 respectively. | 1027 respectively. |
| 1086 | |
| 1087 ``` | 1028 ``` |
| 1088 | 1029 |
| 1089 #### **Variables** | 1030 #### **Variables** |
| 1090 | 1031 |
| 1091 ``` | 1032 ``` |
| 1092 args, console, data, data_deps, depfile, deps, inputs, outputs*, | 1033 args, console, data, data_deps, depfile, deps, inputs, outputs*, |
| 1093 response_file_contents, script*, sources | 1034 response_file_contents, script*, sources |
| 1094 * = required | 1035 * = required |
| 1095 | |
| 1096 ``` | 1036 ``` |
| 1097 | 1037 |
| 1098 #### **Example** | 1038 #### **Example** |
| 1099 | 1039 |
| 1100 ``` | 1040 ``` |
| 1101 action("run_this_guy_once") { | 1041 action("run_this_guy_once") { |
| 1102 script = "doprocessing.py" | 1042 script = "doprocessing.py" |
| 1103 sources = [ "my_configuration.txt" ] | 1043 sources = [ "my_configuration.txt" ] |
| 1104 outputs = [ "$target_gen_dir/insightful_output.txt" ] | 1044 outputs = [ "$target_gen_dir/insightful_output.txt" ] |
| 1105 | 1045 |
| 1106 # Our script imports this Python file so we want to rebuild if it changes. | 1046 # Our script imports this Python file so we want to rebuild if it changes. |
| 1107 inputs = [ "helper_library.py" ] | 1047 inputs = [ "helper_library.py" ] |
| 1108 | 1048 |
| 1109 # Note that we have to manually pass the sources to our script if the | 1049 # Note that we have to manually pass the sources to our script if the |
| 1110 # script needs them as inputs. | 1050 # script needs them as inputs. |
| 1111 args = [ "--out", rebase_path(target_gen_dir, root_build_dir) ] + | 1051 args = [ "--out", rebase_path(target_gen_dir, root_build_dir) ] + |
| 1112 rebase_path(sources, root_build_dir) | 1052 rebase_path(sources, root_build_dir) |
| 1113 } | 1053 } |
| 1114 | |
| 1115 | |
| 1116 ``` | 1054 ``` |
| 1117 ### <a name="action_foreach"></a>**action_foreach**: Declare a target that runs
a script over a set of files. | 1055 ### <a name="action_foreach"></a>**action_foreach**: Declare a target that runs
a script over a set of files. |
| 1118 | 1056 |
| 1119 ``` | 1057 ``` |
| 1120 This target type allows you to run a script once-per-file over a set of | 1058 This target type allows you to run a script once-per-file over a set of |
| 1121 sources. If you want to run a script once that takes many files as input, see | 1059 sources. If you want to run a script once that takes many files as input, see |
| 1122 "gn help action". | 1060 "gn help action". |
| 1123 | |
| 1124 ``` | 1061 ``` |
| 1125 | 1062 |
| 1126 #### **Inputs** | 1063 #### **Inputs** |
| 1127 | 1064 |
| 1128 ``` | 1065 ``` |
| 1129 The script will be run once per file in the "sources" variable. The "outputs" | 1066 The script will be run once per file in the "sources" variable. The "outputs" |
| 1130 variable should specify one or more files with a source expansion pattern in | 1067 variable should specify one or more files with a source expansion pattern in |
| 1131 it (see "gn help source_expansion"). The output file(s) for each script | 1068 it (see "gn help source_expansion"). The output file(s) for each script |
| 1132 invocation should be unique. Normally you use "{{source_name_part}}" in each | 1069 invocation should be unique. Normally you use "{{source_name_part}}" in each |
| 1133 output file. | 1070 output file. |
| 1134 | 1071 |
| 1135 If your script takes additional data as input, such as a shared configuration | 1072 If your script takes additional data as input, such as a shared configuration |
| 1136 file or a Python module it uses, those files should be listed in the "inputs" | 1073 file or a Python module it uses, those files should be listed in the "inputs" |
| 1137 variable. These files are treated as dependencies of each script invocation. | 1074 variable. These files are treated as dependencies of each script invocation. |
| 1138 | 1075 |
| 1139 If the command line length is very long, you can use response files to pass | 1076 If the command line length is very long, you can use response files to pass |
| 1140 args to your script. See "gn help response_file_contents". | 1077 args to your script. See "gn help response_file_contents". |
| 1141 | 1078 |
| 1142 You can dynamically write input dependencies (for incremental rebuilds if an | 1079 You can dynamically write input dependencies (for incremental rebuilds if an |
| 1143 input file changes) by writing a depfile when the script is run (see "gn help | 1080 input file changes) by writing a depfile when the script is run (see "gn help |
| 1144 depfile"). This is more flexible than "inputs". | 1081 depfile"). This is more flexible than "inputs". |
| 1145 The "deps" and "public_deps" for an action will always be | 1082 The "deps" and "public_deps" for an action will always be |
| 1146 completed before any part of the action is run so it can depend on | 1083 completed before any part of the action is run so it can depend on |
| 1147 the output of previous steps. The "data_deps" will be built if the | 1084 the output of previous steps. The "data_deps" will be built if the |
| 1148 action is built, but may not have completed before all steps of the | 1085 action is built, but may not have completed before all steps of the |
| 1149 action are started. This can give additional parallelism in the build | 1086 action are started. This can give additional parallelism in the build |
| 1150 for runtime-only dependencies. | 1087 for runtime-only dependencies. |
| 1151 | |
| 1152 ``` | 1088 ``` |
| 1153 | 1089 |
| 1154 #### **Outputs** | 1090 #### **Outputs** |
| 1155 ``` | 1091 ``` |
| 1156 The script will be executed with the given arguments with the current | 1092 The script will be executed with the given arguments with the current |
| 1157 directory being that of the root build directory. If you pass files | 1093 directory being that of the root build directory. If you pass files |
| 1158 to your script, see "gn help rebase_path" for how to convert | 1094 to your script, see "gn help rebase_path" for how to convert |
| 1159 file names to be relative to the build directory (file names in the | 1095 file names to be relative to the build directory (file names in the |
| 1160 sources, outputs, and inputs will be all treated as relative to the | 1096 sources, outputs, and inputs will be all treated as relative to the |
| 1161 current build file and converted as needed automatically). | 1097 current build file and converted as needed automatically). |
| 1162 | |
| 1163 ``` | 1098 ``` |
| 1164 | 1099 |
| 1165 #### **File name handling** | 1100 #### **File name handling** |
| 1166 ``` | 1101 ``` |
| 1167 All output files must be inside the output directory of the build. | 1102 All output files must be inside the output directory of the build. |
| 1168 You would generally use |$target_out_dir| or |$target_gen_dir| to | 1103 You would generally use |$target_out_dir| or |$target_gen_dir| to |
| 1169 reference the output or generated intermediate file directories, | 1104 reference the output or generated intermediate file directories, |
| 1170 respectively. | 1105 respectively. |
| 1171 | |
| 1172 ``` | 1106 ``` |
| 1173 | 1107 |
| 1174 #### **Variables** | 1108 #### **Variables** |
| 1175 | 1109 |
| 1176 ``` | 1110 ``` |
| 1177 args, console, data, data_deps, depfile, deps, inputs, outputs*, | 1111 args, console, data, data_deps, depfile, deps, inputs, outputs*, |
| 1178 response_file_contents, script*, sources* | 1112 response_file_contents, script*, sources* |
| 1179 * = required | 1113 * = required |
| 1180 | |
| 1181 ``` | 1114 ``` |
| 1182 | 1115 |
| 1183 #### **Example** | 1116 #### **Example** |
| 1184 | 1117 |
| 1185 ``` | 1118 ``` |
| 1186 # Runs the script over each IDL file. The IDL script will generate both a .cc | 1119 # Runs the script over each IDL file. The IDL script will generate both a .cc |
| 1187 # and a .h file for each input. | 1120 # and a .h file for each input. |
| 1188 action_foreach("my_idl") { | 1121 action_foreach("my_idl") { |
| 1189 script = "idl_processor.py" | 1122 script = "idl_processor.py" |
| 1190 sources = [ "foo.idl", "bar.idl" ] | 1123 sources = [ "foo.idl", "bar.idl" ] |
| 1191 | 1124 |
| 1192 # Our script reads this file each time, so we need to list is as a | 1125 # Our script reads this file each time, so we need to list is as a |
| 1193 # dependency so we can rebuild if it changes. | 1126 # dependency so we can rebuild if it changes. |
| 1194 inputs = [ "my_configuration.txt" ] | 1127 inputs = [ "my_configuration.txt" ] |
| 1195 | 1128 |
| 1196 # Transformation from source file name to output file names. | 1129 # Transformation from source file name to output file names. |
| 1197 outputs = [ "$target_gen_dir/{{source_name_part}}.h", | 1130 outputs = [ "$target_gen_dir/{{source_name_part}}.h", |
| 1198 "$target_gen_dir/{{source_name_part}}.cc" ] | 1131 "$target_gen_dir/{{source_name_part}}.cc" ] |
| 1199 | 1132 |
| 1200 # Note that since "args" is opaque to GN, if you specify paths here, you | 1133 # Note that since "args" is opaque to GN, if you specify paths here, you |
| 1201 # will need to convert it to be relative to the build directory using | 1134 # will need to convert it to be relative to the build directory using |
| 1202 # rebase_path(). | 1135 # rebase_path(). |
| 1203 args = [ | 1136 args = [ |
| 1204 "{{source}}", | 1137 "{{source}}", |
| 1205 "-o", | 1138 "-o", |
| 1206 rebase_path(relative_target_gen_dir, root_build_dir) + | 1139 rebase_path(relative_target_gen_dir, root_build_dir) + |
| 1207 "/{{source_name_part}}.h" ] | 1140 "/{{source_name_part}}.h" ] |
| 1208 } | 1141 } |
| 1209 | |
| 1210 | |
| 1211 ``` | 1142 ``` |
| 1212 ### <a name="bundle_data"></a>**bundle_data**: [iOS/OS X] Declare a target witho
ut output. | 1143 ### <a name="bundle_data"></a>**bundle_data**: [iOS/OS X] Declare a target witho
ut output. |
| 1213 | 1144 |
| 1214 ``` | 1145 ``` |
| 1215 This target type allows to declare data that is required at runtime. It is | 1146 This target type allows to declare data that is required at runtime. It is |
| 1216 used to inform "create_bundle" targets of the files to copy into generated | 1147 used to inform "create_bundle" targets of the files to copy into generated |
| 1217 bundle, see "gn help create_bundle" for help. | 1148 bundle, see "gn help create_bundle" for help. |
| 1218 | 1149 |
| 1219 The target must define a list of files as "sources" and a single "outputs". | 1150 The target must define a list of files as "sources" and a single "outputs". |
| 1220 If there are multiple files, source expansions must be used to express the | 1151 If there are multiple files, source expansions must be used to express the |
| 1221 output. The output must reference a file inside of {{bundle_root_dir}}. | 1152 output. The output must reference a file inside of {{bundle_root_dir}}. |
| 1222 | 1153 |
| 1223 This target can be used on all platforms though it is designed only to | 1154 This target can be used on all platforms though it is designed only to |
| 1224 generate iOS/OS X bundle. In cross-platform projects, it is advised to put it | 1155 generate iOS/OS X bundle. In cross-platform projects, it is advised to put it |
| 1225 behind iOS/Mac conditionals. | 1156 behind iOS/Mac conditionals. |
| 1226 | 1157 |
| 1227 See "gn help create_bundle" for more information. | 1158 See "gn help create_bundle" for more information. |
| 1228 | |
| 1229 ``` | 1159 ``` |
| 1230 | 1160 |
| 1231 #### **Variables** | 1161 #### **Variables** |
| 1232 | 1162 |
| 1233 ``` | 1163 ``` |
| 1234 sources*, outputs*, deps, data_deps, public_deps, visibility | 1164 sources*, outputs*, deps, data_deps, public_deps, visibility |
| 1235 * = required | 1165 * = required |
| 1236 | |
| 1237 ``` | 1166 ``` |
| 1238 | 1167 |
| 1239 #### **Examples** | 1168 #### **Examples** |
| 1240 | 1169 |
| 1241 ``` | 1170 ``` |
| 1242 bundle_data("icudata") { | 1171 bundle_data("icudata") { |
| 1243 sources = [ "sources/data/in/icudtl.dat" ] | 1172 sources = [ "sources/data/in/icudtl.dat" ] |
| 1244 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ] | 1173 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ] |
| 1245 } | 1174 } |
| 1246 | 1175 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1257 "src/MaterialTypography.bundle/Roboto-Bold.ttf", | 1186 "src/MaterialTypography.bundle/Roboto-Bold.ttf", |
| 1258 "src/MaterialTypography.bundle/Roboto-Italic.ttf", | 1187 "src/MaterialTypography.bundle/Roboto-Italic.ttf", |
| 1259 "src/MaterialTypography.bundle/Roboto-Regular.ttf", | 1188 "src/MaterialTypography.bundle/Roboto-Regular.ttf", |
| 1260 "src/MaterialTypography.bundle/Roboto-Thin.ttf", | 1189 "src/MaterialTypography.bundle/Roboto-Thin.ttf", |
| 1261 ] | 1190 ] |
| 1262 outputs = [ | 1191 outputs = [ |
| 1263 "{{bundle_resources_dir}}/MaterialTypography.bundle/" | 1192 "{{bundle_resources_dir}}/MaterialTypography.bundle/" |
| 1264 "{{source_file_part}}" | 1193 "{{source_file_part}}" |
| 1265 ] | 1194 ] |
| 1266 } | 1195 } |
| 1267 | |
| 1268 | |
| 1269 ``` | 1196 ``` |
| 1270 ### <a name="copy"></a>**copy**: Declare a target that copies files. | 1197 ### <a name="copy"></a>**copy**: Declare a target that copies files. |
| 1271 | 1198 |
| 1272 #### **File name handling** | 1199 #### **File name handling** |
| 1273 | 1200 |
| 1274 ``` | 1201 ``` |
| 1275 All output files must be inside the output directory of the build. You would | 1202 All output files must be inside the output directory of the build. You would |
| 1276 generally use |$target_out_dir| or |$target_gen_dir| to reference the output | 1203 generally use |$target_out_dir| or |$target_gen_dir| to reference the output |
| 1277 or generated intermediate file directories, respectively. | 1204 or generated intermediate file directories, respectively. |
| 1278 | 1205 |
| 1279 Both "sources" and "outputs" must be specified. Sources can include as many | 1206 Both "sources" and "outputs" must be specified. Sources can include as many |
| 1280 files as you want, but there can only be one item in the outputs list (plural | 1207 files as you want, but there can only be one item in the outputs list (plural |
| 1281 is used for the name for consistency with other target types). | 1208 is used for the name for consistency with other target types). |
| 1282 | 1209 |
| 1283 If there is more than one source file, your output name should specify a | 1210 If there is more than one source file, your output name should specify a |
| 1284 mapping from each source file to an output file name using source expansion | 1211 mapping from each source file to an output file name using source expansion |
| 1285 (see "gn help source_expansion"). The placeholders will look like | 1212 (see "gn help source_expansion"). The placeholders will look like |
| 1286 "{{source_name_part}}", for example. | 1213 "{{source_name_part}}", for example. |
| 1287 | |
| 1288 ``` | 1214 ``` |
| 1289 | 1215 |
| 1290 #### **Examples** | 1216 #### **Examples** |
| 1291 | 1217 |
| 1292 ``` | 1218 ``` |
| 1293 # Write a rule that copies a checked-in DLL to the output directory. | 1219 # Write a rule that copies a checked-in DLL to the output directory. |
| 1294 copy("mydll") { | 1220 copy("mydll") { |
| 1295 sources = [ "mydll.dll" ] | 1221 sources = [ "mydll.dll" ] |
| 1296 outputs = [ "$target_out_dir/mydll.dll" ] | 1222 outputs = [ "$target_out_dir/mydll.dll" ] |
| 1297 } | 1223 } |
| 1298 | 1224 |
| 1299 # Write a rule to copy several files to the target generated files directory. | 1225 # Write a rule to copy several files to the target generated files directory. |
| 1300 copy("myfiles") { | 1226 copy("myfiles") { |
| 1301 sources = [ "data1.dat", "data2.dat", "data3.dat" ] | 1227 sources = [ "data1.dat", "data2.dat", "data3.dat" ] |
| 1302 | 1228 |
| 1303 # Use source expansion to generate output files with the corresponding file | 1229 # Use source expansion to generate output files with the corresponding file |
| 1304 # names in the gen dir. This will just copy each file. | 1230 # names in the gen dir. This will just copy each file. |
| 1305 outputs = [ "$target_gen_dir/{{source_file_part}}" ] | 1231 outputs = [ "$target_gen_dir/{{source_file_part}}" ] |
| 1306 } | 1232 } |
| 1307 | |
| 1308 | |
| 1309 ``` | 1233 ``` |
| 1310 ### <a name="create_bundle"></a>**create_bundle**: [iOS/OS X] Build an OS X / iO
S bundle. | 1234 ### <a name="create_bundle"></a>**create_bundle**: [iOS/OS X] Build an OS X / iO
S bundle. |
| 1311 | 1235 |
| 1312 ``` | 1236 ``` |
| 1313 This target generates an iOS/OS X bundle (which is a directory with a | 1237 This target generates an iOS/OS X bundle (which is a directory with a |
| 1314 well-know structure). This target does not define any sources, instead they | 1238 well-know structure). This target does not define any sources, instead they |
| 1315 are computed from all "bundle_data" target this one depends on transitively | 1239 are computed from all "bundle_data" target this one depends on transitively |
| 1316 (the recursion stops at "create_bundle" targets). | 1240 (the recursion stops at "create_bundle" targets). |
| 1317 | 1241 |
| 1318 The "bundle_*_dir" properties must be defined. They will be used for the | 1242 The "bundle_*_dir" properties must be defined. They will be used for the |
| 1319 expansion of {{bundle_*_dir}} rules in "bundle_data" outputs. | 1243 expansion of {{bundle_*_dir}} rules in "bundle_data" outputs. |
| 1320 | 1244 |
| 1321 This target can be used on all platforms though it is designed only to | 1245 This target can be used on all platforms though it is designed only to |
| 1322 generate iOS/OS X bundle. In cross-platform projects, it is advised to put it | 1246 generate iOS/OS X bundle. In cross-platform projects, it is advised to put it |
| 1323 behind iOS/Mac conditionals. | 1247 behind iOS/Mac conditionals. |
| 1324 | 1248 |
| 1325 If a create_bundle is specified as a data_deps for another target, the bundle | 1249 If a create_bundle is specified as a data_deps for another target, the bundle |
| 1326 is considered a leaf, and its public and private dependencies will not | 1250 is considered a leaf, and its public and private dependencies will not |
| 1327 contribute to any data or data_deps. Required runtime dependencies should be | 1251 contribute to any data or data_deps. Required runtime dependencies should be |
| 1328 placed in the bundle. A create_bundle can declare its own explicit data and | 1252 placed in the bundle. A create_bundle can declare its own explicit data and |
| 1329 data_deps, however. | 1253 data_deps, however. |
| 1330 | |
| 1331 ``` | 1254 ``` |
| 1332 | 1255 |
| 1333 #### **Code signing** | 1256 #### **Code signing** |
| 1334 | 1257 |
| 1335 ``` | 1258 ``` |
| 1336 Some bundle needs to be code signed as part of the build (on iOS all | 1259 Some bundle needs to be code signed as part of the build (on iOS all |
| 1337 application needs to be code signed to run on a device). The code signature | 1260 application needs to be code signed to run on a device). The code signature |
| 1338 can be configured via the code_signing_script variable. | 1261 can be configured via the code_signing_script variable. |
| 1339 | 1262 |
| 1340 If set, code_signing_script is the path of a script that invoked after all | 1263 If set, code_signing_script is the path of a script that invoked after all |
| 1341 files have been moved into the bundle. The script must not change any file in | 1264 files have been moved into the bundle. The script must not change any file in |
| 1342 the bundle, but may add new files. | 1265 the bundle, but may add new files. |
| 1343 | 1266 |
| 1344 If code_signing_script is defined, then code_signing_outputs must also be | 1267 If code_signing_script is defined, then code_signing_outputs must also be |
| 1345 defined and non-empty to inform when the script needs to be re-run. The | 1268 defined and non-empty to inform when the script needs to be re-run. The |
| 1346 code_signing_args will be passed as is to the script (so path have to be | 1269 code_signing_args will be passed as is to the script (so path have to be |
| 1347 rebased) and additional inputs may be listed with the variable | 1270 rebased) and additional inputs may be listed with the variable |
| 1348 code_signing_sources. | 1271 code_signing_sources. |
| 1349 | |
| 1350 ``` | 1272 ``` |
| 1351 | 1273 |
| 1352 #### **Variables** | 1274 #### **Variables** |
| 1353 | 1275 |
| 1354 ``` | 1276 ``` |
| 1355 bundle_root_dir*, bundle_resources_dir*, bundle_executable_dir*, | 1277 bundle_root_dir*, bundle_resources_dir*, bundle_executable_dir*, |
| 1356 bundle_plugins_dir*, bundle_deps_filter, deps, data_deps, public_deps, | 1278 bundle_plugins_dir*, bundle_deps_filter, deps, data_deps, public_deps, |
| 1357 visibility, product_type, code_signing_args, code_signing_script, | 1279 visibility, product_type, code_signing_args, code_signing_script, |
| 1358 code_signing_sources, code_signing_outputs | 1280 code_signing_sources, code_signing_outputs |
| 1359 * = required | 1281 * = required |
| 1360 | |
| 1361 ``` | 1282 ``` |
| 1362 | 1283 |
| 1363 #### **Example** | 1284 #### **Example** |
| 1364 | 1285 |
| 1365 ``` | 1286 ``` |
| 1366 # Defines a template to create an application. On most platform, this is just | 1287 # Defines a template to create an application. On most platform, this is just |
| 1367 # an alias for an "executable" target, but on iOS/OS X, it builds an | 1288 # an alias for an "executable" target, but on iOS/OS X, it builds an |
| 1368 # application bundle. | 1289 # application bundle. |
| 1369 template("app") { | 1290 template("app") { |
| 1370 if (!is_ios && !is_mac) { | 1291 if (!is_ios && !is_mac) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1445 "-e=" + rebase_path( | 1366 "-e=" + rebase_path( |
| 1446 "$target_gen_dir/$app_name.xcent", root_build_dir), | 1367 "$target_gen_dir/$app_name.xcent", root_build_dir), |
| 1447 rebase_path(bundle_root_dir, root_build_dir), | 1368 rebase_path(bundle_root_dir, root_build_dir), |
| 1448 ] | 1369 ] |
| 1449 } else { | 1370 } else { |
| 1450 deps += [ ":${app_name}_bundle_executable" ] | 1371 deps += [ ":${app_name}_bundle_executable" ] |
| 1451 } | 1372 } |
| 1452 } | 1373 } |
| 1453 } | 1374 } |
| 1454 } | 1375 } |
| 1455 | |
| 1456 | |
| 1457 ``` | 1376 ``` |
| 1458 ### <a name="executable"></a>**executable**: Declare an executable target. | 1377 ### <a name="executable"></a>**executable**: Declare an executable target. |
| 1459 | 1378 |
| 1460 #### **Variables** | 1379 #### **Variables** |
| 1461 | 1380 |
| 1462 ``` | 1381 ``` |
| 1463 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, | 1382 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, |
| 1464 asmflags, defines, include_dirs, ldflags, lib_dirs, libs, | 1383 asmflags, defines, include_dirs, ldflags, lib_dirs, libs, |
| 1465 precompiled_header, precompiled_source | 1384 precompiled_header, precompiled_source |
| 1466 Deps: data_deps, deps, public_deps | 1385 Deps: data_deps, deps, public_deps |
| 1467 Dependent configs: all_dependent_configs, public_configs | 1386 Dependent configs: all_dependent_configs, public_configs |
| 1468 General: check_includes, configs, data, inputs, output_name, | 1387 General: check_includes, configs, data, inputs, output_name, |
| 1469 output_extension, public, sources, testonly, visibility | 1388 output_extension, public, sources, testonly, visibility |
| 1470 | |
| 1471 | |
| 1472 ``` | 1389 ``` |
| 1473 ### <a name="group"></a>**group**: Declare a named group of targets. | 1390 ### <a name="group"></a>**group**: Declare a named group of targets. |
| 1474 | 1391 |
| 1475 ``` | 1392 ``` |
| 1476 This target type allows you to create meta-targets that just collect a set of | 1393 This target type allows you to create meta-targets that just collect a set of |
| 1477 dependencies into one named target. Groups can additionally specify configs | 1394 dependencies into one named target. Groups can additionally specify configs |
| 1478 that apply to their dependents. | 1395 that apply to their dependents. |
| 1479 | |
| 1480 ``` | 1396 ``` |
| 1481 | 1397 |
| 1482 #### **Variables** | 1398 #### **Variables** |
| 1483 | 1399 |
| 1484 ``` | 1400 ``` |
| 1485 Deps: data_deps, deps, public_deps | 1401 Deps: data_deps, deps, public_deps |
| 1486 Dependent configs: all_dependent_configs, public_configs | 1402 Dependent configs: all_dependent_configs, public_configs |
| 1487 | |
| 1488 ``` | 1403 ``` |
| 1489 | 1404 |
| 1490 #### **Example** | 1405 #### **Example** |
| 1491 | 1406 |
| 1492 ``` | 1407 ``` |
| 1493 group("all") { | 1408 group("all") { |
| 1494 deps = [ | 1409 deps = [ |
| 1495 "//project:runner", | 1410 "//project:runner", |
| 1496 "//project:unit_tests", | 1411 "//project:unit_tests", |
| 1497 ] | 1412 ] |
| 1498 } | 1413 } |
| 1499 | |
| 1500 | |
| 1501 ``` | 1414 ``` |
| 1502 ### <a name="loadable_module"></a>**loadable_module**: Declare a loadable module
target. | 1415 ### <a name="loadable_module"></a>**loadable_module**: Declare a loadable module
target. |
| 1503 | 1416 |
| 1504 ``` | 1417 ``` |
| 1505 This target type allows you to create an object file that is (and can only | 1418 This target type allows you to create an object file that is (and can only |
| 1506 be) loaded and unloaded at runtime. | 1419 be) loaded and unloaded at runtime. |
| 1507 | 1420 |
| 1508 A loadable module will be specified on the linker line for targets listing | 1421 A loadable module will be specified on the linker line for targets listing |
| 1509 the loadable module in its "deps". If you don't want this (if you don't need | 1422 the loadable module in its "deps". If you don't want this (if you don't need |
| 1510 to dynamically load the library at runtime), then you should use a | 1423 to dynamically load the library at runtime), then you should use a |
| 1511 "shared_library" target type instead. | 1424 "shared_library" target type instead. |
| 1512 | |
| 1513 ``` | 1425 ``` |
| 1514 | 1426 |
| 1515 #### **Variables** | 1427 #### **Variables** |
| 1516 | 1428 |
| 1517 ``` | 1429 ``` |
| 1518 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, | 1430 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, |
| 1519 asmflags, defines, include_dirs, ldflags, lib_dirs, libs, | 1431 asmflags, defines, include_dirs, ldflags, lib_dirs, libs, |
| 1520 precompiled_header, precompiled_source | 1432 precompiled_header, precompiled_source |
| 1521 Deps: data_deps, deps, public_deps | 1433 Deps: data_deps, deps, public_deps |
| 1522 Dependent configs: all_dependent_configs, public_configs | 1434 Dependent configs: all_dependent_configs, public_configs |
| 1523 General: check_includes, configs, data, inputs, output_name, | 1435 General: check_includes, configs, data, inputs, output_name, |
| 1524 output_extension, public, sources, testonly, visibility | 1436 output_extension, public, sources, testonly, visibility |
| 1525 | |
| 1526 | |
| 1527 ``` | 1437 ``` |
| 1528 ### <a name="shared_library"></a>**shared_library**: Declare a shared library ta
rget. | 1438 ### <a name="shared_library"></a>**shared_library**: Declare a shared library ta
rget. |
| 1529 | 1439 |
| 1530 ``` | 1440 ``` |
| 1531 A shared library will be specified on the linker line for targets listing the | 1441 A shared library will be specified on the linker line for targets listing the |
| 1532 shared library in its "deps". If you don't want this (say you dynamically | 1442 shared library in its "deps". If you don't want this (say you dynamically |
| 1533 load the library at runtime), then you should depend on the shared library | 1443 load the library at runtime), then you should depend on the shared library |
| 1534 via "data_deps" or, on Darwin platforms, use a "loadable_module" target type | 1444 via "data_deps" or, on Darwin platforms, use a "loadable_module" target type |
| 1535 instead. | 1445 instead. |
| 1536 | |
| 1537 ``` | 1446 ``` |
| 1538 | 1447 |
| 1539 #### **Variables** | 1448 #### **Variables** |
| 1540 | 1449 |
| 1541 ``` | 1450 ``` |
| 1542 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, | 1451 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, |
| 1543 asmflags, defines, include_dirs, ldflags, lib_dirs, libs, | 1452 asmflags, defines, include_dirs, ldflags, lib_dirs, libs, |
| 1544 precompiled_header, precompiled_source | 1453 precompiled_header, precompiled_source |
| 1545 Deps: data_deps, deps, public_deps | 1454 Deps: data_deps, deps, public_deps |
| 1546 Dependent configs: all_dependent_configs, public_configs | 1455 Dependent configs: all_dependent_configs, public_configs |
| 1547 General: check_includes, configs, data, inputs, output_name, | 1456 General: check_includes, configs, data, inputs, output_name, |
| 1548 output_extension, public, sources, testonly, visibility | 1457 output_extension, public, sources, testonly, visibility |
| 1549 | |
| 1550 | |
| 1551 ``` | 1458 ``` |
| 1552 ### <a name="source_set"></a>**source_set**: Declare a source set target. | 1459 ### <a name="source_set"></a>**source_set**: Declare a source set target. |
| 1553 | 1460 |
| 1554 ``` | 1461 ``` |
| 1555 A source set is a collection of sources that get compiled, but are not linked | 1462 A source set is a collection of sources that get compiled, but are not linked |
| 1556 to produce any kind of library. Instead, the resulting object files are | 1463 to produce any kind of library. Instead, the resulting object files are |
| 1557 implicitly added to the linker line of all targets that depend on the source | 1464 implicitly added to the linker line of all targets that depend on the source |
| 1558 set. | 1465 set. |
| 1559 | 1466 |
| 1560 In most cases, a source set will behave like a static library, except no | 1467 In most cases, a source set will behave like a static library, except no |
| 1561 actual library file will be produced. This will make the build go a little | 1468 actual library file will be produced. This will make the build go a little |
| 1562 faster by skipping creation of a large static library, while maintaining the | 1469 faster by skipping creation of a large static library, while maintaining the |
| 1563 organizational benefits of focused build targets. | 1470 organizational benefits of focused build targets. |
| 1564 | 1471 |
| 1565 The main difference between a source set and a static library is around | 1472 The main difference between a source set and a static library is around |
| 1566 handling of exported symbols. Most linkers assume declaring a function | 1473 handling of exported symbols. Most linkers assume declaring a function |
| 1567 exported means exported from the static library. The linker can then do dead | 1474 exported means exported from the static library. The linker can then do dead |
| 1568 code elimination to delete code not reachable from exported functions. | 1475 code elimination to delete code not reachable from exported functions. |
| 1569 | 1476 |
| 1570 A source set will not do this code elimination since there is no link step. | 1477 A source set will not do this code elimination since there is no link step. |
| 1571 This allows you to link many sources sets into a shared library and have the | 1478 This allows you to link many sources sets into a shared library and have the |
| 1572 "exported symbol" notation indicate "export from the final shared library and | 1479 "exported symbol" notation indicate "export from the final shared library and |
| 1573 not from the intermediate targets." There is no way to express this concept | 1480 not from the intermediate targets." There is no way to express this concept |
| 1574 when linking multiple static libraries into a shared library. | 1481 when linking multiple static libraries into a shared library. |
| 1575 | |
| 1576 ``` | 1482 ``` |
| 1577 | 1483 |
| 1578 #### **Variables** | 1484 #### **Variables** |
| 1579 | 1485 |
| 1580 ``` | 1486 ``` |
| 1581 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, | 1487 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, |
| 1582 asmflags, defines, include_dirs, ldflags, lib_dirs, libs, | 1488 asmflags, defines, include_dirs, ldflags, lib_dirs, libs, |
| 1583 precompiled_header, precompiled_source | 1489 precompiled_header, precompiled_source |
| 1584 Deps: data_deps, deps, public_deps | 1490 Deps: data_deps, deps, public_deps |
| 1585 Dependent configs: all_dependent_configs, public_configs | 1491 Dependent configs: all_dependent_configs, public_configs |
| 1586 General: check_includes, configs, data, inputs, output_name, | 1492 General: check_includes, configs, data, inputs, output_name, |
| 1587 output_extension, public, sources, testonly, visibility | 1493 output_extension, public, sources, testonly, visibility |
| 1588 | |
| 1589 | |
| 1590 ``` | 1494 ``` |
| 1591 ### <a name="static_library"></a>**static_library**: Declare a static library ta
rget. | 1495 ### <a name="static_library"></a>**static_library**: Declare a static library ta
rget. |
| 1592 | 1496 |
| 1593 ``` | 1497 ``` |
| 1594 Make a ".a" / ".lib" file. | 1498 Make a ".a" / ".lib" file. |
| 1595 | 1499 |
| 1596 If you only need the static library for intermediate results in the build, | 1500 If you only need the static library for intermediate results in the build, |
| 1597 you should consider a source_set instead since it will skip the (potentially | 1501 you should consider a source_set instead since it will skip the (potentially |
| 1598 slow) step of creating the intermediate library file. | 1502 slow) step of creating the intermediate library file. |
| 1599 | |
| 1600 ``` | 1503 ``` |
| 1601 | 1504 |
| 1602 #### **Variables** | 1505 #### **Variables** |
| 1603 | 1506 |
| 1604 ``` | 1507 ``` |
| 1605 complete_static_lib | 1508 complete_static_lib |
| 1606 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, | 1509 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, |
| 1607 asmflags, defines, include_dirs, ldflags, lib_dirs, libs, | 1510 asmflags, defines, include_dirs, ldflags, lib_dirs, libs, |
| 1608 precompiled_header, precompiled_source | 1511 precompiled_header, precompiled_source |
| 1609 Deps: data_deps, deps, public_deps | 1512 Deps: data_deps, deps, public_deps |
| 1610 Dependent configs: all_dependent_configs, public_configs | 1513 Dependent configs: all_dependent_configs, public_configs |
| 1611 General: check_includes, configs, data, inputs, output_name, | 1514 General: check_includes, configs, data, inputs, output_name, |
| 1612 output_extension, public, sources, testonly, visibility | 1515 output_extension, public, sources, testonly, visibility |
| 1613 | |
| 1614 | |
| 1615 ``` | 1516 ``` |
| 1616 ### <a name="target"></a>**target**: Declare an target with the given programmat
ic type. | 1517 ### <a name="target"></a>**target**: Declare an target with the given programmat
ic type. |
| 1617 | 1518 |
| 1618 ``` | 1519 ``` |
| 1619 target(target_type_string, target_name_string) { ... } | 1520 target(target_type_string, target_name_string) { ... } |
| 1620 | 1521 |
| 1621 The target() function is a way to invoke a built-in target or template with a | 1522 The target() function is a way to invoke a built-in target or template with a |
| 1622 type determined at runtime. This is useful for cases where the type of a | 1523 type determined at runtime. This is useful for cases where the type of a |
| 1623 target might not be known statically. | 1524 target might not be known statically. |
| 1624 | 1525 |
| 1625 Only templates and built-in target functions are supported for the | 1526 Only templates and built-in target functions are supported for the |
| 1626 target_type_string parameter. Arbitrary functions, configs, and toolchains | 1527 target_type_string parameter. Arbitrary functions, configs, and toolchains |
| 1627 are not supported. | 1528 are not supported. |
| 1628 | 1529 |
| 1629 The call: | 1530 The call: |
| 1630 target("source_set", "doom_melon") { | 1531 target("source_set", "doom_melon") { |
| 1631 Is equivalent to: | 1532 Is equivalent to: |
| 1632 source_set("doom_melon") { | 1533 source_set("doom_melon") { |
| 1633 | |
| 1634 ``` | 1534 ``` |
| 1635 | 1535 |
| 1636 #### **Example** | 1536 #### **Example** |
| 1637 | 1537 |
| 1638 ``` | 1538 ``` |
| 1639 if (foo_build_as_shared) { | 1539 if (foo_build_as_shared) { |
| 1640 my_type = "shared_library" | 1540 my_type = "shared_library" |
| 1641 } else { | 1541 } else { |
| 1642 my_type = "source_set" | 1542 my_type = "source_set" |
| 1643 } | 1543 } |
| 1644 | 1544 |
| 1645 target(my_type, "foo") { | 1545 target(my_type, "foo") { |
| 1646 ... | 1546 ... |
| 1647 } | 1547 } |
| 1648 | |
| 1649 | |
| 1650 ``` | 1548 ``` |
| 1651 ## <a name="functions"></a>Buildfile functions | 1549 ## <a name="functions"></a>Buildfile functions |
| 1652 | 1550 |
| 1653 ### <a name="assert"></a>**assert**: Assert an expression is true at generation
time. | 1551 ### <a name="assert"></a>**assert**: Assert an expression is true at generation
time. |
| 1654 | 1552 |
| 1655 ``` | 1553 ``` |
| 1656 assert(<condition> [, <error string>]) | 1554 assert(<condition> [, <error string>]) |
| 1657 | 1555 |
| 1658 If the condition is false, the build will fail with an error. If the | 1556 If the condition is false, the build will fail with an error. If the |
| 1659 optional second argument is provided, that string will be printed | 1557 optional second argument is provided, that string will be printed |
| 1660 with the error message. | 1558 with the error message. |
| 1661 | |
| 1662 ``` | 1559 ``` |
| 1663 | 1560 |
| 1664 #### **Examples** | 1561 #### **Examples** |
| 1665 | 1562 |
| 1666 ``` | 1563 ``` |
| 1667 assert(is_win) | 1564 assert(is_win) |
| 1668 assert(defined(sources), "Sources must be defined"); | 1565 assert(defined(sources), "Sources must be defined"); |
| 1669 | |
| 1670 | |
| 1671 ``` | 1566 ``` |
| 1672 ### <a name="config"></a>**config**: Defines a configuration object. | 1567 ### <a name="config"></a>**config**: Defines a configuration object. |
| 1673 | 1568 |
| 1674 ``` | 1569 ``` |
| 1675 Configuration objects can be applied to targets and specify sets of compiler | 1570 Configuration objects can be applied to targets and specify sets of compiler |
| 1676 flags, includes, defines, etc. They provide a way to conveniently group sets | 1571 flags, includes, defines, etc. They provide a way to conveniently group sets |
| 1677 of this configuration information. | 1572 of this configuration information. |
| 1678 | 1573 |
| 1679 A config is referenced by its label just like a target. | 1574 A config is referenced by its label just like a target. |
| 1680 | 1575 |
| 1681 The values in a config are additive only. If you want to remove a flag you | 1576 The values in a config are additive only. If you want to remove a flag you |
| 1682 need to remove the corresponding config that sets it. The final set of flags, | 1577 need to remove the corresponding config that sets it. The final set of flags, |
| 1683 defines, etc. for a target is generated in this order: | 1578 defines, etc. for a target is generated in this order: |
| 1684 | 1579 |
| 1685 1. The values specified directly on the target (rather than using a config. | 1580 1. The values specified directly on the target (rather than using a config. |
| 1686 2. The configs specified in the target's "configs" list, in order. | 1581 2. The configs specified in the target's "configs" list, in order. |
| 1687 3. Public_configs from a breadth-first traversal of the dependency tree in | 1582 3. Public_configs from a breadth-first traversal of the dependency tree in |
| 1688 the order that the targets appear in "deps". | 1583 the order that the targets appear in "deps". |
| 1689 4. All dependent configs from a breadth-first traversal of the dependency | 1584 4. All dependent configs from a breadth-first traversal of the dependency |
| 1690 tree in the order that the targets appear in "deps". | 1585 tree in the order that the targets appear in "deps". |
| 1691 | |
| 1692 ``` | 1586 ``` |
| 1693 | 1587 |
| 1694 #### **Variables valid in a config definition** | 1588 #### **Variables valid in a config definition** |
| 1695 ``` | 1589 ``` |
| 1696 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, | 1590 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, |
| 1697 asmflags, defines, include_dirs, ldflags, lib_dirs, libs, | 1591 asmflags, defines, include_dirs, ldflags, lib_dirs, libs, |
| 1698 precompiled_header, precompiled_source | 1592 precompiled_header, precompiled_source |
| 1699 Nested configs: configs | 1593 Nested configs: configs |
| 1700 | |
| 1701 ``` | 1594 ``` |
| 1702 | 1595 |
| 1703 #### **Variables on a target used to apply configs** | 1596 #### **Variables on a target used to apply configs** |
| 1704 | 1597 |
| 1705 ``` | 1598 ``` |
| 1706 all_dependent_configs, configs, public_configs | 1599 all_dependent_configs, configs, public_configs |
| 1707 | |
| 1708 ``` | 1600 ``` |
| 1709 | 1601 |
| 1710 #### **Example** | 1602 #### **Example** |
| 1711 | 1603 |
| 1712 ``` | 1604 ``` |
| 1713 config("myconfig") { | 1605 config("myconfig") { |
| 1714 includes = [ "include/common" ] | 1606 includes = [ "include/common" ] |
| 1715 defines = [ "ENABLE_DOOM_MELON" ] | 1607 defines = [ "ENABLE_DOOM_MELON" ] |
| 1716 } | 1608 } |
| 1717 | 1609 |
| 1718 executable("mything") { | 1610 executable("mything") { |
| 1719 configs = [ ":myconfig" ] | 1611 configs = [ ":myconfig" ] |
| 1720 } | 1612 } |
| 1721 | |
| 1722 | |
| 1723 ``` | 1613 ``` |
| 1724 ### <a name="declare_args"></a>**declare_args**: Declare build arguments. | 1614 ### <a name="declare_args"></a>**declare_args**: Declare build arguments. |
| 1725 | 1615 |
| 1726 ``` | 1616 ``` |
| 1727 Introduces the given arguments into the current scope. If they are not | 1617 Introduces the given arguments into the current scope. If they are not |
| 1728 specified on the command line or in a toolchain's arguments, the default | 1618 specified on the command line or in a toolchain's arguments, the default |
| 1729 values given in the declare_args block will be used. However, these defaults | 1619 values given in the declare_args block will be used. However, these defaults |
| 1730 will not override command-line values. | 1620 will not override command-line values. |
| 1731 | 1621 |
| 1732 See also "gn help buildargs" for an overview. | 1622 See also "gn help buildargs" for an overview. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1759 on the possibly-overridden value of another, write two separate | 1649 on the possibly-overridden value of another, write two separate |
| 1760 declare_args() blocks: | 1650 declare_args() blocks: |
| 1761 | 1651 |
| 1762 declare_args() { | 1652 declare_args() { |
| 1763 enable_foo = true | 1653 enable_foo = true |
| 1764 } | 1654 } |
| 1765 declare_args() { | 1655 declare_args() { |
| 1766 # Bar defaults to same user-overridden state as foo. | 1656 # Bar defaults to same user-overridden state as foo. |
| 1767 enable_bar = enable_foo | 1657 enable_bar = enable_foo |
| 1768 } | 1658 } |
| 1769 | |
| 1770 ``` | 1659 ``` |
| 1771 | 1660 |
| 1772 #### **Example** | 1661 #### **Example** |
| 1773 | 1662 |
| 1774 ``` | 1663 ``` |
| 1775 declare_args() { | 1664 declare_args() { |
| 1776 enable_teleporter = true | 1665 enable_teleporter = true |
| 1777 enable_doom_melon = false | 1666 enable_doom_melon = false |
| 1778 } | 1667 } |
| 1779 | 1668 |
| 1780 If you want to override the (default disabled) Doom Melon: | 1669 If you want to override the (default disabled) Doom Melon: |
| 1781 gn --args="enable_doom_melon=true enable_teleporter=true" | 1670 gn --args="enable_doom_melon=true enable_teleporter=true" |
| 1782 This also sets the teleporter, but it's already defaulted to on so it will | 1671 This also sets the teleporter, but it's already defaulted to on so it will |
| 1783 have no effect. | 1672 have no effect. |
| 1784 | |
| 1785 | |
| 1786 ``` | 1673 ``` |
| 1787 ### <a name="defined"></a>**defined**: Returns whether an identifier is defined. | 1674 ### <a name="defined"></a>**defined**: Returns whether an identifier is defined. |
| 1788 | 1675 |
| 1789 ``` | 1676 ``` |
| 1790 Returns true if the given argument is defined. This is most useful in | 1677 Returns true if the given argument is defined. This is most useful in |
| 1791 templates to assert that the caller set things up properly. | 1678 templates to assert that the caller set things up properly. |
| 1792 | 1679 |
| 1793 You can pass an identifier: | 1680 You can pass an identifier: |
| 1794 defined(foo) | 1681 defined(foo) |
| 1795 which will return true or false depending on whether foo is defined in the | 1682 which will return true or false depending on whether foo is defined in the |
| 1796 current scope. | 1683 current scope. |
| 1797 | 1684 |
| 1798 You can also check a named scope: | 1685 You can also check a named scope: |
| 1799 defined(foo.bar) | 1686 defined(foo.bar) |
| 1800 which will return true or false depending on whether bar is defined in the | 1687 which will return true or false depending on whether bar is defined in the |
| 1801 named scope foo. It will throw an error if foo is not defined or is not a | 1688 named scope foo. It will throw an error if foo is not defined or is not a |
| 1802 scope. | 1689 scope. |
| 1803 | |
| 1804 ``` | 1690 ``` |
| 1805 | 1691 |
| 1806 #### **Example** | 1692 #### **Example** |
| 1807 | 1693 |
| 1808 ``` | 1694 ``` |
| 1809 template("mytemplate") { | 1695 template("mytemplate") { |
| 1810 # To help users call this template properly... | 1696 # To help users call this template properly... |
| 1811 assert(defined(invoker.sources), "Sources must be defined") | 1697 assert(defined(invoker.sources), "Sources must be defined") |
| 1812 | 1698 |
| 1813 # If we want to accept an optional "values" argument, we don't | 1699 # If we want to accept an optional "values" argument, we don't |
| 1814 # want to dereference something that may not be defined. | 1700 # want to dereference something that may not be defined. |
| 1815 if (defined(invoker.values)) { | 1701 if (defined(invoker.values)) { |
| 1816 values = invoker.values | 1702 values = invoker.values |
| 1817 } else { | 1703 } else { |
| 1818 values = "some default value" | 1704 values = "some default value" |
| 1819 } | 1705 } |
| 1820 } | 1706 } |
| 1821 | |
| 1822 | |
| 1823 ``` | 1707 ``` |
| 1824 ### <a name="exec_script"></a>**exec_script**: Synchronously run a script and re
turn the output. | 1708 ### <a name="exec_script"></a>**exec_script**: Synchronously run a script and re
turn the output. |
| 1825 | 1709 |
| 1826 ``` | 1710 ``` |
| 1827 exec_script(filename, | 1711 exec_script(filename, |
| 1828 arguments = [], | 1712 arguments = [], |
| 1829 input_conversion = "", | 1713 input_conversion = "", |
| 1830 file_dependencies = []) | 1714 file_dependencies = []) |
| 1831 | 1715 |
| 1832 Runs the given script, returning the stdout of the script. The build | 1716 Runs the given script, returning the stdout of the script. The build |
| 1833 generation will fail if the script does not exist or returns a nonzero exit | 1717 generation will fail if the script does not exist or returns a nonzero exit |
| 1834 code. | 1718 code. |
| 1835 | 1719 |
| 1836 The current directory when executing the script will be the root build | 1720 The current directory when executing the script will be the root build |
| 1837 directory. If you are passing file names, you will want to use the | 1721 directory. If you are passing file names, you will want to use the |
| 1838 rebase_path() function to make file names relative to this path (see "gn help | 1722 rebase_path() function to make file names relative to this path (see "gn help |
| 1839 rebase_path"). | 1723 rebase_path"). |
| 1840 | |
| 1841 ``` | 1724 ``` |
| 1842 | 1725 |
| 1843 #### **Arguments**: | 1726 #### **Arguments**: |
| 1844 | 1727 |
| 1845 ``` | 1728 ``` |
| 1846 filename: | 1729 filename: |
| 1847 File name of python script to execute. Non-absolute names will be treated | 1730 File name of python script to execute. Non-absolute names will be treated |
| 1848 as relative to the current build file. | 1731 as relative to the current build file. |
| 1849 | 1732 |
| 1850 arguments: | 1733 arguments: |
| 1851 A list of strings to be passed to the script as arguments. May be | 1734 A list of strings to be passed to the script as arguments. May be |
| 1852 unspecified or the empty list which means no arguments. | 1735 unspecified or the empty list which means no arguments. |
| 1853 | 1736 |
| 1854 input_conversion: | 1737 input_conversion: |
| 1855 Controls how the file is read and parsed. See "gn help input_conversion". | 1738 Controls how the file is read and parsed. See "gn help input_conversion". |
| 1856 | 1739 |
| 1857 If unspecified, defaults to the empty string which causes the script | 1740 If unspecified, defaults to the empty string which causes the script |
| 1858 result to be discarded. exec script will return None. | 1741 result to be discarded. exec script will return None. |
| 1859 | 1742 |
| 1860 dependencies: | 1743 dependencies: |
| 1861 (Optional) A list of files that this script reads or otherwise depends | 1744 (Optional) A list of files that this script reads or otherwise depends |
| 1862 on. These dependencies will be added to the build result such that if any | 1745 on. These dependencies will be added to the build result such that if any |
| 1863 of them change, the build will be regenerated and the script will be | 1746 of them change, the build will be regenerated and the script will be |
| 1864 re-run. | 1747 re-run. |
| 1865 | 1748 |
| 1866 The script itself will be an implicit dependency so you do not need to | 1749 The script itself will be an implicit dependency so you do not need to |
| 1867 list it. | 1750 list it. |
| 1868 | |
| 1869 ``` | 1751 ``` |
| 1870 | 1752 |
| 1871 #### **Example** | 1753 #### **Example** |
| 1872 | 1754 |
| 1873 ``` | 1755 ``` |
| 1874 all_lines = exec_script( | 1756 all_lines = exec_script( |
| 1875 "myscript.py", [some_input], "list lines", | 1757 "myscript.py", [some_input], "list lines", |
| 1876 [ rebase_path("data_file.txt", root_build_dir) ]) | 1758 [ rebase_path("data_file.txt", root_build_dir) ]) |
| 1877 | 1759 |
| 1878 # This example just calls the script with no arguments and discards the | 1760 # This example just calls the script with no arguments and discards the |
| 1879 # result. | 1761 # result. |
| 1880 exec_script("//foo/bar/myscript.py") | 1762 exec_script("//foo/bar/myscript.py") |
| 1881 | |
| 1882 | |
| 1883 ``` | 1763 ``` |
| 1884 ### <a name="foreach"></a>**foreach**: Iterate over a list. | 1764 ### <a name="foreach"></a>**foreach**: Iterate over a list. |
| 1885 | 1765 |
| 1886 ``` | 1766 ``` |
| 1887 foreach(<loop_var>, <list>) { | 1767 foreach(<loop_var>, <list>) { |
| 1888 <loop contents> | 1768 <loop contents> |
| 1889 } | 1769 } |
| 1890 | 1770 |
| 1891 Executes the loop contents block over each item in the list, assigning the | 1771 Executes the loop contents block over each item in the list, assigning the |
| 1892 loop_var to each item in sequence. The loop_var will be a copy so assigning | 1772 loop_var to each item in sequence. The loop_var will be a copy so assigning |
| 1893 to it will not mutate the list. | 1773 to it will not mutate the list. |
| 1894 | 1774 |
| 1895 The block does not introduce a new scope, so that variable assignments inside | 1775 The block does not introduce a new scope, so that variable assignments inside |
| 1896 the loop will be visible once the loop terminates. | 1776 the loop will be visible once the loop terminates. |
| 1897 | 1777 |
| 1898 The loop variable will temporarily shadow any existing variables with the | 1778 The loop variable will temporarily shadow any existing variables with the |
| 1899 same name for the duration of the loop. After the loop terminates the loop | 1779 same name for the duration of the loop. After the loop terminates the loop |
| 1900 variable will no longer be in scope, and the previous value (if any) will be | 1780 variable will no longer be in scope, and the previous value (if any) will be |
| 1901 restored. | 1781 restored. |
| 1902 | |
| 1903 ``` | 1782 ``` |
| 1904 | 1783 |
| 1905 #### **Example** | 1784 #### **Example** |
| 1906 | 1785 |
| 1907 ``` | 1786 ``` |
| 1908 mylist = [ "a", "b", "c" ] | 1787 mylist = [ "a", "b", "c" ] |
| 1909 foreach(i, mylist) { | 1788 foreach(i, mylist) { |
| 1910 print(i) | 1789 print(i) |
| 1911 } | 1790 } |
| 1912 | 1791 |
| 1913 Prints: | 1792 Prints: |
| 1914 a | 1793 a |
| 1915 b | 1794 b |
| 1916 c | 1795 c |
| 1917 | |
| 1918 | |
| 1919 ``` | 1796 ``` |
| 1920 ### <a name="forward_variables_from"></a>**forward_variables_from**: Copies vari
ables from a different scope. | 1797 ### <a name="forward_variables_from"></a>**forward_variables_from**: Copies vari
ables from a different scope. |
| 1921 | 1798 |
| 1922 ``` | 1799 ``` |
| 1923 forward_variables_from(from_scope, variable_list_or_star, | 1800 forward_variables_from(from_scope, variable_list_or_star, |
| 1924 variable_to_not_forward_list = []) | 1801 variable_to_not_forward_list = []) |
| 1925 | 1802 |
| 1926 Copies the given variables from the given scope to the local scope if they | 1803 Copies the given variables from the given scope to the local scope if they |
| 1927 exist. This is normally used in the context of templates to use the values of | 1804 exist. This is normally used in the context of templates to use the values of |
| 1928 variables defined in the template invocation to a template-defined target. | 1805 variables defined in the template invocation to a template-defined target. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1943 wouldn't work at all if it didn't clobber). | 1820 wouldn't work at all if it didn't clobber). |
| 1944 | 1821 |
| 1945 The sources assignment filter (see "gn help " | 1822 The sources assignment filter (see "gn help " |
| 1946 "set_sources_assignment_filter") | 1823 "set_sources_assignment_filter") |
| 1947 is never applied by this function. It's assumed than any desired filtering | 1824 is never applied by this function. It's assumed than any desired filtering |
| 1948 was already done when sources was set on the from_scope. | 1825 was already done when sources was set on the from_scope. |
| 1949 | 1826 |
| 1950 If variables_to_not_forward_list is non-empty, then it must contains a list | 1827 If variables_to_not_forward_list is non-empty, then it must contains a list |
| 1951 of variable names that will not be forwarded. This is mostly useful when | 1828 of variable names that will not be forwarded. This is mostly useful when |
| 1952 variable_list_or_star has a value of "*". | 1829 variable_list_or_star has a value of "*". |
| 1953 | |
| 1954 ``` | 1830 ``` |
| 1955 | 1831 |
| 1956 #### **Examples** | 1832 #### **Examples** |
| 1957 | 1833 |
| 1958 ``` | 1834 ``` |
| 1959 # This is a common action template. It would invoke a script with some given | 1835 # This is a common action template. It would invoke a script with some given |
| 1960 # parameters, and wants to use the various types of deps and the visibility | 1836 # parameters, and wants to use the various types of deps and the visibility |
| 1961 # from the invoker if it's defined. It also injects an additional dependency | 1837 # from the invoker if it's defined. It also injects an additional dependency |
| 1962 # to all targets. | 1838 # to all targets. |
| 1963 template("my_test") { | 1839 template("my_test") { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1987 # variable, and forwards all others to the nested target. | 1863 # variable, and forwards all others to the nested target. |
| 1988 template("my_ios_test_app") { | 1864 template("my_ios_test_app") { |
| 1989 ios_test_app(target_name) { | 1865 ios_test_app(target_name) { |
| 1990 forward_variables_from(invoker, "*", ["test_bundle_name"]) | 1866 forward_variables_from(invoker, "*", ["test_bundle_name"]) |
| 1991 if (!defined(extra_substitutions)) { | 1867 if (!defined(extra_substitutions)) { |
| 1992 extra_substitutions = [] | 1868 extra_substitutions = [] |
| 1993 } | 1869 } |
| 1994 extra_substitutions += [ "BUNDLE_ID_TEST_NAME=$test_bundle_name" ] | 1870 extra_substitutions += [ "BUNDLE_ID_TEST_NAME=$test_bundle_name" ] |
| 1995 } | 1871 } |
| 1996 } | 1872 } |
| 1997 | |
| 1998 | |
| 1999 ``` | 1873 ``` |
| 2000 ### <a name="get_label_info"></a>**get_label_info**: Get an attribute from a tar
get's label. | 1874 ### <a name="get_label_info"></a>**get_label_info**: Get an attribute from a tar
get's label. |
| 2001 | 1875 |
| 2002 ``` | 1876 ``` |
| 2003 get_label_info(target_label, what) | 1877 get_label_info(target_label, what) |
| 2004 | 1878 |
| 2005 Given the label of a target, returns some attribute of that target. The | 1879 Given the label of a target, returns some attribute of that target. The |
| 2006 target need not have been previously defined in the same file, since none of | 1880 target need not have been previously defined in the same file, since none of |
| 2007 the attributes depend on the actual target definition, only the label itself. | 1881 the attributes depend on the actual target definition, only the label itself. |
| 2008 | 1882 |
| 2009 See also "gn help get_target_outputs". | 1883 See also "gn help get_target_outputs". |
| 2010 | |
| 2011 ``` | 1884 ``` |
| 2012 | 1885 |
| 2013 #### **Possible values for the "what" parameter** | 1886 #### **Possible values for the "what" parameter** |
| 2014 | 1887 |
| 2015 ``` | 1888 ``` |
| 2016 "name" | 1889 "name" |
| 2017 The short name of the target. This will match the value of the | 1890 The short name of the target. This will match the value of the |
| 2018 "target_name" variable inside that target's declaration. For the label | 1891 "target_name" variable inside that target's declaration. For the label |
| 2019 "//foo/bar:baz" this will return "baz". | 1892 "//foo/bar:baz" this will return "baz". |
| 2020 | 1893 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2044 The fully qualified version of this label, not including the toolchain. | 1917 The fully qualified version of this label, not including the toolchain. |
| 2045 For the input ":bar" it might return "//foo:bar". | 1918 For the input ":bar" it might return "//foo:bar". |
| 2046 | 1919 |
| 2047 "label_with_toolchain" | 1920 "label_with_toolchain" |
| 2048 The fully qualified version of this label, including the toolchain. For | 1921 The fully qualified version of this label, including the toolchain. For |
| 2049 the input ":bar" it might return "//foo:bar(//toolchain:x64)". | 1922 the input ":bar" it might return "//foo:bar(//toolchain:x64)". |
| 2050 | 1923 |
| 2051 "toolchain" | 1924 "toolchain" |
| 2052 The label of the toolchain. This will match the value of the | 1925 The label of the toolchain. This will match the value of the |
| 2053 "current_toolchain" variable when inside that target's declaration. | 1926 "current_toolchain" variable when inside that target's declaration. |
| 2054 | |
| 2055 ``` | 1927 ``` |
| 2056 | 1928 |
| 2057 #### **Examples** | 1929 #### **Examples** |
| 2058 | 1930 |
| 2059 ``` | 1931 ``` |
| 2060 get_label_info(":foo", "name") | 1932 get_label_info(":foo", "name") |
| 2061 # Returns string "foo". | 1933 # Returns string "foo". |
| 2062 | 1934 |
| 2063 get_label_info("//foo/bar:baz", "gen_dir") | 1935 get_label_info("//foo/bar:baz", "gen_dir") |
| 2064 # Returns string "//out/Debug/gen/foo/bar". | 1936 # Returns string "//out/Debug/gen/foo/bar". |
| 2065 | |
| 2066 | |
| 2067 ``` | 1937 ``` |
| 2068 ### <a name="get_path_info"></a>**get_path_info**: Extract parts of a file or di
rectory name. | 1938 ### <a name="get_path_info"></a>**get_path_info**: Extract parts of a file or di
rectory name. |
| 2069 | 1939 |
| 2070 ``` | 1940 ``` |
| 2071 get_path_info(input, what) | 1941 get_path_info(input, what) |
| 2072 | 1942 |
| 2073 The first argument is either a string representing a file or directory name, | 1943 The first argument is either a string representing a file or directory name, |
| 2074 or a list of such strings. If the input is a list the return value will be a | 1944 or a list of such strings. If the input is a list the return value will be a |
| 2075 list containing the result of applying the rule to each item in the input. | 1945 list containing the result of applying the rule to each item in the input. |
| 2076 | |
| 2077 ``` | 1946 ``` |
| 2078 | 1947 |
| 2079 #### **Possible values for the "what" parameter** | 1948 #### **Possible values for the "what" parameter** |
| 2080 | 1949 |
| 2081 ``` | 1950 ``` |
| 2082 "file" | 1951 "file" |
| 2083 The substring after the last slash in the path, including the name and | 1952 The substring after the last slash in the path, including the name and |
| 2084 extension. If the input ends in a slash, the empty string will be | 1953 extension. If the input ends in a slash, the empty string will be |
| 2085 returned. | 1954 returned. |
| 2086 "foo/bar.txt" => "bar.txt" | 1955 "foo/bar.txt" => "bar.txt" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2125 relative to the current directory, and then the source- absolute version | 1994 relative to the current directory, and then the source- absolute version |
| 2126 will be returned. If the input is system- absolute, the same input will | 1995 will be returned. If the input is system- absolute, the same input will |
| 2127 be returned. | 1996 be returned. |
| 2128 "foo/bar.txt" => "//mydir/foo/bar.txt" | 1997 "foo/bar.txt" => "//mydir/foo/bar.txt" |
| 2129 "foo/" => "//mydir/foo/" | 1998 "foo/" => "//mydir/foo/" |
| 2130 "//foo/bar" => "//foo/bar" (already absolute) | 1999 "//foo/bar" => "//foo/bar" (already absolute) |
| 2131 "/usr/include" => "/usr/include" (already absolute) | 2000 "/usr/include" => "/usr/include" (already absolute) |
| 2132 | 2001 |
| 2133 If you want to make the path relative to another directory, or to be | 2002 If you want to make the path relative to another directory, or to be |
| 2134 system-absolute, see rebase_path(). | 2003 system-absolute, see rebase_path(). |
| 2135 | |
| 2136 ``` | 2004 ``` |
| 2137 | 2005 |
| 2138 #### **Examples** | 2006 #### **Examples** |
| 2139 ``` | 2007 ``` |
| 2140 sources = [ "foo.cc", "foo.h" ] | 2008 sources = [ "foo.cc", "foo.h" ] |
| 2141 result = get_path_info(source, "abspath") | 2009 result = get_path_info(source, "abspath") |
| 2142 # result will be [ "//mydir/foo.cc", "//mydir/foo.h" ] | 2010 # result will be [ "//mydir/foo.cc", "//mydir/foo.h" ] |
| 2143 | 2011 |
| 2144 result = get_path_info("//foo/bar/baz.cc", "dir") | 2012 result = get_path_info("//foo/bar/baz.cc", "dir") |
| 2145 # result will be "//foo/bar" | 2013 # result will be "//foo/bar" |
| 2146 | 2014 |
| 2147 # Extract the source-absolute directory name, | 2015 # Extract the source-absolute directory name, |
| 2148 result = get_path_info(get_path_info(path, "dir"), "abspath" | 2016 result = get_path_info(get_path_info(path, "dir"), "abspath" |
| 2149 | |
| 2150 | |
| 2151 ``` | 2017 ``` |
| 2152 ### <a name="get_target_outputs"></a>**get_target_outputs**: [file list] Get the
list of outputs from a target. | 2018 ### <a name="get_target_outputs"></a>**get_target_outputs**: [file list] Get the
list of outputs from a target. |
| 2153 | 2019 |
| 2154 ``` | 2020 ``` |
| 2155 get_target_outputs(target_label) | 2021 get_target_outputs(target_label) |
| 2156 | 2022 |
| 2157 Returns a list of output files for the named target. The named target must | 2023 Returns a list of output files for the named target. The named target must |
| 2158 have been previously defined in the current file before this function is | 2024 have been previously defined in the current file before this function is |
| 2159 called (it can't reference targets in other files because there isn't a | 2025 called (it can't reference targets in other files because there isn't a |
| 2160 defined execution order, and it obviously can't reference targets that are | 2026 defined execution order, and it obviously can't reference targets that are |
| 2161 defined after the function call). | 2027 defined after the function call). |
| 2162 | 2028 |
| 2163 Only copy and action targets are supported. The outputs from binary targets | 2029 Only copy and action targets are supported. The outputs from binary targets |
| 2164 will depend on the toolchain definition which won't necessarily have been | 2030 will depend on the toolchain definition which won't necessarily have been |
| 2165 loaded by the time a given line of code has run, and source sets and groups | 2031 loaded by the time a given line of code has run, and source sets and groups |
| 2166 have no useful output file. | 2032 have no useful output file. |
| 2167 | |
| 2168 ``` | 2033 ``` |
| 2169 | 2034 |
| 2170 #### **Return value** | 2035 #### **Return value** |
| 2171 | 2036 |
| 2172 ``` | 2037 ``` |
| 2173 The names in the resulting list will be absolute file paths (normally like | 2038 The names in the resulting list will be absolute file paths (normally like |
| 2174 "//out/Debug/bar.exe", depending on the build directory). | 2039 "//out/Debug/bar.exe", depending on the build directory). |
| 2175 | 2040 |
| 2176 action targets: this will just return the files specified in the "outputs" | 2041 action targets: this will just return the files specified in the "outputs" |
| 2177 variable of the target. | 2042 variable of the target. |
| 2178 | 2043 |
| 2179 action_foreach targets: this will return the result of applying the output | 2044 action_foreach targets: this will return the result of applying the output |
| 2180 template to the sources (see "gn help source_expansion"). This will be the | 2045 template to the sources (see "gn help source_expansion"). This will be the |
| 2181 same result (though with guaranteed absolute file paths), as | 2046 same result (though with guaranteed absolute file paths), as |
| 2182 process_file_template will return for those inputs (see "gn help | 2047 process_file_template will return for those inputs (see "gn help |
| 2183 process_file_template"). | 2048 process_file_template"). |
| 2184 | 2049 |
| 2185 binary targets (executables, libraries): this will return a list of the | 2050 binary targets (executables, libraries): this will return a list of the |
| 2186 resulting binary file(s). The "main output" (the actual binary or library) | 2051 resulting binary file(s). The "main output" (the actual binary or library) |
| 2187 will always be the 0th element in the result. Depending on the platform and | 2052 will always be the 0th element in the result. Depending on the platform and |
| 2188 output type, there may be other output files as well (like import libraries) | 2053 output type, there may be other output files as well (like import libraries) |
| 2189 which will follow. | 2054 which will follow. |
| 2190 | 2055 |
| 2191 source sets and groups: this will return a list containing the path of the | 2056 source sets and groups: this will return a list containing the path of the |
| 2192 "stamp" file that Ninja will produce once all outputs are generated. This | 2057 "stamp" file that Ninja will produce once all outputs are generated. This |
| 2193 probably isn't very useful. | 2058 probably isn't very useful. |
| 2194 | |
| 2195 ``` | 2059 ``` |
| 2196 | 2060 |
| 2197 #### **Example** | 2061 #### **Example** |
| 2198 | 2062 |
| 2199 ``` | 2063 ``` |
| 2200 # Say this action generates a bunch of C source files. | 2064 # Say this action generates a bunch of C source files. |
| 2201 action_foreach("my_action") { | 2065 action_foreach("my_action") { |
| 2202 sources = [ ... ] | 2066 sources = [ ... ] |
| 2203 outputs = [ ... ] | 2067 outputs = [ ... ] |
| 2204 } | 2068 } |
| 2205 | 2069 |
| 2206 # Compile the resulting source files into a source set. | 2070 # Compile the resulting source files into a source set. |
| 2207 source_set("my_lib") { | 2071 source_set("my_lib") { |
| 2208 sources = get_target_outputs(":my_action") | 2072 sources = get_target_outputs(":my_action") |
| 2209 } | 2073 } |
| 2210 | |
| 2211 | |
| 2212 ``` | 2074 ``` |
| 2213 ### <a name="getenv"></a>**getenv**: Get an environment variable. | 2075 ### <a name="getenv"></a>**getenv**: Get an environment variable. |
| 2214 | 2076 |
| 2215 ``` | 2077 ``` |
| 2216 value = getenv(env_var_name) | 2078 value = getenv(env_var_name) |
| 2217 | 2079 |
| 2218 Returns the value of the given enironment variable. If the value is not | 2080 Returns the value of the given enironment variable. If the value is not |
| 2219 found, it will try to look up the variable with the "opposite" case (based on | 2081 found, it will try to look up the variable with the "opposite" case (based on |
| 2220 the case of the first letter of the variable), but is otherwise | 2082 the case of the first letter of the variable), but is otherwise |
| 2221 case-sensitive. | 2083 case-sensitive. |
| 2222 | 2084 |
| 2223 If the environment variable is not found, the empty string will be returned. | 2085 If the environment variable is not found, the empty string will be returned. |
| 2224 Note: it might be nice to extend this if we had the concept of "none" in the | 2086 Note: it might be nice to extend this if we had the concept of "none" in the |
| 2225 language to indicate lookup failure. | 2087 language to indicate lookup failure. |
| 2226 | |
| 2227 ``` | 2088 ``` |
| 2228 | 2089 |
| 2229 #### **Example** | 2090 #### **Example** |
| 2230 | 2091 |
| 2231 ``` | 2092 ``` |
| 2232 home_dir = getenv("HOME") | 2093 home_dir = getenv("HOME") |
| 2233 | |
| 2234 | |
| 2235 ``` | 2094 ``` |
| 2236 ### <a name="import"></a>**import**: Import a file into the current scope. | 2095 ### <a name="import"></a>**import**: Import a file into the current scope. |
| 2237 | 2096 |
| 2238 ``` | 2097 ``` |
| 2239 The import command loads the rules and variables resulting from executing the | 2098 The import command loads the rules and variables resulting from executing the |
| 2240 given file into the current scope. | 2099 given file into the current scope. |
| 2241 | 2100 |
| 2242 By convention, imported files are named with a .gni extension. | 2101 By convention, imported files are named with a .gni extension. |
| 2243 | 2102 |
| 2244 An import is different than a C++ "include". The imported file is executed in | 2103 An import is different than a C++ "include". The imported file is executed in |
| 2245 a standalone environment from the caller of the import command. The results | 2104 a standalone environment from the caller of the import command. The results |
| 2246 of this execution are cached for other files that import the same .gni file. | 2105 of this execution are cached for other files that import the same .gni file. |
| 2247 | 2106 |
| 2248 Note that you can not import a BUILD.gn file that's otherwise used in the | 2107 Note that you can not import a BUILD.gn file that's otherwise used in the |
| 2249 build. Files must either be imported or implicitly loaded as a result of deps | 2108 build. Files must either be imported or implicitly loaded as a result of deps |
| 2250 rules, but not both. | 2109 rules, but not both. |
| 2251 | 2110 |
| 2252 The imported file's scope will be merged with the scope at the point import | 2111 The imported file's scope will be merged with the scope at the point import |
| 2253 was called. If there is a conflict (both the current scope and the imported | 2112 was called. If there is a conflict (both the current scope and the imported |
| 2254 file define some variable or rule with the same name but different value), a | 2113 file define some variable or rule with the same name but different value), a |
| 2255 runtime error will be thrown. Therefore, it's good practice to minimize the | 2114 runtime error will be thrown. Therefore, it's good practice to minimize the |
| 2256 stuff that an imported file defines. | 2115 stuff that an imported file defines. |
| 2257 | 2116 |
| 2258 Variables and templates beginning with an underscore '_' are considered | 2117 Variables and templates beginning with an underscore '_' are considered |
| 2259 private and will not be imported. Imported files can use such variables for | 2118 private and will not be imported. Imported files can use such variables for |
| 2260 internal computation without affecting other files. | 2119 internal computation without affecting other files. |
| 2261 | |
| 2262 ``` | 2120 ``` |
| 2263 | 2121 |
| 2264 #### **Examples** | 2122 #### **Examples** |
| 2265 | 2123 |
| 2266 ``` | 2124 ``` |
| 2267 import("//build/rules/idl_compilation_rule.gni") | 2125 import("//build/rules/idl_compilation_rule.gni") |
| 2268 | 2126 |
| 2269 # Looks in the current directory. | 2127 # Looks in the current directory. |
| 2270 import("my_vars.gni") | 2128 import("my_vars.gni") |
| 2271 | |
| 2272 | |
| 2273 ``` | 2129 ``` |
| 2274 ### <a name="pool"></a>**pool**: Defines a pool object. | 2130 ### <a name="pool"></a>**pool**: Defines a pool object. |
| 2275 | 2131 |
| 2276 ``` | 2132 ``` |
| 2277 Pool objects can be applied to a tool to limit the parallelism of the | 2133 Pool objects can be applied to a tool to limit the parallelism of the |
| 2278 build. This object has a single property "depth" corresponding to | 2134 build. This object has a single property "depth" corresponding to |
| 2279 the number of tasks that may run simultaneously. | 2135 the number of tasks that may run simultaneously. |
| 2280 | 2136 |
| 2281 As the file containing the pool definition may be executed in the | 2137 As the file containing the pool definition may be executed in the |
| 2282 context of more than one toolchain it is recommended to specify an | 2138 context of more than one toolchain it is recommended to specify an |
| 2283 explicit toolchain when defining and referencing a pool. | 2139 explicit toolchain when defining and referencing a pool. |
| 2284 | 2140 |
| 2285 A pool is referenced by its label just like a target. | 2141 A pool is referenced by its label just like a target. |
| 2286 | |
| 2287 ``` | 2142 ``` |
| 2288 | 2143 |
| 2289 #### **Variables** | 2144 #### **Variables** |
| 2290 | 2145 |
| 2291 ``` | 2146 ``` |
| 2292 depth* | 2147 depth* |
| 2293 * = required | 2148 * = required |
| 2294 | |
| 2295 ``` | 2149 ``` |
| 2296 | 2150 |
| 2297 #### **Example** | 2151 #### **Example** |
| 2298 | 2152 |
| 2299 ``` | 2153 ``` |
| 2300 if (current_toolchain == default_toolchain) { | 2154 if (current_toolchain == default_toolchain) { |
| 2301 pool("link_pool") { | 2155 pool("link_pool") { |
| 2302 depth = 1 | 2156 depth = 1 |
| 2303 } | 2157 } |
| 2304 } | 2158 } |
| 2305 | 2159 |
| 2306 toolchain("toolchain") { | 2160 toolchain("toolchain") { |
| 2307 tool("link") { | 2161 tool("link") { |
| 2308 command = "..." | 2162 command = "..." |
| 2309 pool = ":link_pool($default_toolchain)") | 2163 pool = ":link_pool($default_toolchain)") |
| 2310 } | 2164 } |
| 2311 } | 2165 } |
| 2312 | |
| 2313 | |
| 2314 ``` | 2166 ``` |
| 2315 ### <a name="print"></a>**print**: Prints to the console. | 2167 ### <a name="print"></a>**print**: Prints to the console. |
| 2316 | 2168 |
| 2317 ``` | 2169 ``` |
| 2318 Prints all arguments to the console separated by spaces. A newline is | 2170 Prints all arguments to the console separated by spaces. A newline is |
| 2319 automatically appended to the end. | 2171 automatically appended to the end. |
| 2320 | 2172 |
| 2321 This function is intended for debugging. Note that build files are run in | 2173 This function is intended for debugging. Note that build files are run in |
| 2322 parallel so you may get interleaved prints. A buildfile may also be executed | 2174 parallel so you may get interleaved prints. A buildfile may also be executed |
| 2323 more than once in parallel in the context of different toolchains so the | 2175 more than once in parallel in the context of different toolchains so the |
| 2324 prints from one file may be duplicated or | 2176 prints from one file may be duplicated or |
| 2325 interleaved with itself. | 2177 interleaved with itself. |
| 2326 | |
| 2327 ``` | 2178 ``` |
| 2328 | 2179 |
| 2329 #### **Examples** | 2180 #### **Examples** |
| 2330 | 2181 |
| 2331 ``` | 2182 ``` |
| 2332 print("Hello world") | 2183 print("Hello world") |
| 2333 | 2184 |
| 2334 print(sources, deps) | 2185 print(sources, deps) |
| 2335 | |
| 2336 | |
| 2337 ``` | 2186 ``` |
| 2338 ### <a name="process_file_template"></a>**process_file_template**: Do template e
xpansion over a list of files. | 2187 ### <a name="process_file_template"></a>**process_file_template**: Do template e
xpansion over a list of files. |
| 2339 | 2188 |
| 2340 ``` | 2189 ``` |
| 2341 process_file_template(source_list, template) | 2190 process_file_template(source_list, template) |
| 2342 | 2191 |
| 2343 process_file_template applies a template list to a source file list, | 2192 process_file_template applies a template list to a source file list, |
| 2344 returning the result of applying each template to each source. This is | 2193 returning the result of applying each template to each source. This is |
| 2345 typically used for computing output file names from input files. | 2194 typically used for computing output file names from input files. |
| 2346 | 2195 |
| 2347 In most cases, get_target_outputs() will give the same result with shorter, | 2196 In most cases, get_target_outputs() will give the same result with shorter, |
| 2348 more maintainable code. This function should only be used when that function | 2197 more maintainable code. This function should only be used when that function |
| 2349 can't be used (like there's no target or the target is defined in another | 2198 can't be used (like there's no target or the target is defined in another |
| 2350 build file). | 2199 build file). |
| 2351 | |
| 2352 ``` | 2200 ``` |
| 2353 | 2201 |
| 2354 #### **Arguments** | 2202 #### **Arguments** |
| 2355 | 2203 |
| 2356 ``` | 2204 ``` |
| 2357 The source_list is a list of file names. | 2205 The source_list is a list of file names. |
| 2358 | 2206 |
| 2359 The template can be a string or a list. If it is a list, multiple output | 2207 The template can be a string or a list. If it is a list, multiple output |
| 2360 strings are generated for each input. | 2208 strings are generated for each input. |
| 2361 | 2209 |
| 2362 The template should contain source expansions to which each name in the | 2210 The template should contain source expansions to which each name in the |
| 2363 source list is applied. See "gn help source_expansion". | 2211 source list is applied. See "gn help source_expansion". |
| 2364 | |
| 2365 ``` | 2212 ``` |
| 2366 | 2213 |
| 2367 #### **Example** | 2214 #### **Example** |
| 2368 | 2215 |
| 2369 ``` | 2216 ``` |
| 2370 sources = [ | 2217 sources = [ |
| 2371 "foo.idl", | 2218 "foo.idl", |
| 2372 "bar.idl", | 2219 "bar.idl", |
| 2373 ] | 2220 ] |
| 2374 myoutputs = process_file_template( | 2221 myoutputs = process_file_template( |
| 2375 sources, | 2222 sources, |
| 2376 [ "$target_gen_dir/{{source_name_part}}.cc", | 2223 [ "$target_gen_dir/{{source_name_part}}.cc", |
| 2377 "$target_gen_dir/{{source_name_part}}.h" ]) | 2224 "$target_gen_dir/{{source_name_part}}.h" ]) |
| 2378 | 2225 |
| 2379 The result in this case will be: | 2226 The result in this case will be: |
| 2380 [ "//out/Debug/foo.cc" | 2227 [ "//out/Debug/foo.cc" |
| 2381 "//out/Debug/foo.h" | 2228 "//out/Debug/foo.h" |
| 2382 "//out/Debug/bar.cc" | 2229 "//out/Debug/bar.cc" |
| 2383 "//out/Debug/bar.h" ] | 2230 "//out/Debug/bar.h" ] |
| 2384 | |
| 2385 | |
| 2386 ``` | 2231 ``` |
| 2387 ### <a name="read_file"></a>**read_file**: Read a file into a variable. | 2232 ### <a name="read_file"></a>**read_file**: Read a file into a variable. |
| 2388 | 2233 |
| 2389 ``` | 2234 ``` |
| 2390 read_file(filename, input_conversion) | 2235 read_file(filename, input_conversion) |
| 2391 | 2236 |
| 2392 Whitespace will be trimmed from the end of the file. Throws an error if the | 2237 Whitespace will be trimmed from the end of the file. Throws an error if the |
| 2393 file can not be opened. | 2238 file can not be opened. |
| 2394 | |
| 2395 ``` | 2239 ``` |
| 2396 | 2240 |
| 2397 #### **Arguments** | 2241 #### **Arguments** |
| 2398 | 2242 |
| 2399 ``` | 2243 ``` |
| 2400 filename | 2244 filename |
| 2401 Filename to read, relative to the build file. | 2245 Filename to read, relative to the build file. |
| 2402 | 2246 |
| 2403 input_conversion | 2247 input_conversion |
| 2404 Controls how the file is read and parsed. See "gn help input_conversion". | 2248 Controls how the file is read and parsed. See "gn help input_conversion". |
| 2405 | |
| 2406 ``` | 2249 ``` |
| 2407 | 2250 |
| 2408 #### **Example** | 2251 #### **Example** |
| 2409 | 2252 |
| 2410 ``` | 2253 ``` |
| 2411 lines = read_file("foo.txt", "list lines") | 2254 lines = read_file("foo.txt", "list lines") |
| 2412 | |
| 2413 | |
| 2414 ``` | 2255 ``` |
| 2415 ### <a name="rebase_path"></a>**rebase_path**: Rebase a file or directory to ano
ther location. | 2256 ### <a name="rebase_path"></a>**rebase_path**: Rebase a file or directory to ano
ther location. |
| 2416 | 2257 |
| 2417 ``` | 2258 ``` |
| 2418 converted = rebase_path(input, | 2259 converted = rebase_path(input, |
| 2419 new_base = "", | 2260 new_base = "", |
| 2420 current_base = ".") | 2261 current_base = ".") |
| 2421 | 2262 |
| 2422 Takes a string argument representing a file name, or a list of such strings | 2263 Takes a string argument representing a file name, or a list of such strings |
| 2423 and converts it/them to be relative to a different base directory. | 2264 and converts it/them to be relative to a different base directory. |
| 2424 | 2265 |
| 2425 When invoking the compiler or scripts, GN will automatically convert sources | 2266 When invoking the compiler or scripts, GN will automatically convert sources |
| 2426 and include directories to be relative to the build directory. However, if | 2267 and include directories to be relative to the build directory. However, if |
| 2427 you're passing files directly in the "args" array or doing other manual | 2268 you're passing files directly in the "args" array or doing other manual |
| 2428 manipulations where GN doesn't know something is a file name, you will need | 2269 manipulations where GN doesn't know something is a file name, you will need |
| 2429 to convert paths to be relative to what your tool is expecting. | 2270 to convert paths to be relative to what your tool is expecting. |
| 2430 | 2271 |
| 2431 The common case is to use this to convert paths relative to the current | 2272 The common case is to use this to convert paths relative to the current |
| 2432 directory to be relative to the build directory (which will be the current | 2273 directory to be relative to the build directory (which will be the current |
| 2433 directory when executing scripts). | 2274 directory when executing scripts). |
| 2434 | 2275 |
| 2435 If you want to convert a file path to be source-absolute (that is, beginning | 2276 If you want to convert a file path to be source-absolute (that is, beginning |
| 2436 with a double slash like "//foo/bar"), you should use the get_path_info() | 2277 with a double slash like "//foo/bar"), you should use the get_path_info() |
| 2437 function. This function won't work because it will always make relative | 2278 function. This function won't work because it will always make relative |
| 2438 paths, and it needs to support making paths relative to the source root, so | 2279 paths, and it needs to support making paths relative to the source root, so |
| 2439 can't also generate source-absolute paths without more special-cases. | 2280 can't also generate source-absolute paths without more special-cases. |
| 2440 | |
| 2441 ``` | 2281 ``` |
| 2442 | 2282 |
| 2443 #### **Arguments** | 2283 #### **Arguments** |
| 2444 | 2284 |
| 2445 ``` | 2285 ``` |
| 2446 input | 2286 input |
| 2447 A string or list of strings representing file or directory names These | 2287 A string or list of strings representing file or directory names These |
| 2448 can be relative paths ("foo/bar.txt"), system absolute paths | 2288 can be relative paths ("foo/bar.txt"), system absolute paths |
| 2449 ("/foo/bar.txt"), or source absolute paths ("//foo/bar.txt"). | 2289 ("/foo/bar.txt"), or source absolute paths ("//foo/bar.txt"). |
| 2450 | 2290 |
| 2451 new_base | 2291 new_base |
| 2452 The directory to convert the paths to be relative to. This can be an | 2292 The directory to convert the paths to be relative to. This can be an |
| 2453 absolute path or a relative path (which will be treated as being relative | 2293 absolute path or a relative path (which will be treated as being relative |
| 2454 to the current BUILD-file's directory). | 2294 to the current BUILD-file's directory). |
| 2455 | 2295 |
| 2456 As a special case, if new_base is the empty string (the default), all | 2296 As a special case, if new_base is the empty string (the default), all |
| 2457 paths will be converted to system-absolute native style paths with system | 2297 paths will be converted to system-absolute native style paths with system |
| 2458 path separators. This is useful for invoking external programs. | 2298 path separators. This is useful for invoking external programs. |
| 2459 | 2299 |
| 2460 current_base | 2300 current_base |
| 2461 Directory representing the base for relative paths in the input. If this | 2301 Directory representing the base for relative paths in the input. If this |
| 2462 is not an absolute path, it will be treated as being relative to the | 2302 is not an absolute path, it will be treated as being relative to the |
| 2463 current build file. Use "." (the default) to convert paths from the | 2303 current build file. Use "." (the default) to convert paths from the |
| 2464 current BUILD-file's directory. | 2304 current BUILD-file's directory. |
| 2465 | |
| 2466 ``` | 2305 ``` |
| 2467 | 2306 |
| 2468 #### **Return value** | 2307 #### **Return value** |
| 2469 | 2308 |
| 2470 ``` | 2309 ``` |
| 2471 The return value will be the same type as the input value (either a string or | 2310 The return value will be the same type as the input value (either a string or |
| 2472 a list of strings). All relative and source-absolute file names will be | 2311 a list of strings). All relative and source-absolute file names will be |
| 2473 converted to be relative to the requested output System-absolute paths will | 2312 converted to be relative to the requested output System-absolute paths will |
| 2474 be unchanged. | 2313 be unchanged. |
| 2475 | 2314 |
| 2476 Whether an output path will end in a slash will match whether the | 2315 Whether an output path will end in a slash will match whether the |
| 2477 corresponding input path ends in a slash. It will return "." or "./" | 2316 corresponding input path ends in a slash. It will return "." or "./" |
| 2478 (depending on whether the input ends in a slash) to avoid returning empty | 2317 (depending on whether the input ends in a slash) to avoid returning empty |
| 2479 strings. This means if you want a root path ("//" or "/") not ending in a | 2318 strings. This means if you want a root path ("//" or "/") not ending in a |
| 2480 slash, you can add a dot ("//."). | 2319 slash, you can add a dot ("//."). |
| 2481 | |
| 2482 ``` | 2320 ``` |
| 2483 | 2321 |
| 2484 #### **Example** | 2322 #### **Example** |
| 2485 | 2323 |
| 2486 ``` | 2324 ``` |
| 2487 # Convert a file in the current directory to be relative to the build | 2325 # Convert a file in the current directory to be relative to the build |
| 2488 # directory (the current dir when executing compilers and scripts). | 2326 # directory (the current dir when executing compilers and scripts). |
| 2489 foo = rebase_path("myfile.txt", root_build_dir) | 2327 foo = rebase_path("myfile.txt", root_build_dir) |
| 2490 # might produce "../../project/myfile.txt". | 2328 # might produce "../../project/myfile.txt". |
| 2491 | 2329 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2503 | 2341 |
| 2504 # Extra file args passed manually need to be explicitly converted | 2342 # Extra file args passed manually need to be explicitly converted |
| 2505 # to be relative to the build directory: | 2343 # to be relative to the build directory: |
| 2506 args = [ | 2344 args = [ |
| 2507 "--data", | 2345 "--data", |
| 2508 rebase_path("//mything/data/input.dat", root_build_dir), | 2346 rebase_path("//mything/data/input.dat", root_build_dir), |
| 2509 "--rel", | 2347 "--rel", |
| 2510 rebase_path("relative_path.txt", root_build_dir) | 2348 rebase_path("relative_path.txt", root_build_dir) |
| 2511 ] + rebase_path(sources, root_build_dir) | 2349 ] + rebase_path(sources, root_build_dir) |
| 2512 } | 2350 } |
| 2513 | |
| 2514 | |
| 2515 ``` | 2351 ``` |
| 2516 ### <a name="set_default_toolchain"></a>**set_default_toolchain**: Sets the defa
ult toolchain name. | 2352 ### <a name="set_default_toolchain"></a>**set_default_toolchain**: Sets the defa
ult toolchain name. |
| 2517 | 2353 |
| 2518 ``` | 2354 ``` |
| 2519 set_default_toolchain(toolchain_label) | 2355 set_default_toolchain(toolchain_label) |
| 2520 | 2356 |
| 2521 The given label should identify a toolchain definition (see "gn help | 2357 The given label should identify a toolchain definition (see "gn help |
| 2522 toolchain"). This toolchain will be used for all targets unless otherwise | 2358 toolchain"). This toolchain will be used for all targets unless otherwise |
| 2523 specified. | 2359 specified. |
| 2524 | 2360 |
| 2525 This function is only valid to call during the processing of the build | 2361 This function is only valid to call during the processing of the build |
| 2526 configuration file. Since the build configuration file is processed | 2362 configuration file. Since the build configuration file is processed |
| 2527 separately for each toolchain, this function will be a no-op when called | 2363 separately for each toolchain, this function will be a no-op when called |
| 2528 under any non-default toolchains. | 2364 under any non-default toolchains. |
| 2529 | 2365 |
| 2530 For example, the default toolchain should be appropriate for the current | 2366 For example, the default toolchain should be appropriate for the current |
| 2531 environment. If the current environment is 32-bit and somebody references a | 2367 environment. If the current environment is 32-bit and somebody references a |
| 2532 target with a 64-bit toolchain, we wouldn't want processing of the build | 2368 target with a 64-bit toolchain, we wouldn't want processing of the build |
| 2533 config file for the 64-bit toolchain to reset the default toolchain to | 2369 config file for the 64-bit toolchain to reset the default toolchain to |
| 2534 64-bit, we want to keep it 32-bits. | 2370 64-bit, we want to keep it 32-bits. |
| 2535 | |
| 2536 ``` | 2371 ``` |
| 2537 | 2372 |
| 2538 #### **Argument** | 2373 #### **Argument** |
| 2539 | 2374 |
| 2540 ``` | 2375 ``` |
| 2541 toolchain_label | 2376 toolchain_label |
| 2542 Toolchain name. | 2377 Toolchain name. |
| 2543 | |
| 2544 ``` | 2378 ``` |
| 2545 | 2379 |
| 2546 #### **Example** | 2380 #### **Example** |
| 2547 | 2381 |
| 2548 ``` | 2382 ``` |
| 2549 # Set default toolchain only has an effect when run in the context of the | 2383 # Set default toolchain only has an effect when run in the context of the |
| 2550 # default toolchain. Pick the right one according to the current CPU | 2384 # default toolchain. Pick the right one according to the current CPU |
| 2551 # architecture. | 2385 # architecture. |
| 2552 if (target_cpu == "x64") { | 2386 if (target_cpu == "x64") { |
| 2553 set_default_toolchain("//toolchains:64") | 2387 set_default_toolchain("//toolchains:64") |
| 2554 } else if (target_cpu == "x86") { | 2388 } else if (target_cpu == "x86") { |
| 2555 set_default_toolchain("//toolchains:32") | 2389 set_default_toolchain("//toolchains:32") |
| 2556 } | 2390 } |
| 2557 | |
| 2558 | |
| 2559 ``` | 2391 ``` |
| 2560 ### <a name="set_defaults"></a>**set_defaults**: Set default values for a target
type. | 2392 ### <a name="set_defaults"></a>**set_defaults**: Set default values for a target
type. |
| 2561 | 2393 |
| 2562 ``` | 2394 ``` |
| 2563 set_defaults(<target_type_name>) { <values...> } | 2395 set_defaults(<target_type_name>) { <values...> } |
| 2564 | 2396 |
| 2565 Sets the default values for a given target type. Whenever target_type_name is | 2397 Sets the default values for a given target type. Whenever target_type_name is |
| 2566 seen in the future, the values specified in set_default's block will be | 2398 seen in the future, the values specified in set_default's block will be |
| 2567 copied into the current scope. | 2399 copied into the current scope. |
| 2568 | 2400 |
| 2569 When the target type is used, the variable copying is very strict. If a | 2401 When the target type is used, the variable copying is very strict. If a |
| 2570 variable with that name is already in scope, the build will fail with an | 2402 variable with that name is already in scope, the build will fail with an |
| 2571 error. | 2403 error. |
| 2572 | 2404 |
| 2573 set_defaults can be used for built-in target types ("executable", | 2405 set_defaults can be used for built-in target types ("executable", |
| 2574 "shared_library", etc.) and custom ones defined via the "template" command. | 2406 "shared_library", etc.) and custom ones defined via the "template" command. |
| 2575 It can be called more than once and the most recent call in any scope will | 2407 It can be called more than once and the most recent call in any scope will |
| 2576 apply, but there is no way to refer to the previous defaults and modify them | 2408 apply, but there is no way to refer to the previous defaults and modify them |
| 2577 (each call to set_defaults must supply a complete list of all defaults it | 2409 (each call to set_defaults must supply a complete list of all defaults it |
| 2578 wants). If you want to share defaults, store them in a separate variable. | 2410 wants). If you want to share defaults, store them in a separate variable. |
| 2579 | |
| 2580 ``` | 2411 ``` |
| 2581 | 2412 |
| 2582 #### **Example** | 2413 #### **Example** |
| 2583 | 2414 |
| 2584 ``` | 2415 ``` |
| 2585 set_defaults("static_library") { | 2416 set_defaults("static_library") { |
| 2586 configs = [ "//tools/mything:settings" ] | 2417 configs = [ "//tools/mything:settings" ] |
| 2587 } | 2418 } |
| 2588 | 2419 |
| 2589 static_library("mylib") | 2420 static_library("mylib") |
| 2590 # The configs will be auto-populated as above. You can remove it if | 2421 # The configs will be auto-populated as above. You can remove it if |
| 2591 # you don't want the default for a particular default: | 2422 # you don't want the default for a particular default: |
| 2592 configs -= [ "//tools/mything:settings" ] | 2423 configs -= [ "//tools/mything:settings" ] |
| 2593 } | 2424 } |
| 2594 | |
| 2595 | |
| 2596 ``` | 2425 ``` |
| 2597 ### <a name="set_sources_assignment_filter"></a>**set_sources_assignment_filter*
*: Set a pattern to filter source files. | 2426 ### <a name="set_sources_assignment_filter"></a>**set_sources_assignment_filter*
*: Set a pattern to filter source files. |
| 2598 | 2427 |
| 2599 ``` | 2428 ``` |
| 2600 The sources assignment filter is a list of patterns that remove files from | 2429 The sources assignment filter is a list of patterns that remove files from |
| 2601 the list implicitly whenever the "sources" variable is assigned to. This will | 2430 the list implicitly whenever the "sources" variable is assigned to. This will |
| 2602 do nothing for non-lists. | 2431 do nothing for non-lists. |
| 2603 | 2432 |
| 2604 This is intended to be used to globally filter out files with | 2433 This is intended to be used to globally filter out files with |
| 2605 platform-specific naming schemes when they don't apply, for example you may | 2434 platform-specific naming schemes when they don't apply, for example you may |
| 2606 want to filter out all "*_win.cc" files on non-Windows platforms. | 2435 want to filter out all "*_win.cc" files on non-Windows platforms. |
| 2607 | 2436 |
| 2608 Typically this will be called once in the master build config script to set | 2437 Typically this will be called once in the master build config script to set |
| 2609 up the filter for the current platform. Subsequent calls will overwrite the | 2438 up the filter for the current platform. Subsequent calls will overwrite the |
| 2610 previous values. | 2439 previous values. |
| 2611 | 2440 |
| 2612 If you want to bypass the filter and add a file even if it might be filtered | 2441 If you want to bypass the filter and add a file even if it might be filtered |
| 2613 out, call set_sources_assignment_filter([]) to clear the list of filters. | 2442 out, call set_sources_assignment_filter([]) to clear the list of filters. |
| 2614 This will apply until the current scope exits | 2443 This will apply until the current scope exits |
| 2615 | |
| 2616 ``` | 2444 ``` |
| 2617 | 2445 |
| 2618 #### **How to use patterns** | 2446 #### **How to use patterns** |
| 2619 | 2447 |
| 2620 ``` | 2448 ``` |
| 2621 File patterns are VERY limited regular expressions. They must match the | 2449 File patterns are VERY limited regular expressions. They must match the |
| 2622 entire input string to be counted as a match. In regular expression parlance, | 2450 entire input string to be counted as a match. In regular expression parlance, |
| 2623 there is an implicit "^...$" surrounding your input. If you want to match a | 2451 there is an implicit "^...$" surrounding your input. If you want to match a |
| 2624 substring, you need to use wildcards at the beginning and end. | 2452 substring, you need to use wildcards at the beginning and end. |
| 2625 | 2453 |
| 2626 There are only two special tokens understood by the pattern matcher. | 2454 There are only two special tokens understood by the pattern matcher. |
| 2627 Everything else is a literal. | 2455 Everything else is a literal. |
| 2628 | 2456 |
| 2629 - "*" Matches zero or more of any character. It does not depend on the | 2457 - "*" Matches zero or more of any character. It does not depend on the |
| 2630 preceding character (in regular expression parlance it is equivalent to | 2458 preceding character (in regular expression parlance it is equivalent to |
| 2631 ".*"). | 2459 ".*"). |
| 2632 | 2460 |
| 2633 - "\b" Matches a path boundary. This will match the beginning or end of a | 2461 - "\b" Matches a path boundary. This will match the beginning or end of a |
| 2634 string, or a slash. | 2462 string, or a slash. |
| 2635 | |
| 2636 ``` | 2463 ``` |
| 2637 | 2464 |
| 2638 #### **Pattern examples** | 2465 #### **Pattern examples** |
| 2639 | 2466 |
| 2640 ``` | 2467 ``` |
| 2641 "*asdf*" | 2468 "*asdf*" |
| 2642 Matches a string containing "asdf" anywhere. | 2469 Matches a string containing "asdf" anywhere. |
| 2643 | 2470 |
| 2644 "asdf" | 2471 "asdf" |
| 2645 Matches only the exact string "asdf". | 2472 Matches only the exact string "asdf". |
| 2646 | 2473 |
| 2647 "*.cc" | 2474 "*.cc" |
| 2648 Matches strings ending in the literal ".cc". | 2475 Matches strings ending in the literal ".cc". |
| 2649 | 2476 |
| 2650 "\bwin/*" | 2477 "\bwin/*" |
| 2651 Matches "win/foo" and "foo/win/bar.cc" but not "iwin/foo". | 2478 Matches "win/foo" and "foo/win/bar.cc" but not "iwin/foo". |
| 2652 | |
| 2653 ``` | 2479 ``` |
| 2654 | 2480 |
| 2655 #### **Sources assignment example** | 2481 #### **Sources assignment example** |
| 2656 | 2482 |
| 2657 ``` | 2483 ``` |
| 2658 # Filter out all _win files. | 2484 # Filter out all _win files. |
| 2659 set_sources_assignment_filter([ "*_win.cc", "*_win.h" ]) | 2485 set_sources_assignment_filter([ "*_win.cc", "*_win.h" ]) |
| 2660 sources = [ "a.cc", "b_win.cc" ] | 2486 sources = [ "a.cc", "b_win.cc" ] |
| 2661 print(sources) | 2487 print(sources) |
| 2662 # Will print [ "a.cc" ]. b_win one was filtered out. | 2488 # Will print [ "a.cc" ]. b_win one was filtered out. |
| 2663 | |
| 2664 | |
| 2665 ``` | 2489 ``` |
| 2666 ### <a name="split_list"></a>**split_list**: Splits a list into N different sub-
lists. | 2490 ### <a name="split_list"></a>**split_list**: Splits a list into N different sub-
lists. |
| 2667 | 2491 |
| 2668 ``` | 2492 ``` |
| 2669 result = split_list(input, n) | 2493 result = split_list(input, n) |
| 2670 | 2494 |
| 2671 Given a list and a number N, splits the list into N sub-lists of | 2495 Given a list and a number N, splits the list into N sub-lists of |
| 2672 approximately equal size. The return value is a list of the sub-lists. The | 2496 approximately equal size. The return value is a list of the sub-lists. The |
| 2673 result will always be a list of size N. If N is greater than the number of | 2497 result will always be a list of size N. If N is greater than the number of |
| 2674 elements in the input, it will be padded with empty lists. | 2498 elements in the input, it will be padded with empty lists. |
| 2675 | 2499 |
| 2676 The expected use is to divide source files into smaller uniform chunks. | 2500 The expected use is to divide source files into smaller uniform chunks. |
| 2677 | |
| 2678 ``` | 2501 ``` |
| 2679 | 2502 |
| 2680 #### **Example** | 2503 #### **Example** |
| 2681 | 2504 |
| 2682 ``` | 2505 ``` |
| 2683 The code: | 2506 The code: |
| 2684 mylist = [1, 2, 3, 4, 5, 6] | 2507 mylist = [1, 2, 3, 4, 5, 6] |
| 2685 print(split_list(mylist, 3)) | 2508 print(split_list(mylist, 3)) |
| 2686 | 2509 |
| 2687 Will print: | 2510 Will print: |
| 2688 [[1, 2], [3, 4], [5, 6] | 2511 [[1, 2], [3, 4], [5, 6] |
| 2689 | |
| 2690 | |
| 2691 ``` | 2512 ``` |
| 2692 ### <a name="template"></a>**template**: Define a template rule. | 2513 ### <a name="template"></a>**template**: Define a template rule. |
| 2693 | 2514 |
| 2694 ``` | 2515 ``` |
| 2695 A template defines a custom name that acts like a function. It provides a way | 2516 A template defines a custom name that acts like a function. It provides a way |
| 2696 to add to the built-in target types. | 2517 to add to the built-in target types. |
| 2697 | 2518 |
| 2698 The template() function is used to declare a template. To invoke the | 2519 The template() function is used to declare a template. To invoke the |
| 2699 template, just use the name of the template like any other target type. | 2520 template, just use the name of the template like any other target type. |
| 2700 | 2521 |
| 2701 Often you will want to declare your template in a special file that other | 2522 Often you will want to declare your template in a special file that other |
| 2702 files will import (see "gn help import") so your template rule can be shared | 2523 files will import (see "gn help import") so your template rule can be shared |
| 2703 across build files. | 2524 across build files. |
| 2704 | |
| 2705 ``` | 2525 ``` |
| 2706 | 2526 |
| 2707 #### **Variables and templates**: | 2527 #### **Variables and templates**: |
| 2708 | 2528 |
| 2709 ``` | 2529 ``` |
| 2710 When you call template() it creates a closure around all variables currently | 2530 When you call template() it creates a closure around all variables currently |
| 2711 in scope with the code in the template block. When the template is invoked, | 2531 in scope with the code in the template block. When the template is invoked, |
| 2712 the closure will be executed. | 2532 the closure will be executed. |
| 2713 | 2533 |
| 2714 When the template is invoked, the code in the caller is executed and passed | 2534 When the template is invoked, the code in the caller is executed and passed |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2726 Use the pattern: | 2546 Use the pattern: |
| 2727 | 2547 |
| 2728 if (defined(invoker.deps)) { | 2548 if (defined(invoker.deps)) { |
| 2729 deps = invoker.deps | 2549 deps = invoker.deps |
| 2730 } | 2550 } |
| 2731 | 2551 |
| 2732 The function forward_variables_from() provides a shortcut to forward one or | 2552 The function forward_variables_from() provides a shortcut to forward one or |
| 2733 more or possibly all variables in this manner: | 2553 more or possibly all variables in this manner: |
| 2734 | 2554 |
| 2735 forward_variables_from(invoker, ["deps", "public_deps"]) | 2555 forward_variables_from(invoker, ["deps", "public_deps"]) |
| 2736 | |
| 2737 ``` | 2556 ``` |
| 2738 | 2557 |
| 2739 #### **Target naming** | 2558 #### **Target naming** |
| 2740 | 2559 |
| 2741 ``` | 2560 ``` |
| 2742 Your template should almost always define a built-in target with the name the | 2561 Your template should almost always define a built-in target with the name the |
| 2743 template invoker specified. For example, if you have an IDL template and | 2562 template invoker specified. For example, if you have an IDL template and |
| 2744 somebody does: | 2563 somebody does: |
| 2745 idl("foo") {... | 2564 idl("foo") {... |
| 2746 you will normally want this to expand to something defining a source_set or | 2565 you will normally want this to expand to something defining a source_set or |
| 2747 static_library named "foo" (among other things you may need). This way, when | 2566 static_library named "foo" (among other things you may need). This way, when |
| 2748 another target specifies a dependency on "foo", the static_library or | 2567 another target specifies a dependency on "foo", the static_library or |
| 2749 source_set will be linked. | 2568 source_set will be linked. |
| 2750 | 2569 |
| 2751 It is also important that any other targets your template expands to have | 2570 It is also important that any other targets your template expands to have |
| 2752 unique names, or you will get collisions. | 2571 unique names, or you will get collisions. |
| 2753 | 2572 |
| 2754 Access the invoking name in your template via the implicit "target_name" | 2573 Access the invoking name in your template via the implicit "target_name" |
| 2755 variable. This should also be the basis for how other targets that a template | 2574 variable. This should also be the basis for how other targets that a template |
| 2756 expands to ensure uniqueness. | 2575 expands to ensure uniqueness. |
| 2757 | 2576 |
| 2758 A typical example would be a template that defines an action to generate some | 2577 A typical example would be a template that defines an action to generate some |
| 2759 source files, and a source_set to compile that source. Your template would | 2578 source files, and a source_set to compile that source. Your template would |
| 2760 name the source_set "target_name" because that's what you want external | 2579 name the source_set "target_name" because that's what you want external |
| 2761 targets to depend on to link your code. And you would name the action | 2580 targets to depend on to link your code. And you would name the action |
| 2762 something like "${target_name}_action" to make it unique. The source set | 2581 something like "${target_name}_action" to make it unique. The source set |
| 2763 would have a dependency on the action to make it run. | 2582 would have a dependency on the action to make it run. |
| 2764 | |
| 2765 ``` | 2583 ``` |
| 2766 | 2584 |
| 2767 #### **Example of defining a template** | 2585 #### **Example of defining a template** |
| 2768 | 2586 |
| 2769 ``` | 2587 ``` |
| 2770 template("my_idl") { | 2588 template("my_idl") { |
| 2771 # Be nice and help callers debug problems by checking that the variables | 2589 # Be nice and help callers debug problems by checking that the variables |
| 2772 # the template requires are defined. This gives a nice message rather than | 2590 # the template requires are defined. This gives a nice message rather than |
| 2773 # giving the user an error about an undefined variable in the file defining | 2591 # giving the user an error about an undefined variable in the file defining |
| 2774 # the template | 2592 # the template |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2810 # deps. | 2628 # deps. |
| 2811 source_set(target_name) { | 2629 source_set(target_name) { |
| 2812 # Generates the list of sources, we get these from the action_foreach | 2630 # Generates the list of sources, we get these from the action_foreach |
| 2813 # above. | 2631 # above. |
| 2814 sources = get_target_outputs(":$code_gen_target_name") | 2632 sources = get_target_outputs(":$code_gen_target_name") |
| 2815 | 2633 |
| 2816 # This target depends on the files produced by the above code gen target. | 2634 # This target depends on the files produced by the above code gen target. |
| 2817 deps = [ ":$code_gen_target_name" ] | 2635 deps = [ ":$code_gen_target_name" ] |
| 2818 } | 2636 } |
| 2819 } | 2637 } |
| 2820 | |
| 2821 ``` | 2638 ``` |
| 2822 | 2639 |
| 2823 #### **Example of invoking the resulting template** | 2640 #### **Example of invoking the resulting template** |
| 2824 | 2641 |
| 2825 ``` | 2642 ``` |
| 2826 # This calls the template code above, defining target_name to be | 2643 # This calls the template code above, defining target_name to be |
| 2827 # "foo_idl_files" and "invoker" to be the set of stuff defined in the curly | 2644 # "foo_idl_files" and "invoker" to be the set of stuff defined in the curly |
| 2828 # brackets. | 2645 # brackets. |
| 2829 my_idl("foo_idl_files") { | 2646 my_idl("foo_idl_files") { |
| 2830 # Goes into the template as "invoker.sources". | 2647 # Goes into the template as "invoker.sources". |
| 2831 sources = [ "foo.idl", "bar.idl" ] | 2648 sources = [ "foo.idl", "bar.idl" ] |
| 2832 } | 2649 } |
| 2833 | 2650 |
| 2834 # Here is a target that depends on our template. | 2651 # Here is a target that depends on our template. |
| 2835 executable("my_exe") { | 2652 executable("my_exe") { |
| 2836 # Depend on the name we gave the template call above. Internally, this will | 2653 # Depend on the name we gave the template call above. Internally, this will |
| 2837 # produce a dependency from executable to the source_set inside the | 2654 # produce a dependency from executable to the source_set inside the |
| 2838 # template (since it has this name), which will in turn depend on the code | 2655 # template (since it has this name), which will in turn depend on the code |
| 2839 # gen action. | 2656 # gen action. |
| 2840 deps = [ ":foo_idl_files" ] | 2657 deps = [ ":foo_idl_files" ] |
| 2841 } | 2658 } |
| 2842 | |
| 2843 | |
| 2844 ``` | 2659 ``` |
| 2845 ### <a name="tool"></a>**tool**: Specify arguments to a toolchain tool. | 2660 ### <a name="tool"></a>**tool**: Specify arguments to a toolchain tool. |
| 2846 | 2661 |
| 2847 #### **Usage** | 2662 #### **Usage** |
| 2848 | 2663 |
| 2849 ``` | 2664 ``` |
| 2850 tool(<tool type>) { | 2665 tool(<tool type>) { |
| 2851 <tool variables...> | 2666 <tool variables...> |
| 2852 } | 2667 } |
| 2853 | |
| 2854 ``` | 2668 ``` |
| 2855 | 2669 |
| 2856 #### **Tool types** | 2670 #### **Tool types** |
| 2857 | 2671 |
| 2858 ``` | 2672 ``` |
| 2859 Compiler tools: | 2673 Compiler tools: |
| 2860 "cc": C compiler | 2674 "cc": C compiler |
| 2861 "cxx": C++ compiler | 2675 "cxx": C++ compiler |
| 2862 "objc": Objective C compiler | 2676 "objc": Objective C compiler |
| 2863 "objcxx": Objective C++ compiler | 2677 "objcxx": Objective C++ compiler |
| 2864 "rc": Resource compiler (Windows .rc files) | 2678 "rc": Resource compiler (Windows .rc files) |
| 2865 "asm": Assembler | 2679 "asm": Assembler |
| 2866 | 2680 |
| 2867 Linker tools: | 2681 Linker tools: |
| 2868 "alink": Linker for static libraries (archives) | 2682 "alink": Linker for static libraries (archives) |
| 2869 "solink": Linker for shared libraries | 2683 "solink": Linker for shared libraries |
| 2870 "link": Linker for executables | 2684 "link": Linker for executables |
| 2871 | 2685 |
| 2872 Other tools: | 2686 Other tools: |
| 2873 "stamp": Tool for creating stamp files | 2687 "stamp": Tool for creating stamp files |
| 2874 "copy": Tool to copy files. | 2688 "copy": Tool to copy files. |
| 2875 | 2689 |
| 2876 Platform specific tools: | 2690 Platform specific tools: |
| 2877 "copy_bundle_data": [iOS, OS X] Tool to copy files in a bundle. | 2691 "copy_bundle_data": [iOS, OS X] Tool to copy files in a bundle. |
| 2878 "compile_xcassets": [iOS, OS X] Tool to compile asset catalogs. | 2692 "compile_xcassets": [iOS, OS X] Tool to compile asset catalogs. |
| 2879 | |
| 2880 ``` | 2693 ``` |
| 2881 | 2694 |
| 2882 #### **Tool variables** | 2695 #### **Tool variables** |
| 2883 | 2696 |
| 2884 ``` | 2697 ``` |
| 2885 command [string with substitutions] | 2698 command [string with substitutions] |
| 2886 Valid for: all tools (required) | 2699 Valid for: all tools (required) |
| 2887 | 2700 |
| 2888 The command to run. | 2701 The command to run. |
| 2889 | 2702 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3072 rspfile = "{{output}}.rsp" | 2885 rspfile = "{{output}}.rsp" |
| 3073 rspfile_content = "{{inputs}} {{solibs}} {{libs}}" | 2886 rspfile_content = "{{inputs}} {{solibs}} {{libs}}" |
| 3074 } | 2887 } |
| 3075 | 2888 |
| 3076 runtime_outputs [string list with substitutions] | 2889 runtime_outputs [string list with substitutions] |
| 3077 Valid for: linker tools | 2890 Valid for: linker tools |
| 3078 | 2891 |
| 3079 If specified, this list is the subset of the outputs that should be | 2892 If specified, this list is the subset of the outputs that should be |
| 3080 added to runtime deps (see "gn help runtime_deps"). By default (if | 2893 added to runtime deps (see "gn help runtime_deps"). By default (if |
| 3081 runtime_outputs is empty or unspecified), it will be the link_output. | 2894 runtime_outputs is empty or unspecified), it will be the link_output. |
| 3082 | |
| 3083 ``` | 2895 ``` |
| 3084 | 2896 |
| 3085 #### **Expansions for tool variables** | 2897 #### **Expansions for tool variables** |
| 3086 | 2898 |
| 3087 ``` | 2899 ``` |
| 3088 All paths are relative to the root build directory, which is the current | 2900 All paths are relative to the root build directory, which is the current |
| 3089 directory for running all tools. These expansions are available to all tools: | 2901 directory for running all tools. These expansions are available to all tools: |
| 3090 | 2902 |
| 3091 {{label}} | 2903 {{label}} |
| 3092 The label of the current target. This is typically used in the | 2904 The label of the current target. This is typically used in the |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3241 substitutions are avaiable: | 3053 substitutions are avaiable: |
| 3242 | 3054 |
| 3243 {{inputs}} | 3055 {{inputs}} |
| 3244 Expands to the list of .xcassets to use as input to compile the asset | 3056 Expands to the list of .xcassets to use as input to compile the asset |
| 3245 catalog. | 3057 catalog. |
| 3246 | 3058 |
| 3247 {{bundle_product_type}} | 3059 {{bundle_product_type}} |
| 3248 Expands to the product_type of the bundle that will contain the | 3060 Expands to the product_type of the bundle that will contain the |
| 3249 compiled asset catalog. Usually corresponds to the product_type | 3061 compiled asset catalog. Usually corresponds to the product_type |
| 3250 property of the corresponding create_bundle target. | 3062 property of the corresponding create_bundle target. |
| 3251 | |
| 3252 ``` | 3063 ``` |
| 3253 | 3064 |
| 3254 #### **Separate linking and dependencies for shared libraries** | 3065 #### **Separate linking and dependencies for shared libraries** |
| 3255 | 3066 |
| 3256 ``` | 3067 ``` |
| 3257 Shared libraries are special in that not all changes to them require that | 3068 Shared libraries are special in that not all changes to them require that |
| 3258 dependent targets be re-linked. If the shared library is changed but no | 3069 dependent targets be re-linked. If the shared library is changed but no |
| 3259 imports or exports are different, dependent code needn't be relinked, which | 3070 imports or exports are different, dependent code needn't be relinked, which |
| 3260 can speed up the build. | 3071 can speed up the build. |
| 3261 | 3072 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3277 "{{output_dir}}/{{target_output_name}}" | 3088 "{{output_dir}}/{{target_output_name}}" |
| 3278 "{{output_extension}}.TOC", | 3089 "{{output_extension}}.TOC", |
| 3279 ] | 3090 ] |
| 3280 link_output = | 3091 link_output = |
| 3281 "{{output_dir}}/{{target_output_name}}{{output_extension}}" | 3092 "{{output_dir}}/{{target_output_name}}{{output_extension}}" |
| 3282 depend_output = | 3093 depend_output = |
| 3283 "{{output_dir}}/{{target_output_name}}" | 3094 "{{output_dir}}/{{target_output_name}}" |
| 3284 "{{output_extension}}.TOC" | 3095 "{{output_extension}}.TOC" |
| 3285 restat = true | 3096 restat = true |
| 3286 } | 3097 } |
| 3287 | |
| 3288 ``` | 3098 ``` |
| 3289 | 3099 |
| 3290 #### **Example** | 3100 #### **Example** |
| 3291 | 3101 |
| 3292 ``` | 3102 ``` |
| 3293 toolchain("my_toolchain") { | 3103 toolchain("my_toolchain") { |
| 3294 # Put these at the top to apply to all tools below. | 3104 # Put these at the top to apply to all tools below. |
| 3295 lib_prefix = "-l" | 3105 lib_prefix = "-l" |
| 3296 lib_dir_prefix = "-L" | 3106 lib_dir_prefix = "-L" |
| 3297 | 3107 |
| 3298 tool("cc") { | 3108 tool("cc") { |
| 3299 command = "gcc {{source}} -o {{output}}" | 3109 command = "gcc {{source}} -o {{output}}" |
| 3300 outputs = [ "{{source_out_dir}}/{{source_name_part}}.o" ] | 3110 outputs = [ "{{source_out_dir}}/{{source_name_part}}.o" ] |
| 3301 description = "GCC {{source}}" | 3111 description = "GCC {{source}}" |
| 3302 } | 3112 } |
| 3303 tool("cxx") { | 3113 tool("cxx") { |
| 3304 command = "g++ {{source}} -o {{output}}" | 3114 command = "g++ {{source}} -o {{output}}" |
| 3305 outputs = [ "{{source_out_dir}}/{{source_name_part}}.o" ] | 3115 outputs = [ "{{source_out_dir}}/{{source_name_part}}.o" ] |
| 3306 description = "G++ {{source}}" | 3116 description = "G++ {{source}}" |
| 3307 } | 3117 } |
| 3308 }; | 3118 }; |
| 3309 | |
| 3310 | |
| 3311 ``` | 3119 ``` |
| 3312 ### <a name="toolchain"></a>**toolchain**: Defines a toolchain. | 3120 ### <a name="toolchain"></a>**toolchain**: Defines a toolchain. |
| 3313 | 3121 |
| 3314 ``` | 3122 ``` |
| 3315 A toolchain is a set of commands and build flags used to compile the source | 3123 A toolchain is a set of commands and build flags used to compile the source |
| 3316 code. The toolchain() function defines these commands. | 3124 code. The toolchain() function defines these commands. |
| 3317 | |
| 3318 ``` | 3125 ``` |
| 3319 | 3126 |
| 3320 #### **Toolchain overview** | 3127 #### **Toolchain overview** |
| 3321 | 3128 |
| 3322 ``` | 3129 ``` |
| 3323 You can have more than one toolchain in use at once in a build and a target | 3130 You can have more than one toolchain in use at once in a build and a target |
| 3324 can exist simultaneously in multiple toolchains. A build file is executed | 3131 can exist simultaneously in multiple toolchains. A build file is executed |
| 3325 once for each toolchain it is referenced in so the GN code can vary all | 3132 once for each toolchain it is referenced in so the GN code can vary all |
| 3326 parameters of each target (or which targets exist) on a per-toolchain basis. | 3133 parameters of each target (or which targets exist) on a per-toolchain basis. |
| 3327 | 3134 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3347 3. Loads the destination build file in the context of the configuration file | 3154 3. Loads the destination build file in the context of the configuration file |
| 3348 in the previous step. | 3155 in the previous step. |
| 3349 | 3156 |
| 3350 The toolchain configuration is two-way. In the default toolchain (i.e. the | 3157 The toolchain configuration is two-way. In the default toolchain (i.e. the |
| 3351 main build target) the configuration flows from the build config file to the | 3158 main build target) the configuration flows from the build config file to the |
| 3352 toolchain. The build config file looks at the state of the build (OS type, | 3159 toolchain. The build config file looks at the state of the build (OS type, |
| 3353 CPU architecture, etc.) and decides which toolchain to use (via | 3160 CPU architecture, etc.) and decides which toolchain to use (via |
| 3354 set_default_toolchain()). In secondary toolchains, the configuration flows | 3161 set_default_toolchain()). In secondary toolchains, the configuration flows |
| 3355 from the toolchain to the build config file: the "toolchain_args" in the | 3162 from the toolchain to the build config file: the "toolchain_args" in the |
| 3356 toolchain definition specifies the arguments to re-invoke the build. | 3163 toolchain definition specifies the arguments to re-invoke the build. |
| 3357 | |
| 3358 ``` | 3164 ``` |
| 3359 | 3165 |
| 3360 #### **Functions and variables** | 3166 #### **Functions and variables** |
| 3361 | 3167 |
| 3362 ``` | 3168 ``` |
| 3363 tool() | 3169 tool() |
| 3364 The tool() function call specifies the commands commands to run for a given | 3170 The tool() function call specifies the commands commands to run for a given |
| 3365 step. See "gn help tool". | 3171 step. See "gn help tool". |
| 3366 | 3172 |
| 3367 toolchain_args | 3173 toolchain_args |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3387 Dependencies of this toolchain. These dependencies will be resolved before | 3193 Dependencies of this toolchain. These dependencies will be resolved before |
| 3388 any target in the toolchain is compiled. To avoid circular dependencies | 3194 any target in the toolchain is compiled. To avoid circular dependencies |
| 3389 these must be targets defined in another toolchain. | 3195 these must be targets defined in another toolchain. |
| 3390 | 3196 |
| 3391 This is expressed as a list of targets, and generally these targets will | 3197 This is expressed as a list of targets, and generally these targets will |
| 3392 always specify a toolchain: | 3198 always specify a toolchain: |
| 3393 deps = [ "//foo/bar:baz(//build/toolchain:bootstrap)" ] | 3199 deps = [ "//foo/bar:baz(//build/toolchain:bootstrap)" ] |
| 3394 | 3200 |
| 3395 This concept is somewhat inefficient to express in Ninja (it requires a lot | 3201 This concept is somewhat inefficient to express in Ninja (it requires a lot |
| 3396 of duplicate of rules) so should only be used when absolutely necessary. | 3202 of duplicate of rules) so should only be used when absolutely necessary. |
| 3397 | |
| 3398 ``` | 3203 ``` |
| 3399 | 3204 |
| 3400 #### **Example of defining a toolchain** | 3205 #### **Example of defining a toolchain** |
| 3401 | 3206 |
| 3402 ``` | 3207 ``` |
| 3403 toolchain("32") { | 3208 toolchain("32") { |
| 3404 tool("cc") { | 3209 tool("cc") { |
| 3405 command = "gcc {{source}}" | 3210 command = "gcc {{source}}" |
| 3406 ... | 3211 ... |
| 3407 } | 3212 } |
| 3408 | 3213 |
| 3409 toolchain_args = { | 3214 toolchain_args = { |
| 3410 use_doom_melon = true # Doom melon always required for 32-bit builds. | 3215 use_doom_melon = true # Doom melon always required for 32-bit builds. |
| 3411 current_cpu = "x86" | 3216 current_cpu = "x86" |
| 3412 } | 3217 } |
| 3413 } | 3218 } |
| 3414 | 3219 |
| 3415 toolchain("64") { | 3220 toolchain("64") { |
| 3416 tool("cc") { | 3221 tool("cc") { |
| 3417 command = "gcc {{source}}" | 3222 command = "gcc {{source}}" |
| 3418 ... | 3223 ... |
| 3419 } | 3224 } |
| 3420 | 3225 |
| 3421 toolchain_args = { | 3226 toolchain_args = { |
| 3422 # use_doom_melon is not overridden here, it will take the default. | 3227 # use_doom_melon is not overridden here, it will take the default. |
| 3423 current_cpu = "x64" | 3228 current_cpu = "x64" |
| 3424 } | 3229 } |
| 3425 } | 3230 } |
| 3426 | |
| 3427 ``` | 3231 ``` |
| 3428 | 3232 |
| 3429 #### **Example of cross-toolchain dependencies** | 3233 #### **Example of cross-toolchain dependencies** |
| 3430 | 3234 |
| 3431 ``` | 3235 ``` |
| 3432 If a 64-bit target wants to depend on a 32-bit binary, it would specify a | 3236 If a 64-bit target wants to depend on a 32-bit binary, it would specify a |
| 3433 dependency using data_deps (data deps are like deps that are only needed at | 3237 dependency using data_deps (data deps are like deps that are only needed at |
| 3434 runtime and aren't linked, since you can't link a 32-bit and a 64-bit | 3238 runtime and aren't linked, since you can't link a 32-bit and a 64-bit |
| 3435 library). | 3239 library). |
| 3436 | 3240 |
| 3437 executable("my_program") { | 3241 executable("my_program") { |
| 3438 ... | 3242 ... |
| 3439 if (target_cpu == "x64") { | 3243 if (target_cpu == "x64") { |
| 3440 # The 64-bit build needs this 32-bit helper. | 3244 # The 64-bit build needs this 32-bit helper. |
| 3441 data_deps = [ ":helper(//toolchains:32)" ] | 3245 data_deps = [ ":helper(//toolchains:32)" ] |
| 3442 } | 3246 } |
| 3443 } | 3247 } |
| 3444 | 3248 |
| 3445 if (target_cpu == "x86") { | 3249 if (target_cpu == "x86") { |
| 3446 # Our helper library is only compiled in 32-bits. | 3250 # Our helper library is only compiled in 32-bits. |
| 3447 shared_library("helper") { | 3251 shared_library("helper") { |
| 3448 ... | 3252 ... |
| 3449 } | 3253 } |
| 3450 } | 3254 } |
| 3451 | |
| 3452 | |
| 3453 ``` | 3255 ``` |
| 3454 ### <a name="write_file"></a>**write_file**: Write a file to disk. | 3256 ### <a name="write_file"></a>**write_file**: Write a file to disk. |
| 3455 | 3257 |
| 3456 ``` | 3258 ``` |
| 3457 write_file(filename, data) | 3259 write_file(filename, data) |
| 3458 | 3260 |
| 3459 If data is a list, the list will be written one-item-per-line with no quoting | 3261 If data is a list, the list will be written one-item-per-line with no quoting |
| 3460 or brackets. | 3262 or brackets. |
| 3461 | 3263 |
| 3462 If the file exists and the contents are identical to that being written, the | 3264 If the file exists and the contents are identical to that being written, the |
| 3463 file will not be updated. This will prevent unnecessary rebuilds of targets | 3265 file will not be updated. This will prevent unnecessary rebuilds of targets |
| 3464 that depend on this file. | 3266 that depend on this file. |
| 3465 | 3267 |
| 3466 One use for write_file is to write a list of inputs to an script that might | 3268 One use for write_file is to write a list of inputs to an script that might |
| 3467 be too long for the command line. However, it is preferrable to use response | 3269 be too long for the command line. However, it is preferrable to use response |
| 3468 files for this purpose. See "gn help response_file_contents". | 3270 files for this purpose. See "gn help response_file_contents". |
| 3469 | 3271 |
| 3470 TODO(brettw) we probably need an optional third argument to control list | 3272 TODO(brettw) we probably need an optional third argument to control list |
| 3471 formatting. | 3273 formatting. |
| 3472 | |
| 3473 ``` | 3274 ``` |
| 3474 | 3275 |
| 3475 #### **Arguments** | 3276 #### **Arguments** |
| 3476 | 3277 |
| 3477 ``` | 3278 ``` |
| 3478 filename | 3279 filename |
| 3479 Filename to write. This must be within the output directory. | 3280 Filename to write. This must be within the output directory. |
| 3480 | 3281 |
| 3481 data | 3282 data |
| 3482 The list or string to write. | 3283 The list or string to write. |
| 3483 | |
| 3484 | |
| 3485 ``` | 3284 ``` |
| 3486 ## <a name="predefined_variables"></a>Built-in predefined variables | 3285 ## <a name="predefined_variables"></a>Built-in predefined variables |
| 3487 | 3286 |
| 3488 ### <a name="current_cpu"></a>**current_cpu**: The processor architecture of the
current toolchain. | 3287 ### <a name="current_cpu"></a>**current_cpu**: The processor architecture of the
current toolchain. |
| 3489 | 3288 |
| 3490 ``` | 3289 ``` |
| 3491 The build configuration usually sets this value based on the value of | 3290 The build configuration usually sets this value based on the value of |
| 3492 "host_cpu" (see "gn help host_cpu") and then threads this through the | 3291 "host_cpu" (see "gn help host_cpu") and then threads this through the |
| 3493 toolchain definitions to ensure that it always reflects the appropriate | 3292 toolchain definitions to ensure that it always reflects the appropriate |
| 3494 value. | 3293 value. |
| 3495 | 3294 |
| 3496 This value is not used internally by GN for any purpose. It is set it to the | 3295 This value is not used internally by GN for any purpose. It is set it to the |
| 3497 empty string ("") by default but is declared so that it can be overridden on | 3296 empty string ("") by default but is declared so that it can be overridden on |
| 3498 the command line if so desired. | 3297 the command line if so desired. |
| 3499 | 3298 |
| 3500 See "gn help target_cpu" for a list of common values returned. | 3299 See "gn help target_cpu" for a list of common values returned. |
| 3501 | |
| 3502 ``` | 3300 ``` |
| 3503 ### <a name="current_os"></a>**current_os**: The operating system of the current
toolchain. | 3301 ### <a name="current_os"></a>**current_os**: The operating system of the current
toolchain. |
| 3504 | 3302 |
| 3505 ``` | 3303 ``` |
| 3506 The build configuration usually sets this value based on the value of | 3304 The build configuration usually sets this value based on the value of |
| 3507 "target_os" (see "gn help target_os"), and then threads this through the | 3305 "target_os" (see "gn help target_os"), and then threads this through the |
| 3508 toolchain definitions to ensure that it always reflects the appropriate | 3306 toolchain definitions to ensure that it always reflects the appropriate |
| 3509 value. | 3307 value. |
| 3510 | 3308 |
| 3511 This value is not used internally by GN for any purpose. It is set it to the | 3309 This value is not used internally by GN for any purpose. It is set it to the |
| 3512 empty string ("") by default but is declared so that it can be overridden on | 3310 empty string ("") by default but is declared so that it can be overridden on |
| 3513 the command line if so desired. | 3311 the command line if so desired. |
| 3514 | 3312 |
| 3515 See "gn help target_os" for a list of common values returned. | 3313 See "gn help target_os" for a list of common values returned. |
| 3516 | |
| 3517 | |
| 3518 ``` | 3314 ``` |
| 3519 ### <a name="current_toolchain"></a>**current_toolchain**: Label of the current
toolchain. | 3315 ### <a name="current_toolchain"></a>**current_toolchain**: Label of the current
toolchain. |
| 3520 | 3316 |
| 3521 ``` | 3317 ``` |
| 3522 A fully-qualified label representing the current toolchain. You can use this | 3318 A fully-qualified label representing the current toolchain. You can use this |
| 3523 to make toolchain-related decisions in the build. See also | 3319 to make toolchain-related decisions in the build. See also |
| 3524 "default_toolchain". | 3320 "default_toolchain". |
| 3525 | |
| 3526 ``` | 3321 ``` |
| 3527 | 3322 |
| 3528 #### **Example** | 3323 #### **Example** |
| 3529 | 3324 |
| 3530 ``` | 3325 ``` |
| 3531 if (current_toolchain == "//build:64_bit_toolchain") { | 3326 if (current_toolchain == "//build:64_bit_toolchain") { |
| 3532 executable("output_thats_64_bit_only") { | 3327 executable("output_thats_64_bit_only") { |
| 3533 ... | 3328 ... |
| 3534 | |
| 3535 | |
| 3536 ``` | 3329 ``` |
| 3537 ### <a name="default_toolchain"></a>**default_toolchain**: [string] Label of the
default toolchain. | 3330 ### <a name="default_toolchain"></a>**default_toolchain**: [string] Label of the
default toolchain. |
| 3538 | 3331 |
| 3539 ``` | 3332 ``` |
| 3540 A fully-qualified label representing the default toolchain, which may not | 3333 A fully-qualified label representing the default toolchain, which may not |
| 3541 necessarily be the current one (see "current_toolchain"). | 3334 necessarily be the current one (see "current_toolchain"). |
| 3542 | |
| 3543 | |
| 3544 ``` | 3335 ``` |
| 3545 ### <a name="host_cpu"></a>**host_cpu**: The processor architecture that GN is r
unning on. | 3336 ### <a name="host_cpu"></a>**host_cpu**: The processor architecture that GN is r
unning on. |
| 3546 | 3337 |
| 3547 ``` | 3338 ``` |
| 3548 This is value is exposed so that cross-compile toolchains can access the host | 3339 This is value is exposed so that cross-compile toolchains can access the host |
| 3549 architecture when needed. | 3340 architecture when needed. |
| 3550 | 3341 |
| 3551 The value should generally be considered read-only, but it can be overriden | 3342 The value should generally be considered read-only, but it can be overriden |
| 3552 in order to handle unusual cases where there might be multiple plausible | 3343 in order to handle unusual cases where there might be multiple plausible |
| 3553 values for the host architecture (e.g., if you can do either 32-bit or 64-bit | 3344 values for the host architecture (e.g., if you can do either 32-bit or 64-bit |
| 3554 builds). The value is not used internally by GN for any purpose. | 3345 builds). The value is not used internally by GN for any purpose. |
| 3555 | |
| 3556 ``` | 3346 ``` |
| 3557 | 3347 |
| 3558 #### **Some possible values** | 3348 #### **Some possible values** |
| 3559 | 3349 |
| 3560 ``` | 3350 ``` |
| 3561 - "x64" | 3351 - "x64" |
| 3562 - "x86" | 3352 - "x86" |
| 3563 | |
| 3564 | |
| 3565 ``` | 3353 ``` |
| 3566 ### <a name="host_os"></a>**host_os**: [string] The operating system that GN is
running on. | 3354 ### <a name="host_os"></a>**host_os**: [string] The operating system that GN is
running on. |
| 3567 | 3355 |
| 3568 ``` | 3356 ``` |
| 3569 This value is exposed so that cross-compiles can access the host build | 3357 This value is exposed so that cross-compiles can access the host build |
| 3570 system's settings. | 3358 system's settings. |
| 3571 | 3359 |
| 3572 This value should generally be treated as read-only. It, however, is not used | 3360 This value should generally be treated as read-only. It, however, is not used |
| 3573 internally by GN for any purpose. | 3361 internally by GN for any purpose. |
| 3574 | |
| 3575 ``` | 3362 ``` |
| 3576 | 3363 |
| 3577 #### **Some possible values** | 3364 #### **Some possible values** |
| 3578 | 3365 |
| 3579 ``` | 3366 ``` |
| 3580 - "linux" | 3367 - "linux" |
| 3581 - "mac" | 3368 - "mac" |
| 3582 - "win" | 3369 - "win" |
| 3583 | |
| 3584 | |
| 3585 ``` | 3370 ``` |
| 3586 ### <a name="invoker"></a>**invoker**: [string] The invoking scope inside a temp
late. | 3371 ### <a name="invoker"></a>**invoker**: [string] The invoking scope inside a temp
late. |
| 3587 | 3372 |
| 3588 ``` | 3373 ``` |
| 3589 Inside a template invocation, this variable refers to the scope of the | 3374 Inside a template invocation, this variable refers to the scope of the |
| 3590 invoker of the template. Outside of template invocations, this variable is | 3375 invoker of the template. Outside of template invocations, this variable is |
| 3591 undefined. | 3376 undefined. |
| 3592 | 3377 |
| 3593 All of the variables defined inside the template invocation are accessible as | 3378 All of the variables defined inside the template invocation are accessible as |
| 3594 members of the "invoker" scope. This is the way that templates read values | 3379 members of the "invoker" scope. This is the way that templates read values |
| 3595 set by the callers. | 3380 set by the callers. |
| 3596 | 3381 |
| 3597 This is often used with "defined" to see if a value is set on the invoking | 3382 This is often used with "defined" to see if a value is set on the invoking |
| 3598 scope. | 3383 scope. |
| 3599 | 3384 |
| 3600 See "gn help template" for more examples. | 3385 See "gn help template" for more examples. |
| 3601 | |
| 3602 ``` | 3386 ``` |
| 3603 | 3387 |
| 3604 #### **Example** | 3388 #### **Example** |
| 3605 | 3389 |
| 3606 ``` | 3390 ``` |
| 3607 template("my_template") { | 3391 template("my_template") { |
| 3608 print(invoker.sources) # Prints [ "a.cc", "b.cc" ] | 3392 print(invoker.sources) # Prints [ "a.cc", "b.cc" ] |
| 3609 print(defined(invoker.foo)) # Prints false. | 3393 print(defined(invoker.foo)) # Prints false. |
| 3610 print(defined(invoker.bar)) # Prints true. | 3394 print(defined(invoker.bar)) # Prints true. |
| 3611 } | 3395 } |
| 3612 | 3396 |
| 3613 my_template("doom_melon") { | 3397 my_template("doom_melon") { |
| 3614 sources = [ "a.cc", "b.cc" ] | 3398 sources = [ "a.cc", "b.cc" ] |
| 3615 bar = 123 | 3399 bar = 123 |
| 3616 } | 3400 } |
| 3617 | |
| 3618 | |
| 3619 ``` | 3401 ``` |
| 3620 ### <a name="python_path"></a>**python_path**: Absolute path of Python. | 3402 ### <a name="python_path"></a>**python_path**: Absolute path of Python. |
| 3621 | 3403 |
| 3622 ``` | 3404 ``` |
| 3623 Normally used in toolchain definitions if running some command requires | 3405 Normally used in toolchain definitions if running some command requires |
| 3624 Python. You will normally not need this when invoking scripts since GN | 3406 Python. You will normally not need this when invoking scripts since GN |
| 3625 automatically finds it for you. | 3407 automatically finds it for you. |
| 3626 | |
| 3627 | |
| 3628 ``` | 3408 ``` |
| 3629 ### <a name="root_build_dir"></a>**root_build_dir**: [string] Directory where bu
ild commands are run. | 3409 ### <a name="root_build_dir"></a>**root_build_dir**: [string] Directory where bu
ild commands are run. |
| 3630 | 3410 |
| 3631 ``` | 3411 ``` |
| 3632 This is the root build output directory which will be the current directory | 3412 This is the root build output directory which will be the current directory |
| 3633 when executing all compilers and scripts. | 3413 when executing all compilers and scripts. |
| 3634 | 3414 |
| 3635 Most often this is used with rebase_path (see "gn help rebase_path") to | 3415 Most often this is used with rebase_path (see "gn help rebase_path") to |
| 3636 convert arguments to be relative to a script's current directory. | 3416 convert arguments to be relative to a script's current directory. |
| 3637 | |
| 3638 | |
| 3639 ``` | 3417 ``` |
| 3640 ### <a name="root_gen_dir"></a>**root_gen_dir**: Directory for the toolchain's g
enerated files. | 3418 ### <a name="root_gen_dir"></a>**root_gen_dir**: Directory for the toolchain's g
enerated files. |
| 3641 | 3419 |
| 3642 ``` | 3420 ``` |
| 3643 Absolute path to the root of the generated output directory tree for the | 3421 Absolute path to the root of the generated output directory tree for the |
| 3644 current toolchain. An example would be "//out/Debug/gen" for the default | 3422 current toolchain. An example would be "//out/Debug/gen" for the default |
| 3645 toolchain, or "//out/Debug/arm/gen" for the "arm" toolchain. | 3423 toolchain, or "//out/Debug/arm/gen" for the "arm" toolchain. |
| 3646 | 3424 |
| 3647 This is primarily useful for setting up include paths for generated files. If | 3425 This is primarily useful for setting up include paths for generated files. If |
| 3648 you are passing this to a script, you will want to pass it through | 3426 you are passing this to a script, you will want to pass it through |
| 3649 rebase_path() (see "gn help rebase_path") to convert it to be relative to the | 3427 rebase_path() (see "gn help rebase_path") to convert it to be relative to the |
| 3650 build directory. | 3428 build directory. |
| 3651 | 3429 |
| 3652 See also "target_gen_dir" which is usually a better location for generated | 3430 See also "target_gen_dir" which is usually a better location for generated |
| 3653 files. It will be inside the root generated dir. | 3431 files. It will be inside the root generated dir. |
| 3654 | |
| 3655 | |
| 3656 ``` | 3432 ``` |
| 3657 ### <a name="root_out_dir"></a>**root_out_dir**: [string] Root directory for too
lchain output files. | 3433 ### <a name="root_out_dir"></a>**root_out_dir**: [string] Root directory for too
lchain output files. |
| 3658 | 3434 |
| 3659 ``` | 3435 ``` |
| 3660 Absolute path to the root of the output directory tree for the current | 3436 Absolute path to the root of the output directory tree for the current |
| 3661 toolchain. It will not have a trailing slash. | 3437 toolchain. It will not have a trailing slash. |
| 3662 | 3438 |
| 3663 For the default toolchain this will be the same as the root_build_dir. An | 3439 For the default toolchain this will be the same as the root_build_dir. An |
| 3664 example would be "//out/Debug" for the default toolchain, or | 3440 example would be "//out/Debug" for the default toolchain, or |
| 3665 "//out/Debug/arm" for the "arm" toolchain. | 3441 "//out/Debug/arm" for the "arm" toolchain. |
| 3666 | 3442 |
| 3667 This is primarily useful for setting up script calls. If you are passing this | 3443 This is primarily useful for setting up script calls. If you are passing this |
| 3668 to a script, you will want to pass it through rebase_path() (see "gn help | 3444 to a script, you will want to pass it through rebase_path() (see "gn help |
| 3669 rebase_path") to convert it to be relative to the build directory. | 3445 rebase_path") to convert it to be relative to the build directory. |
| 3670 | 3446 |
| 3671 See also "target_out_dir" which is usually a better location for output | 3447 See also "target_out_dir" which is usually a better location for output |
| 3672 files. It will be inside the root output dir. | 3448 files. It will be inside the root output dir. |
| 3673 | |
| 3674 ``` | 3449 ``` |
| 3675 | 3450 |
| 3676 #### **Example** | 3451 #### **Example** |
| 3677 | 3452 |
| 3678 ``` | 3453 ``` |
| 3679 action("myscript") { | 3454 action("myscript") { |
| 3680 # Pass the output dir to the script. | 3455 # Pass the output dir to the script. |
| 3681 args = [ "-o", rebase_path(root_out_dir, root_build_dir) ] | 3456 args = [ "-o", rebase_path(root_out_dir, root_build_dir) ] |
| 3682 } | 3457 } |
| 3683 | |
| 3684 | |
| 3685 ``` | 3458 ``` |
| 3686 ### <a name="target_cpu"></a>**target_cpu**: The desired cpu architecture for th
e build. | 3459 ### <a name="target_cpu"></a>**target_cpu**: The desired cpu architecture for th
e build. |
| 3687 | 3460 |
| 3688 ``` | 3461 ``` |
| 3689 This value should be used to indicate the desired architecture for the | 3462 This value should be used to indicate the desired architecture for the |
| 3690 primary objects of the build. It will match the cpu architecture of the | 3463 primary objects of the build. It will match the cpu architecture of the |
| 3691 default toolchain, but not necessarily the current toolchain. | 3464 default toolchain, but not necessarily the current toolchain. |
| 3692 | 3465 |
| 3693 In many cases, this is the same as "host_cpu", but in the case of | 3466 In many cases, this is the same as "host_cpu", but in the case of |
| 3694 cross-compiles, this can be set to something different. This value is | 3467 cross-compiles, this can be set to something different. This value is |
| 3695 different from "current_cpu" in that it does not change based on the current | 3468 different from "current_cpu" in that it does not change based on the current |
| 3696 toolchain. When writing rules, "current_cpu" should be used rather than | 3469 toolchain. When writing rules, "current_cpu" should be used rather than |
| 3697 "target_cpu" most of the time. | 3470 "target_cpu" most of the time. |
| 3698 | 3471 |
| 3699 This value is not used internally by GN for any purpose, so it may be set to | 3472 This value is not used internally by GN for any purpose, so it may be set to |
| 3700 whatever value is needed for the build. GN defaults this value to the empty | 3473 whatever value is needed for the build. GN defaults this value to the empty |
| 3701 string ("") and the configuration files should set it to an appropriate value | 3474 string ("") and the configuration files should set it to an appropriate value |
| 3702 (e.g., setting it to the value of "host_cpu") if it is not overridden on the | 3475 (e.g., setting it to the value of "host_cpu") if it is not overridden on the |
| 3703 command line or in the args.gn file. | 3476 command line or in the args.gn file. |
| 3704 | |
| 3705 ``` | 3477 ``` |
| 3706 | 3478 |
| 3707 #### **Possible values** | 3479 #### **Possible values** |
| 3708 | 3480 |
| 3709 ``` | 3481 ``` |
| 3710 - "x86" | 3482 - "x86" |
| 3711 - "x64" | 3483 - "x64" |
| 3712 - "arm" | 3484 - "arm" |
| 3713 - "arm64" | 3485 - "arm64" |
| 3714 - "mipsel" | 3486 - "mipsel" |
| 3715 | |
| 3716 | |
| 3717 ``` | 3487 ``` |
| 3718 ### <a name="target_gen_dir"></a>**target_gen_dir**: Directory for a target's ge
nerated files. | 3488 ### <a name="target_gen_dir"></a>**target_gen_dir**: Directory for a target's ge
nerated files. |
| 3719 | 3489 |
| 3720 ``` | 3490 ``` |
| 3721 Absolute path to the target's generated file directory. This will be the | 3491 Absolute path to the target's generated file directory. This will be the |
| 3722 "root_gen_dir" followed by the relative path to the current build file. If | 3492 "root_gen_dir" followed by the relative path to the current build file. If |
| 3723 your file is in "//tools/doom_melon" then target_gen_dir would be | 3493 your file is in "//tools/doom_melon" then target_gen_dir would be |
| 3724 "//out/Debug/gen/tools/doom_melon". It will not have a trailing slash. | 3494 "//out/Debug/gen/tools/doom_melon". It will not have a trailing slash. |
| 3725 | 3495 |
| 3726 This is primarily useful for setting up include paths for generated files. If | 3496 This is primarily useful for setting up include paths for generated files. If |
| 3727 you are passing this to a script, you will want to pass it through | 3497 you are passing this to a script, you will want to pass it through |
| 3728 rebase_path() (see "gn help rebase_path") to convert it to be relative to the | 3498 rebase_path() (see "gn help rebase_path") to convert it to be relative to the |
| 3729 build directory. | 3499 build directory. |
| 3730 | 3500 |
| 3731 See also "gn help root_gen_dir". | 3501 See also "gn help root_gen_dir". |
| 3732 | |
| 3733 ``` | 3502 ``` |
| 3734 | 3503 |
| 3735 #### **Example** | 3504 #### **Example** |
| 3736 | 3505 |
| 3737 ``` | 3506 ``` |
| 3738 action("myscript") { | 3507 action("myscript") { |
| 3739 # Pass the generated output dir to the script. | 3508 # Pass the generated output dir to the script. |
| 3740 args = [ "-o", rebase_path(target_gen_dir, root_build_dir) ]" | 3509 args = [ "-o", rebase_path(target_gen_dir, root_build_dir) ]" |
| 3741 } | 3510 } |
| 3742 | |
| 3743 | |
| 3744 ``` | 3511 ``` |
| 3745 ### <a name="target_name"></a>**target_name**: [string] The name of the current
target. | 3512 ### <a name="target_name"></a>**target_name**: [string] The name of the current
target. |
| 3746 | 3513 |
| 3747 ``` | 3514 ``` |
| 3748 Inside a target or template invocation, this variable refers to the name | 3515 Inside a target or template invocation, this variable refers to the name |
| 3749 given to the target or template invocation. Outside of these, this variable | 3516 given to the target or template invocation. Outside of these, this variable |
| 3750 is undefined. | 3517 is undefined. |
| 3751 | 3518 |
| 3752 This is most often used in template definitions to name targets defined in | 3519 This is most often used in template definitions to name targets defined in |
| 3753 the template based on the name of the invocation. This is necessary both to | 3520 the template based on the name of the invocation. This is necessary both to |
| 3754 ensure generated targets have unique names and to generate a target with the | 3521 ensure generated targets have unique names and to generate a target with the |
| 3755 exact name of the invocation that other targets can depend on. | 3522 exact name of the invocation that other targets can depend on. |
| 3756 | 3523 |
| 3757 Be aware that this value will always reflect the innermost scope. So when | 3524 Be aware that this value will always reflect the innermost scope. So when |
| 3758 defining a target inside a template, target_name will refer to the target | 3525 defining a target inside a template, target_name will refer to the target |
| 3759 rather than the template invocation. To get the name of the template | 3526 rather than the template invocation. To get the name of the template |
| 3760 invocation in this case, you should save target_name to a temporary variable | 3527 invocation in this case, you should save target_name to a temporary variable |
| 3761 outside of any target definitions. | 3528 outside of any target definitions. |
| 3762 | 3529 |
| 3763 See "gn help template" for more examples. | 3530 See "gn help template" for more examples. |
| 3764 | |
| 3765 ``` | 3531 ``` |
| 3766 | 3532 |
| 3767 #### **Example** | 3533 #### **Example** |
| 3768 | 3534 |
| 3769 ``` | 3535 ``` |
| 3770 executable("doom_melon") { | 3536 executable("doom_melon") { |
| 3771 print(target_name) # Prints "doom_melon". | 3537 print(target_name) # Prints "doom_melon". |
| 3772 } | 3538 } |
| 3773 | 3539 |
| 3774 template("my_template") { | 3540 template("my_template") { |
| 3775 print(target_name) # Prints "space_ray" when invoked below. | 3541 print(target_name) # Prints "space_ray" when invoked below. |
| 3776 | 3542 |
| 3777 executable(target_name + "_impl") { | 3543 executable(target_name + "_impl") { |
| 3778 print(target_name) # Prints "space_ray_impl". | 3544 print(target_name) # Prints "space_ray_impl". |
| 3779 } | 3545 } |
| 3780 } | 3546 } |
| 3781 | 3547 |
| 3782 my_template("space_ray") { | 3548 my_template("space_ray") { |
| 3783 } | 3549 } |
| 3784 | |
| 3785 | |
| 3786 ``` | 3550 ``` |
| 3787 ### <a name="target_os"></a>**target_os**: The desired operating system for the
build. | 3551 ### <a name="target_os"></a>**target_os**: The desired operating system for the
build. |
| 3788 | 3552 |
| 3789 ``` | 3553 ``` |
| 3790 This value should be used to indicate the desired operating system for the | 3554 This value should be used to indicate the desired operating system for the |
| 3791 primary object(s) of the build. It will match the OS of the default | 3555 primary object(s) of the build. It will match the OS of the default |
| 3792 toolchain. | 3556 toolchain. |
| 3793 | 3557 |
| 3794 In many cases, this is the same as "host_os", but in the case of | 3558 In many cases, this is the same as "host_os", but in the case of |
| 3795 cross-compiles, it may be different. This variable differs from "current_os" | 3559 cross-compiles, it may be different. This variable differs from "current_os" |
| 3796 in that it can be referenced from inside any toolchain and will always return | 3560 in that it can be referenced from inside any toolchain and will always return |
| 3797 the initial value. | 3561 the initial value. |
| 3798 | 3562 |
| 3799 This should be set to the most specific value possible. So, "android" or | 3563 This should be set to the most specific value possible. So, "android" or |
| 3800 "chromeos" should be used instead of "linux" where applicable, even though | 3564 "chromeos" should be used instead of "linux" where applicable, even though |
| 3801 Android and ChromeOS are both Linux variants. This can mean that one needs to | 3565 Android and ChromeOS are both Linux variants. This can mean that one needs to |
| 3802 write | 3566 write |
| 3803 | 3567 |
| 3804 if (target_os == "android" || target_os == "linux") { | 3568 if (target_os == "android" || target_os == "linux") { |
| 3805 # ... | 3569 # ... |
| 3806 } | 3570 } |
| 3807 | 3571 |
| 3808 and so forth. | 3572 and so forth. |
| 3809 | 3573 |
| 3810 This value is not used internally by GN for any purpose, so it may be set to | 3574 This value is not used internally by GN for any purpose, so it may be set to |
| 3811 whatever value is needed for the build. GN defaults this value to the empty | 3575 whatever value is needed for the build. GN defaults this value to the empty |
| 3812 string ("") and the configuration files should set it to an appropriate value | 3576 string ("") and the configuration files should set it to an appropriate value |
| 3813 (e.g., setting it to the value of "host_os") if it is not set via the command | 3577 (e.g., setting it to the value of "host_os") if it is not set via the command |
| 3814 line or in the args.gn file. | 3578 line or in the args.gn file. |
| 3815 | |
| 3816 ``` | 3579 ``` |
| 3817 | 3580 |
| 3818 #### **Possible values** | 3581 #### **Possible values** |
| 3819 | 3582 |
| 3820 ``` | 3583 ``` |
| 3821 - "android" | 3584 - "android" |
| 3822 - "chromeos" | 3585 - "chromeos" |
| 3823 - "ios" | 3586 - "ios" |
| 3824 - "linux" | 3587 - "linux" |
| 3825 - "nacl" | 3588 - "nacl" |
| 3826 - "mac" | 3589 - "mac" |
| 3827 - "win" | 3590 - "win" |
| 3828 | |
| 3829 | |
| 3830 ``` | 3591 ``` |
| 3831 ### <a name="target_out_dir"></a>**target_out_dir**: [string] Directory for targ
et output files. | 3592 ### <a name="target_out_dir"></a>**target_out_dir**: [string] Directory for targ
et output files. |
| 3832 | 3593 |
| 3833 ``` | 3594 ``` |
| 3834 Absolute path to the target's generated file directory. If your current | 3595 Absolute path to the target's generated file directory. If your current |
| 3835 target is in "//tools/doom_melon" then this value might be | 3596 target is in "//tools/doom_melon" then this value might be |
| 3836 "//out/Debug/obj/tools/doom_melon". It will not have a trailing slash. | 3597 "//out/Debug/obj/tools/doom_melon". It will not have a trailing slash. |
| 3837 | 3598 |
| 3838 This is primarily useful for setting up arguments for calling scripts. If you | 3599 This is primarily useful for setting up arguments for calling scripts. If you |
| 3839 are passing this to a script, you will want to pass it through rebase_path() | 3600 are passing this to a script, you will want to pass it through rebase_path() |
| 3840 (see "gn help rebase_path") to convert it to be relative to the build | 3601 (see "gn help rebase_path") to convert it to be relative to the build |
| 3841 directory. | 3602 directory. |
| 3842 | 3603 |
| 3843 See also "gn help root_out_dir". | 3604 See also "gn help root_out_dir". |
| 3844 | |
| 3845 ``` | 3605 ``` |
| 3846 | 3606 |
| 3847 #### **Example** | 3607 #### **Example** |
| 3848 | 3608 |
| 3849 ``` | 3609 ``` |
| 3850 action("myscript") { | 3610 action("myscript") { |
| 3851 # Pass the output dir to the script. | 3611 # Pass the output dir to the script. |
| 3852 args = [ "-o", rebase_path(target_out_dir, root_build_dir) ]" | 3612 args = [ "-o", rebase_path(target_out_dir, root_build_dir) ]" |
| 3853 | 3613 |
| 3854 } | 3614 } |
| 3855 | |
| 3856 | |
| 3857 ``` | 3615 ``` |
| 3858 ## <a name="target_variables"></a>Variables you set in targets | 3616 ## <a name="target_variables"></a>Variables you set in targets |
| 3859 | 3617 |
| 3860 ### <a name="all_dependent_configs"></a>**all_dependent_configs**: Configs to be
forced on dependents. | 3618 ### <a name="all_dependent_configs"></a>**all_dependent_configs**: Configs to be
forced on dependents. |
| 3861 | 3619 |
| 3862 ``` | 3620 ``` |
| 3863 A list of config labels. | 3621 A list of config labels. |
| 3864 | 3622 |
| 3865 All targets depending on this one, and recursively, all targets depending on | 3623 All targets depending on this one, and recursively, all targets depending on |
| 3866 those, will have the configs listed in this variable added to them. These | 3624 those, will have the configs listed in this variable added to them. These |
| 3867 configs will also apply to the current target. | 3625 configs will also apply to the current target. |
| 3868 | 3626 |
| 3869 This addition happens in a second phase once a target and all of its | 3627 This addition happens in a second phase once a target and all of its |
| 3870 dependencies have been resolved. Therefore, a target will not see these | 3628 dependencies have been resolved. Therefore, a target will not see these |
| 3871 force-added configs in their "configs" variable while the script is running, | 3629 force-added configs in their "configs" variable while the script is running, |
| 3872 and they can not be removed. As a result, this capability should generally | 3630 and they can not be removed. As a result, this capability should generally |
| 3873 only be used to add defines and include directories necessary to compile a | 3631 only be used to add defines and include directories necessary to compile a |
| 3874 target's headers. | 3632 target's headers. |
| 3875 | 3633 |
| 3876 See also "public_configs". | 3634 See also "public_configs". |
| 3877 | |
| 3878 ``` | 3635 ``` |
| 3879 | 3636 |
| 3880 #### **Ordering of flags and values** | 3637 #### **Ordering of flags and values** |
| 3881 | 3638 |
| 3882 ``` | 3639 ``` |
| 3883 1. Those set on the current target (not in a config). | 3640 1. Those set on the current target (not in a config). |
| 3884 2. Those set on the "configs" on the target in order that the | 3641 2. Those set on the "configs" on the target in order that the |
| 3885 configs appear in the list. | 3642 configs appear in the list. |
| 3886 3. Those set on the "all_dependent_configs" on the target in order | 3643 3. Those set on the "all_dependent_configs" on the target in order |
| 3887 that the configs appear in the list. | 3644 that the configs appear in the list. |
| 3888 4. Those set on the "public_configs" on the target in order that | 3645 4. Those set on the "public_configs" on the target in order that |
| 3889 those configs appear in the list. | 3646 those configs appear in the list. |
| 3890 5. all_dependent_configs pulled from dependencies, in the order of | 3647 5. all_dependent_configs pulled from dependencies, in the order of |
| 3891 the "deps" list. This is done recursively. If a config appears | 3648 the "deps" list. This is done recursively. If a config appears |
| 3892 more than once, only the first occurance will be used. | 3649 more than once, only the first occurance will be used. |
| 3893 6. public_configs pulled from dependencies, in the order of the | 3650 6. public_configs pulled from dependencies, in the order of the |
| 3894 "deps" list. If a dependency is public, they will be applied | 3651 "deps" list. If a dependency is public, they will be applied |
| 3895 recursively. | 3652 recursively. |
| 3896 | |
| 3897 | |
| 3898 ``` | 3653 ``` |
| 3899 ### <a name="allow_circular_includes_from"></a>**allow_circular_includes_from**:
Permit includes from deps. | 3654 ### <a name="allow_circular_includes_from"></a>**allow_circular_includes_from**:
Permit includes from deps. |
| 3900 | 3655 |
| 3901 ``` | 3656 ``` |
| 3902 A list of target labels. Must be a subset of the target's "deps". These | 3657 A list of target labels. Must be a subset of the target's "deps". These |
| 3903 targets will be permitted to include headers from the current target despite | 3658 targets will be permitted to include headers from the current target despite |
| 3904 the dependency going in the opposite direction. | 3659 the dependency going in the opposite direction. |
| 3905 | 3660 |
| 3906 When you use this, both targets must be included in a final binary for it to | 3661 When you use this, both targets must be included in a final binary for it to |
| 3907 link. To keep linker errors from happening, it is good practice to have all | 3662 link. To keep linker errors from happening, it is good practice to have all |
| 3908 external dependencies depend only on one of the two targets, and to set the | 3663 external dependencies depend only on one of the two targets, and to set the |
| 3909 visibility on the other to enforce this. Thus the targets will always be | 3664 visibility on the other to enforce this. Thus the targets will always be |
| 3910 linked together in any output. | 3665 linked together in any output. |
| 3911 | |
| 3912 ``` | 3666 ``` |
| 3913 | 3667 |
| 3914 #### **Details** | 3668 #### **Details** |
| 3915 | 3669 |
| 3916 ``` | 3670 ``` |
| 3917 Normally, for a file in target A to include a file from target B, A must list | 3671 Normally, for a file in target A to include a file from target B, A must list |
| 3918 B as a dependency. This invariant is enforced by the "gn check" command (and | 3672 B as a dependency. This invariant is enforced by the "gn check" command (and |
| 3919 the --check flag to "gn gen" -- see "gn help check"). | 3673 the --check flag to "gn gen" -- see "gn help check"). |
| 3920 | 3674 |
| 3921 Sometimes, two targets might be the same unit for linking purposes (two | 3675 Sometimes, two targets might be the same unit for linking purposes (two |
| 3922 source sets or static libraries that would always be linked together in a | 3676 source sets or static libraries that would always be linked together in a |
| 3923 final executable or shared library) and they each include headers from the | 3677 final executable or shared library) and they each include headers from the |
| 3924 other: you want A to be able to include B's headers, and B to include A's | 3678 other: you want A to be able to include B's headers, and B to include A's |
| 3925 headers. This is not an ideal situation but is sometimes unavoidable. | 3679 headers. This is not an ideal situation but is sometimes unavoidable. |
| 3926 | 3680 |
| 3927 This list, if specified, lists which of the dependencies of the current | 3681 This list, if specified, lists which of the dependencies of the current |
| 3928 target can include header files from the current target. That is, if A | 3682 target can include header files from the current target. That is, if A |
| 3929 depends on B, B can only include headers from A if it is in A's | 3683 depends on B, B can only include headers from A if it is in A's |
| 3930 allow_circular_includes_from list. Normally includes must follow the | 3684 allow_circular_includes_from list. Normally includes must follow the |
| 3931 direction of dependencies, this flag allows them to go in the opposite | 3685 direction of dependencies, this flag allows them to go in the opposite |
| 3932 direction. | 3686 direction. |
| 3933 | |
| 3934 ``` | 3687 ``` |
| 3935 | 3688 |
| 3936 #### **Danger** | 3689 #### **Danger** |
| 3937 | 3690 |
| 3938 ``` | 3691 ``` |
| 3939 In the above example, A's headers are likely to include headers from A's | 3692 In the above example, A's headers are likely to include headers from A's |
| 3940 dependencies. Those dependencies may have public_configs that apply flags, | 3693 dependencies. Those dependencies may have public_configs that apply flags, |
| 3941 defines, and include paths that make those headers work properly. | 3694 defines, and include paths that make those headers work properly. |
| 3942 | 3695 |
| 3943 With allow_circular_includes_from, B can include A's headers, and | 3696 With allow_circular_includes_from, B can include A's headers, and |
| 3944 transitively from A's dependencies, without having the dependencies that | 3697 transitively from A's dependencies, without having the dependencies that |
| 3945 would bring in the public_configs those headers need. The result may be | 3698 would bring in the public_configs those headers need. The result may be |
| 3946 errors or inconsistent builds. | 3699 errors or inconsistent builds. |
| 3947 | 3700 |
| 3948 So when you use allow_circular_includes_from, make sure that any compiler | 3701 So when you use allow_circular_includes_from, make sure that any compiler |
| 3949 settings, flags, and include directories are the same between both targets | 3702 settings, flags, and include directories are the same between both targets |
| 3950 (consider putting such things in a shared config they can both reference). | 3703 (consider putting such things in a shared config they can both reference). |
| 3951 Make sure the dependencies are also the same (you might consider a group to | 3704 Make sure the dependencies are also the same (you might consider a group to |
| 3952 collect such dependencies they both depend on). | 3705 collect such dependencies they both depend on). |
| 3953 | |
| 3954 ``` | 3706 ``` |
| 3955 | 3707 |
| 3956 #### **Example** | 3708 #### **Example** |
| 3957 | 3709 |
| 3958 ``` | 3710 ``` |
| 3959 source_set("a") { | 3711 source_set("a") { |
| 3960 deps = [ ":b", ":a_b_shared_deps" ] | 3712 deps = [ ":b", ":a_b_shared_deps" ] |
| 3961 allow_circular_includes_from = [ ":b" ] | 3713 allow_circular_includes_from = [ ":b" ] |
| 3962 ... | 3714 ... |
| 3963 } | 3715 } |
| 3964 | 3716 |
| 3965 source_set("b") { | 3717 source_set("b") { |
| 3966 deps = [ ":a_b_shared_deps" ] | 3718 deps = [ ":a_b_shared_deps" ] |
| 3967 # Sources here can include headers from a despite lack of deps. | 3719 # Sources here can include headers from a despite lack of deps. |
| 3968 ... | 3720 ... |
| 3969 } | 3721 } |
| 3970 | 3722 |
| 3971 group("a_b_shared_deps") { | 3723 group("a_b_shared_deps") { |
| 3972 public_deps = [ ":c" ] | 3724 public_deps = [ ":c" ] |
| 3973 } | 3725 } |
| 3974 | |
| 3975 | |
| 3976 ``` | 3726 ``` |
| 3977 ### <a name="arflags"></a>**arflags**: Arguments passed to static_library archiv
er. | 3727 ### <a name="arflags"></a>**arflags**: Arguments passed to static_library archiv
er. |
| 3978 | 3728 |
| 3979 ``` | 3729 ``` |
| 3980 A list of flags passed to the archive/lib command that creates static | 3730 A list of flags passed to the archive/lib command that creates static |
| 3981 libraries. | 3731 libraries. |
| 3982 | 3732 |
| 3983 arflags are NOT pushed to dependents, so applying arflags to source sets or | 3733 arflags are NOT pushed to dependents, so applying arflags to source sets or |
| 3984 any other target type will be a no-op. As with ldflags, you could put the | 3734 any other target type will be a no-op. As with ldflags, you could put the |
| 3985 arflags in a config and set that as a public or "all dependent" config, but | 3735 arflags in a config and set that as a public or "all dependent" config, but |
| 3986 that will likely not be what you want. If you have a chain of static | 3736 that will likely not be what you want. If you have a chain of static |
| 3987 libraries dependent on each other, this can cause the flags to propagate up | 3737 libraries dependent on each other, this can cause the flags to propagate up |
| 3988 to other static libraries. Due to the nature of how arflags are typically | 3738 to other static libraries. Due to the nature of how arflags are typically |
| 3989 used, you will normally want to apply them directly on static_library targets | 3739 used, you will normally want to apply them directly on static_library targets |
| 3990 themselves. | 3740 themselves. |
| 3991 | |
| 3992 ``` | 3741 ``` |
| 3993 | 3742 |
| 3994 #### **Ordering of flags and values** | 3743 #### **Ordering of flags and values** |
| 3995 | 3744 |
| 3996 ``` | 3745 ``` |
| 3997 1. Those set on the current target (not in a config). | 3746 1. Those set on the current target (not in a config). |
| 3998 2. Those set on the "configs" on the target in order that the | 3747 2. Those set on the "configs" on the target in order that the |
| 3999 configs appear in the list. | 3748 configs appear in the list. |
| 4000 3. Those set on the "all_dependent_configs" on the target in order | 3749 3. Those set on the "all_dependent_configs" on the target in order |
| 4001 that the configs appear in the list. | 3750 that the configs appear in the list. |
| 4002 4. Those set on the "public_configs" on the target in order that | 3751 4. Those set on the "public_configs" on the target in order that |
| 4003 those configs appear in the list. | 3752 those configs appear in the list. |
| 4004 5. all_dependent_configs pulled from dependencies, in the order of | 3753 5. all_dependent_configs pulled from dependencies, in the order of |
| 4005 the "deps" list. This is done recursively. If a config appears | 3754 the "deps" list. This is done recursively. If a config appears |
| 4006 more than once, only the first occurance will be used. | 3755 more than once, only the first occurance will be used. |
| 4007 6. public_configs pulled from dependencies, in the order of the | 3756 6. public_configs pulled from dependencies, in the order of the |
| 4008 "deps" list. If a dependency is public, they will be applied | 3757 "deps" list. If a dependency is public, they will be applied |
| 4009 recursively. | 3758 recursively. |
| 4010 | |
| 4011 | |
| 4012 ``` | 3759 ``` |
| 4013 ### <a name="args"></a>**args**: Arguments passed to an action. | 3760 ### <a name="args"></a>**args**: Arguments passed to an action. |
| 4014 | 3761 |
| 4015 ``` | 3762 ``` |
| 4016 For action and action_foreach targets, args is the list of arguments to pass | 3763 For action and action_foreach targets, args is the list of arguments to pass |
| 4017 to the script. Typically you would use source expansion (see "gn help | 3764 to the script. Typically you would use source expansion (see "gn help |
| 4018 source_expansion") to insert the source file names. | 3765 source_expansion") to insert the source file names. |
| 4019 | 3766 |
| 4020 See also "gn help action" and "gn help action_foreach". | 3767 See also "gn help action" and "gn help action_foreach". |
| 4021 | |
| 4022 | |
| 4023 ``` | 3768 ``` |
| 4024 ### <a name="asmflags"></a>**asmflags**: Flags passed to the assembler. | 3769 ### <a name="asmflags"></a>**asmflags**: Flags passed to the assembler. |
| 4025 | 3770 |
| 4026 ``` | 3771 ``` |
| 4027 A list of strings. | 3772 A list of strings. |
| 4028 | 3773 |
| 4029 "asmflags" are passed to any invocation of a tool that takes an .asm or .S | 3774 "asmflags" are passed to any invocation of a tool that takes an .asm or .S |
| 4030 file as input. | 3775 file as input. |
| 4031 | |
| 4032 ``` | 3776 ``` |
| 4033 | 3777 |
| 4034 #### **Ordering of flags and values** | 3778 #### **Ordering of flags and values** |
| 4035 | 3779 |
| 4036 ``` | 3780 ``` |
| 4037 1. Those set on the current target (not in a config). | 3781 1. Those set on the current target (not in a config). |
| 4038 2. Those set on the "configs" on the target in order that the | 3782 2. Those set on the "configs" on the target in order that the |
| 4039 configs appear in the list. | 3783 configs appear in the list. |
| 4040 3. Those set on the "all_dependent_configs" on the target in order | 3784 3. Those set on the "all_dependent_configs" on the target in order |
| 4041 that the configs appear in the list. | 3785 that the configs appear in the list. |
| 4042 4. Those set on the "public_configs" on the target in order that | 3786 4. Those set on the "public_configs" on the target in order that |
| 4043 those configs appear in the list. | 3787 those configs appear in the list. |
| 4044 5. all_dependent_configs pulled from dependencies, in the order of | 3788 5. all_dependent_configs pulled from dependencies, in the order of |
| 4045 the "deps" list. This is done recursively. If a config appears | 3789 the "deps" list. This is done recursively. If a config appears |
| 4046 more than once, only the first occurance will be used. | 3790 more than once, only the first occurance will be used. |
| 4047 6. public_configs pulled from dependencies, in the order of the | 3791 6. public_configs pulled from dependencies, in the order of the |
| 4048 "deps" list. If a dependency is public, they will be applied | 3792 "deps" list. If a dependency is public, they will be applied |
| 4049 recursively. | 3793 recursively. |
| 4050 | |
| 4051 | |
| 4052 ``` | 3794 ``` |
| 4053 ### <a name="assert_no_deps"></a>**assert_no_deps**: Ensure no deps on these tar
gets. | 3795 ### <a name="assert_no_deps"></a>**assert_no_deps**: Ensure no deps on these tar
gets. |
| 4054 | 3796 |
| 4055 ``` | 3797 ``` |
| 4056 A list of label patterns. | 3798 A list of label patterns. |
| 4057 | 3799 |
| 4058 This list is a list of patterns that must not match any of the transitive | 3800 This list is a list of patterns that must not match any of the transitive |
| 4059 dependencies of the target. These include all public, private, and data | 3801 dependencies of the target. These include all public, private, and data |
| 4060 dependencies, and cross shared library boundaries. This allows you to express | 3802 dependencies, and cross shared library boundaries. This allows you to express |
| 4061 that undesirable code isn't accidentally added to downstream dependencies in | 3803 that undesirable code isn't accidentally added to downstream dependencies in |
| 4062 a way that might otherwise be difficult to notice. | 3804 a way that might otherwise be difficult to notice. |
| 4063 | 3805 |
| 4064 Checking does not cross executable boundaries. If a target depends on an | 3806 Checking does not cross executable boundaries. If a target depends on an |
| 4065 executable, it's assumed that the executable is a tool that is producing part | 3807 executable, it's assumed that the executable is a tool that is producing part |
| 4066 of the build rather than something that is linked and distributed. This | 3808 of the build rather than something that is linked and distributed. This |
| 4067 allows assert_no_deps to express what is distributed in the final target | 3809 allows assert_no_deps to express what is distributed in the final target |
| 4068 rather than depend on the internal build steps (which may include | 3810 rather than depend on the internal build steps (which may include |
| 4069 non-distributable code). | 3811 non-distributable code). |
| 4070 | 3812 |
| 4071 See "gn help label_pattern" for the format of the entries in the list. These | 3813 See "gn help label_pattern" for the format of the entries in the list. These |
| 4072 patterns allow blacklisting individual targets or whole directory | 3814 patterns allow blacklisting individual targets or whole directory |
| 4073 hierarchies. | 3815 hierarchies. |
| 4074 | 3816 |
| 4075 Sometimes it is desirable to enforce that many targets have no dependencies | 3817 Sometimes it is desirable to enforce that many targets have no dependencies |
| 4076 on a target or set of targets. One efficient way to express this is to create | 3818 on a target or set of targets. One efficient way to express this is to create |
| 4077 a group with the assert_no_deps rule on it, and make that group depend on all | 3819 a group with the assert_no_deps rule on it, and make that group depend on all |
| 4078 targets you want to apply that assertion to. | 3820 targets you want to apply that assertion to. |
| 4079 | |
| 4080 ``` | 3821 ``` |
| 4081 | 3822 |
| 4082 #### **Example** | 3823 #### **Example** |
| 4083 | 3824 |
| 4084 ``` | 3825 ``` |
| 4085 executable("doom_melon") { | 3826 executable("doom_melon") { |
| 4086 deps = [ "//foo:bar" ] | 3827 deps = [ "//foo:bar" ] |
| 4087 ... | 3828 ... |
| 4088 assert_no_deps = [ | 3829 assert_no_deps = [ |
| 4089 "//evil/*", # Don't link any code from the evil directory. | 3830 "//evil/*", # Don't link any code from the evil directory. |
| 4090 "//foo:test_support", # This target is also disallowed. | 3831 "//foo:test_support", # This target is also disallowed. |
| 4091 ] | 3832 ] |
| 4092 } | 3833 } |
| 4093 | |
| 4094 | |
| 4095 ``` | 3834 ``` |
| 4096 ### <a name="bundle_deps_filter"></a>**bundle_deps_filter**: [label list] A list
of labels that are filtered out. | 3835 ### <a name="bundle_deps_filter"></a>**bundle_deps_filter**: [label list] A list
of labels that are filtered out. |
| 4097 | 3836 |
| 4098 ``` | 3837 ``` |
| 4099 A list of target labels. | 3838 A list of target labels. |
| 4100 | 3839 |
| 4101 This list contains target label patterns that should be filtered out when | 3840 This list contains target label patterns that should be filtered out when |
| 4102 creating the bundle. Any target matching one of those label will be removed | 3841 creating the bundle. Any target matching one of those label will be removed |
| 4103 from the dependencies of the create_bundle target. | 3842 from the dependencies of the create_bundle target. |
| 4104 | 3843 |
| 4105 This is mostly useful when creating application extension bundle as the | 3844 This is mostly useful when creating application extension bundle as the |
| 4106 application extension has access to runtime resources from the application | 3845 application extension has access to runtime resources from the application |
| 4107 bundle and thus do not require a second copy. | 3846 bundle and thus do not require a second copy. |
| 4108 | 3847 |
| 4109 See "gn help create_bundle" for more information. | 3848 See "gn help create_bundle" for more information. |
| 4110 | |
| 4111 ``` | 3849 ``` |
| 4112 | 3850 |
| 4113 #### **Example** | 3851 #### **Example** |
| 4114 | 3852 |
| 4115 ``` | 3853 ``` |
| 4116 create_bundle("today_extension") { | 3854 create_bundle("today_extension") { |
| 4117 deps = [ | 3855 deps = [ |
| 4118 "//base" | 3856 "//base" |
| 4119 ] | 3857 ] |
| 4120 bundle_root_dir = "$root_out_dir/today_extension.appex" | 3858 bundle_root_dir = "$root_out_dir/today_extension.appex" |
| 4121 bundle_deps_filter = [ | 3859 bundle_deps_filter = [ |
| 4122 # The extension uses //base but does not use any function calling into | 3860 # The extension uses //base but does not use any function calling into |
| 4123 # third_party/icu and thus does not need the icudtl.dat file. | 3861 # third_party/icu and thus does not need the icudtl.dat file. |
| 4124 "//third_party/icu:icudata", | 3862 "//third_party/icu:icudata", |
| 4125 ] | 3863 ] |
| 4126 } | 3864 } |
| 4127 | |
| 4128 | |
| 4129 ``` | 3865 ``` |
| 4130 ### <a name="bundle_executable_dir"></a>**bundle_executable_dir**: Expansion of
{{bundle_executable_dir}} in | 3866 ### <a name="bundle_executable_dir"></a>**bundle_executable_dir**: Expansion of
{{bundle_executable_dir}} in |
| 4131 ``` | 3867 ``` |
| 4132 create_bundle. | 3868 create_bundle. |
| 4133 | 3869 |
| 4134 A string corresponding to a path in $root_build_dir. | 3870 A string corresponding to a path in $root_build_dir. |
| 4135 | 3871 |
| 4136 This string is used by the "create_bundle" target to expand the | 3872 This string is used by the "create_bundle" target to expand the |
| 4137 {{bundle_executable_dir}} of the "bundle_data" target it depends on. This | 3873 {{bundle_executable_dir}} of the "bundle_data" target it depends on. This |
| 4138 must correspond to a path under "bundle_root_dir". | 3874 must correspond to a path under "bundle_root_dir". |
| 4139 | 3875 |
| 4140 See "gn help bundle_root_dir" for examples. | 3876 See "gn help bundle_root_dir" for examples. |
| 4141 | |
| 4142 | |
| 4143 ``` | 3877 ``` |
| 4144 ### <a name="bundle_plugins_dir"></a>**bundle_plugins_dir**: Expansion of {{bund
le_plugins_dir}} in create_bundle. | 3878 ### <a name="bundle_plugins_dir"></a>**bundle_plugins_dir**: Expansion of {{bund
le_plugins_dir}} in create_bundle. |
| 4145 | 3879 |
| 4146 ``` | 3880 ``` |
| 4147 A string corresponding to a path in $root_build_dir. | 3881 A string corresponding to a path in $root_build_dir. |
| 4148 | 3882 |
| 4149 This string is used by the "create_bundle" target to expand the | 3883 This string is used by the "create_bundle" target to expand the |
| 4150 {{bundle_plugins_dir}} of the "bundle_data" target it depends on. This must | 3884 {{bundle_plugins_dir}} of the "bundle_data" target it depends on. This must |
| 4151 correspond to a path under "bundle_root_dir". | 3885 correspond to a path under "bundle_root_dir". |
| 4152 | 3886 |
| 4153 See "gn help bundle_root_dir" for examples. | 3887 See "gn help bundle_root_dir" for examples. |
| 4154 | |
| 4155 | |
| 4156 ``` | 3888 ``` |
| 4157 ### <a name="bundle_resources_dir"></a>**bundle_resources_dir**: Expansion of {{
bundle_resources_dir}} in | 3889 ### <a name="bundle_resources_dir"></a>**bundle_resources_dir**: Expansion of {{
bundle_resources_dir}} in |
| 4158 ``` | 3890 ``` |
| 4159 create_bundle. | 3891 create_bundle. |
| 4160 | 3892 |
| 4161 A string corresponding to a path in $root_build_dir. | 3893 A string corresponding to a path in $root_build_dir. |
| 4162 | 3894 |
| 4163 This string is used by the "create_bundle" target to expand the | 3895 This string is used by the "create_bundle" target to expand the |
| 4164 {{bundle_resources_dir}} of the "bundle_data" target it depends on. This must | 3896 {{bundle_resources_dir}} of the "bundle_data" target it depends on. This must |
| 4165 correspond to a path under "bundle_root_dir". | 3897 correspond to a path under "bundle_root_dir". |
| 4166 | 3898 |
| 4167 See "gn help bundle_root_dir" for examples. | 3899 See "gn help bundle_root_dir" for examples. |
| 4168 | |
| 4169 | |
| 4170 ``` | 3900 ``` |
| 4171 ### <a name="bundle_root_dir"></a>**bundle_root_dir**: Expansion of {{bundle_roo
t_dir}} in create_bundle. | 3901 ### <a name="bundle_root_dir"></a>**bundle_root_dir**: Expansion of {{bundle_roo
t_dir}} in create_bundle. |
| 4172 | 3902 |
| 4173 ``` | 3903 ``` |
| 4174 A string corresponding to a path in root_build_dir. | 3904 A string corresponding to a path in root_build_dir. |
| 4175 | 3905 |
| 4176 This string is used by the "create_bundle" target to expand the | 3906 This string is used by the "create_bundle" target to expand the |
| 4177 {{bundle_root_dir}} of the "bundle_data" target it depends on. This must | 3907 {{bundle_root_dir}} of the "bundle_data" target it depends on. This must |
| 4178 correspond to a path under root_build_dir. | 3908 correspond to a path under root_build_dir. |
| 4179 | |
| 4180 ``` | 3909 ``` |
| 4181 | 3910 |
| 4182 #### **Example** | 3911 #### **Example** |
| 4183 | 3912 |
| 4184 ``` | 3913 ``` |
| 4185 bundle_data("info_plist") { | 3914 bundle_data("info_plist") { |
| 4186 sources = [ "Info.plist" ] | 3915 sources = [ "Info.plist" ] |
| 4187 outputs = [ "{{bundle_root_dir}}/Info.plist" ] | 3916 outputs = [ "{{bundle_root_dir}}/Info.plist" ] |
| 4188 } | 3917 } |
| 4189 | 3918 |
| 4190 create_bundle("doom_melon.app") { | 3919 create_bundle("doom_melon.app") { |
| 4191 deps = [ ":info_plist" ] | 3920 deps = [ ":info_plist" ] |
| 4192 bundle_root_dir = root_build_dir + "/doom_melon.app/Contents" | 3921 bundle_root_dir = root_build_dir + "/doom_melon.app/Contents" |
| 4193 bundle_resources_dir = bundle_root_dir + "/Resources" | 3922 bundle_resources_dir = bundle_root_dir + "/Resources" |
| 4194 bundle_executable_dir = bundle_root_dir + "/MacOS" | 3923 bundle_executable_dir = bundle_root_dir + "/MacOS" |
| 4195 bundle_plugins_dir = bundle_root_dir + "/PlugIns" | 3924 bundle_plugins_dir = bundle_root_dir + "/PlugIns" |
| 4196 } | 3925 } |
| 4197 | |
| 4198 | |
| 4199 ``` | 3926 ``` |
| 4200 ### <a name="cflags*"></a>**cflags***: Flags passed to the C compiler. | 3927 ### <a name="cflags*"></a>**cflags***: Flags passed to the C compiler. |
| 4201 | 3928 |
| 4202 ``` | 3929 ``` |
| 4203 A list of strings. | 3930 A list of strings. |
| 4204 | 3931 |
| 4205 "cflags" are passed to all invocations of the C, C++, Objective C, and | 3932 "cflags" are passed to all invocations of the C, C++, Objective C, and |
| 4206 Objective C++ compilers. | 3933 Objective C++ compilers. |
| 4207 | 3934 |
| 4208 To target one of these variants individually, use "cflags_c", "cflags_cc", | 3935 To target one of these variants individually, use "cflags_c", "cflags_cc", |
| 4209 "cflags_objc", and "cflags_objcc", respectively. These variant-specific | 3936 "cflags_objc", and "cflags_objcc", respectively. These variant-specific |
| 4210 versions of cflags* will be appended on the compiler command line after | 3937 versions of cflags* will be appended on the compiler command line after |
| 4211 "cflags". | 3938 "cflags". |
| 4212 | 3939 |
| 4213 See also "asmflags" for flags for assembly-language files. | 3940 See also "asmflags" for flags for assembly-language files. |
| 4214 | |
| 4215 ``` | 3941 ``` |
| 4216 | 3942 |
| 4217 #### **Ordering of flags and values** | 3943 #### **Ordering of flags and values** |
| 4218 | 3944 |
| 4219 ``` | 3945 ``` |
| 4220 1. Those set on the current target (not in a config). | 3946 1. Those set on the current target (not in a config). |
| 4221 2. Those set on the "configs" on the target in order that the | 3947 2. Those set on the "configs" on the target in order that the |
| 4222 configs appear in the list. | 3948 configs appear in the list. |
| 4223 3. Those set on the "all_dependent_configs" on the target in order | 3949 3. Those set on the "all_dependent_configs" on the target in order |
| 4224 that the configs appear in the list. | 3950 that the configs appear in the list. |
| 4225 4. Those set on the "public_configs" on the target in order that | 3951 4. Those set on the "public_configs" on the target in order that |
| 4226 those configs appear in the list. | 3952 those configs appear in the list. |
| 4227 5. all_dependent_configs pulled from dependencies, in the order of | 3953 5. all_dependent_configs pulled from dependencies, in the order of |
| 4228 the "deps" list. This is done recursively. If a config appears | 3954 the "deps" list. This is done recursively. If a config appears |
| 4229 more than once, only the first occurance will be used. | 3955 more than once, only the first occurance will be used. |
| 4230 6. public_configs pulled from dependencies, in the order of the | 3956 6. public_configs pulled from dependencies, in the order of the |
| 4231 "deps" list. If a dependency is public, they will be applied | 3957 "deps" list. If a dependency is public, they will be applied |
| 4232 recursively. | 3958 recursively. |
| 4233 | |
| 4234 | |
| 4235 ``` | 3959 ``` |
| 4236 ### <a name="cflags*"></a>**cflags***: Flags passed to the C compiler. | 3960 ### <a name="cflags*"></a>**cflags***: Flags passed to the C compiler. |
| 4237 | 3961 |
| 4238 ``` | 3962 ``` |
| 4239 A list of strings. | 3963 A list of strings. |
| 4240 | 3964 |
| 4241 "cflags" are passed to all invocations of the C, C++, Objective C, and | 3965 "cflags" are passed to all invocations of the C, C++, Objective C, and |
| 4242 Objective C++ compilers. | 3966 Objective C++ compilers. |
| 4243 | 3967 |
| 4244 To target one of these variants individually, use "cflags_c", "cflags_cc", | 3968 To target one of these variants individually, use "cflags_c", "cflags_cc", |
| 4245 "cflags_objc", and "cflags_objcc", respectively. These variant-specific | 3969 "cflags_objc", and "cflags_objcc", respectively. These variant-specific |
| 4246 versions of cflags* will be appended on the compiler command line after | 3970 versions of cflags* will be appended on the compiler command line after |
| 4247 "cflags". | 3971 "cflags". |
| 4248 | 3972 |
| 4249 See also "asmflags" for flags for assembly-language files. | 3973 See also "asmflags" for flags for assembly-language files. |
| 4250 | |
| 4251 ``` | 3974 ``` |
| 4252 | 3975 |
| 4253 #### **Ordering of flags and values** | 3976 #### **Ordering of flags and values** |
| 4254 | 3977 |
| 4255 ``` | 3978 ``` |
| 4256 1. Those set on the current target (not in a config). | 3979 1. Those set on the current target (not in a config). |
| 4257 2. Those set on the "configs" on the target in order that the | 3980 2. Those set on the "configs" on the target in order that the |
| 4258 configs appear in the list. | 3981 configs appear in the list. |
| 4259 3. Those set on the "all_dependent_configs" on the target in order | 3982 3. Those set on the "all_dependent_configs" on the target in order |
| 4260 that the configs appear in the list. | 3983 that the configs appear in the list. |
| 4261 4. Those set on the "public_configs" on the target in order that | 3984 4. Those set on the "public_configs" on the target in order that |
| 4262 those configs appear in the list. | 3985 those configs appear in the list. |
| 4263 5. all_dependent_configs pulled from dependencies, in the order of | 3986 5. all_dependent_configs pulled from dependencies, in the order of |
| 4264 the "deps" list. This is done recursively. If a config appears | 3987 the "deps" list. This is done recursively. If a config appears |
| 4265 more than once, only the first occurance will be used. | 3988 more than once, only the first occurance will be used. |
| 4266 6. public_configs pulled from dependencies, in the order of the | 3989 6. public_configs pulled from dependencies, in the order of the |
| 4267 "deps" list. If a dependency is public, they will be applied | 3990 "deps" list. If a dependency is public, they will be applied |
| 4268 recursively. | 3991 recursively. |
| 4269 | |
| 4270 | |
| 4271 ``` | 3992 ``` |
| 4272 ### <a name="cflags*"></a>**cflags***: Flags passed to the C compiler. | 3993 ### <a name="cflags*"></a>**cflags***: Flags passed to the C compiler. |
| 4273 | 3994 |
| 4274 ``` | 3995 ``` |
| 4275 A list of strings. | 3996 A list of strings. |
| 4276 | 3997 |
| 4277 "cflags" are passed to all invocations of the C, C++, Objective C, and | 3998 "cflags" are passed to all invocations of the C, C++, Objective C, and |
| 4278 Objective C++ compilers. | 3999 Objective C++ compilers. |
| 4279 | 4000 |
| 4280 To target one of these variants individually, use "cflags_c", "cflags_cc", | 4001 To target one of these variants individually, use "cflags_c", "cflags_cc", |
| 4281 "cflags_objc", and "cflags_objcc", respectively. These variant-specific | 4002 "cflags_objc", and "cflags_objcc", respectively. These variant-specific |
| 4282 versions of cflags* will be appended on the compiler command line after | 4003 versions of cflags* will be appended on the compiler command line after |
| 4283 "cflags". | 4004 "cflags". |
| 4284 | 4005 |
| 4285 See also "asmflags" for flags for assembly-language files. | 4006 See also "asmflags" for flags for assembly-language files. |
| 4286 | |
| 4287 ``` | 4007 ``` |
| 4288 | 4008 |
| 4289 #### **Ordering of flags and values** | 4009 #### **Ordering of flags and values** |
| 4290 | 4010 |
| 4291 ``` | 4011 ``` |
| 4292 1. Those set on the current target (not in a config). | 4012 1. Those set on the current target (not in a config). |
| 4293 2. Those set on the "configs" on the target in order that the | 4013 2. Those set on the "configs" on the target in order that the |
| 4294 configs appear in the list. | 4014 configs appear in the list. |
| 4295 3. Those set on the "all_dependent_configs" on the target in order | 4015 3. Those set on the "all_dependent_configs" on the target in order |
| 4296 that the configs appear in the list. | 4016 that the configs appear in the list. |
| 4297 4. Those set on the "public_configs" on the target in order that | 4017 4. Those set on the "public_configs" on the target in order that |
| 4298 those configs appear in the list. | 4018 those configs appear in the list. |
| 4299 5. all_dependent_configs pulled from dependencies, in the order of | 4019 5. all_dependent_configs pulled from dependencies, in the order of |
| 4300 the "deps" list. This is done recursively. If a config appears | 4020 the "deps" list. This is done recursively. If a config appears |
| 4301 more than once, only the first occurance will be used. | 4021 more than once, only the first occurance will be used. |
| 4302 6. public_configs pulled from dependencies, in the order of the | 4022 6. public_configs pulled from dependencies, in the order of the |
| 4303 "deps" list. If a dependency is public, they will be applied | 4023 "deps" list. If a dependency is public, they will be applied |
| 4304 recursively. | 4024 recursively. |
| 4305 | |
| 4306 | |
| 4307 ``` | 4025 ``` |
| 4308 ### <a name="cflags*"></a>**cflags***: Flags passed to the C compiler. | 4026 ### <a name="cflags*"></a>**cflags***: Flags passed to the C compiler. |
| 4309 | 4027 |
| 4310 ``` | 4028 ``` |
| 4311 A list of strings. | 4029 A list of strings. |
| 4312 | 4030 |
| 4313 "cflags" are passed to all invocations of the C, C++, Objective C, and | 4031 "cflags" are passed to all invocations of the C, C++, Objective C, and |
| 4314 Objective C++ compilers. | 4032 Objective C++ compilers. |
| 4315 | 4033 |
| 4316 To target one of these variants individually, use "cflags_c", "cflags_cc", | 4034 To target one of these variants individually, use "cflags_c", "cflags_cc", |
| 4317 "cflags_objc", and "cflags_objcc", respectively. These variant-specific | 4035 "cflags_objc", and "cflags_objcc", respectively. These variant-specific |
| 4318 versions of cflags* will be appended on the compiler command line after | 4036 versions of cflags* will be appended on the compiler command line after |
| 4319 "cflags". | 4037 "cflags". |
| 4320 | 4038 |
| 4321 See also "asmflags" for flags for assembly-language files. | 4039 See also "asmflags" for flags for assembly-language files. |
| 4322 | |
| 4323 ``` | 4040 ``` |
| 4324 | 4041 |
| 4325 #### **Ordering of flags and values** | 4042 #### **Ordering of flags and values** |
| 4326 | 4043 |
| 4327 ``` | 4044 ``` |
| 4328 1. Those set on the current target (not in a config). | 4045 1. Those set on the current target (not in a config). |
| 4329 2. Those set on the "configs" on the target in order that the | 4046 2. Those set on the "configs" on the target in order that the |
| 4330 configs appear in the list. | 4047 configs appear in the list. |
| 4331 3. Those set on the "all_dependent_configs" on the target in order | 4048 3. Those set on the "all_dependent_configs" on the target in order |
| 4332 that the configs appear in the list. | 4049 that the configs appear in the list. |
| 4333 4. Those set on the "public_configs" on the target in order that | 4050 4. Those set on the "public_configs" on the target in order that |
| 4334 those configs appear in the list. | 4051 those configs appear in the list. |
| 4335 5. all_dependent_configs pulled from dependencies, in the order of | 4052 5. all_dependent_configs pulled from dependencies, in the order of |
| 4336 the "deps" list. This is done recursively. If a config appears | 4053 the "deps" list. This is done recursively. If a config appears |
| 4337 more than once, only the first occurance will be used. | 4054 more than once, only the first occurance will be used. |
| 4338 6. public_configs pulled from dependencies, in the order of the | 4055 6. public_configs pulled from dependencies, in the order of the |
| 4339 "deps" list. If a dependency is public, they will be applied | 4056 "deps" list. If a dependency is public, they will be applied |
| 4340 recursively. | 4057 recursively. |
| 4341 | |
| 4342 | |
| 4343 ``` | 4058 ``` |
| 4344 ### <a name="cflags*"></a>**cflags***: Flags passed to the C compiler. | 4059 ### <a name="cflags*"></a>**cflags***: Flags passed to the C compiler. |
| 4345 | 4060 |
| 4346 ``` | 4061 ``` |
| 4347 A list of strings. | 4062 A list of strings. |
| 4348 | 4063 |
| 4349 "cflags" are passed to all invocations of the C, C++, Objective C, and | 4064 "cflags" are passed to all invocations of the C, C++, Objective C, and |
| 4350 Objective C++ compilers. | 4065 Objective C++ compilers. |
| 4351 | 4066 |
| 4352 To target one of these variants individually, use "cflags_c", "cflags_cc", | 4067 To target one of these variants individually, use "cflags_c", "cflags_cc", |
| 4353 "cflags_objc", and "cflags_objcc", respectively. These variant-specific | 4068 "cflags_objc", and "cflags_objcc", respectively. These variant-specific |
| 4354 versions of cflags* will be appended on the compiler command line after | 4069 versions of cflags* will be appended on the compiler command line after |
| 4355 "cflags". | 4070 "cflags". |
| 4356 | 4071 |
| 4357 See also "asmflags" for flags for assembly-language files. | 4072 See also "asmflags" for flags for assembly-language files. |
| 4358 | |
| 4359 ``` | 4073 ``` |
| 4360 | 4074 |
| 4361 #### **Ordering of flags and values** | 4075 #### **Ordering of flags and values** |
| 4362 | 4076 |
| 4363 ``` | 4077 ``` |
| 4364 1. Those set on the current target (not in a config). | 4078 1. Those set on the current target (not in a config). |
| 4365 2. Those set on the "configs" on the target in order that the | 4079 2. Those set on the "configs" on the target in order that the |
| 4366 configs appear in the list. | 4080 configs appear in the list. |
| 4367 3. Those set on the "all_dependent_configs" on the target in order | 4081 3. Those set on the "all_dependent_configs" on the target in order |
| 4368 that the configs appear in the list. | 4082 that the configs appear in the list. |
| 4369 4. Those set on the "public_configs" on the target in order that | 4083 4. Those set on the "public_configs" on the target in order that |
| 4370 those configs appear in the list. | 4084 those configs appear in the list. |
| 4371 5. all_dependent_configs pulled from dependencies, in the order of | 4085 5. all_dependent_configs pulled from dependencies, in the order of |
| 4372 the "deps" list. This is done recursively. If a config appears | 4086 the "deps" list. This is done recursively. If a config appears |
| 4373 more than once, only the first occurance will be used. | 4087 more than once, only the first occurance will be used. |
| 4374 6. public_configs pulled from dependencies, in the order of the | 4088 6. public_configs pulled from dependencies, in the order of the |
| 4375 "deps" list. If a dependency is public, they will be applied | 4089 "deps" list. If a dependency is public, they will be applied |
| 4376 recursively. | 4090 recursively. |
| 4377 | |
| 4378 | |
| 4379 ``` | 4091 ``` |
| 4380 ### <a name="check_includes"></a>**check_includes**: [boolean] Controls whether
a target's files are checked. | 4092 ### <a name="check_includes"></a>**check_includes**: [boolean] Controls whether
a target's files are checked. |
| 4381 | 4093 |
| 4382 ``` | 4094 ``` |
| 4383 When true (the default), the "gn check" command (as well as "gn gen" with the | 4095 When true (the default), the "gn check" command (as well as "gn gen" with the |
| 4384 --check flag) will check this target's sources and headers for proper | 4096 --check flag) will check this target's sources and headers for proper |
| 4385 dependencies. | 4097 dependencies. |
| 4386 | 4098 |
| 4387 When false, the files in this target will be skipped by default. This does | 4099 When false, the files in this target will be skipped by default. This does |
| 4388 not affect other targets that depend on the current target, it just skips | 4100 not affect other targets that depend on the current target, it just skips |
| 4389 checking the includes of the current target's files. | 4101 checking the includes of the current target's files. |
| 4390 | 4102 |
| 4391 If there are a few conditionally included headers that trip up checking, you | 4103 If there are a few conditionally included headers that trip up checking, you |
| 4392 can exclude headers individually by annotating them with "nogncheck" (see "gn | 4104 can exclude headers individually by annotating them with "nogncheck" (see "gn |
| 4393 help nogncheck"). | 4105 help nogncheck"). |
| 4394 | 4106 |
| 4395 The topic "gn help check" has general information on how checking works and | 4107 The topic "gn help check" has general information on how checking works and |
| 4396 advice on how to pass a check in problematic cases. | 4108 advice on how to pass a check in problematic cases. |
| 4397 | |
| 4398 ``` | 4109 ``` |
| 4399 | 4110 |
| 4400 #### **Example** | 4111 #### **Example** |
| 4401 | 4112 |
| 4402 ``` | 4113 ``` |
| 4403 source_set("busted_includes") { | 4114 source_set("busted_includes") { |
| 4404 # This target's includes are messed up, exclude it from checking. | 4115 # This target's includes are messed up, exclude it from checking. |
| 4405 check_includes = false | 4116 check_includes = false |
| 4406 ... | 4117 ... |
| 4407 } | 4118 } |
| 4408 | |
| 4409 | |
| 4410 ``` | 4119 ``` |
| 4411 ### <a name="code_signing_args"></a>**code_signing_args**: [string list] Argumen
ts passed to code signing script. | 4120 ### <a name="code_signing_args"></a>**code_signing_args**: [string list] Argumen
ts passed to code signing script. |
| 4412 | 4121 |
| 4413 ``` | 4122 ``` |
| 4414 For create_bundle targets, code_signing_args is the list of arguments to pass | 4123 For create_bundle targets, code_signing_args is the list of arguments to pass |
| 4415 to the code signing script. Typically you would use source expansion (see "gn | 4124 to the code signing script. Typically you would use source expansion (see "gn |
| 4416 help source_expansion") to insert the source file names. | 4125 help source_expansion") to insert the source file names. |
| 4417 | 4126 |
| 4418 See also "gn help create_bundle". | 4127 See also "gn help create_bundle". |
| 4419 | |
| 4420 | |
| 4421 ``` | 4128 ``` |
| 4422 ### <a name="code_signing_outputs"></a>**code_signing_outputs**: [file list] Out
put files for code signing step. | 4129 ### <a name="code_signing_outputs"></a>**code_signing_outputs**: [file list] Out
put files for code signing step. |
| 4423 | 4130 |
| 4424 ``` | 4131 ``` |
| 4425 Outputs from the code signing step of a create_bundle target. Must refer to | 4132 Outputs from the code signing step of a create_bundle target. Must refer to |
| 4426 files in the build directory. | 4133 files in the build directory. |
| 4427 | 4134 |
| 4428 See also "gn help create_bundle". | 4135 See also "gn help create_bundle". |
| 4429 | |
| 4430 | |
| 4431 ``` | 4136 ``` |
| 4432 ### <a name="code_signing_script"></a>**code_signing_script**: [file name] Scrip
t for code signing." | 4137 ### <a name="code_signing_script"></a>**code_signing_script**: [file name] Scrip
t for code signing." |
| 4433 | 4138 |
| 4434 ``` | 4139 ``` |
| 4435 An absolute or buildfile-relative file name of a Python script to run for a | 4140 An absolute or buildfile-relative file name of a Python script to run for a |
| 4436 create_bundle target to perform code signing step. | 4141 create_bundle target to perform code signing step. |
| 4437 | 4142 |
| 4438 See also "gn help create_bundle". | 4143 See also "gn help create_bundle". |
| 4439 | |
| 4440 | |
| 4441 ``` | 4144 ``` |
| 4442 ### <a name="code_signing_sources"></a>**code_signing_sources**: [file list] Sou
rces for code signing step. | 4145 ### <a name="code_signing_sources"></a>**code_signing_sources**: [file list] Sou
rces for code signing step. |
| 4443 | 4146 |
| 4444 ``` | 4147 ``` |
| 4445 A list of files used as input for code signing script step of a create_bundle | 4148 A list of files used as input for code signing script step of a create_bundle |
| 4446 target. Non-absolute paths will be resolved relative to the current build | 4149 target. Non-absolute paths will be resolved relative to the current build |
| 4447 file. | 4150 file. |
| 4448 | 4151 |
| 4449 See also "gn help create_bundle". | 4152 See also "gn help create_bundle". |
| 4450 | |
| 4451 | |
| 4452 ``` | 4153 ``` |
| 4453 ### <a name="complete_static_lib"></a>**complete_static_lib**: [boolean] Links a
ll deps into a static library. | 4154 ### <a name="complete_static_lib"></a>**complete_static_lib**: [boolean] Links a
ll deps into a static library. |
| 4454 | 4155 |
| 4455 ``` | 4156 ``` |
| 4456 A static library normally doesn't include code from dependencies, but instead | 4157 A static library normally doesn't include code from dependencies, but instead |
| 4457 forwards the static libraries and source sets in its deps up the dependency | 4158 forwards the static libraries and source sets in its deps up the dependency |
| 4458 chain until a linkable target (an executable or shared library) is reached. | 4159 chain until a linkable target (an executable or shared library) is reached. |
| 4459 The final linkable target only links each static library once, even if it | 4160 The final linkable target only links each static library once, even if it |
| 4460 appears more than once in its dependency graph. | 4161 appears more than once in its dependency graph. |
| 4461 | 4162 |
| 4462 In some cases the static library might be the final desired output. For | 4163 In some cases the static library might be the final desired output. For |
| 4463 example, you may be producing a static library for distribution to third | 4164 example, you may be producing a static library for distribution to third |
| 4464 parties. In this case, the static library should include code for all | 4165 parties. In this case, the static library should include code for all |
| 4465 dependencies in one complete package. However, complete static libraries | 4166 dependencies in one complete package. However, complete static libraries |
| 4466 themselves are never linked into other complete static libraries. All | 4167 themselves are never linked into other complete static libraries. All |
| 4467 complete static libraries are for distribution and linking them in would | 4168 complete static libraries are for distribution and linking them in would |
| 4468 cause code duplication in this case. If the static library is not for | 4169 cause code duplication in this case. If the static library is not for |
| 4469 distribution, it should not be complete. | 4170 distribution, it should not be complete. |
| 4470 | 4171 |
| 4471 GN treats non-complete static libraries as source sets when they are linked | 4172 GN treats non-complete static libraries as source sets when they are linked |
| 4472 into complete static libraries. This is done because some tools like AR do | 4173 into complete static libraries. This is done because some tools like AR do |
| 4473 not handle dependent static libraries properly. This makes it easier to write | 4174 not handle dependent static libraries properly. This makes it easier to write |
| 4474 "alink" rules. | 4175 "alink" rules. |
| 4475 | 4176 |
| 4476 In rare cases it makes sense to list a header in more than one target if it | 4177 In rare cases it makes sense to list a header in more than one target if it |
| 4477 could be considered conceptually a member of both. libraries. | 4178 could be considered conceptually a member of both. libraries. |
| 4478 | |
| 4479 ``` | 4179 ``` |
| 4480 | 4180 |
| 4481 #### **Example** | 4181 #### **Example** |
| 4482 | 4182 |
| 4483 ``` | 4183 ``` |
| 4484 static_library("foo") { | 4184 static_library("foo") { |
| 4485 complete_static_lib = true | 4185 complete_static_lib = true |
| 4486 deps = [ "bar" ] | 4186 deps = [ "bar" ] |
| 4487 } | 4187 } |
| 4488 | |
| 4489 | |
| 4490 ``` | 4188 ``` |
| 4491 ### <a name="configs"></a>**configs**: Configs applying to this target or config
. | 4189 ### <a name="configs"></a>**configs**: Configs applying to this target or config
. |
| 4492 | 4190 |
| 4493 ``` | 4191 ``` |
| 4494 A list of config labels. | 4192 A list of config labels. |
| 4495 | |
| 4496 ``` | 4193 ``` |
| 4497 | 4194 |
| 4498 #### **Configs on a target** | 4195 #### **Configs on a target** |
| 4499 | 4196 |
| 4500 ``` | 4197 ``` |
| 4501 When used on a target, the include_dirs, defines, etc. in each config are | 4198 When used on a target, the include_dirs, defines, etc. in each config are |
| 4502 appended in the order they appear to the compile command for each file in the | 4199 appended in the order they appear to the compile command for each file in the |
| 4503 target. They will appear after the include_dirs, defines, etc. that the | 4200 target. They will appear after the include_dirs, defines, etc. that the |
| 4504 target sets directly. | 4201 target sets directly. |
| 4505 | 4202 |
| 4506 Since configs apply after the values set on a target, directly setting a | 4203 Since configs apply after the values set on a target, directly setting a |
| 4507 compiler flag will prepend it to the command line. If you want to append a | 4204 compiler flag will prepend it to the command line. If you want to append a |
| 4508 flag instead, you can put that flag in a one-off config and append that | 4205 flag instead, you can put that flag in a one-off config and append that |
| 4509 config to the target's configs list. | 4206 config to the target's configs list. |
| 4510 | 4207 |
| 4511 The build configuration script will generally set up the default configs | 4208 The build configuration script will generally set up the default configs |
| 4512 applying to a given target type (see "set_defaults"). When a target is being | 4209 applying to a given target type (see "set_defaults"). When a target is being |
| 4513 defined, it can add to or remove from this list. | 4210 defined, it can add to or remove from this list. |
| 4514 | |
| 4515 ``` | 4211 ``` |
| 4516 | 4212 |
| 4517 #### **Configs on a config** | 4213 #### **Configs on a config** |
| 4518 | 4214 |
| 4519 ``` | 4215 ``` |
| 4520 It is possible to create composite configs by specifying configs on a config. | 4216 It is possible to create composite configs by specifying configs on a config. |
| 4521 One might do this to forward values, or to factor out blocks of settings from | 4217 One might do this to forward values, or to factor out blocks of settings from |
| 4522 very large configs into more manageable named chunks. | 4218 very large configs into more manageable named chunks. |
| 4523 | 4219 |
| 4524 In this case, the composite config is expanded to be the concatenation of its | 4220 In this case, the composite config is expanded to be the concatenation of its |
| 4525 own values, and in order, the values from its sub-configs *before* anything | 4221 own values, and in order, the values from its sub-configs *before* anything |
| 4526 else happens. This has some ramifications: | 4222 else happens. This has some ramifications: |
| 4527 | 4223 |
| 4528 - A target has no visibility into a config's sub-configs. Target code only | 4224 - A target has no visibility into a config's sub-configs. Target code only |
| 4529 sees the name of the composite config. It can't remove sub-configs or opt | 4225 sees the name of the composite config. It can't remove sub-configs or opt |
| 4530 in to only parts of it. The composite config may not even be defined | 4226 in to only parts of it. The composite config may not even be defined |
| 4531 before the target is. | 4227 before the target is. |
| 4532 | 4228 |
| 4533 - You can get duplication of values if a config is listed twice, say, on a | 4229 - You can get duplication of values if a config is listed twice, say, on a |
| 4534 target and in a sub-config that also applies. In other cases, the configs | 4230 target and in a sub-config that also applies. In other cases, the configs |
| 4535 applying to a target are de-duped. It's expected that if a config is | 4231 applying to a target are de-duped. It's expected that if a config is |
| 4536 listed as a sub-config that it is only used in that context. (Note that | 4232 listed as a sub-config that it is only used in that context. (Note that |
| 4537 it's possible to fix this and de-dupe, but it's not normally relevant and | 4233 it's possible to fix this and de-dupe, but it's not normally relevant and |
| 4538 complicates the implementation.) | 4234 complicates the implementation.) |
| 4539 | |
| 4540 ``` | 4235 ``` |
| 4541 | 4236 |
| 4542 #### **Ordering of flags and values** | 4237 #### **Ordering of flags and values** |
| 4543 | 4238 |
| 4544 ``` | 4239 ``` |
| 4545 1. Those set on the current target (not in a config). | 4240 1. Those set on the current target (not in a config). |
| 4546 2. Those set on the "configs" on the target in order that the | 4241 2. Those set on the "configs" on the target in order that the |
| 4547 configs appear in the list. | 4242 configs appear in the list. |
| 4548 3. Those set on the "all_dependent_configs" on the target in order | 4243 3. Those set on the "all_dependent_configs" on the target in order |
| 4549 that the configs appear in the list. | 4244 that the configs appear in the list. |
| 4550 4. Those set on the "public_configs" on the target in order that | 4245 4. Those set on the "public_configs" on the target in order that |
| 4551 those configs appear in the list. | 4246 those configs appear in the list. |
| 4552 5. all_dependent_configs pulled from dependencies, in the order of | 4247 5. all_dependent_configs pulled from dependencies, in the order of |
| 4553 the "deps" list. This is done recursively. If a config appears | 4248 the "deps" list. This is done recursively. If a config appears |
| 4554 more than once, only the first occurance will be used. | 4249 more than once, only the first occurance will be used. |
| 4555 6. public_configs pulled from dependencies, in the order of the | 4250 6. public_configs pulled from dependencies, in the order of the |
| 4556 "deps" list. If a dependency is public, they will be applied | 4251 "deps" list. If a dependency is public, they will be applied |
| 4557 recursively. | 4252 recursively. |
| 4558 | |
| 4559 ``` | 4253 ``` |
| 4560 | 4254 |
| 4561 #### **Example** | 4255 #### **Example** |
| 4562 | 4256 |
| 4563 ``` | 4257 ``` |
| 4564 # Configs on a target. | 4258 # Configs on a target. |
| 4565 source_set("foo") { | 4259 source_set("foo") { |
| 4566 # Don't use the default RTTI config that BUILDCONFIG applied to us. | 4260 # Don't use the default RTTI config that BUILDCONFIG applied to us. |
| 4567 configs -= [ "//build:no_rtti" ] | 4261 configs -= [ "//build:no_rtti" ] |
| 4568 | 4262 |
| 4569 # Add some of our own settings. | 4263 # Add some of our own settings. |
| 4570 configs += [ ":mysettings" ] | 4264 configs += [ ":mysettings" ] |
| 4571 } | 4265 } |
| 4572 | 4266 |
| 4573 # Create a default_optimization config that forwards to one of a set of more | 4267 # Create a default_optimization config that forwards to one of a set of more |
| 4574 # specialized configs depending on build flags. This pattern is useful | 4268 # specialized configs depending on build flags. This pattern is useful |
| 4575 # because it allows a target to opt in to either a default set, or a more | 4269 # because it allows a target to opt in to either a default set, or a more |
| 4576 # specific set, while avoid duplicating the settings in two places. | 4270 # specific set, while avoid duplicating the settings in two places. |
| 4577 config("super_optimization") { | 4271 config("super_optimization") { |
| 4578 cflags = [ ... ] | 4272 cflags = [ ... ] |
| 4579 } | 4273 } |
| 4580 config("default_optimization") { | 4274 config("default_optimization") { |
| 4581 if (optimize_everything) { | 4275 if (optimize_everything) { |
| 4582 configs = [ ":super_optimization" ] | 4276 configs = [ ":super_optimization" ] |
| 4583 } else { | 4277 } else { |
| 4584 configs = [ ":no_optimization" ] | 4278 configs = [ ":no_optimization" ] |
| 4585 } | 4279 } |
| 4586 } | 4280 } |
| 4587 | |
| 4588 | |
| 4589 ``` | 4281 ``` |
| 4590 ### <a name="console"></a>**console**: Run this action in the console pool. | 4282 ### <a name="console"></a>**console**: Run this action in the console pool. |
| 4591 | 4283 |
| 4592 ``` | 4284 ``` |
| 4593 Boolean. Defaults to false. | 4285 Boolean. Defaults to false. |
| 4594 | 4286 |
| 4595 Actions marked "console = true" will be run in the built-in ninja "console" | 4287 Actions marked "console = true" will be run in the built-in ninja "console" |
| 4596 pool. They will have access to real stdin and stdout, and output will not be | 4288 pool. They will have access to real stdin and stdout, and output will not be |
| 4597 buffered by ninja. This can be useful for long-running actions with progress | 4289 buffered by ninja. This can be useful for long-running actions with progress |
| 4598 logs, or actions that require user input. | 4290 logs, or actions that require user input. |
| 4599 | 4291 |
| 4600 Only one console pool target can run at any one time in Ninja. Refer to the | 4292 Only one console pool target can run at any one time in Ninja. Refer to the |
| 4601 Ninja documentation on the console pool for more info. | 4293 Ninja documentation on the console pool for more info. |
| 4602 | |
| 4603 ``` | 4294 ``` |
| 4604 | 4295 |
| 4605 #### **Example** | 4296 #### **Example** |
| 4606 | 4297 |
| 4607 ``` | 4298 ``` |
| 4608 action("long_action_with_progress_logs") { | 4299 action("long_action_with_progress_logs") { |
| 4609 console = true | 4300 console = true |
| 4610 } | 4301 } |
| 4611 | |
| 4612 | |
| 4613 ``` | 4302 ``` |
| 4614 ### <a name="data"></a>**data**: Runtime data file dependencies. | 4303 ### <a name="data"></a>**data**: Runtime data file dependencies. |
| 4615 | 4304 |
| 4616 ``` | 4305 ``` |
| 4617 Lists files or directories required to run the given target. These are | 4306 Lists files or directories required to run the given target. These are |
| 4618 typically data files or directories of data files. The paths are interpreted | 4307 typically data files or directories of data files. The paths are interpreted |
| 4619 as being relative to the current build file. Since these are runtime | 4308 as being relative to the current build file. Since these are runtime |
| 4620 dependencies, they do not affect which targets are built or when. To declare | 4309 dependencies, they do not affect which targets are built or when. To declare |
| 4621 input files to a script, use "inputs". | 4310 input files to a script, use "inputs". |
| 4622 | 4311 |
| 4623 Appearing in the "data" section does not imply any special handling such as | 4312 Appearing in the "data" section does not imply any special handling such as |
| 4624 copying them to the output directory. This is just used for declaring runtime | 4313 copying them to the output directory. This is just used for declaring runtime |
| 4625 dependencies. Runtime dependencies can be queried using the "runtime_deps" | 4314 dependencies. Runtime dependencies can be queried using the "runtime_deps" |
| 4626 category of "gn desc" or written during build generation via | 4315 category of "gn desc" or written during build generation via |
| 4627 "--runtime-deps-list-file". | 4316 "--runtime-deps-list-file". |
| 4628 | 4317 |
| 4629 GN doesn't require data files to exist at build-time. So actions that produce | 4318 GN doesn't require data files to exist at build-time. So actions that produce |
| 4630 files that are in turn runtime dependencies can list those generated files | 4319 files that are in turn runtime dependencies can list those generated files |
| 4631 both in the "outputs" list as well as the "data" list. | 4320 both in the "outputs" list as well as the "data" list. |
| 4632 | 4321 |
| 4633 By convention, directories are listed with a trailing slash: | 4322 By convention, directories are listed with a trailing slash: |
| 4634 data = [ "test/data/" ] | 4323 data = [ "test/data/" ] |
| 4635 However, no verification is done on these so GN doesn't enforce this. The | 4324 However, no verification is done on these so GN doesn't enforce this. The |
| 4636 paths are just rebased and passed along when requested. | 4325 paths are just rebased and passed along when requested. |
| 4637 | 4326 |
| 4638 Note: On iOS and OS X, create_bundle targets will not be recursed into when | 4327 Note: On iOS and OS X, create_bundle targets will not be recursed into when |
| 4639 gathering data. See "gn help create_bundle" for details. | 4328 gathering data. See "gn help create_bundle" for details. |
| 4640 | 4329 |
| 4641 See "gn help runtime_deps" for how these are used. | 4330 See "gn help runtime_deps" for how these are used. |
| 4642 | |
| 4643 | |
| 4644 ``` | 4331 ``` |
| 4645 ### <a name="data_deps"></a>**data_deps**: Non-linked dependencies. | 4332 ### <a name="data_deps"></a>**data_deps**: Non-linked dependencies. |
| 4646 | 4333 |
| 4647 ``` | 4334 ``` |
| 4648 A list of target labels. | 4335 A list of target labels. |
| 4649 | 4336 |
| 4650 Specifies dependencies of a target that are not actually linked into the | 4337 Specifies dependencies of a target that are not actually linked into the |
| 4651 current target. Such dependencies will be built and will be available at | 4338 current target. Such dependencies will be built and will be available at |
| 4652 runtime. | 4339 runtime. |
| 4653 | 4340 |
| 4654 This is normally used for things like plugins or helper programs that a | 4341 This is normally used for things like plugins or helper programs that a |
| 4655 target needs at runtime. | 4342 target needs at runtime. |
| 4656 | 4343 |
| 4657 Note: On iOS and OS X, create_bundle targets will not be recursed into when | 4344 Note: On iOS and OS X, create_bundle targets will not be recursed into when |
| 4658 gathering data_deps. See "gn help create_bundle" for details. | 4345 gathering data_deps. See "gn help create_bundle" for details. |
| 4659 | 4346 |
| 4660 See also "gn help deps" and "gn help data". | 4347 See also "gn help deps" and "gn help data". |
| 4661 | |
| 4662 ``` | 4348 ``` |
| 4663 | 4349 |
| 4664 #### **Example** | 4350 #### **Example** |
| 4665 | 4351 |
| 4666 ``` | 4352 ``` |
| 4667 executable("foo") { | 4353 executable("foo") { |
| 4668 deps = [ "//base" ] | 4354 deps = [ "//base" ] |
| 4669 data_deps = [ "//plugins:my_runtime_plugin" ] | 4355 data_deps = [ "//plugins:my_runtime_plugin" ] |
| 4670 } | 4356 } |
| 4671 | |
| 4672 | |
| 4673 ``` | 4357 ``` |
| 4674 ### <a name="defines"></a>**defines**: C preprocessor defines. | 4358 ### <a name="defines"></a>**defines**: C preprocessor defines. |
| 4675 | 4359 |
| 4676 ``` | 4360 ``` |
| 4677 A list of strings | 4361 A list of strings |
| 4678 | 4362 |
| 4679 These strings will be passed to the C/C++ compiler as #defines. The strings | 4363 These strings will be passed to the C/C++ compiler as #defines. The strings |
| 4680 may or may not include an "=" to assign a value. | 4364 may or may not include an "=" to assign a value. |
| 4681 | |
| 4682 ``` | 4365 ``` |
| 4683 | 4366 |
| 4684 #### **Ordering of flags and values** | 4367 #### **Ordering of flags and values** |
| 4685 | 4368 |
| 4686 ``` | 4369 ``` |
| 4687 1. Those set on the current target (not in a config). | 4370 1. Those set on the current target (not in a config). |
| 4688 2. Those set on the "configs" on the target in order that the | 4371 2. Those set on the "configs" on the target in order that the |
| 4689 configs appear in the list. | 4372 configs appear in the list. |
| 4690 3. Those set on the "all_dependent_configs" on the target in order | 4373 3. Those set on the "all_dependent_configs" on the target in order |
| 4691 that the configs appear in the list. | 4374 that the configs appear in the list. |
| 4692 4. Those set on the "public_configs" on the target in order that | 4375 4. Those set on the "public_configs" on the target in order that |
| 4693 those configs appear in the list. | 4376 those configs appear in the list. |
| 4694 5. all_dependent_configs pulled from dependencies, in the order of | 4377 5. all_dependent_configs pulled from dependencies, in the order of |
| 4695 the "deps" list. This is done recursively. If a config appears | 4378 the "deps" list. This is done recursively. If a config appears |
| 4696 more than once, only the first occurance will be used. | 4379 more than once, only the first occurance will be used. |
| 4697 6. public_configs pulled from dependencies, in the order of the | 4380 6. public_configs pulled from dependencies, in the order of the |
| 4698 "deps" list. If a dependency is public, they will be applied | 4381 "deps" list. If a dependency is public, they will be applied |
| 4699 recursively. | 4382 recursively. |
| 4700 | |
| 4701 ``` | 4383 ``` |
| 4702 | 4384 |
| 4703 #### **Example** | 4385 #### **Example** |
| 4704 | 4386 |
| 4705 ``` | 4387 ``` |
| 4706 defines = [ "AWESOME_FEATURE", "LOG_LEVEL=3" ] | 4388 defines = [ "AWESOME_FEATURE", "LOG_LEVEL=3" ] |
| 4707 | |
| 4708 | |
| 4709 ``` | 4389 ``` |
| 4710 ### <a name="depfile"></a>**depfile**: [string] File name for input dependencies
for actions. | 4390 ### <a name="depfile"></a>**depfile**: [string] File name for input dependencies
for actions. |
| 4711 | 4391 |
| 4712 ``` | 4392 ``` |
| 4713 If nonempty, this string specifies that the current action or action_foreach | 4393 If nonempty, this string specifies that the current action or action_foreach |
| 4714 target will generate the given ".d" file containing the dependencies of the | 4394 target will generate the given ".d" file containing the dependencies of the |
| 4715 input. Empty or unset means that the script doesn't generate the files. | 4395 input. Empty or unset means that the script doesn't generate the files. |
| 4716 | 4396 |
| 4717 A depfile should be used only when a target depends on files that are not | 4397 A depfile should be used only when a target depends on files that are not |
| 4718 already specified by a target's inputs and sources. Likewise, depfiles should | 4398 already specified by a target's inputs and sources. Likewise, depfiles should |
| 4719 specify only those dependencies not already included in sources or inputs. | 4399 specify only those dependencies not already included in sources or inputs. |
| 4720 | 4400 |
| 4721 The .d file should go in the target output directory. If you have more than | 4401 The .d file should go in the target output directory. If you have more than |
| 4722 one source file that the script is being run over, you can use the output | 4402 one source file that the script is being run over, you can use the output |
| 4723 file expansions described in "gn help action_foreach" to name the .d file | 4403 file expansions described in "gn help action_foreach" to name the .d file |
| 4724 according to the input." | 4404 according to the input." |
| 4725 | 4405 |
| 4726 The format is that of a Makefile and all paths must be relative to the root | 4406 The format is that of a Makefile and all paths must be relative to the root |
| 4727 build directory. Only one output may be listed and it must match the first | 4407 build directory. Only one output may be listed and it must match the first |
| 4728 output of the action. | 4408 output of the action. |
| 4729 | 4409 |
| 4730 Although depfiles are created by an action, they should not be listed in the | 4410 Although depfiles are created by an action, they should not be listed in the |
| 4731 action's "outputs" unless another target will use the file as an input. | 4411 action's "outputs" unless another target will use the file as an input. |
| 4732 | |
| 4733 ``` | 4412 ``` |
| 4734 | 4413 |
| 4735 #### **Example** | 4414 #### **Example** |
| 4736 | 4415 |
| 4737 ``` | 4416 ``` |
| 4738 action_foreach("myscript_target") { | 4417 action_foreach("myscript_target") { |
| 4739 script = "myscript.py" | 4418 script = "myscript.py" |
| 4740 sources = [ ... ] | 4419 sources = [ ... ] |
| 4741 | 4420 |
| 4742 # Locate the depfile in the output directory named like the | 4421 # Locate the depfile in the output directory named like the |
| 4743 # inputs but with a ".d" appended. | 4422 # inputs but with a ".d" appended. |
| 4744 depfile = "$relative_target_output_dir/{{source_name}}.d" | 4423 depfile = "$relative_target_output_dir/{{source_name}}.d" |
| 4745 | 4424 |
| 4746 # Say our script uses "-o <d file>" to indicate the depfile. | 4425 # Say our script uses "-o <d file>" to indicate the depfile. |
| 4747 args = [ "{{source}}", "-o", depfile ] | 4426 args = [ "{{source}}", "-o", depfile ] |
| 4748 } | 4427 } |
| 4749 | |
| 4750 | |
| 4751 ``` | 4428 ``` |
| 4752 ### <a name="deps"></a>**deps**: Private linked dependencies. | 4429 ### <a name="deps"></a>**deps**: Private linked dependencies. |
| 4753 | 4430 |
| 4754 ``` | 4431 ``` |
| 4755 A list of target labels. | 4432 A list of target labels. |
| 4756 | 4433 |
| 4757 Specifies private dependencies of a target. Private dependencies are | 4434 Specifies private dependencies of a target. Private dependencies are |
| 4758 propagated up the dependency tree and linked to dependant targets, but do not | 4435 propagated up the dependency tree and linked to dependant targets, but do not |
| 4759 grant the ability to include headers from the dependency. Public configs are | 4436 grant the ability to include headers from the dependency. Public configs are |
| 4760 not forwarded. | 4437 not forwarded. |
| 4761 | |
| 4762 ``` | 4438 ``` |
| 4763 | 4439 |
| 4764 #### **Details of dependency propagation** | 4440 #### **Details of dependency propagation** |
| 4765 | 4441 |
| 4766 ``` | 4442 ``` |
| 4767 Source sets, shared libraries, and non-complete static libraries will be | 4443 Source sets, shared libraries, and non-complete static libraries will be |
| 4768 propagated up the dependency tree across groups, non-complete static | 4444 propagated up the dependency tree across groups, non-complete static |
| 4769 libraries and source sets. | 4445 libraries and source sets. |
| 4770 | 4446 |
| 4771 Executables, shared libraries, and complete static libraries will link all | 4447 Executables, shared libraries, and complete static libraries will link all |
| 4772 propagated targets and stop propagation. Actions and copy steps also stop | 4448 propagated targets and stop propagation. Actions and copy steps also stop |
| 4773 propagation, allowing them to take a library as an input but not force | 4449 propagation, allowing them to take a library as an input but not force |
| 4774 dependants to link to it. | 4450 dependants to link to it. |
| 4775 | 4451 |
| 4776 Propagation of all_dependent_configs and public_configs happens independently | 4452 Propagation of all_dependent_configs and public_configs happens independently |
| 4777 of target type. all_dependent_configs are always propagated across all types | 4453 of target type. all_dependent_configs are always propagated across all types |
| 4778 of targets, and public_configs are always propagated across public deps of | 4454 of targets, and public_configs are always propagated across public deps of |
| 4779 all types of targets. | 4455 all types of targets. |
| 4780 | 4456 |
| 4781 Data dependencies are propagated differently. See "gn help data_deps" and | 4457 Data dependencies are propagated differently. See "gn help data_deps" and |
| 4782 "gn help runtime_deps". | 4458 "gn help runtime_deps". |
| 4783 | 4459 |
| 4784 See also "public_deps". | 4460 See also "public_deps". |
| 4785 | |
| 4786 | |
| 4787 ``` | 4461 ``` |
| 4788 ### <a name="include_dirs"></a>**include_dirs**: Additional include directories. | 4462 ### <a name="include_dirs"></a>**include_dirs**: Additional include directories. |
| 4789 | 4463 |
| 4790 ``` | 4464 ``` |
| 4791 A list of source directories. | 4465 A list of source directories. |
| 4792 | 4466 |
| 4793 The directories in this list will be added to the include path for the files | 4467 The directories in this list will be added to the include path for the files |
| 4794 in the affected target. | 4468 in the affected target. |
| 4795 | |
| 4796 ``` | 4469 ``` |
| 4797 | 4470 |
| 4798 #### **Ordering of flags and values** | 4471 #### **Ordering of flags and values** |
| 4799 | 4472 |
| 4800 ``` | 4473 ``` |
| 4801 1. Those set on the current target (not in a config). | 4474 1. Those set on the current target (not in a config). |
| 4802 2. Those set on the "configs" on the target in order that the | 4475 2. Those set on the "configs" on the target in order that the |
| 4803 configs appear in the list. | 4476 configs appear in the list. |
| 4804 3. Those set on the "all_dependent_configs" on the target in order | 4477 3. Those set on the "all_dependent_configs" on the target in order |
| 4805 that the configs appear in the list. | 4478 that the configs appear in the list. |
| 4806 4. Those set on the "public_configs" on the target in order that | 4479 4. Those set on the "public_configs" on the target in order that |
| 4807 those configs appear in the list. | 4480 those configs appear in the list. |
| 4808 5. all_dependent_configs pulled from dependencies, in the order of | 4481 5. all_dependent_configs pulled from dependencies, in the order of |
| 4809 the "deps" list. This is done recursively. If a config appears | 4482 the "deps" list. This is done recursively. If a config appears |
| 4810 more than once, only the first occurance will be used. | 4483 more than once, only the first occurance will be used. |
| 4811 6. public_configs pulled from dependencies, in the order of the | 4484 6. public_configs pulled from dependencies, in the order of the |
| 4812 "deps" list. If a dependency is public, they will be applied | 4485 "deps" list. If a dependency is public, they will be applied |
| 4813 recursively. | 4486 recursively. |
| 4814 | |
| 4815 ``` | 4487 ``` |
| 4816 | 4488 |
| 4817 #### **Example** | 4489 #### **Example** |
| 4818 | 4490 |
| 4819 ``` | 4491 ``` |
| 4820 include_dirs = [ "src/include", "//third_party/foo" ] | 4492 include_dirs = [ "src/include", "//third_party/foo" ] |
| 4821 | |
| 4822 | |
| 4823 ``` | 4493 ``` |
| 4824 ### <a name="inputs"></a>**inputs**: Additional compile-time dependencies. | 4494 ### <a name="inputs"></a>**inputs**: Additional compile-time dependencies. |
| 4825 | 4495 |
| 4826 ``` | 4496 ``` |
| 4827 Inputs are compile-time dependencies of the current target. This means that | 4497 Inputs are compile-time dependencies of the current target. This means that |
| 4828 all inputs must be available before compiling any of the sources or executing | 4498 all inputs must be available before compiling any of the sources or executing |
| 4829 any actions. | 4499 any actions. |
| 4830 | 4500 |
| 4831 Inputs are typically only used for action and action_foreach targets. | 4501 Inputs are typically only used for action and action_foreach targets. |
| 4832 | |
| 4833 ``` | 4502 ``` |
| 4834 | 4503 |
| 4835 #### **Inputs for actions** | 4504 #### **Inputs for actions** |
| 4836 | 4505 |
| 4837 ``` | 4506 ``` |
| 4838 For action and action_foreach targets, inputs should be the inputs to script | 4507 For action and action_foreach targets, inputs should be the inputs to script |
| 4839 that don't vary. These should be all .py files that the script uses via | 4508 that don't vary. These should be all .py files that the script uses via |
| 4840 imports (the main script itself will be an implicit dependency of the action | 4509 imports (the main script itself will be an implicit dependency of the action |
| 4841 so need not be listed). | 4510 so need not be listed). |
| 4842 | 4511 |
| 4843 For action targets, inputs and sources are treated the same, but from a style | 4512 For action targets, inputs and sources are treated the same, but from a style |
| 4844 perspective, it's recommended to follow the same rule as action_foreach and | 4513 perspective, it's recommended to follow the same rule as action_foreach and |
| 4845 put helper files in the inputs, and the data used by the script (if any) in | 4514 put helper files in the inputs, and the data used by the script (if any) in |
| 4846 sources. | 4515 sources. |
| 4847 | 4516 |
| 4848 Note that another way to declare input dependencies from an action is to have | 4517 Note that another way to declare input dependencies from an action is to have |
| 4849 the action write a depfile (see "gn help depfile"). This allows the script to | 4518 the action write a depfile (see "gn help depfile"). This allows the script to |
| 4850 dynamically write input dependencies, that might not be known until actually | 4519 dynamically write input dependencies, that might not be known until actually |
| 4851 executing the script. This is more efficient than doing processing while | 4520 executing the script. This is more efficient than doing processing while |
| 4852 running GN to determine the inputs, and is easier to keep in-sync than | 4521 running GN to determine the inputs, and is easier to keep in-sync than |
| 4853 hardcoding the list. | 4522 hardcoding the list. |
| 4854 | |
| 4855 ``` | 4523 ``` |
| 4856 | 4524 |
| 4857 #### **Script input gotchas** | 4525 #### **Script input gotchas** |
| 4858 | 4526 |
| 4859 ``` | 4527 ``` |
| 4860 It may be tempting to write a script that enumerates all files in a directory | 4528 It may be tempting to write a script that enumerates all files in a directory |
| 4861 as inputs. Don't do this! Even if you specify all the files in the inputs or | 4529 as inputs. Don't do this! Even if you specify all the files in the inputs or |
| 4862 sources in the GN target (or worse, enumerate the files in an exec_script | 4530 sources in the GN target (or worse, enumerate the files in an exec_script |
| 4863 call when running GN, which will be slow), the dependencies will be broken. | 4531 call when running GN, which will be slow), the dependencies will be broken. |
| 4864 | 4532 |
| 4865 The problem happens if a file is ever removed because the inputs are not | 4533 The problem happens if a file is ever removed because the inputs are not |
| 4866 listed on the command line to the script. Because the script hasn't changed | 4534 listed on the command line to the script. Because the script hasn't changed |
| 4867 and all inputs are up to date, the script will not re-run and you will get a | 4535 and all inputs are up to date, the script will not re-run and you will get a |
| 4868 stale build. Instead, either list all inputs on the command line to the | 4536 stale build. Instead, either list all inputs on the command line to the |
| 4869 script, or if there are many, create a separate list file that the script | 4537 script, or if there are many, create a separate list file that the script |
| 4870 reads. As long as this file is listed in the inputs, the build will detect | 4538 reads. As long as this file is listed in the inputs, the build will detect |
| 4871 when it has changed in any way and the action will re-run. | 4539 when it has changed in any way and the action will re-run. |
| 4872 | |
| 4873 ``` | 4540 ``` |
| 4874 | 4541 |
| 4875 #### **Inputs for binary targets** | 4542 #### **Inputs for binary targets** |
| 4876 | 4543 |
| 4877 ``` | 4544 ``` |
| 4878 Any input dependencies will be resolved before compiling any sources. | 4545 Any input dependencies will be resolved before compiling any sources. |
| 4879 Normally, all actions that a target depends on will be run before any files | 4546 Normally, all actions that a target depends on will be run before any files |
| 4880 in a target are compiled. So if you depend on generated headers, you do not | 4547 in a target are compiled. So if you depend on generated headers, you do not |
| 4881 typically need to list them in the inputs section. | 4548 typically need to list them in the inputs section. |
| 4882 | 4549 |
| 4883 Inputs for binary targets will be treated as implicit dependencies, meaning | 4550 Inputs for binary targets will be treated as implicit dependencies, meaning |
| 4884 that changes in any of the inputs will force all sources in the target to be | 4551 that changes in any of the inputs will force all sources in the target to be |
| 4885 recompiled. If an input only applies to a subset of source files, you may | 4552 recompiled. If an input only applies to a subset of source files, you may |
| 4886 want to split those into a separate target to avoid unnecessary recompiles. | 4553 want to split those into a separate target to avoid unnecessary recompiles. |
| 4887 | |
| 4888 ``` | 4554 ``` |
| 4889 | 4555 |
| 4890 #### **Example** | 4556 #### **Example** |
| 4891 | 4557 |
| 4892 ``` | 4558 ``` |
| 4893 action("myscript") { | 4559 action("myscript") { |
| 4894 script = "domything.py" | 4560 script = "domything.py" |
| 4895 inputs = [ "input.data" ] | 4561 inputs = [ "input.data" ] |
| 4896 } | 4562 } |
| 4897 | |
| 4898 | |
| 4899 ``` | 4563 ``` |
| 4900 ### <a name="ldflags"></a>**ldflags**: Flags passed to the linker. | 4564 ### <a name="ldflags"></a>**ldflags**: Flags passed to the linker. |
| 4901 | 4565 |
| 4902 ``` | 4566 ``` |
| 4903 A list of strings. | 4567 A list of strings. |
| 4904 | 4568 |
| 4905 These flags are passed on the command-line to the linker and generally | 4569 These flags are passed on the command-line to the linker and generally |
| 4906 specify various linking options. Most targets will not need these and will | 4570 specify various linking options. Most targets will not need these and will |
| 4907 use "libs" and "lib_dirs" instead. | 4571 use "libs" and "lib_dirs" instead. |
| 4908 | 4572 |
| 4909 ldflags are NOT pushed to dependents, so applying ldflags to source sets or | 4573 ldflags are NOT pushed to dependents, so applying ldflags to source sets or |
| 4910 static libraries will be a no-op. If you want to apply ldflags to dependent | 4574 static libraries will be a no-op. If you want to apply ldflags to dependent |
| 4911 targets, put them in a config and set it in the all_dependent_configs or | 4575 targets, put them in a config and set it in the all_dependent_configs or |
| 4912 public_configs. | 4576 public_configs. |
| 4913 | |
| 4914 ``` | 4577 ``` |
| 4915 | 4578 |
| 4916 #### **Ordering of flags and values** | 4579 #### **Ordering of flags and values** |
| 4917 | 4580 |
| 4918 ``` | 4581 ``` |
| 4919 1. Those set on the current target (not in a config). | 4582 1. Those set on the current target (not in a config). |
| 4920 2. Those set on the "configs" on the target in order that the | 4583 2. Those set on the "configs" on the target in order that the |
| 4921 configs appear in the list. | 4584 configs appear in the list. |
| 4922 3. Those set on the "all_dependent_configs" on the target in order | 4585 3. Those set on the "all_dependent_configs" on the target in order |
| 4923 that the configs appear in the list. | 4586 that the configs appear in the list. |
| 4924 4. Those set on the "public_configs" on the target in order that | 4587 4. Those set on the "public_configs" on the target in order that |
| 4925 those configs appear in the list. | 4588 those configs appear in the list. |
| 4926 5. all_dependent_configs pulled from dependencies, in the order of | 4589 5. all_dependent_configs pulled from dependencies, in the order of |
| 4927 the "deps" list. This is done recursively. If a config appears | 4590 the "deps" list. This is done recursively. If a config appears |
| 4928 more than once, only the first occurance will be used. | 4591 more than once, only the first occurance will be used. |
| 4929 6. public_configs pulled from dependencies, in the order of the | 4592 6. public_configs pulled from dependencies, in the order of the |
| 4930 "deps" list. If a dependency is public, they will be applied | 4593 "deps" list. If a dependency is public, they will be applied |
| 4931 recursively. | 4594 recursively. |
| 4932 | |
| 4933 | |
| 4934 ``` | 4595 ``` |
| 4935 ### <a name="lib_dirs"></a>**lib_dirs**: Additional library directories. | 4596 ### <a name="lib_dirs"></a>**lib_dirs**: Additional library directories. |
| 4936 | 4597 |
| 4937 ``` | 4598 ``` |
| 4938 A list of directories. | 4599 A list of directories. |
| 4939 | 4600 |
| 4940 Specifies additional directories passed to the linker for searching for the | 4601 Specifies additional directories passed to the linker for searching for the |
| 4941 required libraries. If an item is not an absolute path, it will be treated as | 4602 required libraries. If an item is not an absolute path, it will be treated as |
| 4942 being relative to the current build file. | 4603 being relative to the current build file. |
| 4943 | 4604 |
| 4944 libs and lib_dirs work differently than other flags in two respects. | 4605 libs and lib_dirs work differently than other flags in two respects. |
| 4945 First, then are inherited across static library boundaries until a | 4606 First, then are inherited across static library boundaries until a |
| 4946 shared library or executable target is reached. Second, they are | 4607 shared library or executable target is reached. Second, they are |
| 4947 uniquified so each one is only passed once (the first instance of it | 4608 uniquified so each one is only passed once (the first instance of it |
| 4948 will be the one used). | 4609 will be the one used). |
| 4949 | |
| 4950 ``` | 4610 ``` |
| 4951 | 4611 |
| 4952 #### **Ordering of flags and values** | 4612 #### **Ordering of flags and values** |
| 4953 | 4613 |
| 4954 ``` | 4614 ``` |
| 4955 1. Those set on the current target (not in a config). | 4615 1. Those set on the current target (not in a config). |
| 4956 2. Those set on the "configs" on the target in order that the | 4616 2. Those set on the "configs" on the target in order that the |
| 4957 configs appear in the list. | 4617 configs appear in the list. |
| 4958 3. Those set on the "all_dependent_configs" on the target in order | 4618 3. Those set on the "all_dependent_configs" on the target in order |
| 4959 that the configs appear in the list. | 4619 that the configs appear in the list. |
| 4960 4. Those set on the "public_configs" on the target in order that | 4620 4. Those set on the "public_configs" on the target in order that |
| 4961 those configs appear in the list. | 4621 those configs appear in the list. |
| 4962 5. all_dependent_configs pulled from dependencies, in the order of | 4622 5. all_dependent_configs pulled from dependencies, in the order of |
| 4963 the "deps" list. This is done recursively. If a config appears | 4623 the "deps" list. This is done recursively. If a config appears |
| 4964 more than once, only the first occurance will be used. | 4624 more than once, only the first occurance will be used. |
| 4965 6. public_configs pulled from dependencies, in the order of the | 4625 6. public_configs pulled from dependencies, in the order of the |
| 4966 "deps" list. If a dependency is public, they will be applied | 4626 "deps" list. If a dependency is public, they will be applied |
| 4967 recursively. | 4627 recursively. |
| 4968 | 4628 |
| 4969 For "libs" and "lib_dirs" only, the values propagated from | 4629 For "libs" and "lib_dirs" only, the values propagated from |
| 4970 dependencies (as described above) are applied last assuming they | 4630 dependencies (as described above) are applied last assuming they |
| 4971 are not already in the list. | 4631 are not already in the list. |
| 4972 | |
| 4973 ``` | 4632 ``` |
| 4974 | 4633 |
| 4975 #### **Example** | 4634 #### **Example** |
| 4976 | 4635 |
| 4977 ``` | 4636 ``` |
| 4978 lib_dirs = [ "/usr/lib/foo", "lib/doom_melon" ] | 4637 lib_dirs = [ "/usr/lib/foo", "lib/doom_melon" ] |
| 4979 | |
| 4980 | |
| 4981 ``` | 4638 ``` |
| 4982 ### <a name="libs"></a>**libs**: Additional libraries to link. | 4639 ### <a name="libs"></a>**libs**: Additional libraries to link. |
| 4983 | 4640 |
| 4984 ``` | 4641 ``` |
| 4985 A list of library names or library paths. | 4642 A list of library names or library paths. |
| 4986 | 4643 |
| 4987 These libraries will be linked into the final binary (executable or shared | 4644 These libraries will be linked into the final binary (executable or shared |
| 4988 library) containing the current target. | 4645 library) containing the current target. |
| 4989 | 4646 |
| 4990 libs and lib_dirs work differently than other flags in two respects. | 4647 libs and lib_dirs work differently than other flags in two respects. |
| 4991 First, then are inherited across static library boundaries until a | 4648 First, then are inherited across static library boundaries until a |
| 4992 shared library or executable target is reached. Second, they are | 4649 shared library or executable target is reached. Second, they are |
| 4993 uniquified so each one is only passed once (the first instance of it | 4650 uniquified so each one is only passed once (the first instance of it |
| 4994 will be the one used). | 4651 will be the one used). |
| 4995 | |
| 4996 ``` | 4652 ``` |
| 4997 | 4653 |
| 4998 #### **Types of libs** | 4654 #### **Types of libs** |
| 4999 | 4655 |
| 5000 ``` | 4656 ``` |
| 5001 There are several different things that can be expressed in libs: | 4657 There are several different things that can be expressed in libs: |
| 5002 | 4658 |
| 5003 File paths | 4659 File paths |
| 5004 Values containing '/' will be treated as references to files in the | 4660 Values containing '/' will be treated as references to files in the |
| 5005 checkout. They will be rebased to be relative to the build directory and | 4661 checkout. They will be rebased to be relative to the build directory and |
| 5006 specified in the "libs" for linker tools. This facility should be used | 4662 specified in the "libs" for linker tools. This facility should be used |
| 5007 for libraries that are checked in to the version control. For libraries | 4663 for libraries that are checked in to the version control. For libraries |
| 5008 that are generated by the build, use normal GN deps to link them. | 4664 that are generated by the build, use normal GN deps to link them. |
| 5009 | 4665 |
| 5010 System libraries | 4666 System libraries |
| 5011 Values not containing '/' will be treated as system library names. These | 4667 Values not containing '/' will be treated as system library names. These |
| 5012 will be passed unmodified to the linker and prefixed with the | 4668 will be passed unmodified to the linker and prefixed with the |
| 5013 "lib_prefix" attribute of the linker tool. Generally you would set the | 4669 "lib_prefix" attribute of the linker tool. Generally you would set the |
| 5014 "lib_dirs" so the given library is found. Your BUILD.gn file should not | 4670 "lib_dirs" so the given library is found. Your BUILD.gn file should not |
| 5015 specify the switch (like "-l"): this will be encoded in the "lib_prefix" | 4671 specify the switch (like "-l"): this will be encoded in the "lib_prefix" |
| 5016 of the tool. | 4672 of the tool. |
| 5017 | 4673 |
| 5018 Apple frameworks | 4674 Apple frameworks |
| 5019 System libraries ending in ".framework" will be special-cased: the switch | 4675 System libraries ending in ".framework" will be special-cased: the switch |
| 5020 "-framework" will be prepended instead of the lib_prefix, and the | 4676 "-framework" will be prepended instead of the lib_prefix, and the |
| 5021 ".framework" suffix will be trimmed. This is to support the way Mac links | 4677 ".framework" suffix will be trimmed. This is to support the way Mac links |
| 5022 framework dependencies. | 4678 framework dependencies. |
| 5023 | |
| 5024 ``` | 4679 ``` |
| 5025 | 4680 |
| 5026 #### **Ordering of flags and values** | 4681 #### **Ordering of flags and values** |
| 5027 | 4682 |
| 5028 ``` | 4683 ``` |
| 5029 1. Those set on the current target (not in a config). | 4684 1. Those set on the current target (not in a config). |
| 5030 2. Those set on the "configs" on the target in order that the | 4685 2. Those set on the "configs" on the target in order that the |
| 5031 configs appear in the list. | 4686 configs appear in the list. |
| 5032 3. Those set on the "all_dependent_configs" on the target in order | 4687 3. Those set on the "all_dependent_configs" on the target in order |
| 5033 that the configs appear in the list. | 4688 that the configs appear in the list. |
| 5034 4. Those set on the "public_configs" on the target in order that | 4689 4. Those set on the "public_configs" on the target in order that |
| 5035 those configs appear in the list. | 4690 those configs appear in the list. |
| 5036 5. all_dependent_configs pulled from dependencies, in the order of | 4691 5. all_dependent_configs pulled from dependencies, in the order of |
| 5037 the "deps" list. This is done recursively. If a config appears | 4692 the "deps" list. This is done recursively. If a config appears |
| 5038 more than once, only the first occurance will be used. | 4693 more than once, only the first occurance will be used. |
| 5039 6. public_configs pulled from dependencies, in the order of the | 4694 6. public_configs pulled from dependencies, in the order of the |
| 5040 "deps" list. If a dependency is public, they will be applied | 4695 "deps" list. If a dependency is public, they will be applied |
| 5041 recursively. | 4696 recursively. |
| 5042 | 4697 |
| 5043 For "libs" and "lib_dirs" only, the values propagated from | 4698 For "libs" and "lib_dirs" only, the values propagated from |
| 5044 dependencies (as described above) are applied last assuming they | 4699 dependencies (as described above) are applied last assuming they |
| 5045 are not already in the list. | 4700 are not already in the list. |
| 5046 | |
| 5047 ``` | 4701 ``` |
| 5048 | 4702 |
| 5049 #### **Examples** | 4703 #### **Examples** |
| 5050 | 4704 |
| 5051 ``` | 4705 ``` |
| 5052 On Windows: | 4706 On Windows: |
| 5053 libs = [ "ctl3d.lib" ] | 4707 libs = [ "ctl3d.lib" ] |
| 5054 | 4708 |
| 5055 On Linux: | 4709 On Linux: |
| 5056 libs = [ "ld" ] | 4710 libs = [ "ld" ] |
| 5057 | |
| 5058 | |
| 5059 ``` | 4711 ``` |
| 5060 ### <a name="output_dir"></a>**output_dir**: [directory] Directory to put output
file in. | 4712 ### <a name="output_dir"></a>**output_dir**: [directory] Directory to put output
file in. |
| 5061 | 4713 |
| 5062 ``` | 4714 ``` |
| 5063 For library and executable targets, overrides the directory for the final | 4715 For library and executable targets, overrides the directory for the final |
| 5064 output. This must be in the root_build_dir or a child thereof. | 4716 output. This must be in the root_build_dir or a child thereof. |
| 5065 | 4717 |
| 5066 This should generally be in the root_out_dir or a subdirectory thereof (the | 4718 This should generally be in the root_out_dir or a subdirectory thereof (the |
| 5067 root_out_dir will be the same as the root_build_dir for the default | 4719 root_out_dir will be the same as the root_build_dir for the default |
| 5068 toolchain, and will be a subdirectory for other toolchains). Not putting the | 4720 toolchain, and will be a subdirectory for other toolchains). Not putting the |
| 5069 output in a subdirectory of root_out_dir can result in collisions between | 4721 output in a subdirectory of root_out_dir can result in collisions between |
| 5070 different toolchains, so you will need to take steps to ensure that your | 4722 different toolchains, so you will need to take steps to ensure that your |
| 5071 target is only present in one toolchain. | 4723 target is only present in one toolchain. |
| 5072 | 4724 |
| 5073 Normally the toolchain specifies the output directory for libraries and | 4725 Normally the toolchain specifies the output directory for libraries and |
| 5074 executables (see "gn help tool"). You will have to consult that for the | 4726 executables (see "gn help tool"). You will have to consult that for the |
| 5075 default location. The default location will be used if output_dir is | 4727 default location. The default location will be used if output_dir is |
| 5076 undefined or empty. | 4728 undefined or empty. |
| 5077 | |
| 5078 ``` | 4729 ``` |
| 5079 | 4730 |
| 5080 #### **Example** | 4731 #### **Example** |
| 5081 | 4732 |
| 5082 ``` | 4733 ``` |
| 5083 shared_library("doom_melon") { | 4734 shared_library("doom_melon") { |
| 5084 output_dir = "$root_out_dir/plugin_libs" | 4735 output_dir = "$root_out_dir/plugin_libs" |
| 5085 ... | 4736 ... |
| 5086 } | 4737 } |
| 5087 | |
| 5088 | |
| 5089 ``` | 4738 ``` |
| 5090 ### <a name="output_extension"></a>**output_extension**: Value to use for the ou
tput's file extension. | 4739 ### <a name="output_extension"></a>**output_extension**: Value to use for the ou
tput's file extension. |
| 5091 | 4740 |
| 5092 ``` | 4741 ``` |
| 5093 Normally the file extension for a target is based on the target type and the | 4742 Normally the file extension for a target is based on the target type and the |
| 5094 operating system, but in rare cases you will need to override the name (for | 4743 operating system, but in rare cases you will need to override the name (for |
| 5095 example to use "libfreetype.so.6" instead of libfreetype.so on Linux). | 4744 example to use "libfreetype.so.6" instead of libfreetype.so on Linux). |
| 5096 | 4745 |
| 5097 This value should not include a leading dot. If undefined, the default | 4746 This value should not include a leading dot. If undefined, the default |
| 5098 specified on the tool will be used. If set to the empty string, no output | 4747 specified on the tool will be used. If set to the empty string, no output |
| 5099 extension will be used. | 4748 extension will be used. |
| 5100 | 4749 |
| 5101 The output_extension will be used to set the "{{output_extension}}" expansion | 4750 The output_extension will be used to set the "{{output_extension}}" expansion |
| 5102 which the linker tool will generally use to specify the output file name. See | 4751 which the linker tool will generally use to specify the output file name. See |
| 5103 "gn help tool". | 4752 "gn help tool". |
| 5104 | |
| 5105 ``` | 4753 ``` |
| 5106 | 4754 |
| 5107 #### **Example** | 4755 #### **Example** |
| 5108 | 4756 |
| 5109 ``` | 4757 ``` |
| 5110 shared_library("freetype") { | 4758 shared_library("freetype") { |
| 5111 if (is_linux) { | 4759 if (is_linux) { |
| 5112 # Call the output "libfreetype.so.6" | 4760 # Call the output "libfreetype.so.6" |
| 5113 output_extension = "so.6" | 4761 output_extension = "so.6" |
| 5114 } | 4762 } |
| 5115 ... | 4763 ... |
| 5116 } | 4764 } |
| 5117 | 4765 |
| 5118 # On Windows, generate a "mysettings.cpl" control panel applet. Control panel | 4766 # On Windows, generate a "mysettings.cpl" control panel applet. Control panel |
| 5119 # applets are actually special shared libraries. | 4767 # applets are actually special shared libraries. |
| 5120 if (is_win) { | 4768 if (is_win) { |
| 5121 shared_library("mysettings") { | 4769 shared_library("mysettings") { |
| 5122 output_extension = "cpl" | 4770 output_extension = "cpl" |
| 5123 ... | 4771 ... |
| 5124 } | 4772 } |
| 5125 } | 4773 } |
| 5126 | |
| 5127 | |
| 5128 ``` | 4774 ``` |
| 5129 ### <a name="output_name"></a>**output_name**: Define a name for the output file
other than the default. | 4775 ### <a name="output_name"></a>**output_name**: Define a name for the output file
other than the default. |
| 5130 | 4776 |
| 5131 ``` | 4777 ``` |
| 5132 Normally the output name of a target will be based on the target name, so the | 4778 Normally the output name of a target will be based on the target name, so the |
| 5133 target "//foo/bar:bar_unittests" will generate an output file such as | 4779 target "//foo/bar:bar_unittests" will generate an output file such as |
| 5134 "bar_unittests.exe" (using Windows as an example). | 4780 "bar_unittests.exe" (using Windows as an example). |
| 5135 | 4781 |
| 5136 Sometimes you will want an alternate name to avoid collisions or if the | 4782 Sometimes you will want an alternate name to avoid collisions or if the |
| 5137 internal name isn't appropriate for public distribution. | 4783 internal name isn't appropriate for public distribution. |
| 5138 | 4784 |
| 5139 The output name should have no extension or prefixes, these will be added | 4785 The output name should have no extension or prefixes, these will be added |
| 5140 using the default system rules. For example, on Linux an output name of "foo" | 4786 using the default system rules. For example, on Linux an output name of "foo" |
| 5141 will produce a shared library "libfoo.so". There is no way to override the | 4787 will produce a shared library "libfoo.so". There is no way to override the |
| 5142 output prefix of a linker tool on a per- target basis. If you need more | 4788 output prefix of a linker tool on a per- target basis. If you need more |
| 5143 flexibility, create a copy target to produce the file you want. | 4789 flexibility, create a copy target to produce the file you want. |
| 5144 | 4790 |
| 5145 This variable is valid for all binary output target types. | 4791 This variable is valid for all binary output target types. |
| 5146 | |
| 5147 ``` | 4792 ``` |
| 5148 | 4793 |
| 5149 #### **Example** | 4794 #### **Example** |
| 5150 | 4795 |
| 5151 ``` | 4796 ``` |
| 5152 static_library("doom_melon") { | 4797 static_library("doom_melon") { |
| 5153 output_name = "fluffy_bunny" | 4798 output_name = "fluffy_bunny" |
| 5154 } | 4799 } |
| 5155 | |
| 5156 | |
| 5157 ``` | 4800 ``` |
| 5158 ### <a name="output_prefix_override"></a>**output_prefix_override**: Don't use p
refix for output name. | 4801 ### <a name="output_prefix_override"></a>**output_prefix_override**: Don't use p
refix for output name. |
| 5159 | 4802 |
| 5160 ``` | 4803 ``` |
| 5161 A boolean that overrides the output prefix for a target. Defaults to false. | 4804 A boolean that overrides the output prefix for a target. Defaults to false. |
| 5162 | 4805 |
| 5163 Some systems use prefixes for the names of the final target output file. The | 4806 Some systems use prefixes for the names of the final target output file. The |
| 5164 normal example is "libfoo.so" on Linux for a target named "foo". | 4807 normal example is "libfoo.so" on Linux for a target named "foo". |
| 5165 | 4808 |
| 5166 The output prefix for a given target type is specified on the linker tool | 4809 The output prefix for a given target type is specified on the linker tool |
| 5167 (see "gn help tool"). Sometimes this prefix is undesired. | 4810 (see "gn help tool"). Sometimes this prefix is undesired. |
| 5168 | 4811 |
| 5169 See also "gn help output_extension". | 4812 See also "gn help output_extension". |
| 5170 | |
| 5171 ``` | 4813 ``` |
| 5172 | 4814 |
| 5173 #### **Example** | 4815 #### **Example** |
| 5174 | 4816 |
| 5175 ``` | 4817 ``` |
| 5176 shared_library("doom_melon") { | 4818 shared_library("doom_melon") { |
| 5177 # Normally this will produce "libdoom_melon.so" on Linux. Setting this flag | 4819 # Normally this will produce "libdoom_melon.so" on Linux. Setting this flag |
| 5178 # will produce "doom_melon.so". | 4820 # will produce "doom_melon.so". |
| 5179 output_prefix_override = true | 4821 output_prefix_override = true |
| 5180 ... | 4822 ... |
| 5181 } | 4823 } |
| 5182 | |
| 5183 | |
| 5184 ``` | 4824 ``` |
| 5185 ### <a name="outputs"></a>**outputs**: Output files for actions and copy targets
. | 4825 ### <a name="outputs"></a>**outputs**: Output files for actions and copy targets
. |
| 5186 | 4826 |
| 5187 ``` | 4827 ``` |
| 5188 Outputs is valid for "copy", "action", and "action_foreach" target types and | 4828 Outputs is valid for "copy", "action", and "action_foreach" target types and |
| 5189 indicates the resulting files. Outputs must always refer to files in the | 4829 indicates the resulting files. Outputs must always refer to files in the |
| 5190 build directory. | 4830 build directory. |
| 5191 | 4831 |
| 5192 copy | 4832 copy |
| 5193 Copy targets should have exactly one entry in the outputs list. If there is | 4833 Copy targets should have exactly one entry in the outputs list. If there is |
| 5194 exactly one source, this can be a literal file name or a source expansion. | 4834 exactly one source, this can be a literal file name or a source expansion. |
| 5195 If there is more than one source, this must contain a source expansion to | 4835 If there is more than one source, this must contain a source expansion to |
| 5196 map a single input name to a single output name. See "gn help copy". | 4836 map a single input name to a single output name. See "gn help copy". |
| 5197 | 4837 |
| 5198 action_foreach | 4838 action_foreach |
| 5199 Action_foreach targets must always use source expansions to map input files | 4839 Action_foreach targets must always use source expansions to map input files |
| 5200 to output files. There can be more than one output, which means that each | 4840 to output files. There can be more than one output, which means that each |
| 5201 invocation of the script will produce a set of files (presumably based on | 4841 invocation of the script will produce a set of files (presumably based on |
| 5202 the name of the input file). See "gn help action_foreach". | 4842 the name of the input file). See "gn help action_foreach". |
| 5203 | 4843 |
| 5204 action | 4844 action |
| 5205 Action targets (excluding action_foreach) must list literal output file(s) | 4845 Action targets (excluding action_foreach) must list literal output file(s) |
| 5206 with no source expansions. See "gn help action". | 4846 with no source expansions. See "gn help action". |
| 5207 | |
| 5208 | |
| 5209 ``` | 4847 ``` |
| 5210 ### <a name="precompiled_header"></a>**precompiled_header**: [string] Header fil
e to precompile. | 4848 ### <a name="precompiled_header"></a>**precompiled_header**: [string] Header fil
e to precompile. |
| 5211 | 4849 |
| 5212 ``` | 4850 ``` |
| 5213 Precompiled headers will be used when a target specifies this value, or a | 4851 Precompiled headers will be used when a target specifies this value, or a |
| 5214 config applying to this target specifies this value. In addition, the tool | 4852 config applying to this target specifies this value. In addition, the tool |
| 5215 corresponding to the source files must also specify precompiled headers (see | 4853 corresponding to the source files must also specify precompiled headers (see |
| 5216 "gn help tool"). The tool will also specify what type of precompiled headers | 4854 "gn help tool"). The tool will also specify what type of precompiled headers |
| 5217 to use, by setting precompiled_header_type to either "gcc" or "msvc". | 4855 to use, by setting precompiled_header_type to either "gcc" or "msvc". |
| 5218 | 4856 |
| 5219 The precompiled header/source variables can be specified on a target or a | 4857 The precompiled header/source variables can be specified on a target or a |
| 5220 config, but must be the same for all configs applying to a given target since | 4858 config, but must be the same for all configs applying to a given target since |
| 5221 a target can only have one precompiled header. | 4859 a target can only have one precompiled header. |
| 5222 | 4860 |
| 5223 If you use both C and C++ sources, the precompiled header and source file | 4861 If you use both C and C++ sources, the precompiled header and source file |
| 5224 will be compiled once per language. You will want to make sure to wrap C++ | 4862 will be compiled once per language. You will want to make sure to wrap C++ |
| 5225 includes in __cplusplus #ifdefs so the file will compile in C mode. | 4863 includes in __cplusplus #ifdefs so the file will compile in C mode. |
| 5226 | |
| 5227 ``` | 4864 ``` |
| 5228 | 4865 |
| 5229 #### **GCC precompiled headers** | 4866 #### **GCC precompiled headers** |
| 5230 | 4867 |
| 5231 ``` | 4868 ``` |
| 5232 When using GCC-style precompiled headers, "precompiled_source" contains the | 4869 When using GCC-style precompiled headers, "precompiled_source" contains the |
| 5233 path of a .h file that is precompiled and then included by all source files | 4870 path of a .h file that is precompiled and then included by all source files |
| 5234 in targets that set "precompiled_source". | 4871 in targets that set "precompiled_source". |
| 5235 | 4872 |
| 5236 The value of "precompiled_header" is not used with GCC-style precompiled | 4873 The value of "precompiled_header" is not used with GCC-style precompiled |
| 5237 headers. | 4874 headers. |
| 5238 | |
| 5239 ``` | 4875 ``` |
| 5240 | 4876 |
| 5241 #### **MSVC precompiled headers** | 4877 #### **MSVC precompiled headers** |
| 5242 | 4878 |
| 5243 ``` | 4879 ``` |
| 5244 When using MSVC-style precompiled headers, the "precompiled_header" value is | 4880 When using MSVC-style precompiled headers, the "precompiled_header" value is |
| 5245 a string corresponding to the header. This is NOT a path to a file that GN | 4881 a string corresponding to the header. This is NOT a path to a file that GN |
| 5246 recognises, but rather the exact string that appears in quotes after | 4882 recognises, but rather the exact string that appears in quotes after |
| 5247 an #include line in source code. The compiler will match this string against | 4883 an #include line in source code. The compiler will match this string against |
| 5248 includes or forced includes (/FI). | 4884 includes or forced includes (/FI). |
| (...skipping 20 matching lines...) Expand all Loading... |
| 5269 # Either your source files should #include "build/precompile.h" | 4905 # Either your source files should #include "build/precompile.h" |
| 5270 # first, or you can do this to force-include the header. | 4906 # first, or you can do this to force-include the header. |
| 5271 cflags = [ "/FI$precompiled_header" ] | 4907 cflags = [ "/FI$precompiled_header" ] |
| 5272 } | 4908 } |
| 5273 | 4909 |
| 5274 And then define a target that uses the config: | 4910 And then define a target that uses the config: |
| 5275 | 4911 |
| 5276 executable("doom_melon") { | 4912 executable("doom_melon") { |
| 5277 configs += [ ":use_precompiled_headers" ] | 4913 configs += [ ":use_precompiled_headers" ] |
| 5278 ... | 4914 ... |
| 5279 | |
| 5280 | |
| 5281 ``` | 4915 ``` |
| 5282 ### <a name="precompiled_header_type"></a>**precompiled_header_type**: [string]
"gcc" or "msvc". | 4916 ### <a name="precompiled_header_type"></a>**precompiled_header_type**: [string]
"gcc" or "msvc". |
| 5283 | 4917 |
| 5284 ``` | 4918 ``` |
| 5285 See "gn help precompiled_header". | 4919 See "gn help precompiled_header". |
| 5286 | |
| 5287 | |
| 5288 ``` | 4920 ``` |
| 5289 ### <a name="precompiled_source"></a>**precompiled_source**: [file name] Source
file to precompile. | 4921 ### <a name="precompiled_source"></a>**precompiled_source**: [file name] Source
file to precompile. |
| 5290 | 4922 |
| 5291 ``` | 4923 ``` |
| 5292 The source file that goes along with the precompiled_header when using | 4924 The source file that goes along with the precompiled_header when using |
| 5293 "msvc"-style precompiled headers. It will be implicitly added to the sources | 4925 "msvc"-style precompiled headers. It will be implicitly added to the sources |
| 5294 of the target. See "gn help precompiled_header". | 4926 of the target. See "gn help precompiled_header". |
| 5295 | |
| 5296 | |
| 5297 ``` | 4927 ``` |
| 5298 ### <a name="product_type"></a>**product_type**: Product type for Xcode projects
. | 4928 ### <a name="product_type"></a>**product_type**: Product type for Xcode projects
. |
| 5299 | 4929 |
| 5300 ``` | 4930 ``` |
| 5301 Correspond to the type of the product of a create_bundle target. Only | 4931 Correspond to the type of the product of a create_bundle target. Only |
| 5302 meaningful to Xcode (used as part of the Xcode project generation). | 4932 meaningful to Xcode (used as part of the Xcode project generation). |
| 5303 | 4933 |
| 5304 When generating Xcode project files, only create_bundle target with a | 4934 When generating Xcode project files, only create_bundle target with a |
| 5305 non-empty product_type will have a corresponding target in Xcode project. | 4935 non-empty product_type will have a corresponding target in Xcode project. |
| 5306 | |
| 5307 | |
| 5308 ``` | 4936 ``` |
| 5309 ### <a name="public"></a>**public**: Declare public header files for a target. | 4937 ### <a name="public"></a>**public**: Declare public header files for a target. |
| 5310 | 4938 |
| 5311 ``` | 4939 ``` |
| 5312 A list of files that other targets can include. These permissions are checked | 4940 A list of files that other targets can include. These permissions are checked |
| 5313 via the "check" command (see "gn help check"). | 4941 via the "check" command (see "gn help check"). |
| 5314 | 4942 |
| 5315 If no public files are declared, other targets (assuming they have visibility | 4943 If no public files are declared, other targets (assuming they have visibility |
| 5316 to depend on this target can include any file in the sources list. If this | 4944 to depend on this target can include any file in the sources list. If this |
| 5317 variable is defined on a target, dependent targets may only include files on | 4945 variable is defined on a target, dependent targets may only include files on |
| 5318 this whitelist. | 4946 this whitelist. |
| 5319 | 4947 |
| 5320 Header file permissions are also subject to visibility. A target must be | 4948 Header file permissions are also subject to visibility. A target must be |
| 5321 visible to another target to include any files from it at all and the public | 4949 visible to another target to include any files from it at all and the public |
| 5322 headers indicate which subset of those files are permitted. See "gn help | 4950 headers indicate which subset of those files are permitted. See "gn help |
| 5323 visibility" for more. | 4951 visibility" for more. |
| 5324 | 4952 |
| 5325 Public files are inherited through the dependency tree. So if there is a | 4953 Public files are inherited through the dependency tree. So if there is a |
| 5326 dependency A -> B -> C, then A can include C's public headers. However, the | 4954 dependency A -> B -> C, then A can include C's public headers. However, the |
| 5327 same is NOT true of visibility, so unless A is in C's visibility list, the | 4955 same is NOT true of visibility, so unless A is in C's visibility list, the |
| 5328 include will be rejected. | 4956 include will be rejected. |
| 5329 | 4957 |
| 5330 GN only knows about files declared in the "sources" and "public" sections of | 4958 GN only knows about files declared in the "sources" and "public" sections of |
| 5331 targets. If a file is included that is not known to the build, it will be | 4959 targets. If a file is included that is not known to the build, it will be |
| 5332 allowed. | 4960 allowed. |
| 5333 | |
| 5334 ``` | 4961 ``` |
| 5335 | 4962 |
| 5336 #### **Examples** | 4963 #### **Examples** |
| 5337 | 4964 |
| 5338 ``` | 4965 ``` |
| 5339 These exact files are public: | 4966 These exact files are public: |
| 5340 public = [ "foo.h", "bar.h" ] | 4967 public = [ "foo.h", "bar.h" ] |
| 5341 | 4968 |
| 5342 No files are public (no targets may include headers from this one): | 4969 No files are public (no targets may include headers from this one): |
| 5343 public = [] | 4970 public = [] |
| 5344 | |
| 5345 | |
| 5346 ``` | 4971 ``` |
| 5347 ### <a name="public_configs"></a>**public_configs**: Configs to be applied on de
pendents. | 4972 ### <a name="public_configs"></a>**public_configs**: Configs to be applied on de
pendents. |
| 5348 | 4973 |
| 5349 ``` | 4974 ``` |
| 5350 A list of config labels. | 4975 A list of config labels. |
| 5351 | 4976 |
| 5352 Targets directly depending on this one will have the configs listed in this | 4977 Targets directly depending on this one will have the configs listed in this |
| 5353 variable added to them. These configs will also apply to the current target. | 4978 variable added to them. These configs will also apply to the current target. |
| 5354 | 4979 |
| 5355 This addition happens in a second phase once a target and all of its | 4980 This addition happens in a second phase once a target and all of its |
| 5356 dependencies have been resolved. Therefore, a target will not see these | 4981 dependencies have been resolved. Therefore, a target will not see these |
| 5357 force-added configs in their "configs" variable while the script is running, | 4982 force-added configs in their "configs" variable while the script is running, |
| 5358 and they can not be removed. As a result, this capability should generally | 4983 and they can not be removed. As a result, this capability should generally |
| 5359 only be used to add defines and include directories necessary to compile a | 4984 only be used to add defines and include directories necessary to compile a |
| 5360 target's headers. | 4985 target's headers. |
| 5361 | 4986 |
| 5362 See also "all_dependent_configs". | 4987 See also "all_dependent_configs". |
| 5363 | |
| 5364 ``` | 4988 ``` |
| 5365 | 4989 |
| 5366 #### **Ordering of flags and values** | 4990 #### **Ordering of flags and values** |
| 5367 | 4991 |
| 5368 ``` | 4992 ``` |
| 5369 1. Those set on the current target (not in a config). | 4993 1. Those set on the current target (not in a config). |
| 5370 2. Those set on the "configs" on the target in order that the | 4994 2. Those set on the "configs" on the target in order that the |
| 5371 configs appear in the list. | 4995 configs appear in the list. |
| 5372 3. Those set on the "all_dependent_configs" on the target in order | 4996 3. Those set on the "all_dependent_configs" on the target in order |
| 5373 that the configs appear in the list. | 4997 that the configs appear in the list. |
| 5374 4. Those set on the "public_configs" on the target in order that | 4998 4. Those set on the "public_configs" on the target in order that |
| 5375 those configs appear in the list. | 4999 those configs appear in the list. |
| 5376 5. all_dependent_configs pulled from dependencies, in the order of | 5000 5. all_dependent_configs pulled from dependencies, in the order of |
| 5377 the "deps" list. This is done recursively. If a config appears | 5001 the "deps" list. This is done recursively. If a config appears |
| 5378 more than once, only the first occurance will be used. | 5002 more than once, only the first occurance will be used. |
| 5379 6. public_configs pulled from dependencies, in the order of the | 5003 6. public_configs pulled from dependencies, in the order of the |
| 5380 "deps" list. If a dependency is public, they will be applied | 5004 "deps" list. If a dependency is public, they will be applied |
| 5381 recursively. | 5005 recursively. |
| 5382 | |
| 5383 | |
| 5384 ``` | 5006 ``` |
| 5385 ### <a name="public_deps"></a>**public_deps**: Declare public dependencies. | 5007 ### <a name="public_deps"></a>**public_deps**: Declare public dependencies. |
| 5386 | 5008 |
| 5387 ``` | 5009 ``` |
| 5388 Public dependencies are like private dependencies (see "gn help deps") but | 5010 Public dependencies are like private dependencies (see "gn help deps") but |
| 5389 additionally express that the current target exposes the listed deps as part | 5011 additionally express that the current target exposes the listed deps as part |
| 5390 of its public API. | 5012 of its public API. |
| 5391 | 5013 |
| 5392 This has several ramifications: | 5014 This has several ramifications: |
| 5393 | 5015 |
| 5394 - public_configs that are part of the dependency are forwarded to direct | 5016 - public_configs that are part of the dependency are forwarded to direct |
| 5395 dependents. | 5017 dependents. |
| 5396 | 5018 |
| 5397 - Public headers in the dependency are usable by dependents (includes do | 5019 - Public headers in the dependency are usable by dependents (includes do |
| 5398 not require a direct dependency or visibility). | 5020 not require a direct dependency or visibility). |
| 5399 | 5021 |
| 5400 - If the current target is a shared library, other shared libraries that it | 5022 - If the current target is a shared library, other shared libraries that it |
| 5401 publicly depends on (directly or indirectly) are propagated up the | 5023 publicly depends on (directly or indirectly) are propagated up the |
| 5402 dependency tree to dependents for linking. | 5024 dependency tree to dependents for linking. |
| 5403 | |
| 5404 ``` | 5025 ``` |
| 5405 | 5026 |
| 5406 #### **Discussion** | 5027 #### **Discussion** |
| 5407 | 5028 |
| 5408 ``` | 5029 ``` |
| 5409 Say you have three targets: A -> B -> C. C's visibility may allow B to depend | 5030 Say you have three targets: A -> B -> C. C's visibility may allow B to depend |
| 5410 on it but not A. Normally, this would prevent A from including any headers | 5031 on it but not A. Normally, this would prevent A from including any headers |
| 5411 from C, and C's public_configs would apply only to B. | 5032 from C, and C's public_configs would apply only to B. |
| 5412 | 5033 |
| 5413 If B lists C in its public_deps instead of regular deps, A will now inherit | 5034 If B lists C in its public_deps instead of regular deps, A will now inherit |
| 5414 C's public_configs and the ability to include C's public headers. | 5035 C's public_configs and the ability to include C's public headers. |
| 5415 | 5036 |
| 5416 Generally if you are writing a target B and you include C's headers as part | 5037 Generally if you are writing a target B and you include C's headers as part |
| 5417 of B's public headers, or targets depending on B should consider B and C to | 5038 of B's public headers, or targets depending on B should consider B and C to |
| 5418 be part of a unit, you should use public_deps instead of deps. | 5039 be part of a unit, you should use public_deps instead of deps. |
| 5419 | |
| 5420 ``` | 5040 ``` |
| 5421 | 5041 |
| 5422 #### **Example** | 5042 #### **Example** |
| 5423 | 5043 |
| 5424 ``` | 5044 ``` |
| 5425 # This target can include files from "c" but not from | 5045 # This target can include files from "c" but not from |
| 5426 # "super_secret_implementation_details". | 5046 # "super_secret_implementation_details". |
| 5427 executable("a") { | 5047 executable("a") { |
| 5428 deps = [ ":b" ] | 5048 deps = [ ":b" ] |
| 5429 } | 5049 } |
| 5430 | 5050 |
| 5431 shared_library("b") { | 5051 shared_library("b") { |
| 5432 deps = [ ":super_secret_implementation_details" ] | 5052 deps = [ ":super_secret_implementation_details" ] |
| 5433 public_deps = [ ":c" ] | 5053 public_deps = [ ":c" ] |
| 5434 } | 5054 } |
| 5435 | |
| 5436 | |
| 5437 ``` | 5055 ``` |
| 5438 ### <a name="response_file_contents"></a>**response_file_contents**: Contents of
a response file for actions. | 5056 ### <a name="response_file_contents"></a>**response_file_contents**: Contents of
a response file for actions. |
| 5439 | 5057 |
| 5440 ``` | 5058 ``` |
| 5441 Sometimes the arguments passed to a script can be too long for the system's | 5059 Sometimes the arguments passed to a script can be too long for the system's |
| 5442 command-line capabilities. This is especially the case on Windows where the | 5060 command-line capabilities. This is especially the case on Windows where the |
| 5443 maximum command-line length is less than 8K. A response file allows you to | 5061 maximum command-line length is less than 8K. A response file allows you to |
| 5444 pass an unlimited amount of data to a script in a temporary file for an | 5062 pass an unlimited amount of data to a script in a temporary file for an |
| 5445 action or action_foreach target. | 5063 action or action_foreach target. |
| 5446 | 5064 |
| 5447 If the response_file_contents variable is defined and non-empty, the list | 5065 If the response_file_contents variable is defined and non-empty, the list |
| 5448 will be treated as script args (including possibly substitution patterns) | 5066 will be treated as script args (including possibly substitution patterns) |
| 5449 that will be written to a temporary file at build time. The name of the | 5067 that will be written to a temporary file at build time. The name of the |
| 5450 temporary file will be substituted for "{{response_file_name}}" in the script | 5068 temporary file will be substituted for "{{response_file_name}}" in the script |
| 5451 args. | 5069 args. |
| 5452 | 5070 |
| 5453 The response file contents will always be quoted and escaped according to | 5071 The response file contents will always be quoted and escaped according to |
| 5454 Unix shell rules. To parse the response file, the Python script should use | 5072 Unix shell rules. To parse the response file, the Python script should use |
| 5455 "shlex.split(file_contents)". | 5073 "shlex.split(file_contents)". |
| 5456 | |
| 5457 ``` | 5074 ``` |
| 5458 | 5075 |
| 5459 #### **Example** | 5076 #### **Example** |
| 5460 | 5077 |
| 5461 ``` | 5078 ``` |
| 5462 action("process_lots_of_files") { | 5079 action("process_lots_of_files") { |
| 5463 script = "process.py", | 5080 script = "process.py", |
| 5464 inputs = [ ... huge list of files ... ] | 5081 inputs = [ ... huge list of files ... ] |
| 5465 | 5082 |
| 5466 # Write all the inputs to a response file for the script. Also, | 5083 # Write all the inputs to a response file for the script. Also, |
| 5467 # make the paths relative to the script working directory. | 5084 # make the paths relative to the script working directory. |
| 5468 response_file_contents = rebase_path(inputs, root_build_dir) | 5085 response_file_contents = rebase_path(inputs, root_build_dir) |
| 5469 | 5086 |
| 5470 # The script expects the name of the response file in --file-list. | 5087 # The script expects the name of the response file in --file-list. |
| 5471 args = [ | 5088 args = [ |
| 5472 "--enable-foo", | 5089 "--enable-foo", |
| 5473 "--file-list={{response_file_name}}", | 5090 "--file-list={{response_file_name}}", |
| 5474 ] | 5091 ] |
| 5475 } | 5092 } |
| 5476 | |
| 5477 | |
| 5478 ``` | 5093 ``` |
| 5479 ### <a name="script"></a>**script**: Script file for actions. | 5094 ### <a name="script"></a>**script**: Script file for actions. |
| 5480 | 5095 |
| 5481 ``` | 5096 ``` |
| 5482 An absolute or buildfile-relative file name of a Python script to run for a | 5097 An absolute or buildfile-relative file name of a Python script to run for a |
| 5483 action and action_foreach targets (see "gn help action" and "gn help | 5098 action and action_foreach targets (see "gn help action" and "gn help |
| 5484 action_foreach"). | 5099 action_foreach"). |
| 5485 | |
| 5486 | |
| 5487 ``` | 5100 ``` |
| 5488 ### <a name="sources"></a>**sources**: Source files for a target | 5101 ### <a name="sources"></a>**sources**: Source files for a target |
| 5489 | 5102 |
| 5490 ``` | 5103 ``` |
| 5491 A list of files. Non-absolute paths will be resolved relative to the current | 5104 A list of files. Non-absolute paths will be resolved relative to the current |
| 5492 build file. | 5105 build file. |
| 5493 | |
| 5494 ``` | 5106 ``` |
| 5495 | 5107 |
| 5496 #### **Sources for binary targets** | 5108 #### **Sources for binary targets** |
| 5497 | 5109 |
| 5498 ``` | 5110 ``` |
| 5499 For binary targets (source sets, executables, and libraries), the known file | 5111 For binary targets (source sets, executables, and libraries), the known file |
| 5500 types will be compiled with the associated tools. Unknown file types and | 5112 types will be compiled with the associated tools. Unknown file types and |
| 5501 headers will be skipped. However, you should still list all C/C+ header files | 5113 headers will be skipped. However, you should still list all C/C+ header files |
| 5502 so GN knows about the existance of those files for the purposes of include | 5114 so GN knows about the existance of those files for the purposes of include |
| 5503 checking. | 5115 checking. |
| 5504 | 5116 |
| 5505 As a special case, a file ending in ".def" will be treated as a Windows | 5117 As a special case, a file ending in ".def" will be treated as a Windows |
| 5506 module definition file. It will be appended to the link line with a | 5118 module definition file. It will be appended to the link line with a |
| 5507 preceeding "/DEF:" string. There must be at most one .def file in a target | 5119 preceeding "/DEF:" string. There must be at most one .def file in a target |
| 5508 and they do not cross dependency boundaries (so specifying a .def file in a | 5120 and they do not cross dependency boundaries (so specifying a .def file in a |
| 5509 static library or source set will have no effect on the executable or shared | 5121 static library or source set will have no effect on the executable or shared |
| 5510 library they're linked into). | 5122 library they're linked into). |
| 5511 | |
| 5512 ``` | 5123 ``` |
| 5513 | 5124 |
| 5514 #### **Sources for non-binary targets** | 5125 #### **Sources for non-binary targets** |
| 5515 | 5126 |
| 5516 ``` | 5127 ``` |
| 5517 action_foreach | 5128 action_foreach |
| 5518 The sources are the set of files that the script will be executed over. The | 5129 The sources are the set of files that the script will be executed over. The |
| 5519 script will run once per file. | 5130 script will run once per file. |
| 5520 | 5131 |
| 5521 action | 5132 action |
| 5522 The sources will be treated the same as inputs. See "gn help inputs" for | 5133 The sources will be treated the same as inputs. See "gn help inputs" for |
| 5523 more information and usage advice. | 5134 more information and usage advice. |
| 5524 | 5135 |
| 5525 copy | 5136 copy |
| 5526 The source are the source files to copy. | 5137 The source are the source files to copy. |
| 5527 | |
| 5528 | |
| 5529 ``` | 5138 ``` |
| 5530 ### <a name="testonly"></a>**testonly**: Declares a target must only be used for
testing. | 5139 ### <a name="testonly"></a>**testonly**: Declares a target must only be used for
testing. |
| 5531 | 5140 |
| 5532 ``` | 5141 ``` |
| 5533 Boolean. Defaults to false. | 5142 Boolean. Defaults to false. |
| 5534 | 5143 |
| 5535 When a target is marked "testonly = true", it must only be depended on by | 5144 When a target is marked "testonly = true", it must only be depended on by |
| 5536 other test-only targets. Otherwise, GN will issue an error that the | 5145 other test-only targets. Otherwise, GN will issue an error that the |
| 5537 depenedency is not allowed. | 5146 depenedency is not allowed. |
| 5538 | 5147 |
| 5539 This feature is intended to prevent accidentally shipping test code in a | 5148 This feature is intended to prevent accidentally shipping test code in a |
| 5540 final product. | 5149 final product. |
| 5541 | |
| 5542 ``` | 5150 ``` |
| 5543 | 5151 |
| 5544 #### **Example** | 5152 #### **Example** |
| 5545 | 5153 |
| 5546 ``` | 5154 ``` |
| 5547 source_set("test_support") { | 5155 source_set("test_support") { |
| 5548 testonly = true | 5156 testonly = true |
| 5549 ... | 5157 ... |
| 5550 } | 5158 } |
| 5551 | |
| 5552 | |
| 5553 ``` | 5159 ``` |
| 5554 ### <a name="visibility"></a>**visibility**: A list of labels that can depend on
a target. | 5160 ### <a name="visibility"></a>**visibility**: A list of labels that can depend on
a target. |
| 5555 | 5161 |
| 5556 ``` | 5162 ``` |
| 5557 A list of labels and label patterns that define which targets can depend on | 5163 A list of labels and label patterns that define which targets can depend on |
| 5558 the current one. These permissions are checked via the "check" command (see | 5164 the current one. These permissions are checked via the "check" command (see |
| 5559 "gn help check"). | 5165 "gn help check"). |
| 5560 | 5166 |
| 5561 If visibility is not defined, it defaults to public ("*"). | 5167 If visibility is not defined, it defaults to public ("*"). |
| 5562 | 5168 |
| 5563 If visibility is defined, only the targets with labels that match it can | 5169 If visibility is defined, only the targets with labels that match it can |
| 5564 depend on the current target. The empty list means no targets can depend on | 5170 depend on the current target. The empty list means no targets can depend on |
| 5565 the current target. | 5171 the current target. |
| 5566 | 5172 |
| 5567 Tip: Often you will want the same visibility for all targets in a BUILD file. | 5173 Tip: Often you will want the same visibility for all targets in a BUILD file. |
| 5568 In this case you can just put the definition at the top, outside of any | 5174 In this case you can just put the definition at the top, outside of any |
| 5569 target, and the targets will inherit that scope and see the definition. | 5175 target, and the targets will inherit that scope and see the definition. |
| 5570 | |
| 5571 ``` | 5176 ``` |
| 5572 | 5177 |
| 5573 #### **Patterns** | 5178 #### **Patterns** |
| 5574 | 5179 |
| 5575 ``` | 5180 ``` |
| 5576 See "gn help label_pattern" for more details on what types of patterns are | 5181 See "gn help label_pattern" for more details on what types of patterns are |
| 5577 supported. If a toolchain is specified, only targets in that toolchain will | 5182 supported. If a toolchain is specified, only targets in that toolchain will |
| 5578 be matched. If a toolchain is not specified on a pattern, targets in all | 5183 be matched. If a toolchain is not specified on a pattern, targets in all |
| 5579 toolchains will be matched. | 5184 toolchains will be matched. |
| 5580 | |
| 5581 ``` | 5185 ``` |
| 5582 | 5186 |
| 5583 #### **Examples** | 5187 #### **Examples** |
| 5584 | 5188 |
| 5585 ``` | 5189 ``` |
| 5586 Only targets in the current buildfile ("private"): | 5190 Only targets in the current buildfile ("private"): |
| 5587 visibility = [ ":*" ] | 5191 visibility = [ ":*" ] |
| 5588 | 5192 |
| 5589 No targets (used for targets that should be leaf nodes): | 5193 No targets (used for targets that should be leaf nodes): |
| 5590 visibility = [] | 5194 visibility = [] |
| 5591 | 5195 |
| 5592 Any target ("public", the default): | 5196 Any target ("public", the default): |
| 5593 visibility = [ "*" ] | 5197 visibility = [ "*" ] |
| 5594 | 5198 |
| 5595 All targets in the current directory and any subdirectory: | 5199 All targets in the current directory and any subdirectory: |
| 5596 visibility = [ "./*" ] | 5200 visibility = [ "./*" ] |
| 5597 | 5201 |
| 5598 Any target in "//bar/BUILD.gn": | 5202 Any target in "//bar/BUILD.gn": |
| 5599 visibility = [ "//bar:*" ] | 5203 visibility = [ "//bar:*" ] |
| 5600 | 5204 |
| 5601 Any target in "//bar/" or any subdirectory thereof: | 5205 Any target in "//bar/" or any subdirectory thereof: |
| 5602 visibility = [ "//bar/*" ] | 5206 visibility = [ "//bar/*" ] |
| 5603 | 5207 |
| 5604 Just these specific targets: | 5208 Just these specific targets: |
| 5605 visibility = [ ":mything", "//foo:something_else" ] | 5209 visibility = [ ":mything", "//foo:something_else" ] |
| 5606 | 5210 |
| 5607 Any target in the current directory and any subdirectory thereof, plus | 5211 Any target in the current directory and any subdirectory thereof, plus |
| 5608 any targets in "//bar/" and any subdirectory thereof. | 5212 any targets in "//bar/" and any subdirectory thereof. |
| 5609 visibility = [ "./*", "//bar/*" ] | 5213 visibility = [ "./*", "//bar/*" ] |
| 5610 | |
| 5611 | |
| 5612 ``` | 5214 ``` |
| 5613 ### <a name="write_runtime_deps"></a>**write_runtime_deps**: Writes the target's
runtime_deps to the given path. | 5215 ### <a name="write_runtime_deps"></a>**write_runtime_deps**: Writes the target's
runtime_deps to the given path. |
| 5614 | 5216 |
| 5615 ``` | 5217 ``` |
| 5616 Does not synchronously write the file, but rather schedules it to be written | 5218 Does not synchronously write the file, but rather schedules it to be written |
| 5617 at the end of generation. | 5219 at the end of generation. |
| 5618 | 5220 |
| 5619 If the file exists and the contents are identical to that being written, the | 5221 If the file exists and the contents are identical to that being written, the |
| 5620 file will not be updated. This will prevent unnecessary rebuilds of targets | 5222 file will not be updated. This will prevent unnecessary rebuilds of targets |
| 5621 that depend on this file. | 5223 that depend on this file. |
| 5622 | 5224 |
| 5623 Path must be within the output directory. | 5225 Path must be within the output directory. |
| 5624 | 5226 |
| 5625 See "gn help runtime_deps" for how the runtime dependencies are computed. | 5227 See "gn help runtime_deps" for how the runtime dependencies are computed. |
| 5626 | 5228 |
| 5627 The format of this file will list one file per line with no escaping. The | 5229 The format of this file will list one file per line with no escaping. The |
| 5628 files will be relative to the root_build_dir. The first line of the file will | 5230 files will be relative to the root_build_dir. The first line of the file will |
| 5629 be the main output file of the target itself. The file contents will be the | 5231 be the main output file of the target itself. The file contents will be the |
| 5630 same as requesting the runtime deps be written on the command line (see "gn | 5232 same as requesting the runtime deps be written on the command line (see "gn |
| 5631 help --runtime-deps-list-file"). | 5233 help --runtime-deps-list-file"). |
| 5632 | |
| 5633 | |
| 5634 ``` | 5234 ``` |
| 5635 ## <a name="other"></a>Other help topics | 5235 ## <a name="other"></a>Other help topics |
| 5636 | 5236 |
| 5637 ### <a name="buildargs"></a>**Build Arguments Overview** | 5237 ### <a name="buildargs"></a>**Build Arguments Overview** |
| 5638 | 5238 |
| 5639 ``` | 5239 ``` |
| 5640 Build arguments are variables passed in from outside of the build that build | 5240 Build arguments are variables passed in from outside of the build that build |
| 5641 files can query to determine how the build works. | 5241 files can query to determine how the build works. |
| 5642 | |
| 5643 ``` | 5242 ``` |
| 5644 | 5243 |
| 5645 #### **How build arguments are set** | 5244 #### **How build arguments are set** |
| 5646 | 5245 |
| 5647 ``` | 5246 ``` |
| 5648 First, system default arguments are set based on the current system. The | 5247 First, system default arguments are set based on the current system. The |
| 5649 built-in arguments are: | 5248 built-in arguments are: |
| 5650 - host_cpu | 5249 - host_cpu |
| 5651 - host_os | 5250 - host_os |
| 5652 - current_cpu | 5251 - current_cpu |
| 5653 - current_os | 5252 - current_os |
| 5654 - target_cpu | 5253 - target_cpu |
| 5655 - target_os | 5254 - target_os |
| 5656 | 5255 |
| 5657 Next, project-specific overrides are applied. These are specified inside | 5256 Next, project-specific overrides are applied. These are specified inside |
| 5658 the default_args variable of //.gn. See "gn help dotfile" for more. | 5257 the default_args variable of //.gn. See "gn help dotfile" for more. |
| 5659 | 5258 |
| 5660 If specified, arguments from the --args command line flag are used. If that | 5259 If specified, arguments from the --args command line flag are used. If that |
| 5661 flag is not specified, args from previous builds in the build directory will | 5260 flag is not specified, args from previous builds in the build directory will |
| 5662 be used (this is in the file args.gn in the build directory). | 5261 be used (this is in the file args.gn in the build directory). |
| 5663 | 5262 |
| 5664 Last, for targets being compiled with a non-default toolchain, the toolchain | 5263 Last, for targets being compiled with a non-default toolchain, the toolchain |
| 5665 overrides are applied. These are specified in the toolchain_args section of a | 5264 overrides are applied. These are specified in the toolchain_args section of a |
| 5666 toolchain definition. The use-case for this is that a toolchain may be | 5265 toolchain definition. The use-case for this is that a toolchain may be |
| 5667 building code for a different platform, and that it may want to always | 5266 building code for a different platform, and that it may want to always |
| 5668 specify Posix, for example. See "gn help toolchain" for more. | 5267 specify Posix, for example. See "gn help toolchain" for more. |
| 5669 | 5268 |
| 5670 If you specify an override for a build argument that never appears in a | 5269 If you specify an override for a build argument that never appears in a |
| 5671 "declare_args" call, a nonfatal error will be displayed. | 5270 "declare_args" call, a nonfatal error will be displayed. |
| 5672 | |
| 5673 ``` | 5271 ``` |
| 5674 | 5272 |
| 5675 #### **Examples** | 5273 #### **Examples** |
| 5676 | 5274 |
| 5677 ``` | 5275 ``` |
| 5678 gn args out/FooBar | 5276 gn args out/FooBar |
| 5679 Create the directory out/FooBar and open an editor. You would type | 5277 Create the directory out/FooBar and open an editor. You would type |
| 5680 something like this into that file: | 5278 something like this into that file: |
| 5681 enable_doom_melon=false | 5279 enable_doom_melon=false |
| 5682 os="android" | 5280 os="android" |
| 5683 | 5281 |
| 5684 gn gen out/FooBar --args="enable_doom_melon=true os=\"android\"" | 5282 gn gen out/FooBar --args="enable_doom_melon=true os=\"android\"" |
| 5685 This will overwrite the build directory with the given arguments. (Note | 5283 This will overwrite the build directory with the given arguments. (Note |
| 5686 that the quotes inside the args command will usually need to be escaped | 5284 that the quotes inside the args command will usually need to be escaped |
| 5687 for your shell to pass through strings values.) | 5285 for your shell to pass through strings values.) |
| 5688 | |
| 5689 ``` | 5286 ``` |
| 5690 | 5287 |
| 5691 #### **How build arguments are used** | 5288 #### **How build arguments are used** |
| 5692 | 5289 |
| 5693 ``` | 5290 ``` |
| 5694 If you want to use an argument, you use declare_args() and specify default | 5291 If you want to use an argument, you use declare_args() and specify default |
| 5695 values. These default values will apply if none of the steps listed in the | 5292 values. These default values will apply if none of the steps listed in the |
| 5696 "How build arguments are set" section above apply to the given argument, but | 5293 "How build arguments are set" section above apply to the given argument, but |
| 5697 the defaults will not override any of these. | 5294 the defaults will not override any of these. |
| 5698 | 5295 |
| 5699 Often, the root build config file will declare global arguments that will be | 5296 Often, the root build config file will declare global arguments that will be |
| 5700 passed to all buildfiles. Individual build files can also specify arguments | 5297 passed to all buildfiles. Individual build files can also specify arguments |
| 5701 that apply only to those files. It is also useful to specify build args in an | 5298 that apply only to those files. It is also useful to specify build args in an |
| 5702 "import"-ed file if you want such arguments to apply to multiple buildfiles. | 5299 "import"-ed file if you want such arguments to apply to multiple buildfiles. |
| 5703 | |
| 5704 | |
| 5705 ``` | 5300 ``` |
| 5706 ### <a name="dotfile"></a>**.gn file** | 5301 ### <a name="dotfile"></a>**.gn file** |
| 5707 | 5302 |
| 5708 ``` | 5303 ``` |
| 5709 When gn starts, it will search the current directory and parent directories | 5304 When gn starts, it will search the current directory and parent directories |
| 5710 for a file called ".gn". This indicates the source root. You can override | 5305 for a file called ".gn". This indicates the source root. You can override |
| 5711 this detection by using the --root command-line argument | 5306 this detection by using the --root command-line argument |
| 5712 | 5307 |
| 5713 The .gn file in the source root will be executed. The syntax is the same as a | 5308 The .gn file in the source root will be executed. The syntax is the same as a |
| 5714 buildfile, but with very limited build setup-specific meaning. | 5309 buildfile, but with very limited build setup-specific meaning. |
| 5715 | 5310 |
| 5716 If you specify --root, by default GN will look for the file .gn in that | 5311 If you specify --root, by default GN will look for the file .gn in that |
| 5717 directory. If you want to specify a different file, you can additionally pass | 5312 directory. If you want to specify a different file, you can additionally pass |
| 5718 --dotfile: | 5313 --dotfile: |
| 5719 | 5314 |
| 5720 gn gen out/Debug --root=/home/build --dotfile=/home/my_gn_file.gn | 5315 gn gen out/Debug --root=/home/build --dotfile=/home/my_gn_file.gn |
| 5721 | |
| 5722 ``` | 5316 ``` |
| 5723 | 5317 |
| 5724 #### **Variables** | 5318 #### **Variables** |
| 5725 | 5319 |
| 5726 ``` | 5320 ``` |
| 5727 arg_file_template [optional] | 5321 arg_file_template [optional] |
| 5728 Path to a file containing the text that should be used as the default | 5322 Path to a file containing the text that should be used as the default |
| 5729 args.gn content when you run `gn args`. | 5323 args.gn content when you run `gn args`. |
| 5730 | 5324 |
| 5731 buildconfig [required] | 5325 buildconfig [required] |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5777 The secondary source root must be inside the main source tree. | 5371 The secondary source root must be inside the main source tree. |
| 5778 | 5372 |
| 5779 default_args [optional] | 5373 default_args [optional] |
| 5780 Scope containing the default overrides for declared arguments. These | 5374 Scope containing the default overrides for declared arguments. These |
| 5781 overrides take precedence over the default values specified in the | 5375 overrides take precedence over the default values specified in the |
| 5782 declare_args() block, but can be overriden using --args or the | 5376 declare_args() block, but can be overriden using --args or the |
| 5783 args.gn file. | 5377 args.gn file. |
| 5784 | 5378 |
| 5785 This is intended to be used when subprojects declare arguments with | 5379 This is intended to be used when subprojects declare arguments with |
| 5786 default values that need to be changed for whatever reason. | 5380 default values that need to be changed for whatever reason. |
| 5787 | |
| 5788 ``` | 5381 ``` |
| 5789 | 5382 |
| 5790 #### **Example .gn file contents** | 5383 #### **Example .gn file contents** |
| 5791 | 5384 |
| 5792 ``` | 5385 ``` |
| 5793 buildconfig = "//build/config/BUILDCONFIG.gn" | 5386 buildconfig = "//build/config/BUILDCONFIG.gn" |
| 5794 | 5387 |
| 5795 check_targets = [ | 5388 check_targets = [ |
| 5796 "//doom_melon/*", # Check everything in this subtree. | 5389 "//doom_melon/*", # Check everything in this subtree. |
| 5797 "//tools:mind_controlling_ant", # Check this specific target. | 5390 "//tools:mind_controlling_ant", # Check this specific target. |
| 5798 ] | 5391 ] |
| 5799 | 5392 |
| 5800 root = "//:root" | 5393 root = "//:root" |
| 5801 | 5394 |
| 5802 secondary_source = "//build/config/temporary_buildfiles/" | 5395 secondary_source = "//build/config/temporary_buildfiles/" |
| 5803 | 5396 |
| 5804 default_args = { | 5397 default_args = { |
| 5805 # Default to release builds for this project. | 5398 # Default to release builds for this project. |
| 5806 is_debug = false | 5399 is_debug = false |
| 5807 is_component_build = false | 5400 is_component_build = false |
| 5808 } | 5401 } |
| 5809 | |
| 5810 | |
| 5811 ``` | 5402 ``` |
| 5812 ### <a name="execution"></a>**Build graph and execution overview** | 5403 ### <a name="execution"></a>**Build graph and execution overview** |
| 5813 | 5404 |
| 5814 #### **Overall build flow** | 5405 #### **Overall build flow** |
| 5815 | 5406 |
| 5816 ``` | 5407 ``` |
| 5817 1. Look for ".gn" file (see "gn help dotfile") in the current directory and | 5408 1. Look for ".gn" file (see "gn help dotfile") in the current directory and |
| 5818 walk up the directory tree until one is found. Set this directory to be | 5409 walk up the directory tree until one is found. Set this directory to be |
| 5819 the "source root" and interpret this file to find the name of the build | 5410 the "source root" and interpret this file to find the name of the build |
| 5820 config file. | 5411 config file. |
| 5821 | 5412 |
| 5822 2. Execute the build config file identified by .gn to set up the global | 5413 2. Execute the build config file identified by .gn to set up the global |
| 5823 variables and default toolchain name. Any arguments, variables, defaults, | 5414 variables and default toolchain name. Any arguments, variables, defaults, |
| 5824 etc. set up in this file will be visible to all files in the build. | 5415 etc. set up in this file will be visible to all files in the build. |
| 5825 | 5416 |
| 5826 3. Load the //BUILD.gn (in the source root directory). | 5417 3. Load the //BUILD.gn (in the source root directory). |
| 5827 | 5418 |
| 5828 4. Recursively evaluate rules and load BUILD.gn in other directories as | 5419 4. Recursively evaluate rules and load BUILD.gn in other directories as |
| 5829 necessary to resolve dependencies. If a BUILD file isn't found in the | 5420 necessary to resolve dependencies. If a BUILD file isn't found in the |
| 5830 specified location, GN will look in the corresponding location inside | 5421 specified location, GN will look in the corresponding location inside |
| 5831 the secondary_source defined in the dotfile (see "gn help dotfile"). | 5422 the secondary_source defined in the dotfile (see "gn help dotfile"). |
| 5832 | 5423 |
| 5833 5. When a target's dependencies are resolved, write out the `.ninja` | 5424 5. When a target's dependencies are resolved, write out the `.ninja` |
| 5834 file to disk. | 5425 file to disk. |
| 5835 | 5426 |
| 5836 6. When all targets are resolved, write out the root build.ninja file. | 5427 6. When all targets are resolved, write out the root build.ninja file. |
| 5837 | |
| 5838 ``` | 5428 ``` |
| 5839 | 5429 |
| 5840 #### **Executing target definitions and templates** | 5430 #### **Executing target definitions and templates** |
| 5841 | 5431 |
| 5842 ``` | 5432 ``` |
| 5843 Build files are loaded in parallel. This means it is impossible to | 5433 Build files are loaded in parallel. This means it is impossible to |
| 5844 interrogate a target from GN code for any information not derivable from its | 5434 interrogate a target from GN code for any information not derivable from its |
| 5845 label (see "gn help label"). The exception is the get_target_outputs() | 5435 label (see "gn help label"). The exception is the get_target_outputs() |
| 5846 function which requires the target being interrogated to have been defined | 5436 function which requires the target being interrogated to have been defined |
| 5847 previously in the same file. | 5437 previously in the same file. |
| 5848 | 5438 |
| 5849 Targets are declared by their type and given a name: | 5439 Targets are declared by their type and given a name: |
| 5850 | 5440 |
| 5851 static_library("my_static_library") { | 5441 static_library("my_static_library") { |
| 5852 ... target parameter definitions ... | 5442 ... target parameter definitions ... |
| 5853 } | 5443 } |
| 5854 | 5444 |
| 5855 There is also a generic "target" function for programatically defined types | 5445 There is also a generic "target" function for programatically defined types |
| 5856 (see "gn help target"). You can define new types using templates (see "gn | 5446 (see "gn help target"). You can define new types using templates (see "gn |
| 5857 help template"). A template defines some custom code that expands to one or | 5447 help template"). A template defines some custom code that expands to one or |
| 5858 more other targets. | 5448 more other targets. |
| 5859 | 5449 |
| 5860 Before executing the code inside the target's { }, the target defaults are | 5450 Before executing the code inside the target's { }, the target defaults are |
| 5861 applied (see "gn help set_defaults"). It will inject implicit variable | 5451 applied (see "gn help set_defaults"). It will inject implicit variable |
| 5862 definitions that can be overridden by the target code as necessary. Typically | 5452 definitions that can be overridden by the target code as necessary. Typically |
| 5863 this mechanism is used to inject a default set of configs that define the | 5453 this mechanism is used to inject a default set of configs that define the |
| 5864 global compiler and linker flags. | 5454 global compiler and linker flags. |
| 5865 | |
| 5866 ``` | 5455 ``` |
| 5867 | 5456 |
| 5868 #### **Which targets are built** | 5457 #### **Which targets are built** |
| 5869 | 5458 |
| 5870 ``` | 5459 ``` |
| 5871 All targets encountered in the default toolchain (see "gn help toolchain") | 5460 All targets encountered in the default toolchain (see "gn help toolchain") |
| 5872 will have build rules generated for them, even if no other targets reference | 5461 will have build rules generated for them, even if no other targets reference |
| 5873 them. Their dependencies must resolve and they will be added to the implicit | 5462 them. Their dependencies must resolve and they will be added to the implicit |
| 5874 "all" rule (see "gn help ninja_rules"). | 5463 "all" rule (see "gn help ninja_rules"). |
| 5875 | 5464 |
| 5876 Targets in non-default toolchains will only be generated when they are | 5465 Targets in non-default toolchains will only be generated when they are |
| 5877 required (directly or transitively) to build a target in the default | 5466 required (directly or transitively) to build a target in the default |
| 5878 toolchain. | 5467 toolchain. |
| 5879 | 5468 |
| 5880 See also "gn help ninja_rules". | 5469 See also "gn help ninja_rules". |
| 5881 | |
| 5882 ``` | 5470 ``` |
| 5883 | 5471 |
| 5884 #### **Dependencies** | 5472 #### **Dependencies** |
| 5885 | 5473 |
| 5886 ``` | 5474 ``` |
| 5887 The only difference between "public_deps" and "deps" except for pushing | 5475 The only difference between "public_deps" and "deps" except for pushing |
| 5888 configs around the build tree and allowing includes for the purposes of "gn | 5476 configs around the build tree and allowing includes for the purposes of "gn |
| 5889 check". | 5477 check". |
| 5890 | 5478 |
| 5891 A target's "data_deps" are guaranteed to be built whenever the target is | 5479 A target's "data_deps" are guaranteed to be built whenever the target is |
| 5892 built, but the ordering is not defined. The meaning of this is dependencies | 5480 built, but the ordering is not defined. The meaning of this is dependencies |
| 5893 required at runtime. Currently data deps will be complete before the target | 5481 required at runtime. Currently data deps will be complete before the target |
| 5894 is linked, but this is not semantically guaranteed and this is undesirable | 5482 is linked, but this is not semantically guaranteed and this is undesirable |
| 5895 from a build performance perspective. Since we hope to change this in the | 5483 from a build performance perspective. Since we hope to change this in the |
| 5896 future, do not rely on this behavior. | 5484 future, do not rely on this behavior. |
| 5897 | |
| 5898 | |
| 5899 ``` | 5485 ``` |
| 5900 ### <a name="grammar"></a>**Language and grammar for GN build files** | 5486 ### <a name="grammar"></a>**Language and grammar for GN build files** |
| 5901 | 5487 |
| 5902 #### **Tokens** | 5488 #### **Tokens** |
| 5903 | 5489 |
| 5904 ``` | 5490 ``` |
| 5905 GN build files are read as sequences of tokens. While splitting the file | 5491 GN build files are read as sequences of tokens. While splitting the file |
| 5906 into tokens, the next token is the longest sequence of characters that form a | 5492 into tokens, the next token is the longest sequence of characters that form a |
| 5907 valid token. | 5493 valid token. |
| 5908 | |
| 5909 ``` | 5494 ``` |
| 5910 | 5495 |
| 5911 #### **White space and comments** | 5496 #### **White space and comments** |
| 5912 | 5497 |
| 5913 ``` | 5498 ``` |
| 5914 White space is comprised of spaces (U+0020), horizontal tabs (U+0009), | 5499 White space is comprised of spaces (U+0020), horizontal tabs (U+0009), |
| 5915 carriage returns (U+000D), and newlines (U+000A). | 5500 carriage returns (U+000D), and newlines (U+000A). |
| 5916 | 5501 |
| 5917 Comments start at the character "#" and stop at the next newline. | 5502 Comments start at the character "#" and stop at the next newline. |
| 5918 | 5503 |
| 5919 White space and comments are ignored except that they may separate tokens | 5504 White space and comments are ignored except that they may separate tokens |
| 5920 that would otherwise combine into a single token. | 5505 that would otherwise combine into a single token. |
| 5921 | |
| 5922 ``` | 5506 ``` |
| 5923 | 5507 |
| 5924 #### **Identifiers** | 5508 #### **Identifiers** |
| 5925 | 5509 |
| 5926 ``` | 5510 ``` |
| 5927 Identifiers name variables and functions. | 5511 Identifiers name variables and functions. |
| 5928 | 5512 |
| 5929 identifier = letter { letter | digit } . | 5513 identifier = letter { letter | digit } . |
| 5930 letter = "A" ... "Z" | "a" ... "z" | "_" . | 5514 letter = "A" ... "Z" | "a" ... "z" | "_" . |
| 5931 digit = "0" ... "9" . | 5515 digit = "0" ... "9" . |
| 5932 | |
| 5933 ``` | 5516 ``` |
| 5934 | 5517 |
| 5935 #### **Keywords** | 5518 #### **Keywords** |
| 5936 | 5519 |
| 5937 ``` | 5520 ``` |
| 5938 The following keywords are reserved and may not be used as identifiers: | 5521 The following keywords are reserved and may not be used as identifiers: |
| 5939 | 5522 |
| 5940 else false if true | 5523 else false if true |
| 5941 | |
| 5942 ``` | 5524 ``` |
| 5943 | 5525 |
| 5944 #### **Integer literals** | 5526 #### **Integer literals** |
| 5945 | 5527 |
| 5946 ``` | 5528 ``` |
| 5947 An integer literal represents a decimal integer value. | 5529 An integer literal represents a decimal integer value. |
| 5948 | 5530 |
| 5949 integer = [ "-" ] digit { digit } . | 5531 integer = [ "-" ] digit { digit } . |
| 5950 | 5532 |
| 5951 Leading zeros and negative zero are disallowed. | 5533 Leading zeros and negative zero are disallowed. |
| 5952 | |
| 5953 ``` | 5534 ``` |
| 5954 | 5535 |
| 5955 #### **String literals** | 5536 #### **String literals** |
| 5956 | 5537 |
| 5957 ``` | 5538 ``` |
| 5958 A string literal represents a string value consisting of the quoted | 5539 A string literal represents a string value consisting of the quoted |
| 5959 characters with possible escape sequences and variable expansions. | 5540 characters with possible escape sequences and variable expansions. |
| 5960 | 5541 |
| 5961 string = `"` { char | escape | expansion } `"` . | 5542 string = `"` { char | escape | expansion } `"` . |
| 5962 escape = `\` ( "$" | `"` | char ) . | 5543 escape = `\` ( "$" | `"` | char ) . |
| (...skipping 14 matching lines...) Expand all Loading... |
| 5977 | 5558 |
| 5978 To insert an arbitrary byte value, use $0xFF. For example, to insert a | 5559 To insert an arbitrary byte value, use $0xFF. For example, to insert a |
| 5979 newline character: "Line one$0x0ALine two". | 5560 newline character: "Line one$0x0ALine two". |
| 5980 | 5561 |
| 5981 An expansion will evaluate the variable following the '$' and insert a | 5562 An expansion will evaluate the variable following the '$' and insert a |
| 5982 stringified version of it into the result. For example, to concat two path | 5563 stringified version of it into the result. For example, to concat two path |
| 5983 components with a slash separating them: | 5564 components with a slash separating them: |
| 5984 "$var_one/$var_two" | 5565 "$var_one/$var_two" |
| 5985 Use the "${var_one}" format to be explicitly deliniate the variable for | 5566 Use the "${var_one}" format to be explicitly deliniate the variable for |
| 5986 otherwise-ambiguous cases. | 5567 otherwise-ambiguous cases. |
| 5987 | |
| 5988 ``` | 5568 ``` |
| 5989 | 5569 |
| 5990 #### **Punctuation** | 5570 #### **Punctuation** |
| 5991 | 5571 |
| 5992 ``` | 5572 ``` |
| 5993 The following character sequences represent punctuation: | 5573 The following character sequences represent punctuation: |
| 5994 | 5574 |
| 5995 + += == != ( ) | 5575 + += == != ( ) |
| 5996 - -= < <= [ ] | 5576 - -= < <= [ ] |
| 5997 ! = > >= { } | 5577 ! = > >= { } |
| 5998 && || . , | 5578 && || . , |
| 5999 | |
| 6000 ``` | 5579 ``` |
| 6001 | 5580 |
| 6002 #### **Grammar** | 5581 #### **Grammar** |
| 6003 | 5582 |
| 6004 ``` | 5583 ``` |
| 6005 The input tokens form a syntax tree following a context-free grammar: | 5584 The input tokens form a syntax tree following a context-free grammar: |
| 6006 | 5585 |
| 6007 File = StatementList . | 5586 File = StatementList . |
| 6008 | 5587 |
| 6009 Statement = Assignment | Call | Condition . | 5588 Statement = Assignment | Call | Condition . |
| (...skipping 17 matching lines...) Expand all Loading... |
| 6027 | 5606 |
| 6028 AssignOp = "=" | "+=" | "-=" . | 5607 AssignOp = "=" | "+=" | "-=" . |
| 6029 UnaryOp = "!" . | 5608 UnaryOp = "!" . |
| 6030 BinaryOp = "+" | "-" // highest priority | 5609 BinaryOp = "+" | "-" // highest priority |
| 6031 | "<" | "<=" | ">" | ">=" | 5610 | "<" | "<=" | ">" | ">=" |
| 6032 | "==" | "!=" | 5611 | "==" | "!=" |
| 6033 | "&&" | 5612 | "&&" |
| 6034 | "||" . // lowest priority | 5613 | "||" . // lowest priority |
| 6035 | 5614 |
| 6036 All binary operators are left-associative. | 5615 All binary operators are left-associative. |
| 6037 | |
| 6038 ``` | 5616 ``` |
| 6039 | 5617 |
| 6040 #### **Types** | 5618 #### **Types** |
| 6041 | 5619 |
| 6042 ``` | 5620 ``` |
| 6043 The GN language is dynamically typed. The following types are used: | 5621 The GN language is dynamically typed. The following types are used: |
| 6044 | 5622 |
| 6045 - Boolean: Uses the keywords "true" and "false". There is no implicit | 5623 - Boolean: Uses the keywords "true" and "false". There is no implicit |
| 6046 conversion between booleans and integers. | 5624 conversion between booleans and integers. |
| 6047 | 5625 |
| 6048 - Integers: All numbers in GN are signed 64-bit integers. | 5626 - Integers: All numbers in GN are signed 64-bit integers. |
| 6049 | 5627 |
| 6050 - Strings: Strings are 8-bit with no enforced encoding. When a string is | 5628 - Strings: Strings are 8-bit with no enforced encoding. When a string is |
| 6051 used to interact with other systems with particular encodings (like the | 5629 used to interact with other systems with particular encodings (like the |
| 6052 Windows and Mac filesystems) it is assumed to be UTF-8. See "String | 5630 Windows and Mac filesystems) it is assumed to be UTF-8. See "String |
| 6053 literals" above for more. | 5631 literals" above for more. |
| 6054 | 5632 |
| 6055 - Lists: Lists are arbitrary-length ordered lists of values. See "Lists" | 5633 - Lists: Lists are arbitrary-length ordered lists of values. See "Lists" |
| 6056 below for more. | 5634 below for more. |
| 6057 | 5635 |
| 6058 - Scopes: Scopes are like dictionaries that use variable names for keys. See | 5636 - Scopes: Scopes are like dictionaries that use variable names for keys. See |
| 6059 "Scopes" below for more. | 5637 "Scopes" below for more. |
| 6060 | |
| 6061 ``` | 5638 ``` |
| 6062 | 5639 |
| 6063 #### **Lists** | 5640 #### **Lists** |
| 6064 | 5641 |
| 6065 ``` | 5642 ``` |
| 6066 Lists are created with [] and using commas to separate items: | 5643 Lists are created with [] and using commas to separate items: |
| 6067 | 5644 |
| 6068 mylist = [ 0, 1, 2, "some string" ] | 5645 mylist = [ 0, 1, 2, "some string" ] |
| 6069 | 5646 |
| 6070 A comma after the last item is optional. Lists are dereferenced using 0-based | 5647 A comma after the last item is optional. Lists are dereferenced using 0-based |
| (...skipping 16 matching lines...) Expand all Loading... |
| 6087 list. This is to prevent accidentally overwriting data when in most cases | 5664 list. This is to prevent accidentally overwriting data when in most cases |
| 6088 '+=' was intended. To overwrite a list on purpose, first assign it to the | 5665 '+=' was intended. To overwrite a list on purpose, first assign it to the |
| 6089 empty list: | 5666 empty list: |
| 6090 | 5667 |
| 6091 mylist = [] | 5668 mylist = [] |
| 6092 mylist = otherlist | 5669 mylist = otherlist |
| 6093 | 5670 |
| 6094 When assigning to a list named 'sources' using '=' or '+=', list items may be | 5671 When assigning to a list named 'sources' using '=' or '+=', list items may be |
| 6095 automatically filtered out. See "gn help set_sources_assignment_filter" for | 5672 automatically filtered out. See "gn help set_sources_assignment_filter" for |
| 6096 more. | 5673 more. |
| 6097 | |
| 6098 ``` | 5674 ``` |
| 6099 | 5675 |
| 6100 #### **Scopes** | 5676 #### **Scopes** |
| 6101 | 5677 |
| 6102 ``` | 5678 ``` |
| 6103 All execution happens in the context of a scope which holds the current state | 5679 All execution happens in the context of a scope which holds the current state |
| 6104 (like variables). With the exception of loops and conditions, '{' introduces | 5680 (like variables). With the exception of loops and conditions, '{' introduces |
| 6105 a new scope that has a parent reference to the old scope. | 5681 a new scope that has a parent reference to the old scope. |
| 6106 | 5682 |
| 6107 Variable reads recursively search all nested scopes until the variable is | 5683 Variable reads recursively search all nested scopes until the variable is |
| (...skipping 14 matching lines...) Expand all Loading... |
| 6122 bar = "something" | 5698 bar = "something" |
| 6123 } | 5699 } |
| 6124 | 5700 |
| 6125 Inside such a scope definition can be any GN code including conditionals and | 5701 Inside such a scope definition can be any GN code including conditionals and |
| 6126 function calls. After the close of the scope, it will contain all variables | 5702 function calls. After the close of the scope, it will contain all variables |
| 6127 explicitly set by the code contained inside it. After this, the values can be | 5703 explicitly set by the code contained inside it. After this, the values can be |
| 6128 read, modified, or added to: | 5704 read, modified, or added to: |
| 6129 | 5705 |
| 6130 myvalues.foo += 2 | 5706 myvalues.foo += 2 |
| 6131 empty_scope.new_thing = [ 1, 2, 3 ] | 5707 empty_scope.new_thing = [ 1, 2, 3 ] |
| 6132 | |
| 6133 | |
| 6134 ``` | 5708 ``` |
| 6135 ### <a name="input_conversion"></a>**input_conversion**: Specifies how to transf
orm input to a variable. | 5709 ### <a name="input_conversion"></a>**input_conversion**: Specifies how to transf
orm input to a variable. |
| 6136 | 5710 |
| 6137 ``` | 5711 ``` |
| 6138 input_conversion is an argument to read_file and exec_script that specifies | 5712 input_conversion is an argument to read_file and exec_script that specifies |
| 6139 how the result of the read operation should be converted into a variable. | 5713 how the result of the read operation should be converted into a variable. |
| 6140 | 5714 |
| 6141 "" (the default) | 5715 "" (the default) |
| 6142 Discard the result and return None. | 5716 Discard the result and return None. |
| 6143 | 5717 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6176 | 5750 |
| 6177 "trim ..." | 5751 "trim ..." |
| 6178 Prefixing any of the other transformations with the word "trim" will | 5752 Prefixing any of the other transformations with the word "trim" will |
| 6179 result in whitespace being trimmed from the beginning and end of the | 5753 result in whitespace being trimmed from the beginning and end of the |
| 6180 result before processing. | 5754 result before processing. |
| 6181 | 5755 |
| 6182 Examples: "trim string" or "trim list lines" | 5756 Examples: "trim string" or "trim list lines" |
| 6183 | 5757 |
| 6184 Note that "trim value" is useless because the value parser skips | 5758 Note that "trim value" is useless because the value parser skips |
| 6185 whitespace anyway. | 5759 whitespace anyway. |
| 6186 | |
| 6187 | |
| 6188 ``` | 5760 ``` |
| 6189 ### <a name="label_pattern"></a>**Label patterns** | 5761 ### <a name="label_pattern"></a>**Label patterns** |
| 6190 | 5762 |
| 6191 ``` | 5763 ``` |
| 6192 A label pattern is a way of expressing one or more labels in a portion of the | 5764 A label pattern is a way of expressing one or more labels in a portion of the |
| 6193 source tree. They are not general regular expressions. | 5765 source tree. They are not general regular expressions. |
| 6194 | 5766 |
| 6195 They can take the following forms only: | 5767 They can take the following forms only: |
| 6196 | 5768 |
| 6197 - Explicit (no wildcard): | 5769 - Explicit (no wildcard): |
| (...skipping 15 matching lines...) Expand all Loading... |
| 6213 | 5785 |
| 6214 "//foo:bar(//build/toochain:mac)" | 5786 "//foo:bar(//build/toochain:mac)" |
| 6215 An explicit target in an explicit toolchain. | 5787 An explicit target in an explicit toolchain. |
| 6216 | 5788 |
| 6217 ":*(//build/toolchain/linux:32bit)" | 5789 ":*(//build/toolchain/linux:32bit)" |
| 6218 All targets in the current build file using the 32-bit Linux toolchain. | 5790 All targets in the current build file using the 32-bit Linux toolchain. |
| 6219 | 5791 |
| 6220 "//foo/*(//build/toolchain:win)" | 5792 "//foo/*(//build/toolchain:win)" |
| 6221 All targets in //foo and any subdirectory using the Windows | 5793 All targets in //foo and any subdirectory using the Windows |
| 6222 toolchain. | 5794 toolchain. |
| 6223 | |
| 6224 | |
| 6225 ``` | 5795 ``` |
| 6226 ### <a name="labels"></a>**About labels** | 5796 ### <a name="labels"></a>**About labels** |
| 6227 | 5797 |
| 6228 ``` | 5798 ``` |
| 6229 Everything that can participate in the dependency graph (targets, configs, | 5799 Everything that can participate in the dependency graph (targets, configs, |
| 6230 and toolchains) are identified by labels. A common label looks like: | 5800 and toolchains) are identified by labels. A common label looks like: |
| 6231 | 5801 |
| 6232 //base/test:test_support | 5802 //base/test:test_support |
| 6233 | 5803 |
| 6234 This consists of a source-root-absolute path, a colon, and a name. This means | 5804 This consists of a source-root-absolute path, a colon, and a name. This means |
| 6235 to look for the thing named "test_support" in "base/test/BUILD.gn". | 5805 to look for the thing named "test_support" in "base/test/BUILD.gn". |
| 6236 | 5806 |
| 6237 You can also specify system absolute paths if necessary. Typically such | 5807 You can also specify system absolute paths if necessary. Typically such |
| 6238 paths would be specified via a build arg so the developer can specify where | 5808 paths would be specified via a build arg so the developer can specify where |
| 6239 the component is on their system. | 5809 the component is on their system. |
| 6240 | 5810 |
| 6241 /usr/local/foo:bar (Posix) | 5811 /usr/local/foo:bar (Posix) |
| 6242 /C:/Program Files/MyLibs:bar (Windows) | 5812 /C:/Program Files/MyLibs:bar (Windows) |
| 6243 | |
| 6244 ``` | 5813 ``` |
| 6245 | 5814 |
| 6246 #### **Toolchains** | 5815 #### **Toolchains** |
| 6247 | 5816 |
| 6248 ``` | 5817 ``` |
| 6249 A canonical label includes the label of the toolchain being used. Normally, | 5818 A canonical label includes the label of the toolchain being used. Normally, |
| 6250 the toolchain label is implicitly inherited from the current execution | 5819 the toolchain label is implicitly inherited from the current execution |
| 6251 context, but you can override this to specify cross-toolchain dependencies: | 5820 context, but you can override this to specify cross-toolchain dependencies: |
| 6252 | 5821 |
| 6253 //base/test:test_support(//build/toolchain/win:msvc) | 5822 //base/test:test_support(//build/toolchain/win:msvc) |
| 6254 | 5823 |
| 6255 Here GN will look for the toolchain definition called "msvc" in the file | 5824 Here GN will look for the toolchain definition called "msvc" in the file |
| 6256 "//build/toolchain/win" to know how to compile this target. | 5825 "//build/toolchain/win" to know how to compile this target. |
| 6257 | |
| 6258 ``` | 5826 ``` |
| 6259 | 5827 |
| 6260 #### **Relative labels** | 5828 #### **Relative labels** |
| 6261 | 5829 |
| 6262 ``` | 5830 ``` |
| 6263 If you want to refer to something in the same buildfile, you can omit | 5831 If you want to refer to something in the same buildfile, you can omit |
| 6264 the path name and just start with a colon. This format is recommended for | 5832 the path name and just start with a colon. This format is recommended for |
| 6265 all same-file references. | 5833 all same-file references. |
| 6266 | 5834 |
| 6267 :base | 5835 :base |
| 6268 | 5836 |
| 6269 Labels can be specified as being relative to the current directory. | 5837 Labels can be specified as being relative to the current directory. |
| 6270 Stylistically, we prefer to use absolute paths for all non-file-local | 5838 Stylistically, we prefer to use absolute paths for all non-file-local |
| 6271 references unless a build file needs to be run in different contexts (like a | 5839 references unless a build file needs to be run in different contexts (like a |
| 6272 project needs to be both standalone and pulled into other projects in | 5840 project needs to be both standalone and pulled into other projects in |
| 6273 difference places in the directory hierarchy). | 5841 difference places in the directory hierarchy). |
| 6274 | 5842 |
| 6275 source/plugin:myplugin | 5843 source/plugin:myplugin |
| 6276 ../net:url_request | 5844 ../net:url_request |
| 6277 | |
| 6278 ``` | 5845 ``` |
| 6279 | 5846 |
| 6280 #### **Implicit names** | 5847 #### **Implicit names** |
| 6281 | 5848 |
| 6282 ``` | 5849 ``` |
| 6283 If a name is unspecified, it will inherit the directory name. Stylistically, | 5850 If a name is unspecified, it will inherit the directory name. Stylistically, |
| 6284 we prefer to omit the colon and name when possible: | 5851 we prefer to omit the colon and name when possible: |
| 6285 | 5852 |
| 6286 //net -> //net:net | 5853 //net -> //net:net |
| 6287 //tools/gn -> //tools/gn:gn | 5854 //tools/gn -> //tools/gn:gn |
| 6288 | |
| 6289 | |
| 6290 ``` | 5855 ``` |
| 6291 ### <a name="ninja_rules"></a>**Ninja build rules** | 5856 ### <a name="ninja_rules"></a>**Ninja build rules** |
| 6292 | 5857 |
| 6293 #### **The "all" and "default" rules** | 5858 #### **The "all" and "default" rules** |
| 6294 | 5859 |
| 6295 ``` | 5860 ``` |
| 6296 All generated targets (see "gn help execution") will be added to an implicit | 5861 All generated targets (see "gn help execution") will be added to an implicit |
| 6297 build rule called "all" so "ninja all" will always compile everything. The | 5862 build rule called "all" so "ninja all" will always compile everything. The |
| 6298 default rule will be used by Ninja if no specific target is specified (just | 5863 default rule will be used by Ninja if no specific target is specified (just |
| 6299 typing "ninja"). If there is a target named "//:default" it will be the | 5864 typing "ninja"). If there is a target named "//:default" it will be the |
| 6300 default build rule, otherwise the implicit "all" rule will be used. | 5865 default build rule, otherwise the implicit "all" rule will be used. |
| 6301 | |
| 6302 ``` | 5866 ``` |
| 6303 | 5867 |
| 6304 #### **Phony rules** | 5868 #### **Phony rules** |
| 6305 | 5869 |
| 6306 ``` | 5870 ``` |
| 6307 GN generates Ninja "phony" rules for targets in the default toolchain. The | 5871 GN generates Ninja "phony" rules for targets in the default toolchain. The |
| 6308 phony rules can collide with each other and with the names of generated files | 5872 phony rules can collide with each other and with the names of generated files |
| 6309 so are generated with the following priority: | 5873 so are generated with the following priority: |
| 6310 | 5874 |
| 6311 1. Actual files generated by the build always take precedence. | 5875 1. Actual files generated by the build always take precedence. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 6329 | 5893 |
| 6330 7. Labels with an implicit name part (when the short names match the | 5894 7. Labels with an implicit name part (when the short names match the |
| 6331 directory). So you can use "ninja foo/bar" to compile "//foo/bar:bar". | 5895 directory). So you can use "ninja foo/bar" to compile "//foo/bar:bar". |
| 6332 | 5896 |
| 6333 These "phony" rules are provided only for running Ninja since this matches | 5897 These "phony" rules are provided only for running Ninja since this matches |
| 6334 people's historical expectations for building. For consistency with the rest | 5898 people's historical expectations for building. For consistency with the rest |
| 6335 of the program, GN introspection commands accept explicit labels. | 5899 of the program, GN introspection commands accept explicit labels. |
| 6336 | 5900 |
| 6337 To explicitly compile a target in a non-default toolchain, you must give | 5901 To explicitly compile a target in a non-default toolchain, you must give |
| 6338 Ninja the exact name of the output file relative to the build directory. | 5902 Ninja the exact name of the output file relative to the build directory. |
| 6339 | |
| 6340 | |
| 6341 ``` | 5903 ``` |
| 6342 ### <a name="nogncheck"></a>**nogncheck**: Skip an include line from checking. | 5904 ### <a name="nogncheck"></a>**nogncheck**: Skip an include line from checking. |
| 6343 | 5905 |
| 6344 ``` | 5906 ``` |
| 6345 GN's header checker helps validate that the includes match the build | 5907 GN's header checker helps validate that the includes match the build |
| 6346 dependency graph. Sometimes an include might be conditional or otherwise | 5908 dependency graph. Sometimes an include might be conditional or otherwise |
| 6347 problematic, but you want to specifically allow it. In this case, it can be | 5909 problematic, but you want to specifically allow it. In this case, it can be |
| 6348 whitelisted. | 5910 whitelisted. |
| 6349 | 5911 |
| 6350 Include lines containing the substring "nogncheck" will be excluded from | 5912 Include lines containing the substring "nogncheck" will be excluded from |
| 6351 header checking. The most common case is a conditional include: | 5913 header checking. The most common case is a conditional include: |
| 6352 | 5914 |
| 6353 #if defined(ENABLE_DOOM_MELON) | 5915 #if defined(ENABLE_DOOM_MELON) |
| 6354 #include "tools/doom_melon/doom_melon.h" // nogncheck | 5916 #include "tools/doom_melon/doom_melon.h" // nogncheck |
| 6355 #endif | 5917 #endif |
| 6356 | 5918 |
| 6357 If the build file has a conditional dependency on the corresponding target | 5919 If the build file has a conditional dependency on the corresponding target |
| 6358 that matches the conditional include, everything will always link correctly: | 5920 that matches the conditional include, everything will always link correctly: |
| 6359 | 5921 |
| 6360 source_set("mytarget") { | 5922 source_set("mytarget") { |
| 6361 ... | 5923 ... |
| 6362 if (enable_doom_melon) { | 5924 if (enable_doom_melon) { |
| 6363 defines = [ "ENABLE_DOOM_MELON" ] | 5925 defines = [ "ENABLE_DOOM_MELON" ] |
| 6364 deps += [ "//tools/doom_melon" ] | 5926 deps += [ "//tools/doom_melon" ] |
| 6365 } | 5927 } |
| 6366 | 5928 |
| 6367 But GN's header checker does not understand preprocessor directives, won't | 5929 But GN's header checker does not understand preprocessor directives, won't |
| 6368 know it matches the build dependencies, and will flag this include as | 5930 know it matches the build dependencies, and will flag this include as |
| 6369 incorrect when the condition is false. | 5931 incorrect when the condition is false. |
| 6370 | |
| 6371 ``` | 5932 ``` |
| 6372 | 5933 |
| 6373 #### **More information** | 5934 #### **More information** |
| 6374 | 5935 |
| 6375 ``` | 5936 ``` |
| 6376 The topic "gn help check" has general information on how checking works and | 5937 The topic "gn help check" has general information on how checking works and |
| 6377 advice on fixing problems. Targets can also opt-out of checking, see | 5938 advice on fixing problems. Targets can also opt-out of checking, see |
| 6378 "gn help check_includes". | 5939 "gn help check_includes". |
| 6379 | |
| 6380 | |
| 6381 ``` | 5940 ``` |
| 6382 ### <a name="runtime_deps"></a>**Runtime dependencies** | 5941 ### <a name="runtime_deps"></a>**Runtime dependencies** |
| 6383 | 5942 |
| 6384 ``` | 5943 ``` |
| 6385 Runtime dependencies of a target are exposed via the "runtime_deps" category | 5944 Runtime dependencies of a target are exposed via the "runtime_deps" category |
| 6386 of "gn desc" (see "gn help desc") or they can be written at build generation | 5945 of "gn desc" (see "gn help desc") or they can be written at build generation |
| 6387 time via write_runtime_deps(), or --runtime-deps-list-file (see "gn help | 5946 time via write_runtime_deps(), or --runtime-deps-list-file (see "gn help |
| 6388 --runtime-deps-list-file"). | 5947 --runtime-deps-list-file"). |
| 6389 | 5948 |
| 6390 To a first approximation, the runtime dependencies of a target are the set of | 5949 To a first approximation, the runtime dependencies of a target are the set of |
| 6391 "data" files, data directories, and the shared libraries from all transitive | 5950 "data" files, data directories, and the shared libraries from all transitive |
| 6392 dependencies. Executables, shared libraries, and loadable modules are | 5951 dependencies. Executables, shared libraries, and loadable modules are |
| 6393 considered runtime dependencies of themselves. | 5952 considered runtime dependencies of themselves. |
| 6394 | |
| 6395 ``` | 5953 ``` |
| 6396 | 5954 |
| 6397 #### **Executables** | 5955 #### **Executables** |
| 6398 | 5956 |
| 6399 ``` | 5957 ``` |
| 6400 Executable targets and those executable targets' transitive dependencies are | 5958 Executable targets and those executable targets' transitive dependencies are |
| 6401 not considered unless that executable is listed in "data_deps". Otherwise, GN | 5959 not considered unless that executable is listed in "data_deps". Otherwise, GN |
| 6402 assumes that the executable (and everything it requires) is a build-time | 5960 assumes that the executable (and everything it requires) is a build-time |
| 6403 dependency only. | 5961 dependency only. |
| 6404 | |
| 6405 ``` | 5962 ``` |
| 6406 | 5963 |
| 6407 #### **Actions and copies** | 5964 #### **Actions and copies** |
| 6408 | 5965 |
| 6409 ``` | 5966 ``` |
| 6410 Action and copy targets that are listed as "data_deps" will have all of their | 5967 Action and copy targets that are listed as "data_deps" will have all of their |
| 6411 outputs and data files considered as runtime dependencies. Action and copy | 5968 outputs and data files considered as runtime dependencies. Action and copy |
| 6412 targets that are "deps" or "public_deps" will have only their data files | 5969 targets that are "deps" or "public_deps" will have only their data files |
| 6413 considered as runtime dependencies. These targets can list an output file in | 5970 considered as runtime dependencies. These targets can list an output file in |
| 6414 both the "outputs" and "data" lists to force an output file as a runtime | 5971 both the "outputs" and "data" lists to force an output file as a runtime |
| (...skipping 15 matching lines...) Expand all Loading... |
| 6430 | 5987 |
| 6431 - List the outputs of the action in it's data section (if the results of | 5988 - List the outputs of the action in it's data section (if the results of |
| 6432 that action are always runtime files). | 5989 that action are always runtime files). |
| 6433 - Have B list the action in data_deps (if the outputs of the actions are | 5990 - Have B list the action in data_deps (if the outputs of the actions are |
| 6434 always runtime files). | 5991 always runtime files). |
| 6435 - Have B list the action in both deps and data deps (if the outputs might be | 5992 - Have B list the action in both deps and data deps (if the outputs might be |
| 6436 used in both contexts and you don't care about unnecessary entries in the | 5993 used in both contexts and you don't care about unnecessary entries in the |
| 6437 list of files required at runtime). | 5994 list of files required at runtime). |
| 6438 - Split B into run-time and build-time versions with the appropriate "deps" | 5995 - Split B into run-time and build-time versions with the appropriate "deps" |
| 6439 for each. | 5996 for each. |
| 6440 | |
| 6441 ``` | 5997 ``` |
| 6442 | 5998 |
| 6443 #### **Static libraries and source sets** | 5999 #### **Static libraries and source sets** |
| 6444 | 6000 |
| 6445 ``` | 6001 ``` |
| 6446 The results of static_library or source_set targets are not considered | 6002 The results of static_library or source_set targets are not considered |
| 6447 runtime dependencies since these are assumed to be intermediate targets only. | 6003 runtime dependencies since these are assumed to be intermediate targets only. |
| 6448 If you need to list a static library as a runtime dependency, you can | 6004 If you need to list a static library as a runtime dependency, you can |
| 6449 manually compute the .a/.lib file name for the current platform and list it | 6005 manually compute the .a/.lib file name for the current platform and list it |
| 6450 in the "data" list of a target (possibly on the static library target | 6006 in the "data" list of a target (possibly on the static library target |
| 6451 itself). | 6007 itself). |
| 6452 | |
| 6453 ``` | 6008 ``` |
| 6454 | 6009 |
| 6455 #### **Multiple outputs** | 6010 #### **Multiple outputs** |
| 6456 | 6011 |
| 6457 ``` | 6012 ``` |
| 6458 Linker tools can specify which of their outputs should be considered when | 6013 Linker tools can specify which of their outputs should be considered when |
| 6459 computing the runtime deps by setting runtime_outputs. If this is unset on | 6014 computing the runtime deps by setting runtime_outputs. If this is unset on |
| 6460 the tool, the default will be the first output only. | 6015 the tool, the default will be the first output only. |
| 6461 | |
| 6462 | |
| 6463 ``` | 6016 ``` |
| 6464 ### <a name="source_expansion"></a>**How Source Expansion Works** | 6017 ### <a name="source_expansion"></a>**How Source Expansion Works** |
| 6465 | 6018 |
| 6466 ``` | 6019 ``` |
| 6467 Source expansion is used for the action_foreach and copy target types to map | 6020 Source expansion is used for the action_foreach and copy target types to map |
| 6468 source file names to output file names or arguments. | 6021 source file names to output file names or arguments. |
| 6469 | 6022 |
| 6470 To perform source expansion in the outputs, GN maps every entry in the | 6023 To perform source expansion in the outputs, GN maps every entry in the |
| 6471 sources to every entry in the outputs list, producing the cross product of | 6024 sources to every entry in the outputs list, producing the cross product of |
| 6472 all combinations, expanding placeholders (see below). | 6025 all combinations, expanding placeholders (see below). |
| 6473 | 6026 |
| 6474 Source expansion in the args works similarly, but performing the placeholder | 6027 Source expansion in the args works similarly, but performing the placeholder |
| 6475 substitution produces a different set of arguments for each invocation of the | 6028 substitution produces a different set of arguments for each invocation of the |
| 6476 script. | 6029 script. |
| 6477 | 6030 |
| 6478 If no placeholders are found, the outputs or args list will be treated as a | 6031 If no placeholders are found, the outputs or args list will be treated as a |
| 6479 static list of literal file names that do not depend on the sources. | 6032 static list of literal file names that do not depend on the sources. |
| 6480 | 6033 |
| 6481 See "gn help copy" and "gn help action_foreach" for more on how this is | 6034 See "gn help copy" and "gn help action_foreach" for more on how this is |
| 6482 applied. | 6035 applied. |
| 6483 | |
| 6484 ``` | 6036 ``` |
| 6485 | 6037 |
| 6486 #### **Placeholders** | 6038 #### **Placeholders** |
| 6487 | 6039 |
| 6488 ``` | 6040 ``` |
| 6489 This section discusses only placeholders for actions. There are other | 6041 This section discusses only placeholders for actions. There are other |
| 6490 placeholders used in the definition of tools. See "gn help tool" for those. | 6042 placeholders used in the definition of tools. See "gn help tool" for those. |
| 6491 | 6043 |
| 6492 {{source}} | 6044 {{source}} |
| 6493 The name of the source file including directory (*). This will generally | 6045 The name of the source file including directory (*). This will generally |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6528 out directory if the source file is in a different directory than the | 6080 out directory if the source file is in a different directory than the |
| 6529 build.gn file. | 6081 build.gn file. |
| 6530 "//foo/bar/baz.txt" => "obj/foo/bar" | 6082 "//foo/bar/baz.txt" => "obj/foo/bar" |
| 6531 | 6083 |
| 6532 {{source_target_relative}} | 6084 {{source_target_relative}} |
| 6533 The path to the source file relative to the target's directory. This will | 6085 The path to the source file relative to the target's directory. This will |
| 6534 generally be used for replicating the source directory layout in the | 6086 generally be used for replicating the source directory layout in the |
| 6535 output directory. This can only be used in actions and it is an error to | 6087 output directory. This can only be used in actions and it is an error to |
| 6536 use in process_file_template where there is no "target". | 6088 use in process_file_template where there is no "target". |
| 6537 "//foo/bar/baz.txt" => "baz.txt" | 6089 "//foo/bar/baz.txt" => "baz.txt" |
| 6538 | |
| 6539 ``` | 6090 ``` |
| 6540 | 6091 |
| 6541 #### **(*) Note on directories** | 6092 #### **(*) Note on directories** |
| 6542 | 6093 |
| 6543 ``` | 6094 ``` |
| 6544 Paths containing directories (except the source_root_relative_dir) will be | 6095 Paths containing directories (except the source_root_relative_dir) will be |
| 6545 different depending on what context the expansion is evaluated in. Generally | 6096 different depending on what context the expansion is evaluated in. Generally |
| 6546 it should "just work" but it means you can't concatenate strings containing | 6097 it should "just work" but it means you can't concatenate strings containing |
| 6547 these values with reasonable results. | 6098 these values with reasonable results. |
| 6548 | 6099 |
| 6549 Details: source expansions can be used in the "outputs" variable, the "args" | 6100 Details: source expansions can be used in the "outputs" variable, the "args" |
| 6550 variable, and in calls to "process_file_template". The "args" are passed to a | 6101 variable, and in calls to "process_file_template". The "args" are passed to a |
| 6551 script which is run from the build directory, so these directories will | 6102 script which is run from the build directory, so these directories will |
| 6552 relative to the build directory for the script to find. In the other cases, | 6103 relative to the build directory for the script to find. In the other cases, |
| 6553 the directories will be source- absolute (begin with a "//") because the | 6104 the directories will be source- absolute (begin with a "//") because the |
| 6554 results of those expansions will be handled by GN internally. | 6105 results of those expansions will be handled by GN internally. |
| 6555 | |
| 6556 ``` | 6106 ``` |
| 6557 | 6107 |
| 6558 #### **Examples** | 6108 #### **Examples** |
| 6559 | 6109 |
| 6560 ``` | 6110 ``` |
| 6561 Non-varying outputs: | 6111 Non-varying outputs: |
| 6562 action("hardcoded_outputs") { | 6112 action("hardcoded_outputs") { |
| 6563 sources = [ "input1.idl", "input2.idl" ] | 6113 sources = [ "input1.idl", "input2.idl" ] |
| 6564 outputs = [ "$target_out_dir/output1.dat", | 6114 outputs = [ "$target_out_dir/output1.dat", |
| 6565 "$target_out_dir/output2.dat" ] | 6115 "$target_out_dir/output2.dat" ] |
| 6566 } | 6116 } |
| 6567 The outputs in this case will be the two literal files given. | 6117 The outputs in this case will be the two literal files given. |
| 6568 | 6118 |
| 6569 Varying outputs: | 6119 Varying outputs: |
| 6570 action_foreach("varying_outputs") { | 6120 action_foreach("varying_outputs") { |
| 6571 sources = [ "input1.idl", "input2.idl" ] | 6121 sources = [ "input1.idl", "input2.idl" ] |
| 6572 outputs = [ "{{source_gen_dir}}/{{source_name_part}}.h", | 6122 outputs = [ "{{source_gen_dir}}/{{source_name_part}}.h", |
| 6573 "{{source_gen_dir}}/{{source_name_part}}.cc" ] | 6123 "{{source_gen_dir}}/{{source_name_part}}.cc" ] |
| 6574 } | 6124 } |
| 6575 Performing source expansion will result in the following output names: | 6125 Performing source expansion will result in the following output names: |
| 6576 //out/Debug/obj/mydirectory/input1.h | 6126 //out/Debug/obj/mydirectory/input1.h |
| 6577 //out/Debug/obj/mydirectory/input1.cc | 6127 //out/Debug/obj/mydirectory/input1.cc |
| 6578 //out/Debug/obj/mydirectory/input2.h | 6128 //out/Debug/obj/mydirectory/input2.h |
| 6579 //out/Debug/obj/mydirectory/input2.cc | 6129 //out/Debug/obj/mydirectory/input2.cc |
| 6580 | |
| 6581 | |
| 6582 ``` | 6130 ``` |
| 6583 ## <a name="switches"></a>Command Line Switches | 6131 ## <a name="switches"></a>Command Line Switches |
| 6584 | 6132 |
| 6585 **Available global switches | 6133 **Available global switches |
| 6586 ** Do "gn help --the_switch_you_want_help_on" for more. Individual | 6134 ** Do "gn help --the_switch_you_want_help_on" for more. Individual |
| 6587 commands may take command-specific switches not listed here. See the | 6135 commands may take command-specific switches not listed here. See the |
| 6588 help on your specific command for more. | 6136 help on your specific command for more. |
| 6589 | 6137 |
| 6590 ``` | 6138 ``` |
| 6591 | |
| 6592 * [--args: Specifies build arguments overrides.](#--args) | 6139 * [--args: Specifies build arguments overrides.](#--args) |
| 6593 * [--color: Force colored output.](#--color) | 6140 * [--color: Force colored output.](#--color) |
| 6594 * [--dotfile: Override the name of the ".gn" file.](#--dotfile) | 6141 * [--dotfile: Override the name of the ".gn" file.](#--dotfile) |
| 6595 * [--fail-on-unused-args: Treat unused build args as fatal errors.](#--fai
l-on-unused-args) | 6142 * [--fail-on-unused-args: Treat unused build args as fatal errors.](#--fai
l-on-unused-args) |
| 6596 * [--markdown: Write help output in the Markdown format.](#--markdown) | 6143 * [--markdown: Write help output in the Markdown format.](#--markdown) |
| 6597 * [--nocolor: Force non-colored output.](#--nocolor) | 6144 * [--nocolor: Force non-colored output.](#--nocolor) |
| 6598 * [-q: Quiet mode. Don't print output on success.](#-q) | 6145 * [-q: Quiet mode. Don't print output on success.](#-q) |
| 6599 * [--root: Explicitly specify source root.](#--root) | 6146 * [--root: Explicitly specify source root.](#--root) |
| 6600 * [--runtime-deps-list-file: Save runtime dependencies for targets in file
.](#--runtime-deps-list-file) | 6147 * [--runtime-deps-list-file: Save runtime dependencies for targets in file
.](#--runtime-deps-list-file) |
| 6601 * [--script-executable: Set the executable used to execute scripts.](#--sc
ript-executable) | 6148 * [--script-executable: Set the executable used to execute scripts.](#--sc
ript-executable) |
| 6602 * [--threads: Specify number of worker threads.](#--threads) | 6149 * [--threads: Specify number of worker threads.](#--threads) |
| 6603 * [--time: Outputs a summary of how long everything took.](#--time) | 6150 * [--time: Outputs a summary of how long everything took.](#--time) |
| 6604 * [--tracelog: Writes a Chrome-compatible trace log to the given file.](#-
-tracelog) | 6151 * [--tracelog: Writes a Chrome-compatible trace log to the given file.](#-
-tracelog) |
| 6605 * [-v: Verbose logging.](#-v) | 6152 * [-v: Verbose logging.](#-v) |
| 6606 * [--version: Prints the GN version number and exits.](#--version) | 6153 * [--version: Prints the GN version number and exits.](#--version) |
| 6607 | |
| 6608 ``` | 6154 ``` |
| 6609 | 6155 |
| OLD | NEW |