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

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

Issue 2149213002: Document GN invoker and target name variables. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reference Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/gn/functions.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # GN Reference 1 # GN Reference
2 2
3 *This page is automatically generated from* `gn help --markdown all`. 3 *This page is automatically generated from* `gn help --markdown all`.
4 4
5 ## **\--args**: Specifies build arguments overrides. 5 ## **\--args**: Specifies build arguments overrides.
6 6
7 ``` 7 ```
8 See "gn help buildargs" for an overview of how build arguments work. 8 See "gn help buildargs" for an overview of how build arguments work.
9 9
10 Most operations take a build directory. The build arguments are taken 10 Most operations take a build directory. The build arguments are taken
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 The "configs" section will list all configs that apply. For targets 532 The "configs" section will list all configs that apply. For targets
533 this will include configs specified in the "configs" variable of 533 this will include configs specified in the "configs" variable of
534 the target, and also configs pushed onto this target via public 534 the target, and also configs pushed onto this target via public
535 or "all dependent" configs. 535 or "all dependent" configs.
536 536
537 Configs can have child configs. Specifying --tree will show the 537 Configs can have child configs. Specifying --tree will show the
538 hierarchy. 538 hierarchy.
539 539
540 ``` 540 ```
541 541
542 ### **Printing outputs**
543
544 ```
545 The "outputs" section will list all outputs that apply, including
546 the outputs computed from the tool definition (eg for "executable",
547 "static_library", ... targets).
548
549 ```
550
542 ### **Printing deps** 551 ### **Printing deps**
543 552
544 ``` 553 ```
545 Deps will include all public, private, and data deps (TODO this could 554 Deps will include all public, private, and data deps (TODO this could
546 be clarified and enhanced) sorted in order applying. The following 555 be clarified and enhanced) sorted in order applying. The following
547 may be used: 556 may be used:
548 557
549 --all 558 --all
550 Collects all recursive dependencies and prints a sorted flat list. 559 Collects all recursive dependencies and prints a sorted flat list.
551 Also usable with --tree (see below). 560 Also usable with --tree (see below).
(...skipping 1934 matching lines...) Expand 10 before | Expand all | Expand 10 after
2486 Sets the default values for a given target type. Whenever 2495 Sets the default values for a given target type. Whenever
2487 target_type_name is seen in the future, the values specified in 2496 target_type_name is seen in the future, the values specified in
2488 set_default's block will be copied into the current scope. 2497 set_default's block will be copied into the current scope.
2489 2498
2490 When the target type is used, the variable copying is very strict. 2499 When the target type is used, the variable copying is very strict.
2491 If a variable with that name is already in scope, the build will fail 2500 If a variable with that name is already in scope, the build will fail
2492 with an error. 2501 with an error.
2493 2502
2494 set_defaults can be used for built-in target types ("executable", 2503 set_defaults can be used for built-in target types ("executable",
2495 "shared_library", etc.) and custom ones defined via the "template" 2504 "shared_library", etc.) and custom ones defined via the "template"
2496 command. 2505 command. It can be called more than once and the most recent call in
2506 any scope will apply, but there is no way to refer to the previous
2507 defaults and modify them (each call to set_defaults must supply a
2508 complete list of all defaults it wants). If you want to share
2509 defaults, store them in a separate variable.
2497 2510
2498 ``` 2511 ```
2499 2512
2500 ### **Example**: 2513 ### **Example**
2514
2501 ``` 2515 ```
2502 set_defaults("static_library") { 2516 set_defaults("static_library") {
2503 configs = [ "//tools/mything:settings" ] 2517 configs = [ "//tools/mything:settings" ]
2504 } 2518 }
2505 2519
2506 static_library("mylib") 2520 static_library("mylib")
2507 # The configs will be auto-populated as above. You can remove it if 2521 # The configs will be auto-populated as above. You can remove it if
2508 # you don't want the default for a particular default: 2522 # you don't want the default for a particular default:
2509 configs -= "//tools/mything:settings" 2523 configs -= "//tools/mything:settings"
2510 } 2524 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
2638 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, 2652 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc,
2639 asmflags, defines, include_dirs, ldflags, lib_dirs, libs, 2653 asmflags, defines, include_dirs, ldflags, lib_dirs, libs,
2640 precompiled_header, precompiled_source 2654 precompiled_header, precompiled_source
2641 Deps: data_deps, deps, public_deps 2655 Deps: data_deps, deps, public_deps
2642 Dependent configs: all_dependent_configs, public_configs 2656 Dependent configs: all_dependent_configs, public_configs
2643 General: check_includes, configs, data, inputs, output_name, 2657 General: check_includes, configs, data, inputs, output_name,
2644 output_extension, public, sources, testonly, visibility 2658 output_extension, public, sources, testonly, visibility
2645 2659
2646 2660
2647 ``` 2661 ```
2662 ## **split_list**: Splits a list into N different sub-lists.
2663
2664 ```
2665 result = split_list(input, n)
2666
2667 Given a list and a number N, splits the list into N sub-lists of
2668 approximately equal size. The return value is a list of the sub-lists.
2669 The result will always be a list of size N. If N is greater than the
2670 number of elements in the input, it will be padded with empty lists.
2671
2672 The expected use is to divide source files into smaller uniform
2673 chunks.
2674
2675 ```
2676
2677 ### **Example**
2678
2679 ```
2680 The code:
2681 mylist = [1, 2, 3, 4, 5, 6]
2682 print(split_list(mylist, 3))
2683
2684 Will print:
2685 [[1, 2], [3, 4], [5, 6]
2686
2687
2688 ```
2648 ## **static_library**: Declare a static library target. 2689 ## **static_library**: Declare a static library target.
2649 2690
2650 ``` 2691 ```
2651 Make a ".a" / ".lib" file. 2692 Make a ".a" / ".lib" file.
2652 2693
2653 If you only need the static library for intermediate results in the 2694 If you only need the static library for intermediate results in the
2654 build, you should consider a source_set instead since it will skip 2695 build, you should consider a source_set instead since it will skip
2655 the (potentially slow) step of creating the intermediate library file. 2696 the (potentially slow) step of creating the intermediate library file.
2656 2697
2657 ``` 2698 ```
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after
3584 ``` 3625 ```
3585 3626
3586 ### **Some possible values**: 3627 ### **Some possible values**:
3587 ``` 3628 ```
3588 - "linux" 3629 - "linux"
3589 - "mac" 3630 - "mac"
3590 - "win" 3631 - "win"
3591 3632
3592 3633
3593 ``` 3634 ```
3635 ## **invoker**: [string] The invoking scope inside a template.
3636
3637 ```
3638 Inside a template invocation, this variable refers to the scope of
3639 the invoker of the template. Outside of template invocations, this
3640 variable is undefined.
3641
3642 All of the variables defined inside the template invocation are
3643 accessible as members of the "invoker" scope. This is the way that
3644 templates read values set by the callers.
3645
3646 This is often used with "defined" to see if a value is set on the
3647 invoking scope.
3648
3649 See "gn help template" for more examples.
3650
3651 ```
3652
3653 ### **Example**
3654
3655 ```
3656 template("my_template") {
3657 print(invoker.sources) # Prints [ "a.cc", "b.cc" ]
3658 print(defined(invoker.foo)) # Prints false.
3659 print(defined(invoker.bar)) # Prints true.
3660 }
3661
3662 my_template("doom_melon") {
3663 sources = [ "a.cc", "b.cc" ]
3664 bar = 123
3665 }
3666
3667
3668 ```
3594 ## **python_path**: Absolute path of Python. 3669 ## **python_path**: Absolute path of Python.
3595 3670
3596 ``` 3671 ```
3597 Normally used in toolchain definitions if running some command 3672 Normally used in toolchain definitions if running some command
3598 requires Python. You will normally not need this when invoking scripts 3673 requires Python. You will normally not need this when invoking scripts
3599 since GN automatically finds it for you. 3674 since GN automatically finds it for you.
3600 3675
3601 3676
3602 ``` 3677 ```
3603 ## **root_build_dir**: [string] Directory where build commands are run. 3678 ## **root_build_dir**: [string] Directory where build commands are run.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
3714 ### **Example** 3789 ### **Example**
3715 3790
3716 ``` 3791 ```
3717 action("myscript") { 3792 action("myscript") {
3718 # Pass the generated output dir to the script. 3793 # Pass the generated output dir to the script.
3719 args = [ "-o", rebase_path(target_gen_dir, root_build_dir) ] 3794 args = [ "-o", rebase_path(target_gen_dir, root_build_dir) ]
3720 } 3795 }
3721 3796
3722 3797
3723 ``` 3798 ```
3799 ## **target_name**: [string] The name of the current target.
3800
3801 ```
3802 Inside a target or template invocation, this variable refers to the
3803 name given to the target or template invocation. Outside of these,
3804 this variable is undefined.
3805
3806 This is most often used in template definitions to name targets
3807 defined in the template based on the name of the invocation. This
3808 is necessary both to ensure generated targets have unique names and
3809 to generate a target with the exact name of the invocation that
3810 other targets can depend on.
3811
3812 Be aware that this value will always reflect the innermost scope. So
3813 when defining a target inside a template, target_name will refer to
3814 the target rather than the template invocation. To get the name of the
3815 template invocation in this case, you should save target_name to a
3816 temporary variable outside of any target definitions.
3817
3818 See "gn help template" for more examples.
3819
3820 ```
3821
3822 ### **Example**
3823
3824 ```
3825 executable("doom_melon") {
3826 print(target_name) # Prints "doom_melon".
3827 }
3828
3829 template("my_template") {
3830 print(target_name) # Prints "space_ray" when invoked below.
3831
3832 executable(target_name + "_impl") {
3833 print(target_name) # Prints "space_ray_impl".
3834 }
3835 }
3836
3837 my_template("space_ray") {
3838 }
3839
3840
3841 ```
3724 ## **target_os**: The desired operating system for the build. 3842 ## **target_os**: The desired operating system for the build.
3725 3843
3726 ``` 3844 ```
3727 This value should be used to indicate the desired operating system 3845 This value should be used to indicate the desired operating system
3728 for the primary object(s) of the build. It will match the OS of 3846 for the primary object(s) of the build. It will match the OS of
3729 the default toolchain. 3847 the default toolchain.
3730 3848
3731 In many cases, this is the same as "host_os", but in the case of 3849 In many cases, this is the same as "host_os", but in the case of
3732 cross-compiles, it may be different. This variable differs from 3850 cross-compiles, it may be different. This variable differs from
3733 "current_os" in that it can be referenced from inside any 3851 "current_os" in that it can be referenced from inside any
(...skipping 2450 matching lines...) Expand 10 before | Expand all | Expand 10 after
6184 ** \--root**: Explicitly specify source root. 6302 ** \--root**: Explicitly specify source root.
6185 ** \--runtime-deps-list-file**: Save runtime dependencies for targets in file. 6303 ** \--runtime-deps-list-file**: Save runtime dependencies for targets in file.
6186 ** \--script-executable**: Set the executable used to execute scripts. 6304 ** \--script-executable**: Set the executable used to execute scripts.
6187 ** \--threads**: Specify number of worker threads. 6305 ** \--threads**: Specify number of worker threads.
6188 ** \--time**: Outputs a summary of how long everything took. 6306 ** \--time**: Outputs a summary of how long everything took.
6189 ** \--tracelog**: Writes a Chrome-compatible trace log to the given file. 6307 ** \--tracelog**: Writes a Chrome-compatible trace log to the given file.
6190 ** -v**: Verbose logging. 6308 ** -v**: Verbose logging.
6191 ** \--version**: Prints the GN version number and exits. 6309 ** \--version**: Prints the GN version number and exits.
6192 6310
6193 ``` 6311 ```
OLDNEW
« no previous file with comments | « no previous file | tools/gn/functions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698