Chromium Code Reviews| Index: tools/grit/repack.gni |
| diff --git a/tools/grit/repack.gni b/tools/grit/repack.gni |
| index 0f257bb7c4274c1f478ac05e1c3018d37676593b..8fa74b4e6a8ac21e95cb080c358544556ab23612 100644 |
| --- a/tools/grit/repack.gni |
| +++ b/tools/grit/repack.gni |
| @@ -13,12 +13,26 @@ import("//tools/grit/grit_rule.gni") |
| # output [required] |
| # File name (single string) of the output file. |
| # |
| +# define_bundle_data [optional] |
| +# Whether to define a bundle_data() for the resulting pak. |
| +# |
| +# bundle_output [optional] |
| +# Path of the file in the application bundle, defaults to |
| +# {{bundle_resources_dir}}/{{source_file_part}}. |
| +# |
| # deps [optional] |
| # public_deps [optional] |
| # visibility [optional] |
| # Normal meaning. |
| template("repack") { |
| - action(target_name) { |
| + _define_bundle_data = |
| + defined(invoker.define_bundle_data) && invoker.define_bundle_data |
| + _repack_target_name = target_name |
| + if (_define_bundle_data) { |
| + _repack_target_name = "${target_name}__repack" |
| + } |
| + |
| + action(_repack_target_name) { |
| forward_variables_from(invoker, |
| [ |
| "deps", |
| @@ -26,6 +40,9 @@ template("repack") { |
| "testonly", |
| "visibility", |
| ]) |
| + if (defined(visibility) && _define_bundle_data) { |
| + visibility += [ ":${invoker.target_name}" ] |
| + } |
| assert(defined(invoker.sources), "Need sources for $target_name") |
| assert(defined(invoker.output), "Need output for $target_name") |
| @@ -46,63 +63,120 @@ template("repack") { |
| args += [ rebase_path(invoker.output, root_build_dir) ] |
| args += rebase_path(invoker.sources, root_build_dir) |
| } |
| + |
| + if (_define_bundle_data) { |
| + bundle_data(target_name) { |
| + forward_variables_from(invoker, |
| + [ |
| + "testonly", |
| + "visibility", |
| + ]) |
| + |
| + public_deps = [ |
| + ":$_repack_target_name", |
| + ] |
| + sources = [ |
| + invoker.output, |
| + ] |
| + if (defined(invoker.bundle_output)) { |
| + outputs = [ |
| + invoker.bundle_output, |
| + ] |
| + } else { |
| + outputs = [ |
| + "{{bundle_resources_dir}}/{{source_file_part}}", |
| + ] |
| + } |
| + } |
| + } |
| } |
| -# This template combines repacking resources and defining a bundle_data target |
| -# to move them to the application bundle. This is mostly useful on iOS. |
| +# Repacks a set of .pak files for each locale. |
| # |
| # Parameters: |
| -# sources [required] |
| -# List of pak files that need to be combined. |
| # |
| -# output [required] |
| -# File name (single string) of the output file. |
| +# input_locales [required] |
| +# List of locale names to use as inputs. |
| # |
| -# bundle_output [optional] |
| -# Path of the file in the application bundle, defaults to |
| -# {{bundle_resources_dir}}/{{source_file_part}} if omitted. |
| +# output_locales [required] |
| +# A list containing the corresponding output names for each of the |
| +# 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.
|
| +# |
| +# source_patterns [required] |
| +# The pattern for pak files which need repacked. The filenames always end |
| +# with "${locale}.pak". |
| +# E.g.: |
| +# ${root_gen_dir}/foo_ expands to ${root_gen_dir}/foo_zh-CN.pak |
| +# when locale is zh-CN. |
| +# |
| +# output_dir [optional] |
| +# Directory in which to put all pak files. |
| # |
| # deps [optional] |
| # visibility [optional] |
| +# testonly [optional] |
| +# define_bundle_data [optional] |
| +# bundle_output [optional] |
| +# repack_whitelist [optional] |
| # Normal meaning. |
| -template("repack_and_bundle") { |
| - assert(defined(invoker.bundle_output), "Need bundle_output for $target_name") |
| +template("repack_locales") { |
| + # 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.
|
| + _output_locales = invoker.output_locales |
| + _output_dir = "$target_gen_dir/$target_name" |
| + if (defined(invoker.output_dir)) { |
| + _output_dir = invoker.output_dir |
| + } |
| - _repack_target_name = target_name + "_repack" |
| - _bundle_target_name = target_name |
| + # Collects all targets the loop generates. |
| + _locale_targets = [] |
| - repack(_repack_target_name) { |
| - visibility = [ ":$_bundle_target_name" ] |
| - forward_variables_from(invoker, |
| - [ |
| - "deps", |
| - "output", |
| - "sources", |
| - "testonly", |
| - ]) |
| + # This loop iterates over the input locales and also keeps a counter so it |
| + # can simultaneously iterate over the output locales (using GN's very |
| + # limited looping capabilities). |
| + _current_index = 0 |
| + foreach(_input_locale, invoker.input_locales) { |
| + _output_locale = _output_locales[_current_index] |
| + |
| + # Compute the name of the target for the current file. Save it for the deps. |
| + _current_name = "${target_name}_${_input_locale}" |
| + _locale_targets += [ ":$_current_name" ] |
| + |
| + repack(_current_name) { |
| + forward_variables_from(invoker, |
| + [ |
| + "define_bundle_data", |
| + "bundle_output", |
| + "deps", |
| + "repack_whitelist", |
| + "testonly", |
| + ]) |
| + visibility = [ ":${invoker.target_name}" ] |
| + if (is_ios) { |
| + output = "$_output_dir/${_output_locale}.lproj/locale.pak" |
| + if (defined(define_bundle_data) && define_bundle_data && |
| + !defined(bundle_output)) { |
| + bundle_output = "{{bundle_resources_dir}}/${_output_locale}.lproj/{{source_file_part}}" |
| + } |
| + } else { |
| + output = "$_output_dir/${_output_locale}.pak" |
| + } |
| + set_sources_assignment_filter([]) |
| + sources = [] |
| + foreach(_pattern, invoker.source_patterns) { |
| + sources += [ "${_pattern}${_input_locale}.pak" ] |
| + } |
| + } |
| + |
| + _current_index = _current_index + 1 |
| } |
| - bundle_data(_bundle_target_name) { |
| + # The group that external targets depend on which collects all deps. |
| + group(target_name) { |
| forward_variables_from(invoker, |
| [ |
| - "testonly", |
| "visibility", |
| + "testonly", |
| ]) |
| - |
| - public_deps = [ |
| - ":$_repack_target_name", |
| - ] |
| - sources = [ |
| - invoker.output, |
| - ] |
| - if (defined(invoker.bundle_output)) { |
| - outputs = [ |
| - invoker.bundle_output, |
| - ] |
| - } else { |
| - outputs = [ |
| - "{{bundle_resources_dir}}/{{source_file_part}}", |
| - ] |
| - } |
| + public_deps = _locale_targets |
| } |
| } |