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

Side by Side Diff: tools/grit/grit_rule.gni

Issue 1311133008: Revert of Move GN grit scripts out of secondary tree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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 | « tools/grit/BUILD.gn ('k') | tools/grit/repack.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 # Instantiate grit. This will produce a script target to run grit, and a
6 # static library that compiles the .cc files.
7 #
8 # Parameters
9 #
10 # source (required)
11 # Path to .grd file.
12 #
13 # outputs (required)
14 # List of outputs from grit, relative to the target_gen_dir. Grit will
15 # verify at build time that this list is correct and will fail if there
16 # is a mismatch between the outputs specified by the .grd file and the
17 # outputs list here.
18 #
19 # To get this list, you can look in the .grd file for
20 # <output filename="..." and put those filename here. The base directory
21 # of the list in Grit and the output list specified in the GN grit target
22 # are the same (the target_gen_dir) so you can generally copy the names
23 # exactly.
24 #
25 # To get the list of outputs programatically, run:
26 # python tools/grit/grit_info.py --outputs . path/to/your.grd
27 # And strip the leading "./" from the output files.
28 #
29 # defines (optional)
30 # Extra defines to pass to grit (on top of the global grit_defines list).
31 #
32 # grit_flags (optional)
33 # List of strings containing extra command-line flags to pass to Grit.
34 #
35 # resource_ids (optional)
36 # Path to a grit "firstidsfile". Default is
37 # //tools/gritsettings/resource_ids. Set to "" to use the value specified
38 # in the <grit> nodes of the processed files.
39 #
40 # output_dir (optional)
41 # Directory for generated files. If you specify this, you will often
42 # want to specify output_name if the target name is not particularly
43 # unique, since this can cause files from multiple grit targets to
44 # overwrite each other.
45 #
46 # output_name (optiona)
47 # Provide an alternate base name for the generated files, like the .d
48 # files. Normally these are based on the target name and go in the
49 # output_dir, but if multiple targets with the same name end up in
50 # the same output_dir, they can collide.
51 #
52 # depfile_dir (optional)
53 # If set, used to store the depfile and corresponding stamp file.
54 # Defaults to output_dir
55 #
56 # use_qualified_include (optional)
57 # If set, output_dir is not added to include_dirs.
58 #
59 # configs (optional)
60 # List of additional configs to be applied to the generated target.
61 # deps (optional)
62 # inputs (optional)
63 # List of additional files, required for grit to process source file.
64 # visibility (optional)
65 # Normal meaning.
66 #
67 # Example
68 #
69 # grit("my_resources") {
70 # # Source and outputs are required.
71 # source = "myfile.grd"
72 # outputs = [
73 # "foo_strings.h",
74 # "foo_strings.pak",
75 # ]
76 #
77 # grit_flags = [ "-E", "foo=bar" ] # Optional extra flags.
78 # # You can also put deps here if the grit source depends on generated
79 # # files.
80 # }
81 import("//build/config/chrome_build.gni")
82 import("//build/config/crypto.gni")
83 import("//build/config/features.gni")
84 import("//build/config/ui.gni")
85
86 grit_defines = []
87
88 # Mac and iOS want Title Case strings.
89 use_titlecase_in_grd_files = is_mac || is_ios
90 if (use_titlecase_in_grd_files) {
91 grit_defines += [
92 "-D",
93 "use_titlecase",
94 ]
95 }
96
97 if (is_chrome_branded) {
98 grit_defines += [
99 "-D",
100 "_google_chrome",
101 "-E",
102 "CHROMIUM_BUILD=google_chrome",
103 ]
104 } else {
105 grit_defines += [
106 "-D",
107 "_chromium",
108 "-E",
109 "CHROMIUM_BUILD=chromium",
110 ]
111 }
112
113 if (is_chromeos) {
114 grit_defines += [
115 "-D",
116 "chromeos",
117 "-D",
118 "scale_factors=2x",
119 ]
120 }
121
122 if (is_desktop_linux) {
123 grit_defines += [
124 "-D",
125 "desktop_linux",
126 ]
127 }
128
129 if (toolkit_views) {
130 grit_defines += [
131 "-D",
132 "toolkit_views",
133 ]
134 }
135
136 if (use_aura) {
137 grit_defines += [
138 "-D",
139 "use_aura",
140 ]
141 }
142
143 if (use_ash) {
144 grit_defines += [
145 "-D",
146 "use_ash",
147 ]
148 }
149
150 if (use_nss_certs) {
151 grit_defines += [
152 "-D",
153 "use_nss_certs",
154 ]
155 }
156
157 if (use_ozone) {
158 grit_defines += [
159 "-D",
160 "use_ozone",
161 ]
162 }
163
164 if (enable_image_loader_extension) {
165 grit_defines += [
166 "-D",
167 "image_loader_extension",
168 ]
169 }
170
171 if (is_android) {
172 grit_defines += [
173 "-t",
174 "android",
175 "-E",
176 "ANDROID_JAVA_TAGGED_ONLY=true",
177 ]
178 }
179
180 if (is_mac || is_ios) {
181 grit_defines += [
182 "-D",
183 "scale_factors=2x",
184 ]
185 }
186
187 if (is_ios) {
188 grit_defines += [
189 "-t",
190 "ios",
191
192 # iOS uses a whitelist to filter resources.
193 "-w",
194 rebase_path("//build/ios/grit_whitelist.txt", root_build_dir),
195 ]
196 }
197
198 if (enable_extensions) {
199 grit_defines += [
200 "-D",
201 "enable_extensions",
202 ]
203 }
204 if (enable_media_router) {
205 grit_defines += [
206 "-D",
207 "enable_media_router",
208 ]
209 }
210 if (enable_plugins) {
211 grit_defines += [
212 "-D",
213 "enable_plugins",
214 ]
215 }
216 if (enable_basic_printing || enable_print_preview) {
217 grit_defines += [
218 "-D",
219 "enable_printing",
220 ]
221 if (enable_print_preview) {
222 grit_defines += [
223 "-D",
224 "enable_print_preview",
225 ]
226 }
227 }
228 if (enable_themes) {
229 grit_defines += [
230 "-D",
231 "enable_themes",
232 ]
233 }
234 if (enable_app_list) {
235 grit_defines += [
236 "-D",
237 "enable_app_list",
238 ]
239 }
240 if (enable_settings_app) {
241 grit_defines += [
242 "-D",
243 "enable_settings_app",
244 ]
245 }
246 if (enable_google_now) {
247 grit_defines += [
248 "-D",
249 "enable_google_now",
250 ]
251 }
252
253 # Note: use_concatenated_impulse_responses is omitted. It is never used and
254 # should probably be removed from GYP build.
255 if (enable_webrtc) {
256 grit_defines += [
257 "-D",
258 "enable_webrtc",
259 ]
260 }
261 if (enable_hangout_services_extension) {
262 grit_defines += [
263 "-D",
264 "enable_hangout_services_extension",
265 ]
266 }
267 if (enable_task_manager) {
268 grit_defines += [
269 "-D",
270 "enable_task_manager",
271 ]
272 }
273 if (enable_notifications) {
274 grit_defines += [
275 "-D",
276 "enable_notifications",
277 ]
278 }
279 if (enable_wifi_bootstrapping) {
280 grit_defines += [
281 "-D",
282 "enable_wifi_bootstrapping",
283 ]
284 }
285 if (enable_service_discovery) {
286 grit_defines += [
287 "-D",
288 "enable_service_discovery",
289 ]
290 }
291 if (mac_views_browser) {
292 grit_defines += [
293 "-D",
294 "mac_views_browser",
295 ]
296 }
297 if (enable_topchrome_md) {
298 grit_defines += [
299 "-D",
300 "enable_topchrome_md",
301 ]
302 }
303
304 grit_resource_id_file = "//tools/gritsettings/resource_ids"
305 grit_info_script = "//tools/grit/grit_info.py"
306
307 template("grit") {
308 assert(defined(invoker.source),
309 "\"source\" must be defined for the grit template $target_name")
310
311 grit_inputs = [ invoker.source ]
312
313 if (defined(invoker.resource_ids)) {
314 resource_ids = invoker.resource_ids
315 } else {
316 resource_ids = grit_resource_id_file
317 }
318 if (resource_ids != "") {
319 # The script depends on the ID file. Only add this dependency if the ID
320 # file is specified.
321 grit_inputs += [ resource_ids ]
322 }
323
324 if (defined(invoker.output_dir)) {
325 output_dir = invoker.output_dir
326 } else {
327 output_dir = target_gen_dir
328 }
329
330 if (defined(invoker.output_name)) {
331 grit_output_name = invoker.output_name
332 } else {
333 grit_output_name = target_name
334 }
335
336 if (defined(invoker.depfile_dir)) {
337 depfile_dir = invoker.depfile_dir
338 } else {
339 depfile_dir = output_dir
340 }
341
342 # These are all passed as arguments to the script so have to be relative to
343 # the build directory.
344 if (resource_ids != "") {
345 resource_ids = rebase_path(resource_ids, root_build_dir)
346 }
347 rebased_output_dir = rebase_path(output_dir, root_build_dir)
348 source_path = rebase_path(invoker.source, root_build_dir)
349
350 if (defined(invoker.grit_flags)) {
351 grit_flags = invoker.grit_flags
352 } else {
353 grit_flags = [] # These are optional so default to empty list.
354 }
355
356 assert_files_flags = []
357
358 # We want to make sure the declared outputs actually match what Grit is
359 # writing. We write the list to a file (some of the output lists are long
360 # enough to not fit on a Windows command line) and ask Grit to verify those
361 # are the actual outputs at runtime.
362 asserted_list_file =
363 "$target_out_dir/${grit_output_name}_expected_outputs.txt"
364 write_file(asserted_list_file,
365 rebase_path(invoker.outputs, root_build_dir, output_dir))
366 assert_files_flags += [ "--assert-file-list=" +
367 rebase_path(asserted_list_file, root_build_dir) ]
368 grit_outputs =
369 get_path_info(rebase_path(invoker.outputs, ".", output_dir), "abspath")
370
371 # The config and the action below get this visibility son only the generated
372 # source set can depend on them. The variable "target_name" will get
373 # overwritten inside the inner classes so we need to compute it here.
374 target_visibility = [ ":$target_name" ]
375
376 # The current grit setup makes an file in $output_dir/grit/foo.h that
377 # the source code expects to include via "grit/foo.h". It would be nice to
378 # change this to including absolute paths relative to the root gen directory
379 # (like "mycomponent/foo.h"). This config sets up the include path.
380 grit_config = target_name + "_grit_config"
381 config(grit_config) {
382 if (!defined(invoker.use_qualified_include) ||
383 !invoker.use_qualified_include) {
384 include_dirs = [ output_dir ]
385 }
386 visibility = target_visibility
387 }
388
389 grit_custom_target = target_name + "_grit"
390 action(grit_custom_target) {
391 script = "//tools/grit/grit.py"
392 inputs = grit_inputs
393
394 depfile = "$depfile_dir/${grit_output_name}_stamp.d"
395 outputs = [ "${depfile}.stamp" ] + grit_outputs
396
397 args = [
398 "-i",
399 source_path,
400 "build",
401 ]
402 if (resource_ids != "") {
403 args += [
404 "-f",
405 resource_ids,
406 ]
407 }
408 args += [
409 "-o",
410 rebased_output_dir,
411 "--depdir",
412 ".",
413 "--depfile",
414 rebase_path(depfile, root_build_dir),
415 "--write-only-new=1",
416 "--depend-on-stamp",
417 ] + grit_defines
418
419 # Add extra defines with -D flags.
420 if (defined(invoker.defines)) {
421 foreach(i, invoker.defines) {
422 args += [
423 "-D",
424 i,
425 ]
426 }
427 }
428
429 args += grit_flags + assert_files_flags
430
431 if (defined(invoker.visibility)) {
432 # This needs to include both what the invoker specified (since they
433 # probably include generated headers from this target), as well as the
434 # generated source set (since there's no guarantee that the visibility
435 # specified by the invoker includes our target).
436 #
437 # Only define visibility at all if the invoker specified it. Otherwise,
438 # we want to keep the public "no visibility specified" default.
439 visibility = target_visibility + invoker.visibility
440 }
441
442 deps = [
443 "//tools/grit:grit_sources",
444 ]
445 if (defined(invoker.deps)) {
446 deps += invoker.deps
447 }
448 if (defined(invoker.inputs)) {
449 inputs += invoker.inputs
450 }
451 }
452
453 # This is the thing that people actually link with, it must be named the
454 # same as the argument the template was invoked with.
455 source_set(target_name) {
456 # Since we generate a file, we need to be run before the targets that
457 # depend on us.
458 sources = grit_outputs
459
460 # Deps set on the template invocation will go on the action that runs
461 # grit above rather than this library. This target needs to depend on the
462 # action publicly so other scripts can take the outputs from the grit
463 # script as inputs.
464 public_deps = [
465 ":$grit_custom_target",
466 ]
467 public_configs = [ ":$grit_config" ]
468
469 if (defined(invoker.public_configs)) {
470 public_configs += invoker.public_configs
471 }
472
473 if (defined(invoker.configs)) {
474 configs += invoker.configs
475 }
476
477 if (defined(invoker.visibility)) {
478 visibility = invoker.visibility
479 }
480 output_name = grit_output_name
481 }
482 }
OLDNEW
« no previous file with comments | « tools/grit/BUILD.gn ('k') | tools/grit/repack.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698