| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 # Instantiate grit. This will produce a script target to run grit, and a | 5 # Instantiate grit. This will produce a script target to run grit, and a |
| 6 # static library that compiles the .cc files. | 6 # static library that compiles the .cc files. |
| 7 # | 7 # |
| 8 # Parameters | 8 # Parameters |
| 9 # | 9 # |
| 10 # source (required) | 10 # source (required) |
| 11 # Path to .grd file. | 11 # Path to .grd file. |
| 12 # | 12 # |
| 13 # source_is_generated (optional, defaults to false) |
| 14 # Declares that the input is generated so that grit_info is not run |
| 15 # on the file when compute_grit_inputs_for_analyze is set (because the |
| 16 # file will not exist at analyze time). For "analyze" to be correct in |
| 17 # this case, the inputs to the grit file must either be listed in the |
| 18 # inputs variable or are listed as inputs to dependencies of this target. |
| 19 # |
| 20 # inputs (optional) |
| 21 # List of additional files, required for grit to process source file. |
| 22 # |
| 13 # outputs (required) | 23 # outputs (required) |
| 14 # List of outputs from grit, relative to the target_gen_dir. Grit will | 24 # 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 | 25 # 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 | 26 # is a mismatch between the outputs specified by the .grd file and the |
| 17 # outputs list here. | 27 # outputs list here. |
| 18 # | 28 # |
| 19 # To get this list, you can look in the .grd file for | 29 # To get this list, you can look in the .grd file for |
| 20 # <output filename="..." and put those filename here. The base directory | 30 # <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 | 31 # 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 | 32 # are the same (the target_gen_dir) so you can generally copy the names |
| (...skipping 29 matching lines...) Expand all Loading... |
| 52 # depfile_dir (optional) | 62 # depfile_dir (optional) |
| 53 # If set, used to store the depfile and corresponding stamp file. | 63 # If set, used to store the depfile and corresponding stamp file. |
| 54 # Defaults to output_dir | 64 # Defaults to output_dir |
| 55 # | 65 # |
| 56 # use_qualified_include (optional) | 66 # use_qualified_include (optional) |
| 57 # If set, output_dir is not added to include_dirs. | 67 # If set, output_dir is not added to include_dirs. |
| 58 # | 68 # |
| 59 # configs (optional) | 69 # configs (optional) |
| 60 # List of additional configs to be applied to the generated target. | 70 # List of additional configs to be applied to the generated target. |
| 61 # deps (optional) | 71 # deps (optional) |
| 62 # inputs (optional) | |
| 63 # List of additional files, required for grit to process source file. | |
| 64 # visibility (optional) | 72 # visibility (optional) |
| 65 # Normal meaning. | 73 # Normal meaning. |
| 66 # | 74 # |
| 67 # Example | 75 # Example |
| 68 # | 76 # |
| 69 # grit("my_resources") { | 77 # grit("my_resources") { |
| 70 # # Source and outputs are required. | 78 # # Source and outputs are required. |
| 71 # source = "myfile.grd" | 79 # source = "myfile.grd" |
| 72 # outputs = [ | 80 # outputs = [ |
| 73 # "foo_strings.h", | 81 # "foo_strings.h", |
| 74 # "foo_strings.pak", | 82 # "foo_strings.pak", |
| 75 # ] | 83 # ] |
| 76 # | 84 # |
| 77 # grit_flags = [ "-E", "foo=bar" ] # Optional extra flags. | 85 # grit_flags = [ "-E", "foo=bar" ] # Optional extra flags. |
| 78 # # You can also put deps here if the grit source depends on generated | 86 # # You can also put deps here if the grit source depends on generated |
| 79 # # files. | 87 # # files. |
| 80 # } | 88 # } |
| 81 import("//build/config/android/config.gni") | 89 import("//build/config/android/config.gni") |
| 82 import("//build/config/chrome_build.gni") | 90 import("//build/config/chrome_build.gni") |
| 83 import("//build/config/crypto.gni") | 91 import("//build/config/crypto.gni") |
| 84 import("//build/config/features.gni") | 92 import("//build/config/features.gni") |
| 85 import("//build/config/ui.gni") | 93 import("//build/config/ui.gni") |
| 86 import("//third_party/closure_compiler/closure_args.gni") | 94 import("//third_party/closure_compiler/closure_args.gni") |
| 87 | 95 |
| 88 assert(!enable_resource_whitelist_generation || is_android, | 96 assert(!enable_resource_whitelist_generation || is_android, |
| 89 "resource whitelist generation only works on android") | 97 "resource whitelist generation only works on android") |
| 90 | 98 |
| 99 declare_args() { |
| 100 # When set, this will fork out to grit at GN-time to get all inputs |
| 101 # referenced by the .grd file. |
| 102 # |
| 103 # Normal builds don't need this since proper incremental builds are handled |
| 104 # by grit writing out the inputs in .d files at build-time. But for analyze |
| 105 # to work on the bots, it needs to know about all input files at GN-time so |
| 106 # it knows which tests to trigger when something changes. This option will |
| 107 # slow down the GN run. |
| 108 compute_grit_inputs_for_analyze = false |
| 109 } |
| 110 |
| 91 grit_defines = [] | 111 grit_defines = [] |
| 92 | 112 |
| 93 # Mac and iOS want Title Case strings. | 113 # Mac and iOS want Title Case strings. |
| 94 use_titlecase_in_grd_files = is_mac || is_ios | 114 use_titlecase_in_grd_files = is_mac || is_ios |
| 95 if (use_titlecase_in_grd_files) { | 115 if (use_titlecase_in_grd_files) { |
| 96 grit_defines += [ | 116 grit_defines += [ |
| 97 "-D", | 117 "-D", |
| 98 "use_titlecase", | 118 "use_titlecase", |
| 99 ] | 119 ] |
| 100 } | 120 } |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 _strip_resource_files = is_android | 325 _strip_resource_files = is_android |
| 306 _js_minifier = "//third_party/closure_compiler/js_minify.py" | 326 _js_minifier = "//third_party/closure_compiler/js_minify.py" |
| 307 | 327 |
| 308 grit_resource_id_file = "//tools/gritsettings/resource_ids" | 328 grit_resource_id_file = "//tools/gritsettings/resource_ids" |
| 309 grit_info_script = "//tools/grit/grit_info.py" | 329 grit_info_script = "//tools/grit/grit_info.py" |
| 310 | 330 |
| 311 template("grit") { | 331 template("grit") { |
| 312 assert(defined(invoker.source), | 332 assert(defined(invoker.source), |
| 313 "\"source\" must be defined for the grit template $target_name") | 333 "\"source\" must be defined for the grit template $target_name") |
| 314 | 334 |
| 315 grit_inputs = [ invoker.source ] | |
| 316 | |
| 317 if (defined(invoker.resource_ids)) { | 335 if (defined(invoker.resource_ids)) { |
| 318 resource_ids = invoker.resource_ids | 336 resource_ids = invoker.resource_ids |
| 319 } else { | 337 } else { |
| 320 resource_ids = grit_resource_id_file | 338 resource_ids = grit_resource_id_file |
| 321 } | 339 } |
| 322 if (resource_ids != "") { | |
| 323 # The script depends on the ID file. Only add this dependency if the ID | |
| 324 # file is specified. | |
| 325 grit_inputs += [ resource_ids ] | |
| 326 } | |
| 327 | 340 |
| 328 if (defined(invoker.output_dir)) { | 341 if (defined(invoker.output_dir)) { |
| 329 output_dir = invoker.output_dir | 342 output_dir = invoker.output_dir |
| 330 } else { | 343 } else { |
| 331 output_dir = target_gen_dir | 344 output_dir = target_gen_dir |
| 332 } | 345 } |
| 333 | 346 |
| 334 if (defined(invoker.output_name)) { | 347 if (defined(invoker.output_name)) { |
| 335 grit_output_name = invoker.output_name | 348 grit_output_name = invoker.output_name |
| 336 } else { | 349 } else { |
| 337 grit_output_name = target_name | 350 grit_output_name = target_name |
| 338 } | 351 } |
| 339 | 352 |
| 340 if (defined(invoker.depfile_dir)) { | 353 if (defined(invoker.depfile_dir)) { |
| 341 depfile_dir = invoker.depfile_dir | 354 depfile_dir = invoker.depfile_dir |
| 342 } else { | 355 } else { |
| 343 depfile_dir = output_dir | 356 depfile_dir = output_dir |
| 344 } | 357 } |
| 345 | 358 |
| 346 # These are all passed as arguments to the script so have to be relative to | 359 # These are all passed as arguments to the script so have to be relative to |
| 347 # the build directory. | 360 # the build directory. |
| 348 if (resource_ids != "") { | |
| 349 resource_ids = rebase_path(resource_ids, root_build_dir) | |
| 350 } | |
| 351 rebased_output_dir = rebase_path(output_dir, root_build_dir) | 361 rebased_output_dir = rebase_path(output_dir, root_build_dir) |
| 352 source_path = rebase_path(invoker.source, root_build_dir) | 362 source_path = rebase_path(invoker.source, root_build_dir) |
| 353 | 363 |
| 364 # Compute flags. |
| 354 grit_flags = [] | 365 grit_flags = [] |
| 355 if (enable_resource_whitelist_generation) { | 366 if (enable_resource_whitelist_generation) { |
| 356 grit_flags += [ "-h" ] | 367 grit_flags += [ "-h" ] |
| 357 if (is_win) { | 368 if (is_win) { |
| 358 grit_flags += [ "#define {textual_id} __pragma(message(\"whitelisted_resou
rce_{numeric_id}\")) {numeric_id}" ] | 369 grit_flags += [ "#define {textual_id} __pragma(message(\"whitelisted_resou
rce_{numeric_id}\")) {numeric_id}" ] |
| 359 } else { | 370 } else { |
| 360 grit_flags += [ "#define {textual_id} _Pragma(\"whitelisted_resource_{nume
ric_id}\") {numeric_id}" ] | 371 grit_flags += [ "#define {textual_id} _Pragma(\"whitelisted_resource_{nume
ric_id}\") {numeric_id}" ] |
| 361 } | 372 } |
| 362 } | 373 } |
| 363 if (defined(invoker.grit_flags)) { | 374 if (defined(invoker.grit_flags)) { |
| 364 grit_flags += invoker.grit_flags | 375 grit_flags += invoker.grit_flags |
| 365 } | 376 } |
| 377 if (resource_ids != "") { |
| 378 grit_flags += [ |
| 379 "-f", |
| 380 rebase_path(resource_ids, root_build_dir), |
| 381 ] |
| 382 } |
| 383 |
| 384 if (defined(invoker.source_is_generated)) { |
| 385 source_is_generated = invoker.source_is_generated |
| 386 } else { |
| 387 source_is_generated = false |
| 388 } |
| 366 | 389 |
| 367 assert_files_flags = [] | 390 assert_files_flags = [] |
| 368 | 391 |
| 369 # We want to make sure the declared outputs actually match what Grit is | 392 # We want to make sure the declared outputs actually match what Grit is |
| 370 # writing. We write the list to a file (some of the output lists are long | 393 # writing. We write the list to a file (some of the output lists are long |
| 371 # enough to not fit on a Windows command line) and ask Grit to verify those | 394 # enough to not fit on a Windows command line) and ask Grit to verify those |
| 372 # are the actual outputs at runtime. | 395 # are the actual outputs at runtime. |
| 373 asserted_list_file = | 396 asserted_list_file = |
| 374 "$target_out_dir/${grit_output_name}_expected_outputs.txt" | 397 "$target_out_dir/${grit_output_name}_expected_outputs.txt" |
| 375 write_file(asserted_list_file, | 398 write_file(asserted_list_file, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 400 "-Wunknown-pragmas", | 423 "-Wunknown-pragmas", |
| 401 "-Wno-error=unknown-pragmas", | 424 "-Wno-error=unknown-pragmas", |
| 402 ] | 425 ] |
| 403 } | 426 } |
| 404 visibility = target_visibility | 427 visibility = target_visibility |
| 405 } | 428 } |
| 406 | 429 |
| 407 grit_custom_target = target_name + "_grit" | 430 grit_custom_target = target_name + "_grit" |
| 408 action(grit_custom_target) { | 431 action(grit_custom_target) { |
| 409 script = "//tools/grit/grit.py" | 432 script = "//tools/grit/grit.py" |
| 410 inputs = grit_inputs | 433 |
| 434 inputs = [ |
| 435 invoker.source, |
| 436 ] |
| 437 if (resource_ids != "") { |
| 438 # The script depends on the ID file. Only add this dependency if the ID |
| 439 # file is specified. |
| 440 inputs += [ resource_ids ] |
| 441 } |
| 411 | 442 |
| 412 depfile = "$depfile_dir/${grit_output_name}_stamp.d" | 443 depfile = "$depfile_dir/${grit_output_name}_stamp.d" |
| 413 outputs = [ "${depfile}.stamp" ] + grit_outputs | 444 outputs = [ "${depfile}.stamp" ] + grit_outputs |
| 414 | 445 |
| 415 args = [ | 446 args = [ |
| 416 "-i", | 447 "-i", |
| 417 source_path, | 448 source_path, |
| 418 "build", | 449 "build", |
| 419 ] | 450 "-o", |
| 420 if (resource_ids != "") { | 451 rebased_output_dir, |
| 421 args += [ | 452 "--depdir", |
| 422 "-f", | 453 ".", |
| 423 resource_ids, | 454 "--depfile", |
| 424 ] | 455 rebase_path(depfile, root_build_dir), |
| 425 } | 456 "--write-only-new=1", |
| 426 args += [ | 457 "--depend-on-stamp", |
| 427 "-o", | 458 ] + grit_defines |
| 428 rebased_output_dir, | |
| 429 "--depdir", | |
| 430 ".", | |
| 431 "--depfile", | |
| 432 rebase_path(depfile, root_build_dir), | |
| 433 "--write-only-new=1", | |
| 434 "--depend-on-stamp", | |
| 435 ] + grit_defines | |
| 436 | 459 |
| 437 # Add extra defines with -D flags. | 460 # Add extra defines with -D flags. |
| 461 define_args = [] |
| 438 if (defined(invoker.defines)) { | 462 if (defined(invoker.defines)) { |
| 439 foreach(i, invoker.defines) { | 463 foreach(i, invoker.defines) { |
| 440 args += [ | 464 define_args += [ |
| 441 "-D", | 465 "-D", |
| 442 i, | 466 i, |
| 443 ] | 467 ] |
| 444 } | 468 } |
| 445 } | 469 } |
| 446 | 470 |
| 447 args += grit_flags + assert_files_flags | 471 args += define_args + grit_flags + assert_files_flags |
| 448 | 472 |
| 449 if (_strip_resource_files) { | 473 if (_strip_resource_files) { |
| 450 js_minifier_command = rebase_path(_js_minifier) | 474 js_minifier_command = rebase_path(_js_minifier) |
| 451 js_minifier_command = "$js_minifier_command --closure_args" | 475 js_minifier_command = "$js_minifier_command --closure_args" |
| 452 foreach(closure_arg, | 476 foreach(closure_arg, |
| 453 common_closure_args + minifying_closure_args + | 477 common_closure_args + minifying_closure_args + |
| 454 default_disabled_closure_args) { | 478 default_disabled_closure_args) { |
| 455 js_minifier_command = "$js_minifier_command $closure_arg" | 479 js_minifier_command = "$js_minifier_command $closure_arg" |
| 456 } | 480 } |
| 457 args += [ | 481 args += [ |
| 458 "--js-minifier", | 482 "--js-minifier", |
| 459 js_minifier_command, | 483 js_minifier_command, |
| 460 ] | 484 ] |
| 461 inputs += [ _js_minifier ] | 485 inputs += [ _js_minifier ] |
| 462 } | 486 } |
| 463 | 487 |
| 488 # Must be after the args are computed since they are re-used. |
| 489 # See the comments for the two variables used in this condition for |
| 490 # why this works this way. |
| 491 if (compute_grit_inputs_for_analyze && !source_is_generated) { |
| 492 grit_info_script = "//tools/grit/grit_info.py" |
| 493 grit_info_args = [ |
| 494 "--inputs", |
| 495 source_path, |
| 496 ] + grit_flags + grit_defines |
| 497 |
| 498 # Only call exec_script when the user has explicitly opted into greater |
| 499 # precision at the expense of performance. |
| 500 rel_inputs = exec_script(grit_info_script, |
| 501 grit_info_args, |
| 502 "list lines", |
| 503 [ grit_info_script ]) |
| 504 inputs += rebase_path(rel_inputs, ".", root_build_dir) |
| 505 } else { |
| 506 assert(source_is_generated || !source_is_generated) # Prevent error. |
| 507 } |
| 508 |
| 464 if (defined(invoker.visibility)) { | 509 if (defined(invoker.visibility)) { |
| 465 # This needs to include both what the invoker specified (since they | 510 # This needs to include both what the invoker specified (since they |
| 466 # probably include generated headers from this target), as well as the | 511 # probably include generated headers from this target), as well as the |
| 467 # generated source set (since there's no guarantee that the visibility | 512 # generated source set (since there's no guarantee that the visibility |
| 468 # specified by the invoker includes our target). | 513 # specified by the invoker includes our target). |
| 469 # | 514 # |
| 470 # Only define visibility at all if the invoker specified it. Otherwise, | 515 # Only define visibility at all if the invoker specified it. Otherwise, |
| 471 # we want to keep the public "no visibility specified" default. | 516 # we want to keep the public "no visibility specified" default. |
| 472 visibility = target_visibility + invoker.visibility | 517 visibility = target_visibility + invoker.visibility |
| 473 } | 518 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 if (defined(invoker.configs)) { | 551 if (defined(invoker.configs)) { |
| 507 configs += invoker.configs | 552 configs += invoker.configs |
| 508 } | 553 } |
| 509 | 554 |
| 510 if (defined(invoker.visibility)) { | 555 if (defined(invoker.visibility)) { |
| 511 visibility = invoker.visibility | 556 visibility = invoker.visibility |
| 512 } | 557 } |
| 513 output_name = grit_output_name | 558 output_name = grit_output_name |
| 514 } | 559 } |
| 515 } | 560 } |
| OLD | NEW |