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.
5 # Instantiate grit. This will produce a script target to run grit, and a
6 # static library that compiles the .cc files.
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
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
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.
30 # Extra defines to pass to grit (on top of the global grit_defines list).
32 # grit_flags (optional)
33 # List of strings containing extra command-line flags to pass to Grit.
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.
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.
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.
52 # depfile_dir (optional)
53 # If set, used to store the depfile and corresponding stamp file.
54 # Defaults to output_dir
56 # use_qualified_include (optional)
57 # If set, output_dir is not added to include_dirs.
60 # List of additional configs to be applied to the generated target.
63 # List of additional files, required for grit to process source file.
64 # visibility (optional)
69 # grit("my_resources") {
70 # # Source and outputs are required.
71 # source = "myfile.grd"
77 # grit_flags = [ "-E", "foo=bar" ] # Optional extra flags.
78 # # You can also put deps here if the grit source depends on generated
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")
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) {
97 if (is_chrome_branded) {
102 "CHROMIUM_BUILD=google_chrome",
109 "CHROMIUM_BUILD=chromium",
122 if (is_desktop_linux) {
164 if (enable_image_loader_extension) {
167 "image_loader_extension",
176 "ANDROID_JAVA_TAGGED_ONLY=true",
180 if (is_mac || is_ios) {
192 # iOS uses a whitelist to filter resources.
194 rebase_path("//build/ios/grit_whitelist.txt", root_build_dir),
198 if (enable_extensions) {
204 if (enable_media_router) {
207 "enable_media_router",
210 if (enable_plugins) {
216 if (enable_basic_printing || enable_print_preview) {
221 if (enable_print_preview) {
224 "enable_print_preview",
234 if (enable_app_list) {
240 if (enable_settings_app) {
243 "enable_settings_app",
246 if (enable_google_now) {
253 # Note: use_concatenated_impulse_responses is omitted. It is never used and
254 # should probably be removed from GYP build.
261 if (enable_hangout_services_extension) {
264 "enable_hangout_services_extension",
267 if (enable_task_manager) {
270 "enable_task_manager",
273 if (enable_notifications) {
276 "enable_notifications",
279 if (enable_wifi_bootstrapping) {
282 "enable_wifi_bootstrapping",
285 if (enable_service_discovery) {
288 "enable_service_discovery",
291 if (mac_views_browser) {
298 grit_resource_id_file = "//tools/gritsettings/resource_ids"
299 grit_info_script = "//tools/grit/grit_info.py"
302 assert(defined(invoker.source),
303 "\"source\" must be defined for the grit template $target_name")
305 grit_inputs = [ invoker.source ]
307 if (defined(invoker.resource_ids)) {
308 resource_ids = invoker.resource_ids
310 resource_ids = grit_resource_id_file
312 if (resource_ids != "") {
313 # The script depends on the ID file. Only add this dependency if the ID
315 grit_inputs += [ resource_ids ]
318 if (defined(invoker.output_dir)) {
319 output_dir = invoker.output_dir
321 output_dir = target_gen_dir
324 if (defined(invoker.output_name)) {
325 grit_output_name = invoker.output_name
327 grit_output_name = target_name
330 if (defined(invoker.depfile_dir)) {
331 depfile_dir = invoker.depfile_dir
333 depfile_dir = output_dir
336 # These are all passed as arguments to the script so have to be relative to
337 # the build directory.
338 if (resource_ids != "") {
339 resource_ids = rebase_path(resource_ids, root_build_dir)
341 rebased_output_dir = rebase_path(output_dir, root_build_dir)
342 source_path = rebase_path(invoker.source, root_build_dir)
344 if (defined(invoker.grit_flags)) {
345 grit_flags = invoker.grit_flags
347 grit_flags = [] # These are optional so default to empty list.
350 assert_files_flags = []
352 # We want to make sure the declared outputs actually match what Grit is
353 # writing. We write the list to a file (some of the output lists are long
354 # enough to not fit on a Windows command line) and ask Grit to verify those
355 # are the actual outputs at runtime.
357 "$target_out_dir/${grit_output_name}_expected_outputs.txt"
358 write_file(asserted_list_file,
359 rebase_path(invoker.outputs, root_build_dir, output_dir))
360 assert_files_flags += [ "--assert-file-list=" +
361 rebase_path(asserted_list_file, root_build_dir) ]
363 get_path_info(rebase_path(invoker.outputs, ".", output_dir), "abspath")
365 # The config and the action below get this visibility son only the generated
366 # source set can depend on them. The variable "target_name" will get
367 # overwritten inside the inner classes so we need to compute it here.
368 target_visibility = [ ":$target_name" ]
370 # The current grit setup makes an file in $output_dir/grit/foo.h that
371 # the source code expects to include via "grit/foo.h". It would be nice to
372 # change this to including absolute paths relative to the root gen directory
373 # (like "mycomponent/foo.h"). This config sets up the include path.
374 grit_config = target_name + "_grit_config"
375 config(grit_config) {
376 if (!defined(invoker.use_qualified_include) ||
377 !invoker.use_qualified_include) {
378 include_dirs = [ output_dir ]
380 visibility = target_visibility
383 grit_custom_target = target_name + "_grit"
384 action(grit_custom_target) {
385 script = "//tools/grit/grit.py"
388 depfile = "$depfile_dir/${grit_output_name}_stamp.d"
389 outputs = [ "${depfile}.stamp" ] + grit_outputs
396 if (resource_ids != "") {
408 rebase_path(depfile, root_build_dir),
409 "--write-only-new=1",
413 # Add extra defines with -D flags.
414 if (defined(invoker.defines)) {
415 foreach(i, invoker.defines) {
423 args += grit_flags + assert_files_flags
425 if (defined(invoker.visibility)) {
426 # This needs to include both what the invoker specified (since they
427 # probably include generated headers from this target), as well as the
428 # generated source set (since there's no guarantee that the visibility
429 # specified by the invoker includes our target).
431 # Only define visibility at all if the invoker specified it. Otherwise,
432 # we want to keep the public "no visibility specified" default.
433 visibility = target_visibility + invoker.visibility
437 "//tools/grit:grit_sources",
439 if (defined(invoker.deps)) {
442 if (defined(invoker.inputs)) {
443 inputs += invoker.inputs
447 # This is the thing that people actually link with, it must be named the
448 # same as the argument the template was invoked with.
449 source_set(target_name) {
450 # Since we generate a file, we need to be run before the targets that
452 sources = grit_outputs
454 # Deps set on the template invocation will go on the action that runs
455 # grit above rather than this library. This target needs to depend on the
456 # action publicly so other scripts can take the outputs from the grit
459 ":$grit_custom_target",
461 public_configs = [ ":$grit_config" ]
463 if (defined(invoker.public_configs)) {
464 public_configs += invoker.public_configs
467 if (defined(invoker.configs)) {
468 configs += invoker.configs
471 if (defined(invoker.visibility)) {
472 visibility = invoker.visibility
474 output_name = grit_output_name