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

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

Issue 2340673002: Revert of 🍵 Refactor the various locale_paks() templates to be more shared (Closed)
Patch Set: Created 4 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 | « ios/web/test/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 import("//tools/grit/grit_rule.gni") 5 import("//tools/grit/grit_rule.gni")
6 6
7 # This file defines a template to invoke grit repack in a consistent manner. 7 # This file defines a template to invoke grit repack in a consistent manner.
8 # 8 #
9 # Parameters: 9 # Parameters:
10 # sources [required] 10 # sources [required]
11 # List of pak files that need to be combined. 11 # List of pak files that need to be combined.
12 # 12 #
13 # output [required] 13 # output [required]
14 # File name (single string) of the output file. 14 # File name (single string) of the output file.
15 # 15 #
16 # copy_data_to_bundle [optional]
17 # Whether to define a bundle_data() for the resulting pak.
18 #
19 # bundle_output [optional]
20 # Path of the file in the application bundle, defaults to
21 # {{bundle_resources_dir}}/{{source_file_part}}.
22 #
23 # deps [optional] 16 # deps [optional]
24 # public_deps [optional] 17 # public_deps [optional]
25 # visibility [optional] 18 # visibility [optional]
26 # Normal meaning. 19 # Normal meaning.
27 template("repack") { 20 template("repack") {
28 _copy_data_to_bundle = 21 action(target_name) {
29 defined(invoker.copy_data_to_bundle) && invoker.copy_data_to_bundle
30 _repack_target_name = target_name
31 if (_copy_data_to_bundle) {
32 _repack_target_name = "${target_name}__repack"
33 }
34
35 action(_repack_target_name) {
36 forward_variables_from(invoker, 22 forward_variables_from(invoker,
37 [ 23 [
38 "deps", 24 "deps",
39 "public_deps", 25 "public_deps",
40 "testonly", 26 "testonly",
41 "visibility", 27 "visibility",
42 ]) 28 ])
43 if (defined(visibility) && _copy_data_to_bundle) {
44 visibility += [ ":${invoker.target_name}" ]
45 }
46 assert(defined(invoker.sources), "Need sources for $target_name") 29 assert(defined(invoker.sources), "Need sources for $target_name")
47 assert(defined(invoker.output), "Need output for $target_name") 30 assert(defined(invoker.output), "Need output for $target_name")
48 31
49 script = "//tools/grit/grit/format/repack.py" 32 script = "//tools/grit/grit/format/repack.py"
50 33
51 inputs = invoker.sources 34 inputs = invoker.sources
52 outputs = [ 35 outputs = [
53 invoker.output, 36 invoker.output,
54 ] 37 ]
55 38
56 args = [] 39 args = []
57 if (defined(invoker.repack_whitelist)) { 40 if (defined(invoker.repack_whitelist)) {
58 inputs += [ invoker.repack_whitelist ] 41 inputs += [ invoker.repack_whitelist ]
59 _rebased_whitelist = rebase_path(invoker.repack_whitelist) 42 _rebased_whitelist = rebase_path(invoker.repack_whitelist)
60 args += [ "--whitelist=$_rebased_whitelist" ] 43 args += [ "--whitelist=$_rebased_whitelist" ]
61 args += [ "--suppress-removed-key-output" ] 44 args += [ "--suppress-removed-key-output" ]
62 } 45 }
63 args += [ rebase_path(invoker.output, root_build_dir) ] 46 args += [ rebase_path(invoker.output, root_build_dir) ]
64 args += rebase_path(invoker.sources, root_build_dir) 47 args += rebase_path(invoker.sources, root_build_dir)
65 } 48 }
49 }
66 50
67 if (_copy_data_to_bundle) { 51 # This template combines repacking resources and defining a bundle_data target
68 bundle_data(target_name) { 52 # to move them to the application bundle. This is mostly useful on iOS.
69 forward_variables_from(invoker, 53 #
70 [ 54 # Parameters:
71 "testonly", 55 # sources [required]
72 "visibility", 56 # List of pak files that need to be combined.
73 ]) 57 #
58 # output [required]
59 # File name (single string) of the output file.
60 #
61 # bundle_output [optional]
62 # Path of the file in the application bundle, defaults to
63 # {{bundle_resources_dir}}/{{source_file_part}} if omitted.
64 #
65 # deps [optional]
66 # visibility [optional]
67 # Normal meaning.
68 template("repack_and_bundle") {
69 assert(defined(invoker.bundle_output), "Need bundle_output for $target_name")
74 70
75 public_deps = [ 71 _repack_target_name = target_name + "_repack"
76 ":$_repack_target_name", 72 _bundle_target_name = target_name
73
74 repack(_repack_target_name) {
75 visibility = [ ":$_bundle_target_name" ]
76 forward_variables_from(invoker,
77 [
78 "deps",
79 "output",
80 "sources",
81 "testonly",
82 ])
83 }
84
85 bundle_data(_bundle_target_name) {
86 forward_variables_from(invoker,
87 [
88 "testonly",
89 "visibility",
90 ])
91
92 public_deps = [
93 ":$_repack_target_name",
94 ]
95 sources = [
96 invoker.output,
97 ]
98 if (defined(invoker.bundle_output)) {
99 outputs = [
100 invoker.bundle_output,
77 ] 101 ]
78 sources = [ 102 } else {
79 invoker.output, 103 outputs = [
104 "{{bundle_resources_dir}}/{{source_file_part}}",
80 ] 105 ]
81 if (defined(invoker.bundle_output)) {
82 outputs = [
83 invoker.bundle_output,
84 ]
85 } else {
86 outputs = [
87 "{{bundle_resources_dir}}/{{source_file_part}}",
88 ]
89 }
90 } 106 }
91 } 107 }
92 } 108 }
93
94 # Repacks a set of .pak files for each locale.
95 #
96 # Parameters:
97 #
98 # input_locales [required]
99 # List of locale names to use as inputs.
100 #
101 # output_locales [required]
102 # A list containing the corresponding output names for each of the
103 # input names. Mac and iOS use different names in some cases.
104 #
105 # source_patterns [required]
106 # The pattern for pak files which need repacked. The filenames always end
107 # with "${locale}.pak".
108 # E.g.:
109 # ${root_gen_dir}/foo_ expands to ${root_gen_dir}/foo_zh-CN.pak
110 # when locale is zh-CN.
111 #
112 # output_dir [optional]
113 # Directory in which to put all pak files.
114 #
115 # deps [optional]
116 # visibility [optional]
117 # testonly [optional]
118 # copy_data_to_bundle [optional]
119 # repack_whitelist [optional]
120 # Normal meaning.
121 template("repack_locales") {
122 # GN can't handle invoker.output_locales[foo] (http://crbug.com/614747).
123 _output_locales = invoker.output_locales
124 _output_dir = "$target_gen_dir/$target_name"
125 if (defined(invoker.output_dir)) {
126 _output_dir = invoker.output_dir
127 }
128
129 # Collects all targets the loop generates.
130 _locale_targets = []
131
132 # This loop iterates over the input locales and also keeps a counter so it
133 # can simultaneously iterate over the output locales (using GN's very
134 # limited looping capabilities).
135 _current_index = 0
136 foreach(_input_locale, invoker.input_locales) {
137 _output_locale = _output_locales[_current_index]
138
139 # Compute the name of the target for the current file. Save it for the deps.
140 _current_name = "${target_name}_${_input_locale}"
141 _locale_targets += [ ":$_current_name" ]
142
143 repack(_current_name) {
144 forward_variables_from(invoker,
145 [
146 "copy_data_to_bundle",
147 "bundle_output",
148 "deps",
149 "repack_whitelist",
150 "testonly",
151 ])
152 visibility = [ ":${invoker.target_name}" ]
153 if (is_ios) {
154 output = "$_output_dir/${_output_locale}.lproj/locale.pak"
155 if (defined(copy_data_to_bundle) && copy_data_to_bundle) {
156 bundle_output =
157 "{{bundle_resources_dir}}/${_output_locale}.lproj/locale.pak"
158 }
159 } else {
160 output = "$_output_dir/${_output_locale}.pak"
161 }
162 set_sources_assignment_filter([])
163 sources = []
164 foreach(_pattern, invoker.source_patterns) {
165 sources += [ "${_pattern}${_input_locale}.pak" ]
166 }
167 }
168
169 _current_index = _current_index + 1
170 }
171
172 # The group that external targets depend on which collects all deps.
173 group(target_name) {
174 forward_variables_from(invoker,
175 [
176 "visibility",
177 "testonly",
178 ])
179 public_deps = _locale_targets
180 }
181 }
OLDNEW
« no previous file with comments | « ios/web/test/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698