3 GN has several different ways to check dependencies. Many of them are checked by
4 the `gn check` command. Running checks involve opening and scanning all source
5 files so this isn't run every time a build is updated. To run check on an
10 To run the check as part of the "gen" command to update the build (this is what
13 gn gen out/mybuild --check
21 Targets can control which other targets may depend on them by specifying
22 `visibility`. Visibility is always checked when running any GN command (not just
25 By default, targets are "public" meaning any target can depend on them. If you
26 supply a list, visibility will be listed to those targets (possibly including
31 ":*", # All targets in this file.
32 "//content/*", # All targets in content and any subdirectory thereof.
33 "//tools:doom_melon", # This specific target.
37 See `gn help visibility` for more details and examples.
39 ### Public header files
41 Targets can control which headers may be included by dependent targets so as to
42 define a public API. If your target specifies only `sources`, then all headers
43 listed there are public and can be included by all dependents.
45 If your target defines a `public` variable, only the files listed in that list
46 will be public. Files in `sources` but not `public` (they can be in both or only
47 one) may not be included by dependent targets.
64 ### Public dependencies
66 In order to include files from your target, that target must be listed in your
67 target's dependencies. By default, transitively depending on a target doesn't
68 give your files this privilege.
70 If a target exposes a dependency as part of its public API, then it can list
71 that dependency as a `public_deps`:
85 Targets that depend on `foo` can include files from `base` but not from
86 `doom_melon`. To include public headers from `doom\_melon, a target would need
87 to depend directly on it.
89 Public dependencies work transitively, so listing a target as a public
90 dependency also exposes that target's public dependencies. Along with the
91 ability to include headers, public dependencies forward the `public_configs`
92 which allow settings like defines and include directories to apply to
95 ## Putting it all together
97 In order to include a header from target Y in a file that is part of target X:
99 * X must be in Y's `visibility` list (or B must have no `visibility` defined).
100 * The header must be in Y's `public` headers (or Y must have no `public`
102 * X must depend directly on Y, or there must be a path from X to Y following
103 only public dependencies.
105 ### What gets checked
107 Chrome currently doesn't come close to passing a `gn check` pass. You can check
108 specific targets or subtrees for issues:
110 gn check out/mybuild //base
112 gn check out/mybuild "//mojo/*"