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

Side by Side Diff: tools/gn/target.cc

Issue 2504133003: Add more gn documentation (Closed)
Patch Set: Created 4 years, 1 month 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 | « tools/gn/target.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "tools/gn/target.h" 5 #include "tools/gn/target.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 failure_path_str->insert(0, prepend_path); 190 failure_path_str->insert(0, prepend_path);
191 return false; 191 return false;
192 } 192 }
193 } 193 }
194 194
195 return true; 195 return true;
196 } 196 }
197 197
198 } // namespace 198 } // namespace
199 199
200 const char kExecution_Help[] =
201 R"(Build graph and execution overview
202
203 Overall build flow
204
205 1. Look for ".gn" file (see "gn help dotfile") in the current directory and
206 walk up the directory tree until one is found. Set this directory to be
207 the "source root" and interpret this file to find the name of the build
208 config file.
209
210 2. Execute the build config file identified by .gn to set up the global
211 variables and default toolchain name. Any arguments, variables, defaults,
212 etc. set up in this file will be visible to all files in the build.
213
214 3. Load the //BUILD.gn (in the source root directory).
215
216 4. Recursively evaluate rules and load BUILD.gn in other directories as
217 necessary to resolve dependencies. If a BUILD file isn't found in the
218 specified location, GN will look in the corresponding location inside
219 the secondary_source defined in the dotfile (see "gn help dotfile").
220
221 5. When a target's dependencies are resolved, write out the `.ninja`
222 file to disk.
223
224 6. When all targets are resolved, write out the root build.ninja file.
225
226 Executing target definitions and templates
227
228 Build files are loaded in parallel. This means it is impossible to
229 interrogate a target from GN code for any information not derivable from its
230 label (see "gn help label"). The exception is the get_target_outputs()
231 function which requires the target being interrogated to have been defined
232 previously in the same file.
233
234 Targets are declared by their type and given a name:
235
236 static_library("my_static_library") {
237 ... target parameter definitions ...
238 }
239
240 There is also a generic "target" function for programatically defined types
241 (see "gn help target"). You can define new types using templates (see "gn
242 help template"). A template defines some custom code that expands to one or
243 more other targets.
244
245 Before executing the code inside the target's { }, the target defaults are
246 applied (see "gn help set_defaults"). It will inject implicit variable
247 definitions that can be overridden by the target code as necessary. Typically
248 this mechanism is used to inject a default set of configs that define the
249 global compiler and linker flags.
250
251 Which targets are built
252
253 All targets encountered in the default toolchain (see "gn help toolchain")
254 will have build rules generated for them, even if no other targets reference
255 them. Their dependencies must resolve and they will be added to the implicit
256 "all" rule (see "gn help ninja_rules").
257
258 Targets in non-default toolchains will only be generated when they are
259 required (directly or transitively) to build a target in the default
260 toolchain.
261
262 See also "gn help ninja_rules".
263
264 Dependencies
265
266 The only difference between "public_deps" and "deps" except for pushing
267 configs around the build tree and allowing includes for the purposes of "gn
268 check".
269
270 A target's "data_deps" are guaranteed to be built whenever the target is
271 built, but the ordering is not defined. The meaning of this is dependencies
272 required at runtime. Currently data deps will be complete before the target
273 is linked, but this is not semantically guaranteed and this is undesirable
274 from a build performance perspective. Since we hope to change this in the
275 future, do not rely on this behavior.
276 )";
277
200 Target::Target(const Settings* settings, const Label& label) 278 Target::Target(const Settings* settings, const Label& label)
201 : Item(settings, label), 279 : Item(settings, label),
202 output_type_(UNKNOWN), 280 output_type_(UNKNOWN),
203 output_prefix_override_(false), 281 output_prefix_override_(false),
204 output_extension_set_(false), 282 output_extension_set_(false),
205 all_headers_public_(true), 283 all_headers_public_(true),
206 check_includes_(true), 284 check_includes_(true),
207 complete_static_lib_(false), 285 complete_static_lib_(false),
208 testonly_(false), 286 testonly_(false),
209 toolchain_(nullptr) { 287 toolchain_(nullptr) {
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 check_data_deps = g_scheduler->IsFileGeneratedByWriteRuntimeDeps(out_file); 846 check_data_deps = g_scheduler->IsFileGeneratedByWriteRuntimeDeps(out_file);
769 // Check object files (much slower and very rare) only if the "normal" 847 // Check object files (much slower and very rare) only if the "normal"
770 // output check failed. 848 // output check failed.
771 consider_object_files = !check_data_deps; 849 consider_object_files = !check_data_deps;
772 if (!EnsureFileIsGeneratedByDependency(this, out_file, true, 850 if (!EnsureFileIsGeneratedByDependency(this, out_file, true,
773 consider_object_files, 851 consider_object_files,
774 check_data_deps, &seen_targets)) 852 check_data_deps, &seen_targets))
775 g_scheduler->AddUnknownGeneratedInput(this, source); 853 g_scheduler->AddUnknownGeneratedInput(this, source);
776 } 854 }
777 } 855 }
OLDNEW
« no previous file with comments | « tools/gn/target.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698