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 # 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 # |
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 _copy_data_to_bundle = |
| 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) { |
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) && _copy_data_to_bundle) { |
| 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 (_copy_data_to_bundle) { |
| 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 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. |
64 # | 114 # |
65 # deps [optional] | 115 # deps [optional] |
66 # visibility [optional] | 116 # visibility [optional] |
| 117 # testonly [optional] |
| 118 # copy_data_to_bundle [optional] |
| 119 # repack_whitelist [optional] |
67 # Normal meaning. | 120 # Normal meaning. |
68 template("repack_and_bundle") { | 121 template("repack_locales") { |
69 assert(defined(invoker.bundle_output), "Need bundle_output for $target_name") | 122 # GN can't handle invoker.output_locales[foo] (http://crbug.com/614747). |
| 123 _output_locales = invoker.output_locales |
| 124 if (defined(invoker.output_dir)) { |
| 125 _output_dir = invoker.output_dir |
| 126 } else { |
| 127 if (is_ios) { |
| 128 _output_dir = "$target_gen_dir" |
| 129 } else { |
| 130 _output_dir = "$target_gen_dir/$target_name" |
| 131 } |
| 132 } |
70 | 133 |
71 _repack_target_name = target_name + "_repack" | 134 # Collects all targets the loop generates. |
72 _bundle_target_name = target_name | 135 _locale_targets = [] |
73 | 136 |
74 repack(_repack_target_name) { | 137 # This loop iterates over the input locales and also keeps a counter so it |
75 visibility = [ ":$_bundle_target_name" ] | 138 # can simultaneously iterate over the output locales (using GN's very |
| 139 # limited looping capabilities). |
| 140 _current_index = 0 |
| 141 foreach(_input_locale, invoker.input_locales) { |
| 142 _output_locale = _output_locales[_current_index] |
| 143 |
| 144 # Compute the name of the target for the current file. Save it for the deps. |
| 145 _current_name = "${target_name}_${_input_locale}" |
| 146 _locale_targets += [ ":$_current_name" ] |
| 147 |
| 148 repack(_current_name) { |
| 149 forward_variables_from(invoker, |
| 150 [ |
| 151 "copy_data_to_bundle", |
| 152 "bundle_output", |
| 153 "deps", |
| 154 "repack_whitelist", |
| 155 "testonly", |
| 156 ]) |
| 157 visibility = [ ":${invoker.target_name}" ] |
| 158 if (is_ios) { |
| 159 output = "$_output_dir/${_output_locale}.lproj/locale.pak" |
| 160 if (defined(copy_data_to_bundle) && copy_data_to_bundle) { |
| 161 bundle_output = |
| 162 "{{bundle_resources_dir}}/${_output_locale}.lproj/locale.pak" |
| 163 } |
| 164 } else { |
| 165 output = "$_output_dir/${_output_locale}.pak" |
| 166 } |
| 167 set_sources_assignment_filter([]) |
| 168 sources = [] |
| 169 foreach(_pattern, invoker.source_patterns) { |
| 170 sources += [ "${_pattern}${_input_locale}.pak" ] |
| 171 } |
| 172 } |
| 173 |
| 174 _current_index = _current_index + 1 |
| 175 } |
| 176 |
| 177 # The group that external targets depend on which collects all deps. |
| 178 group(target_name) { |
76 forward_variables_from(invoker, | 179 forward_variables_from(invoker, |
77 [ | 180 [ |
78 "deps", | 181 "visibility", |
79 "output", | |
80 "sources", | |
81 "testonly", | 182 "testonly", |
82 ]) | 183 ]) |
83 } | 184 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 } | 185 } |
108 } | 186 } |
OLD | NEW |