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 3# found in the LICENSE file. 4 5import("//build/config/features.gni") 6import("//build/config/ui.gni") 7import("//tools/grit/repack.gni") 8 9# Arguments: 10# 11# locale 12# Internal name of locale. e.g. "pt-BR" 13# 14# output 15# Output file name. 16# 17# visibility 18# Normal meaning. 19template("_repack_one_locale") { 20 locale = invoker.locale 21 22 repack(target_name) { 23 visibility = invoker.visibility 24 25 # Each input pak file should also have a deps line for completeness. 26 sources = [ 27 "${root_gen_dir}/chrome/app/resources/platform_locale_settings_${locale}.pak", 28 "${root_gen_dir}/chrome/generated_resources_${locale}.pak", 29 "${root_gen_dir}/chrome/locale_settings_${locale}.pak", 30 "${root_gen_dir}/components/strings/components_strings_${locale}.pak", 31 ] 32 deps = [ 33 "//chrome/app/resources:platform_locale_settings", 34 "//chrome/app:generated_resources", 35 "//chrome/app/resources:locale_settings", 36 "//components/strings", 37 ] 38 39 if (use_ash) { 40 sources += [ 41 "${root_gen_dir}/ash/strings/ash_strings_${locale}.pak", 42 ] 43 deps += [ 44 "//ash/strings", 45 ] 46 } 47 if (is_chromeos) { 48 sources += [ 49 "${root_gen_dir}/ui/chromeos/strings/ui_chromeos_strings_${locale}.pak", 50 ] 51 deps += [ 52 "//ui/chromeos/strings", 53 ] 54 } 55 if (!is_ios) { 56 sources += [ 57 "${root_gen_dir}/content/app/strings/content_strings_${locale}.pak", 58 "${root_gen_dir}/ui/strings/ui_strings_${locale}.pak", 59 "${root_gen_dir}/ui/strings/app_locale_settings_${locale}.pak", 60 ] 61 deps += [ 62 "//content/app/strings", 63 "//ui/strings:ui_strings", 64 "//ui/strings:app_locale_settings", 65 ] 66 } 67 if (enable_autofill_dialog && !is_ios && !is_android) { 68 sources += [ 69 "${root_gen_dir}/third_party/libaddressinput/address_input_strings_${locale}.pak", 70 ] 71 deps += [ 72 "//third_party/libaddressinput:strings", 73 ] 74 } 75 if (enable_extensions) { 76 sources += [ 77 "${root_gen_dir}/device/bluetooth/device_bluetooth_strings_${locale}.pak", 78 # TODO(jamescook): When Android stops building extensions code move 79 # this to the OS != 'ios' and OS != 'android' section. 80 "${root_gen_dir}/extensions/strings/extensions_strings_${locale}.pak", 81 ] 82 deps += [ 83 "//device/bluetooth:strings", 84 "//extensions/strings", 85 ] 86 } 87 88 if (is_chrome_branded) { 89 sources += [ 90 "${root_gen_dir}/chrome/google_chrome_strings_${locale}.pak", 91 ] 92 deps += [ 93 "//chrome/app:google_chrome_strings", 94 ] 95 } else { 96 sources += [ 97 "${root_gen_dir}/chrome/chromium_strings_${locale}.pak", 98 ] 99 deps += [ 100 "//chrome/app:chromium_strings", 101 ] 102 } 103 104 output = invoker.output 105 } 106} 107 108# Creates an action to call the repack_locales script. 109# 110# The GYP version generates the locales in the "gen" directory and then copies 111# it to the root build directory. This isn't easy to express in a GN copy 112# rule since the files on Mac have a complex structure. So we generate the 113# files into the final place and skip the "gen" directory. 114# 115# This template uses GN's looping constructs to avoid the complex call to 116# chrome/tools/build/repack_locales.py which wraps the repack commands in the 117# GYP build. 118# 119# Arguments 120# 121# input_locales 122# List of locale names to use as inputs. 123# 124# output_locales 125# A list containing the corresponding output names for each of the 126# input names. Mac uses different names in some cases. 127# 128# visibility 129template("chrome_repack_locales") { 130 # This is the name of the group below that will collect all the invidual 131 # locale targets. External targets will depend on this. 132 group_target_name = target_name 133 134 # GN's subscript is too stupid to do invoker.output_locales[foo] so we need 135 # to make a copy and do output_locales[foo]. 136 output_locales = invoker.output_locales 137 138 # Collects all targets the loop generates. 139 locale_targets = [] 140 141 # This loop iterates over the input locales and also keeps a counter so it 142 # can simultaneously iterate over the output locales (using GN's very 143 # limited looping capabilities). 144 current_index = 0 145 foreach(input_locale, invoker.input_locales) { 146 output_locale = output_locales[current_index] 147 148 # Compute the name of the target for the current file. Save it for the deps. 149 current_name = "${target_name}_${input_locale}" 150 locale_targets += [ ":$current_name" ] 151 152 _repack_one_locale(current_name) { 153 visibility = [ ":$group_target_name" ] 154 locale = input_locale 155 156 # Compute the output name. Mac uses a different location. 157 if (is_mac || is_ios) { 158 output = "${root_gen_dir}/repack/${output_locale}.lproj/locale.pak" 159 } else { 160 output = "${root_out_dir}/locales/${output_locale}.pak" 161 } 162 } 163 164 current_index = current_index + 1 165 } 166 167 # The group that external targets depend on which collects all deps. 168 group(group_target_name) { 169 if (defined(invoker.visibility)) { 170 visibility = invoker.visibility 171 } 172 deps = locale_targets 173 } 174} 175