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 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 # define_bundle_data [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 # | |
16 # deps [optional] | 23 # deps [optional] |
17 # public_deps [optional] | 24 # public_deps [optional] |
18 # visibility [optional] | 25 # visibility [optional] |
19 # Normal meaning. | 26 # Normal meaning. |
20 template("repack") { | 27 template("repack") { |
21 action(target_name) { | 28 _define_bundle_data = |
29 defined(invoker.define_bundle_data) && invoker.define_bundle_data | |
30 _repack_target_name = target_name | |
31 if (_define_bundle_data) { | |
32 _repack_target_name = "${target_name}__repack" | |
33 } | |
34 | |
35 action(_repack_target_name) { | |
22 forward_variables_from(invoker, | 36 forward_variables_from(invoker, |
23 [ | 37 [ |
24 "deps", | 38 "deps", |
25 "public_deps", | 39 "public_deps", |
26 "testonly", | 40 "testonly", |
27 "visibility", | 41 "visibility", |
28 ]) | 42 ]) |
43 if (defined(visibility) && _define_bundle_data) { | |
44 visibility += [ ":${invoker.target_name}" ] | |
45 } | |
29 assert(defined(invoker.sources), "Need sources for $target_name") | 46 assert(defined(invoker.sources), "Need sources for $target_name") |
30 assert(defined(invoker.output), "Need output for $target_name") | 47 assert(defined(invoker.output), "Need output for $target_name") |
31 | 48 |
32 script = "//tools/grit/grit/format/repack.py" | 49 script = "//tools/grit/grit/format/repack.py" |
33 | 50 |
34 inputs = invoker.sources | 51 inputs = invoker.sources |
35 outputs = [ | 52 outputs = [ |
36 invoker.output, | 53 invoker.output, |
37 ] | 54 ] |
38 | 55 |
39 args = [] | 56 args = [] |
40 if (defined(invoker.repack_whitelist)) { | 57 if (defined(invoker.repack_whitelist)) { |
41 inputs += [ invoker.repack_whitelist ] | 58 inputs += [ invoker.repack_whitelist ] |
42 _rebased_whitelist = rebase_path(invoker.repack_whitelist) | 59 _rebased_whitelist = rebase_path(invoker.repack_whitelist) |
43 args += [ "--whitelist=$_rebased_whitelist" ] | 60 args += [ "--whitelist=$_rebased_whitelist" ] |
44 args += [ "--suppress-removed-key-output" ] | 61 args += [ "--suppress-removed-key-output" ] |
45 } | 62 } |
46 args += [ rebase_path(invoker.output, root_build_dir) ] | 63 args += [ rebase_path(invoker.output, root_build_dir) ] |
47 args += rebase_path(invoker.sources, root_build_dir) | 64 args += rebase_path(invoker.sources, root_build_dir) |
48 } | 65 } |
66 | |
67 if (_define_bundle_data) { | |
68 bundle_data(target_name) { | |
69 forward_variables_from(invoker, | |
70 [ | |
71 "testonly", | |
72 "visibility", | |
73 ]) | |
74 | |
75 public_deps = [ | |
76 ":$_repack_target_name", | |
77 ] | |
78 sources = [ | |
79 invoker.output, | |
80 ] | |
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 } | |
91 } | |
49 } | 92 } |
50 | 93 |
51 # This template combines repacking resources and defining a bundle_data target | 94 # Repacks a set of .pak files for each locale. |
52 # to move them to the application bundle. This is mostly useful on iOS. | |
53 # | 95 # |
54 # Parameters: | 96 # Parameters: |
55 # sources [required] | |
56 # List of pak files that need to be combined. | |
57 # | 97 # |
58 # output [required] | 98 # input_locales [required] |
59 # File name (single string) of the output file. | 99 # List of locale names to use as inputs. |
60 # | 100 # |
61 # bundle_output [optional] | 101 # output_locales [required] |
62 # Path of the file in the application bundle, defaults to | 102 # A list containing the corresponding output names for each of the |
63 # {{bundle_resources_dir}}/{{source_file_part}} if omitted. | 103 # input names. Mac uses different names in some cases. |
sdefresne
2016/09/13 07:59:19
nit: Mac and iOS uses different names in some case
agrieve
2016/09/13 14:06:58
Done.
| |
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. | |
64 # | 114 # |
65 # deps [optional] | 115 # deps [optional] |
66 # visibility [optional] | 116 # visibility [optional] |
117 # testonly [optional] | |
118 # define_bundle_data [optional] | |
119 # bundle_output [optional] | |
120 # repack_whitelist [optional] | |
67 # Normal meaning. | 121 # Normal meaning. |
68 template("repack_and_bundle") { | 122 template("repack_locales") { |
69 assert(defined(invoker.bundle_output), "Need bundle_output for $target_name") | 123 # GN's subscript can't handle invoker.output_locales[foo]. |
sdefresne
2016/09/13 07:59:19
nit: can you add reference to crbug.com/614747 (wh
agrieve
2016/09/13 14:06:58
Done.
| |
124 _output_locales = invoker.output_locales | |
125 _output_dir = "$target_gen_dir/$target_name" | |
126 if (defined(invoker.output_dir)) { | |
127 _output_dir = invoker.output_dir | |
128 } | |
70 | 129 |
71 _repack_target_name = target_name + "_repack" | 130 # Collects all targets the loop generates. |
72 _bundle_target_name = target_name | 131 _locale_targets = [] |
73 | 132 |
74 repack(_repack_target_name) { | 133 # This loop iterates over the input locales and also keeps a counter so it |
75 visibility = [ ":$_bundle_target_name" ] | 134 # can simultaneously iterate over the output locales (using GN's very |
135 # limited looping capabilities). | |
136 _current_index = 0 | |
137 foreach(_input_locale, invoker.input_locales) { | |
138 _output_locale = _output_locales[_current_index] | |
139 | |
140 # Compute the name of the target for the current file. Save it for the deps. | |
141 _current_name = "${target_name}_${_input_locale}" | |
142 _locale_targets += [ ":$_current_name" ] | |
143 | |
144 repack(_current_name) { | |
145 forward_variables_from(invoker, | |
146 [ | |
147 "define_bundle_data", | |
148 "bundle_output", | |
149 "deps", | |
150 "repack_whitelist", | |
151 "testonly", | |
152 ]) | |
153 visibility = [ ":${invoker.target_name}" ] | |
154 if (is_ios) { | |
155 output = "$_output_dir/${_output_locale}.lproj/locale.pak" | |
156 if (defined(define_bundle_data) && define_bundle_data && | |
157 !defined(bundle_output)) { | |
158 bundle_output = "{{bundle_resources_dir}}/${_output_locale}.lproj/{{so urce_file_part}}" | |
159 } | |
160 } else { | |
161 output = "$_output_dir/${_output_locale}.pak" | |
162 } | |
163 set_sources_assignment_filter([]) | |
164 sources = [] | |
165 foreach(_pattern, invoker.source_patterns) { | |
166 sources += [ "${_pattern}${_input_locale}.pak" ] | |
167 } | |
168 } | |
169 | |
170 _current_index = _current_index + 1 | |
171 } | |
172 | |
173 # The group that external targets depend on which collects all deps. | |
174 group(target_name) { | |
76 forward_variables_from(invoker, | 175 forward_variables_from(invoker, |
77 [ | 176 [ |
78 "deps", | 177 "visibility", |
79 "output", | |
80 "sources", | |
81 "testonly", | 178 "testonly", |
82 ]) | 179 ]) |
83 } | 180 public_deps = _locale_targets |
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, | |
101 ] | |
102 } else { | |
103 outputs = [ | |
104 "{{bundle_resources_dir}}/{{source_file_part}}", | |
105 ] | |
106 } | |
107 } | 181 } |
108 } | 182 } |
OLD | NEW |