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

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

Issue 2094193004: Strip comments and whitespace from Javascript resources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to comments, plus rebases. Created 4 years, 5 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
OLDNEW
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
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")
86 import("//third_party/closure_compiler/compile_js2.gni")
85 87
86 declare_args() { 88 declare_args() {
87 # Enables used resource whitelist generation. 89 # Enables used resource whitelist generation.
88 enable_resource_whitelist_generation = false 90 enable_resource_whitelist_generation = false
89 } 91 }
90 92
91 grit_defines = [] 93 grit_defines = []
94 grit_environment = []
92 95
93 # Mac and iOS want Title Case strings. 96 # Mac and iOS want Title Case strings.
94 use_titlecase_in_grd_files = is_mac || is_ios 97 use_titlecase_in_grd_files = is_mac || is_ios
95 if (use_titlecase_in_grd_files) { 98 if (use_titlecase_in_grd_files) {
96 grit_defines += [ 99 grit_defines += [
97 "-D", 100 "-D",
98 "use_titlecase", 101 "use_titlecase",
99 ] 102 ]
100 } 103 }
101 104
102 if (is_chrome_branded) { 105 if (is_chrome_branded) {
103 grit_defines += [ 106 grit_defines += [
104 "-D", 107 "-D",
105 "_google_chrome", 108 "_google_chrome",
109 ]
110 grit_environment += [
106 "-E", 111 "-E",
107 "CHROMIUM_BUILD=google_chrome", 112 "CHROMIUM_BUILD=google_chrome",
108 ] 113 ]
109 } else { 114 } else {
110 grit_defines += [ 115 grit_defines += [
111 "-D", 116 "-D",
112 "_chromium", 117 "_chromium",
118 ]
119 grit_environment += [
113 "-E", 120 "-E",
114 "CHROMIUM_BUILD=chromium", 121 "CHROMIUM_BUILD=chromium",
115 ] 122 ]
116 } 123 }
117 124
118 if (is_chromeos) { 125 if (is_chromeos) {
119 grit_defines += [ 126 grit_defines += [
120 "-D", 127 "-D",
121 "chromeos", 128 "chromeos",
122 "-D", 129 "-D",
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 } 174 }
168 175
169 if (enable_image_loader_extension) { 176 if (enable_image_loader_extension) {
170 grit_defines += [ 177 grit_defines += [
171 "-D", 178 "-D",
172 "image_loader_extension", 179 "image_loader_extension",
173 ] 180 ]
174 } 181 }
175 182
176 if (is_android) { 183 if (is_android) {
177 grit_defines += [ 184 grit_environment += [
178 "-E", 185 "-E",
179 "ANDROID_JAVA_TAGGED_ONLY=true", 186 "ANDROID_JAVA_TAGGED_ONLY=true",
180 ] 187 ]
181 } 188 }
182 189
183 if (is_mac || is_ios) { 190 if (is_mac || is_ios) {
184 grit_defines += [ 191 grit_defines += [
185 "-D", 192 "-D",
186 "scale_factors=2x", 193 "scale_factors=2x",
187 ] 194 ]
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 } 427 }
421 args += [ 428 args += [
422 "-o", 429 "-o",
423 rebased_output_dir, 430 rebased_output_dir,
424 "--depdir", 431 "--depdir",
425 ".", 432 ".",
426 "--depfile", 433 "--depfile",
427 rebase_path(depfile, root_build_dir), 434 rebase_path(depfile, root_build_dir),
428 "--write-only-new=1", 435 "--write-only-new=1",
429 "--depend-on-stamp", 436 "--depend-on-stamp",
430 ] + grit_defines 437 ] + grit_defines + grit_environment
431 438
432 # Add extra defines with -D flags. 439 # Add extra defines with -D flags.
433 if (defined(invoker.defines)) { 440 if (defined(invoker.defines)) {
434 foreach(i, invoker.defines) { 441 foreach(i, invoker.defines) {
435 args += [ 442 args += [
436 "-D", 443 "-D",
437 i, 444 i,
438 ] 445 ]
439 } 446 }
440 } 447 }
441 448
449 if (defined(invoker.moved_file_list)) {
450 response_file_contents = invoker.moved_file_list
451 args += [ "--moved-input-file-list={{response_file_name}}" ]
452 }
453
442 args += grit_flags + assert_files_flags 454 args += grit_flags + assert_files_flags
443 455
444 if (defined(invoker.visibility)) { 456 if (defined(invoker.visibility)) {
445 # This needs to include both what the invoker specified (since they 457 # This needs to include both what the invoker specified (since they
446 # probably include generated headers from this target), as well as the 458 # probably include generated headers from this target), as well as the
447 # generated source set (since there's no guarantee that the visibility 459 # generated source set (since there's no guarantee that the visibility
448 # specified by the invoker includes our target). 460 # specified by the invoker includes our target).
449 # 461 #
450 # Only define visibility at all if the invoker specified it. Otherwise, 462 # Only define visibility at all if the invoker specified it. Otherwise,
451 # we want to keep the public "no visibility specified" default. 463 # we want to keep the public "no visibility specified" default.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 if (defined(invoker.configs)) { 498 if (defined(invoker.configs)) {
487 configs += invoker.configs 499 configs += invoker.configs
488 } 500 }
489 501
490 if (defined(invoker.visibility)) { 502 if (defined(invoker.visibility)) {
491 visibility = invoker.visibility 503 visibility = invoker.visibility
492 } 504 }
493 output_name = grit_output_name 505 output_name = grit_output_name
494 } 506 }
495 } 507 }
508
509 flatten_resource_path = "//tools/grit/flatten_resource.py"
510 closure_compiler_path = "//third_party/closure_compiler/compiler/compiler.jar"
511
512 template("strip_js") {
513 assert(defined(invoker.sources),
514 "Need sources in $target_name listing the js files.")
515
516 _target_name = target_name
517
518 action_foreach("${_target_name}_flatten") {
519 script = flatten_resource_path
520 sources = invoker.sources
521 output = "{{source_gen_dir}}/flattened_${target_name}/{{source_file_part}}"
522 outputs = [
523 output,
524 ]
525 args = grit_defines
526 args += [
527 rebase_path("{{source}}"),
528 rebase_path("$root_out_dir/$output"),
529 ]
530 }
531
532 compile_js2_foreach(_target_name) {
533 sources = get_target_outputs(":${_target_name}_flatten")
534 deps = [
535 ":${_target_name}_flatten",
536 ]
537 strip_whitespace = true
538 }
539 }
540
541 template("strip_and_grit") {
542 _target_name = target_name
543
544 if (strip_resource_files) {
545 strip_js("${_target_name}_stripped") {
546 sources = invoker.js_resource_files
547 }
548 grit(_target_name) {
549 forward_variables_from(invoker,
550 [
551 "source",
552 "outputs",
553 "outputs_dir",
554 "defines",
555 "grit_flags",
556 "output_dir",
557 ])
558 moved_file_list = []
559
560 foreach(js_resource_file, invoker.js_resource_files) {
561 name = get_path_info(js_resource_file, "file")
562
563 # Generating the actual paths is messy, because, to avoid name clashes b oth the
Dan Beam 2016/07/14 17:47:59 80 col wrap
564 # actions in strip_js use {{source_gen_dir}}, hence adding $root_gen_dir to
565 # the front of the path twice.
566 gen_dir = get_path_info(js_resource_file, "gen_dir")
567 gen_dir_rebased = rebase_path(gen_dir, "//")
568 stripped_target_name = "${_target_name}_stripped"
569 actual = "${root_gen_dir}/${gen_dir_rebased}/flattened_${stripped_target _name}_flatten/closure_${stripped_target_name}/${name}"
570 abs_orig = rebase_path(js_resource_file)
571 abs_actual = rebase_path(actual)
572 moved_file_list += [ "$abs_orig:$abs_actual" ]
573 }
574
575 deps = invoker.deps
576 deps += [ ":${_target_name}_stripped" ]
577 }
578 } else {
579 # If we can't run the closure compiler simply run grit.
580 grit(_target_name) {
581 forward_variables_from(invoker,
582 [
583 "source",
584 "outputs",
585 "outputs_dir",
586 "defines",
587 "grit_flags",
588 "output_dir",
589 ])
590
591 inputs = invoker.js_resource_files
592
593 deps = invoker.deps
594 }
595 }
596 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698