OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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/repack.gni") | 5 import("//tools/grit/repack.gni") |
6 | 6 |
7 # Pack all resources for an application extension for all locales. | 7 # Pack all resources for an application extension for a given locale. |
8 # | 8 # |
9 # Arguments (in addition to those from repack_locales): | 9 # Arguments: |
10 # | 10 # |
11 # extension [required] | 11 # extension [required] |
12 # name of the application extension. | 12 # name of the application extension. |
13 # | 13 # |
14 template("extension_repack_all_locales") { | 14 # input_locale [required] |
15 # Wraps repack_locales(), setting the source_patterns and deps required for | 15 # name of the locale to pack. |
16 # Chrome. | 16 # |
17 # Generates a collection of bundle_data targets. | 17 # output_locale [required] |
18 repack_locales(target_name) { | 18 # name of the locale (may be different from input_locale as iOS |
19 forward_variables_from(invoker, "*", [ "extension" ]) | 19 # and Chrome does not use the same convention for naming locales |
| 20 # with country variants). |
| 21 # |
| 22 # copy_data_to_bundle [required] |
| 23 # controls whether bundle_data targets are defined to copy the repacked |
| 24 # data into the final bundle. |
| 25 # |
| 26 # visibility [optional] |
| 27 # usual meaning. |
| 28 # |
| 29 template("_extension_repack_one_locale") { |
| 30 assert(defined(invoker.extension), "Need extension for $target_name") |
| 31 assert(defined(invoker.input_locale), "Need input_locale for $target_name") |
| 32 assert(defined(invoker.output_locale), "Need output_locale for $target_name") |
20 | 33 |
21 source_patterns = [ "$root_gen_dir/ios/${invoker.extension}/ios_${invoker.ex
tension}_strings_" ] | 34 if (invoker.copy_data_to_bundle) { |
| 35 _target_type = "repack_and_bundle" |
| 36 } else { |
| 37 _target_type = "repack" |
| 38 } |
| 39 |
| 40 target(_target_type, target_name) { |
| 41 forward_variables_from(invoker, [ "visibility" ]) |
22 | 42 |
23 deps = [ | 43 deps = [ |
24 "//ios/chrome/${invoker.extension}/strings", | 44 "//ios/chrome/${invoker.extension}/strings", |
25 ] | 45 ] |
| 46 |
| 47 sources = [ |
| 48 "$root_gen_dir/ios/${invoker.extension}/" + |
| 49 "ios_${invoker.extension}_strings_${invoker.input_locale}.pak", |
| 50 ] |
| 51 |
| 52 output = "$target_gen_dir/${invoker.output_locale}.lproj/locale.pak" |
| 53 if (invoker.copy_data_to_bundle) { |
| 54 bundle_output = "{{bundle_resources_dir}}/" + |
| 55 "${invoker.output_locale}.lproj/locale.pak" |
| 56 } |
26 } | 57 } |
27 } | 58 } |
| 59 |
| 60 # Pack all resources for an application extension for all locales. |
| 61 # |
| 62 # Arguments: |
| 63 # |
| 64 # extension [required] |
| 65 # name of the application extension. |
| 66 # |
| 67 # input_locales [required] |
| 68 # list of all locales to pack. |
| 69 # |
| 70 # output_locales [required] |
| 71 # list of all locales in application bundle (may differ from input |
| 72 # locales as iOS and Chrome does not use the same convention for |
| 73 # naming locales with country variants). |
| 74 # |
| 75 # Must be the same length as input_locales. |
| 76 # |
| 77 # copy_data_to_bundle [optional] |
| 78 # controls whether bundle_data targets are defined to copy the repacked |
| 79 # data into the final bundle (defaults to true if not defined). |
| 80 # |
| 81 # visibility [optional] |
| 82 # usual meaning. |
| 83 # |
| 84 template("extension_repack_all_locales") { |
| 85 assert(defined(invoker.extension), "Need extension for $target_name") |
| 86 assert(defined(invoker.input_locales), "Need input_locales for $target_name") |
| 87 assert(defined(invoker.output_locales), |
| 88 "Need output_locales for $target_name") |
| 89 |
| 90 _target_name = target_name |
| 91 |
| 92 _copy_data_to_bundle = true |
| 93 if (defined(invoker.copy_data_to_bundle)) { |
| 94 _copy_data_to_bundle = invoker.copy_data_to_bundle |
| 95 } |
| 96 |
| 97 # TODO(614747): GN parser does not grok invoker.output_locales[foo]. Use a |
| 98 # local variables to workaround this issue until the issue is fixed. |
| 99 _current_locale = 0 |
| 100 _output_locales = invoker.output_locales |
| 101 |
| 102 # Collect all locale targets to avoid looping twice over the locales. |
| 103 _locale_targets = [] |
| 104 |
| 105 foreach(_input_locale, invoker.input_locales) { |
| 106 _output_locale = _output_locales[_current_locale] |
| 107 |
| 108 _locale_target = _target_name + "_$_input_locale" |
| 109 _extension_repack_one_locale(_locale_target) { |
| 110 visibility = [ ":$_target_name" ] |
| 111 input_locale = _input_locale |
| 112 output_locale = _output_locale |
| 113 extension = invoker.extension |
| 114 copy_data_to_bundle = _copy_data_to_bundle |
| 115 } |
| 116 |
| 117 _locale_targets += [ ":$_locale_target" ] |
| 118 _current_locale = _current_locale + 1 |
| 119 } |
| 120 |
| 121 group(_target_name) { |
| 122 forward_variables_from(invoker, [ "visibility" ]) |
| 123 public_deps = _locale_targets |
| 124 } |
| 125 } |
OLD | NEW |