| 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("//build/config/chrome_build.gni") | 5 import("//build/config/chrome_build.gni") |
| 6 import("//build/config/features.gni") | 6 import("//build/config/features.gni") |
| 7 import("//build/config/ui.gni") | 7 import("//build/config/ui.gni") |
| 8 import("//tools/grit/repack.gni") | 8 import("//tools/grit/repack.gni") |
| 9 | 9 |
| 10 # Wraps repack_locales(), setting the source_patterns and deps required for | 10 # Arguments: |
| 11 # Chrome. | |
| 12 # | 11 # |
| 13 # Extra Parameters: | 12 # locale |
| 13 # Internal name of locale. e.g. "pt-BR" |
| 14 # | 14 # |
| 15 # additional_source_patterns [optional] | 15 # output |
| 16 # Extra source_patterns for repack_locales(). | 16 # Output file name. |
| 17 template("chrome_repack_locales") { | 17 # |
| 18 repack_locales(target_name) { | 18 # visibility |
| 19 forward_variables_from(invoker, "*", [ "additional_source_patterns" ]) | 19 # Normal meaning. |
| 20 # |
| 21 # additional_source_patterns |
| 22 # The pattern of additional pak files which need repacked, the name of |
| 23 # pak always ends with '_${locale}.pak' e.g. foo_zh-CN.pak, since the |
| 24 # locale is argument of template, the sources in this list should be |
| 25 # the file name without '_${locale}.pak', tempate expands sources to |
| 26 # the full name, e.g |
| 27 # ${root_gen_dir}/foo expands to ${root_gen_dir}/foo_zh-CN.pak |
| 28 # when locale is zh-CN. |
| 29 # |
| 30 # additional_deps |
| 31 # The corresponding deps of additonal_source_patterns. |
| 32 # |
| 33 template("_repack_one_locale") { |
| 34 locale = invoker.locale |
| 20 | 35 |
| 21 # Each input pak file should also have a deps line. | 36 repack(target_name) { |
| 22 source_patterns = [ | 37 visibility = invoker.visibility |
| 23 "${root_gen_dir}/chrome/generated_resources_", | 38 |
| 24 "${root_gen_dir}/chrome/locale_settings_", | 39 # Each input pak file should also have a deps line for completeness. |
| 25 "${root_gen_dir}/chrome/platform_locale_settings_", | 40 sources = [ |
| 26 "${root_gen_dir}/components/strings/components_locale_settings_", | 41 "${root_gen_dir}/chrome/generated_resources_${locale}.pak", |
| 27 "${root_gen_dir}/components/strings/components_strings_", | 42 "${root_gen_dir}/chrome/locale_settings_${locale}.pak", |
| 43 "${root_gen_dir}/chrome/platform_locale_settings_${locale}.pak", |
| 44 "${root_gen_dir}/components/strings/components_locale_settings_${locale}.p
ak", |
| 45 "${root_gen_dir}/components/strings/components_strings_${locale}.pak", |
| 28 ] | 46 ] |
| 29 if (!defined(deps)) { | 47 deps = [ |
| 30 deps = [] | |
| 31 } | |
| 32 deps += [ | |
| 33 "//chrome/app:generated_resources", | 48 "//chrome/app:generated_resources", |
| 34 "//chrome/app/resources:locale_settings", | 49 "//chrome/app/resources:locale_settings", |
| 35 "//chrome/app/resources:platform_locale_settings", | 50 "//chrome/app/resources:platform_locale_settings", |
| 36 "//components/strings:components_locale_settings", | 51 "//components/strings:components_locale_settings", |
| 37 "//components/strings:components_strings", | 52 "//components/strings:components_strings", |
| 38 ] | 53 ] |
| 39 | 54 |
| 55 if (defined(invoker.additional_source_patterns)) { |
| 56 sources += process_file_template(invoker.additional_source_patterns, |
| 57 [ "{{source}}_${locale}.pak" ]) |
| 58 deps += invoker.additional_deps |
| 59 } |
| 60 |
| 40 if (use_ash) { | 61 if (use_ash) { |
| 41 source_patterns += [ "${root_gen_dir}/ash/common/strings/ash_strings_" ] | 62 sources += |
| 63 [ "${root_gen_dir}/ash/common/strings/ash_strings_${locale}.pak" ] |
| 42 deps += [ "//ash/common/strings" ] | 64 deps += [ "//ash/common/strings" ] |
| 43 } | 65 } |
| 44 if (is_chromeos) { | 66 if (is_chromeos) { |
| 45 source_patterns += [ | 67 sources += [ |
| 46 "${root_gen_dir}/remoting/resources/", | 68 "${root_gen_dir}/remoting/resources/${locale}.pak", |
| 47 "${root_gen_dir}/ui/chromeos/strings/ui_chromeos_strings_", | 69 "${root_gen_dir}/ui/chromeos/strings/ui_chromeos_strings_${locale}.pak", |
| 48 ] | 70 ] |
| 49 deps += [ | 71 deps += [ |
| 50 "//remoting/resources", | 72 "//remoting/resources", |
| 51 "//ui/chromeos/strings", | 73 "//ui/chromeos/strings", |
| 52 ] | 74 ] |
| 53 } | 75 } |
| 54 if (!is_ios) { | 76 if (!is_ios) { |
| 55 source_patterns += [ | 77 sources += [ |
| 56 "${root_gen_dir}/content/app/strings/content_strings_", | 78 "${root_gen_dir}/content/app/strings/content_strings_${locale}.pak", |
| 57 "${root_gen_dir}/device/bluetooth/strings/bluetooth_strings_", | 79 "${root_gen_dir}/device/bluetooth/strings/bluetooth_strings_${locale}.pa
k", |
| 58 "${root_gen_dir}/third_party/libaddressinput/address_input_strings_", | 80 "${root_gen_dir}/third_party/libaddressinput/address_input_strings_${loc
ale}.pak", |
| 59 "${root_gen_dir}/ui/strings/app_locale_settings_", | 81 "${root_gen_dir}/ui/strings/app_locale_settings_${locale}.pak", |
| 60 "${root_gen_dir}/ui/strings/ui_strings_", | 82 "${root_gen_dir}/ui/strings/ui_strings_${locale}.pak", |
| 61 ] | 83 ] |
| 62 deps += [ | 84 deps += [ |
| 63 "//content/app/strings", | 85 "//content/app/strings", |
| 64 "//device/bluetooth/strings", | 86 "//device/bluetooth/strings", |
| 65 "//third_party/libaddressinput:strings", | 87 "//third_party/libaddressinput:strings", |
| 66 "//ui/strings:app_locale_settings", | 88 "//ui/strings:app_locale_settings", |
| 67 "//ui/strings:ui_strings", | 89 "//ui/strings:ui_strings", |
| 68 ] | 90 ] |
| 69 } | 91 } |
| 70 if (enable_extensions) { | 92 if (enable_extensions) { |
| 71 source_patterns += [ | 93 sources += [ |
| 72 # TODO(jamescook): When Android stops building extensions code move | 94 # TODO(jamescook): When Android stops building extensions code move |
| 73 # this to the OS != 'ios' and OS != 'android' section. | 95 # this to the OS != 'ios' and OS != 'android' section. |
| 74 "${root_gen_dir}/extensions/strings/extensions_strings_", | 96 "${root_gen_dir}/extensions/strings/extensions_strings_${locale}.pak", |
| 75 ] | 97 ] |
| 76 deps += [ "//extensions/strings" ] | 98 deps += [ "//extensions/strings" ] |
| 77 } | 99 } |
| 78 | 100 |
| 79 if (is_chrome_branded) { | 101 if (is_chrome_branded) { |
| 80 source_patterns += [ | 102 sources += [ |
| 81 "${root_gen_dir}/chrome/google_chrome_strings_", | 103 "${root_gen_dir}/chrome/google_chrome_strings_${locale}.pak", |
| 82 "${root_gen_dir}/components/strings/components_google_chrome_strings_", | 104 "${root_gen_dir}/components/strings/components_google_chrome_strings_${l
ocale}.pak", |
| 83 ] | 105 ] |
| 84 deps += [ | 106 deps += [ |
| 85 "//chrome/app:google_chrome_strings", | 107 "//chrome/app:google_chrome_strings", |
| 86 "//components/strings:components_google_chrome_strings", | 108 "//components/strings:components_google_chrome_strings", |
| 87 ] | 109 ] |
| 88 } else { | 110 } else { |
| 89 source_patterns += [ | 111 sources += [ |
| 90 "${root_gen_dir}/chrome/chromium_strings_", | 112 "${root_gen_dir}/chrome/chromium_strings_${locale}.pak", |
| 91 "${root_gen_dir}/components/strings/components_chromium_strings_", | 113 "${root_gen_dir}/components/strings/components_chromium_strings_${locale
}.pak", |
| 92 ] | 114 ] |
| 93 deps += [ | 115 deps += [ |
| 94 "//chrome/app:chromium_strings", | 116 "//chrome/app:chromium_strings", |
| 95 "//components/strings:components_chromium_strings", | 117 "//components/strings:components_chromium_strings", |
| 96 ] | 118 ] |
| 97 } | 119 } |
| 98 | 120 |
| 99 if (defined(invoker.additional_source_patterns)) { | 121 if (enable_resource_whitelist_generation) { |
| 100 source_patterns += invoker.additional_source_patterns | 122 repack_whitelist = "$root_gen_dir/chrome/resource_whitelist.txt" |
| 123 deps += [ "//chrome:resource_whitelist" ] |
| 124 } |
| 125 output = invoker.output |
| 126 } |
| 127 } |
| 128 |
| 129 # Creates an action to call the repack_locales script. |
| 130 # |
| 131 # The GYP version generates the locales in the "gen" directory and then copies |
| 132 # it to the root build directory. This isn't easy to express in a GN copy |
| 133 # rule since the files on Mac have a complex structure. So we generate the |
| 134 # files into the final place and skip the "gen" directory. |
| 135 # |
| 136 # This template uses GN's looping constructs to avoid the complex call to |
| 137 # chrome/tools/build/repack_locales.py which wraps the repack commands in the |
| 138 # GYP build. |
| 139 # |
| 140 # Arguments |
| 141 # |
| 142 # input_locales |
| 143 # List of locale names to use as inputs. |
| 144 # |
| 145 # output_locales |
| 146 # A list containing the corresponding output names for each of the |
| 147 # input names. Mac uses different names in some cases. |
| 148 # |
| 149 # visibility |
| 150 # |
| 151 # additional_source_patterns |
| 152 # Pass to template("_repack_one_locale") |
| 153 # |
| 154 # additional_deps |
| 155 # Pass to template("_repack_one_locale") |
| 156 # |
| 157 # output_dir |
| 158 # this is used to override default output dir. |
| 159 # |
| 160 template("chrome_repack_locales") { |
| 161 # This is the name of the group below that will collect all the invidual |
| 162 # locale targets. External targets will depend on this. |
| 163 group_target_name = target_name |
| 164 |
| 165 # GN's subscript is too stupid to do invoker.output_locales[foo] so we need |
| 166 # to make a copy and do output_locales[foo]. |
| 167 output_locales = invoker.output_locales |
| 168 |
| 169 # Collects all targets the loop generates. |
| 170 locale_targets = [] |
| 171 |
| 172 # This loop iterates over the input locales and also keeps a counter so it |
| 173 # can simultaneously iterate over the output locales (using GN's very |
| 174 # limited looping capabilities). |
| 175 current_index = 0 |
| 176 foreach(input_locale, invoker.input_locales) { |
| 177 output_locale = output_locales[current_index] |
| 178 |
| 179 # Compute the name of the target for the current file. Save it for the deps. |
| 180 current_name = "${target_name}_${input_locale}" |
| 181 locale_targets += [ ":$current_name" ] |
| 182 |
| 183 _repack_one_locale(current_name) { |
| 184 visibility = [ ":$group_target_name" ] |
| 185 locale = input_locale |
| 186 |
| 187 # Compute the output name. Mac uses a different location. |
| 188 if (defined(invoker.output_dir)) { |
| 189 output = "${invoker.output_dir}/${output_locale}.pak" |
| 190 } else if (is_mac || is_ios) { |
| 191 output = "${root_gen_dir}/repack/locales/${output_locale}.pak" |
| 192 } else { |
| 193 output = "${root_out_dir}/locales/${output_locale}.pak" |
| 194 } |
| 195 |
| 196 if (defined(invoker.additional_source_patterns)) { |
| 197 additional_source_patterns = invoker.additional_source_patterns |
| 198 additional_deps = invoker.additional_deps |
| 199 } |
| 101 } | 200 } |
| 102 | 201 |
| 103 if (!defined(output_dir)) { | 202 current_index = current_index + 1 |
| 104 if (is_mac || is_ios) { | 203 } |
| 105 output_dir = "${root_gen_dir}/repack/locales" | 204 |
| 106 } else { | 205 # The group that external targets depend on which collects all deps. |
| 107 output_dir = "${root_out_dir}/locales" | 206 group(group_target_name) { |
| 108 } | 207 forward_variables_from(invoker, [ "visibility" ]) |
| 109 } | 208 public_deps = locale_targets |
| 110 } | 209 } |
| 111 } | 210 } |
| OLD | NEW |