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) |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 # ] | 75 # ] |
76 # | 76 # |
77 # grit_flags = [ "-E", "foo=bar" ] # Optional extra flags. | 77 # grit_flags = [ "-E", "foo=bar" ] # Optional extra flags. |
78 # # You can also put deps here if the grit source depends on generated | 78 # # You can also put deps here if the grit source depends on generated |
79 # # files. | 79 # # files. |
80 # } | 80 # } |
81 import("//build/config/chrome_build.gni") | 81 import("//build/config/chrome_build.gni") |
82 import("//build/config/crypto.gni") | 82 import("//build/config/crypto.gni") |
83 import("//build/config/features.gni") | 83 import("//build/config/features.gni") |
84 import("//build/config/ui.gni") | 84 import("//build/config/ui.gni") |
85 import("//build/util/java_action.gni") | |
85 | 86 |
86 declare_args() { | 87 declare_args() { |
87 # Enables used resource whitelist generation. | 88 # Enables used resource whitelist generation. |
88 enable_resource_whitelist_generation = false | 89 enable_resource_whitelist_generation = false |
89 } | 90 } |
90 | 91 |
91 grit_defines = [] | 92 grit_defines = [] |
93 grit_environment = [] | |
92 | 94 |
93 # Mac and iOS want Title Case strings. | 95 # Mac and iOS want Title Case strings. |
94 use_titlecase_in_grd_files = is_mac || is_ios | 96 use_titlecase_in_grd_files = is_mac || is_ios |
95 if (use_titlecase_in_grd_files) { | 97 if (use_titlecase_in_grd_files) { |
96 grit_defines += [ | 98 grit_defines += [ |
97 "-D", | 99 "-D", |
98 "use_titlecase", | 100 "use_titlecase", |
99 ] | 101 ] |
100 } | 102 } |
101 | 103 |
102 if (is_chrome_branded) { | 104 if (is_chrome_branded) { |
103 grit_defines += [ | 105 grit_defines += [ |
104 "-D", | 106 "-D", |
105 "_google_chrome", | 107 "_google_chrome", |
108 ] | |
109 grit_environment += [ | |
106 "-E", | 110 "-E", |
107 "CHROMIUM_BUILD=google_chrome", | 111 "CHROMIUM_BUILD=google_chrome", |
108 ] | 112 ] |
109 } else { | 113 } else { |
110 grit_defines += [ | 114 grit_defines += [ |
111 "-D", | 115 "-D", |
112 "_chromium", | 116 "_chromium", |
117 ] | |
118 grit_environment += [ | |
113 "-E", | 119 "-E", |
114 "CHROMIUM_BUILD=chromium", | 120 "CHROMIUM_BUILD=chromium", |
115 ] | 121 ] |
116 } | 122 } |
117 | 123 |
118 if (is_chromeos) { | 124 if (is_chromeos) { |
119 grit_defines += [ | 125 grit_defines += [ |
120 "-D", | 126 "-D", |
121 "chromeos", | 127 "chromeos", |
122 "-D", | 128 "-D", |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 } | 173 } |
168 | 174 |
169 if (enable_image_loader_extension) { | 175 if (enable_image_loader_extension) { |
170 grit_defines += [ | 176 grit_defines += [ |
171 "-D", | 177 "-D", |
172 "image_loader_extension", | 178 "image_loader_extension", |
173 ] | 179 ] |
174 } | 180 } |
175 | 181 |
176 if (is_android) { | 182 if (is_android) { |
177 grit_defines += [ | 183 grit_environment += [ |
178 "-E", | 184 "-E", |
179 "ANDROID_JAVA_TAGGED_ONLY=true", | 185 "ANDROID_JAVA_TAGGED_ONLY=true", |
180 ] | 186 ] |
181 } | 187 } |
182 | 188 |
183 if (is_mac || is_ios) { | 189 if (is_mac || is_ios) { |
184 grit_defines += [ | 190 grit_defines += [ |
185 "-D", | 191 "-D", |
186 "scale_factors=2x", | 192 "scale_factors=2x", |
187 ] | 193 ] |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
426 } | 432 } |
427 args += [ | 433 args += [ |
428 "-o", | 434 "-o", |
429 rebased_output_dir, | 435 rebased_output_dir, |
430 "--depdir", | 436 "--depdir", |
431 ".", | 437 ".", |
432 "--depfile", | 438 "--depfile", |
433 rebase_path(depfile, root_build_dir), | 439 rebase_path(depfile, root_build_dir), |
434 "--write-only-new=1", | 440 "--write-only-new=1", |
435 "--depend-on-stamp", | 441 "--depend-on-stamp", |
436 ] + grit_defines | 442 ] + grit_defines + grit_environment |
437 | 443 |
438 # Add extra defines with -D flags. | 444 # Add extra defines with -D flags. |
439 if (defined(invoker.defines)) { | 445 if (defined(invoker.defines)) { |
440 foreach(i, invoker.defines) { | 446 foreach(i, invoker.defines) { |
441 args += [ | 447 args += [ |
442 "-D", | 448 "-D", |
443 i, | 449 i, |
444 ] | 450 ] |
445 } | 451 } |
446 } | 452 } |
447 | 453 |
454 if (defined(invoker.moved_file_list)) { | |
455 response_file_contents = invoker.moved_file_list | |
456 args += [ "--moved-input-file-list={{response_file_name}}" ] | |
457 } | |
458 | |
448 args += grit_flags + assert_files_flags | 459 args += grit_flags + assert_files_flags |
449 | 460 |
450 if (defined(invoker.visibility)) { | 461 if (defined(invoker.visibility)) { |
451 # This needs to include both what the invoker specified (since they | 462 # This needs to include both what the invoker specified (since they |
452 # probably include generated headers from this target), as well as the | 463 # probably include generated headers from this target), as well as the |
453 # generated source set (since there's no guarantee that the visibility | 464 # generated source set (since there's no guarantee that the visibility |
454 # specified by the invoker includes our target). | 465 # specified by the invoker includes our target). |
455 # | 466 # |
456 # Only define visibility at all if the invoker specified it. Otherwise, | 467 # Only define visibility at all if the invoker specified it. Otherwise, |
457 # we want to keep the public "no visibility specified" default. | 468 # we want to keep the public "no visibility specified" default. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
492 if (defined(invoker.configs)) { | 503 if (defined(invoker.configs)) { |
493 configs += invoker.configs | 504 configs += invoker.configs |
494 } | 505 } |
495 | 506 |
496 if (defined(invoker.visibility)) { | 507 if (defined(invoker.visibility)) { |
497 visibility = invoker.visibility | 508 visibility = invoker.visibility |
498 } | 509 } |
499 output_name = grit_output_name | 510 output_name = grit_output_name |
500 } | 511 } |
501 } | 512 } |
513 | |
514 flatten_resource_path = "//tools/grit/flatten_resource.py" | |
515 closure_compiler_path = "//third_party/closure_compiler/compiler/compiler.jar" | |
516 | |
517 template("strip_js") { | |
518 assert(defined(invoker.sources), | |
519 "Need sources in $target_name listing the js files.") | |
520 | |
521 _target_name = target_name | |
522 | |
523 action_foreach("${_target_name}_flatten") { | |
524 script = flatten_resource_path | |
525 sources = invoker.sources | |
526 outputs = [ | |
527 "{{source_gen_dir}}/{{source_name_part}}.${_target_name}_flattened_js", | |
528 ] | |
529 args = grit_defines | |
530 args += [ | |
531 rebase_path("{{source}}"), | |
532 rebase_path( | |
533 "$root_out_dir/{{source_gen_dir}}/{{source_name_part}}.${_target_name} _flattened_js"), | |
534 ] | |
535 } | |
536 | |
537 java_action_foreach(_target_name) { | |
Dan Beam
2016/06/29 22:20:57
does this run in an optimized way, i.e.
https://c
aberent
2016/07/14 15:41:36
Now it does. See compile_js2.gni
| |
538 script = closure_compiler_path | |
539 sources = get_target_outputs(":${_target_name}_flatten") | |
540 outputs = [ | |
541 "{{source_gen_dir}}/{{source_name_part}}_${_target_name}.js", | |
542 ] | |
543 | |
544 args = [ | |
545 "--compilation_level", | |
546 "WHITESPACE_ONLY", | |
547 "--js_output_file", | |
548 rebase_path( | |
549 "$root_out_dir/{{source_gen_dir}}/{{source_name_part}}_${_target_name} .js"), | |
Dan Beam
2016/06/29 22:20:57
what about source maps?
third_party/closure_compi
aberent
2016/07/14 15:41:36
Done.
| |
550 "--js", | |
551 "{{source}}", | |
552 "--language_out=ES5", | |
Dan Beam
2016/06/29 22:20:57
don't you want a --language_in as well?
aberent
2016/07/14 15:41:36
Done. See compile_js2.gni
| |
553 ] | |
554 deps = [ | |
555 ":${_target_name}_flatten", | |
556 ] | |
557 } | |
558 } | |
559 | |
560 template("strip_and_grit") { | |
561 _target_name = target_name | |
562 | |
563 if (strip_resource_files) { | |
564 strip_js("${_target_name}_stripped") { | |
565 sources = invoker.js_resource_files | |
566 } | |
567 grit(_target_name) { | |
568 forward_variables_from(invoker, | |
569 [ | |
570 "source", | |
571 "outputs", | |
572 "outputs_dir", | |
573 "defines", | |
574 "grit_flags", | |
575 "output_dir", | |
576 ]) | |
577 moved_file_list = [] | |
578 | |
579 foreach(js_resource_file, invoker.js_resource_files) { | |
580 name = get_path_info(js_resource_file, "name") | |
581 | |
582 # Generating the actual paths is messy, because, to avoid name clashes b oth the | |
583 # actions in strip_js use {{source_gen_dir}}, hence adding $root_gen_dir to | |
584 # the front of the path twice. | |
585 gen_dir = get_path_info(js_resource_file, "gen_dir") | |
586 gen_dir_rebased = rebase_path(gen_dir, "//") | |
587 actual = "${root_gen_dir}/${gen_dir_rebased}/${name}_${_target_name}_str ipped.js" | |
588 abs_orig = rebase_path(js_resource_file) | |
589 abs_actual = rebase_path(actual) | |
590 moved_file_list += [ "$abs_orig:$abs_actual" ] | |
591 } | |
592 | |
593 deps = invoker.deps | |
594 deps += [ ":${_target_name}_stripped" ] | |
595 } | |
596 } else { | |
597 # If we can't run the closure compiler simply run grit. | |
598 grit(_target_name) { | |
599 forward_variables_from(invoker, | |
600 [ | |
601 "source", | |
602 "outputs", | |
603 "outputs_dir", | |
604 "defines", | |
605 "grit_flags", | |
606 "output_dir", | |
607 ]) | |
608 | |
609 inputs = invoker.js_resource_files | |
610 | |
611 deps = invoker.deps | |
612 } | |
613 } | |
614 } | |
OLD | NEW |