Commit 659ad253 authored by sdefresne's avatar sdefresne Committed by Commit bot

Reland of Refactor the various locale_paks() templates to be more shared

Reverted by:
https://codereview.chromium.org/2338213002/

Reason for reland:
Now gn gens for enable_resource_whitelist_generation = true

Main motivation for this is to more easily add per-target
repack_whitelist.

TBR=michaelbai@chromium.org,thakis@chromium.org,agrieve@chromium.org,estevenson@chromium.org,rsesek@chromium.org,brettw@chromium.org
BUG=645716

Review-Url: https://codereview.chromium.org/2339213003
Cr-Commit-Position: refs/heads/master@{#418859}
parent 3d6d1455
# Copyright 2015 The Chromium Authors. All rights reserved. # Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
#
# This is a copy of src/chrome/chrome_repack_locales.gni with the necessary
# modifications to meet WebView's requirement.
import("//build/config/chrome_build.gni")
import("//build/config/features.gni")
import("//build/config/ui.gni")
import("//tools/grit/repack.gni") import("//tools/grit/repack.gni")
import("webview_repack_locales_list.gni") import("webview_repack_locales_list.gni")
# Arguments: # Wraps repack_locales(), setting the source_patterns and deps required for
# # Chrome.
# locale template("webview_repack_locales") {
# Internal name of locale. e.g. "pt-BR" repack_locales(target_name) {
# forward_variables_from(invoker, "*")
# output
# Output file name.
#
# visibility
# Normal meaning.
template("_repack_one_locale") {
locale = invoker.locale
repack(target_name) {
visibility = invoker.visibility
# Adding webview specific pak file? You should add it to # Adding webview specific pak file? You should add it to
# webview_repack_locales_source_patterns, so it is also included in # webview_repack_locales_source_patterns, so it is also included in
# Monochrome. # Monochrome.
# Each input pak file should also have a deps line for completeness. source_patterns = [
sources = [ "${root_gen_dir}/android_webview/components_strings_",
"${root_gen_dir}/android_webview/components_strings_${locale}.pak", "${root_gen_dir}/content/app/strings/content_strings_",
"${root_gen_dir}/content/app/strings/content_strings_${locale}.pak", "${root_gen_dir}/ui/strings/app_locale_settings_",
"${root_gen_dir}/ui/strings/app_locale_settings_${locale}.pak",
] ]
deps = [ deps = [
"//android_webview:generate_components_strings", "//android_webview:generate_components_strings",
"//content/app/strings", "//content/app/strings",
"//ui/strings:app_locale_settings", "//ui/strings:app_locale_settings",
] ]
sources += process_file_template(webview_repack_locales_source_patterns, source_patterns += webview_repack_locales_source_patterns
[ "{{source}}_${locale}.pak" ])
deps += webview_repack_locales_deps deps += webview_repack_locales_deps
output = invoker.output output_dir = "$root_out_dir/android_webview/locales"
}
}
# Creates an action to call the repack_locales script.
#
# The GYP version generates the locales in the "gen" directory and then copies
# it to the root build directory. This isn't easy to express in a GN copy
# rule since the files on Mac have a complex structure. So we generate the
# files into the final place and skip the "gen" directory.
#
# This template uses GN's looping constructs to avoid the complex call to
# chrome/tools/build/repack_locales.py which wraps the repack commands in the
# GYP build.
#
# Arguments
#
# input_locales
# List of locale names to use as inputs.
#
# output_locales
# A list containing the corresponding output names for each of the
# input names.
#
# visibility
template("webview_repack_locales") {
# This is the name of the group below that will collect all the invidual
# locale targets. External targets will depend on this.
group_target_name = target_name
# GN's subscript is too stupid to do invoker.output_locales[foo] so we need
# to make a copy and do output_locales[foo].
output_locales = invoker.output_locales
# Collects all targets the loop generates.
locale_targets = []
# 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_one_locale(current_name) {
visibility = [ ":$group_target_name" ]
locale = input_locale
output = "${root_out_dir}/android_webview/locales/${output_locale}.pak"
}
current_index = current_index + 1
}
# The group that external targets depend on which collects all deps.
group(group_target_name) {
forward_variables_from(invoker, [ "visibility" ])
public_deps = locale_targets
} }
} }
...@@ -5,6 +5,6 @@ ...@@ -5,6 +5,6 @@
# For how to add pattern, see additional_source_patterns argument of # For how to add pattern, see additional_source_patterns argument of
# _repack_one_locale in chrome/chrome_repack_locales.gni. # _repack_one_locale in chrome/chrome_repack_locales.gni.
webview_repack_locales_source_patterns = webview_repack_locales_source_patterns =
[ "${root_gen_dir}/android_webview/aw_strings" ] [ "${root_gen_dir}/android_webview/aw_strings_" ]
webview_repack_locales_deps = [ "//android_webview:generate_aw_strings" ] webview_repack_locales_deps = [ "//android_webview:generate_aw_strings" ]
...@@ -1453,7 +1453,7 @@ repack("packed_extra_resources") { ...@@ -1453,7 +1453,7 @@ repack("packed_extra_resources") {
if (enable_resource_whitelist_generation) { if (enable_resource_whitelist_generation) {
repack_whitelist = android_resource_whitelist repack_whitelist = android_resource_whitelist
deps += [ "//chrome:resource_whitelist" ] deps += [ ":resource_whitelist" ]
} }
} }
...@@ -1481,6 +1481,13 @@ chrome_repack_locales("repack_locales_pack") { ...@@ -1481,6 +1481,13 @@ chrome_repack_locales("repack_locales_pack") {
} else { } else {
output_locales = locales output_locales = locales
} }
if (enable_resource_whitelist_generation) {
repack_whitelist = android_resource_whitelist
deps = [
":resource_whitelist",
]
}
} }
chrome_repack_locales("repack_pseudo_locales_pack") { chrome_repack_locales("repack_pseudo_locales_pack") {
...@@ -1493,6 +1500,13 @@ chrome_repack_locales("repack_pseudo_locales_pack") { ...@@ -1493,6 +1500,13 @@ chrome_repack_locales("repack_pseudo_locales_pack") {
} else { } else {
output_locales = [ "fake-bidi" ] output_locales = [ "fake-bidi" ]
} }
if (enable_resource_whitelist_generation) {
repack_whitelist = android_resource_whitelist
deps = [
":resource_whitelist",
]
}
} }
# Generates a rule to repack a set of resources, substituting a given string # Generates a rule to repack a set of resources, substituting a given string
...@@ -1566,7 +1580,7 @@ template("chrome_repack_percent") { ...@@ -1566,7 +1580,7 @@ template("chrome_repack_percent") {
if (enable_resource_whitelist_generation) { if (enable_resource_whitelist_generation) {
repack_whitelist = android_resource_whitelist repack_whitelist = android_resource_whitelist
deps += [ "//chrome:resource_whitelist" ] deps += [ ":resource_whitelist" ]
} }
} }
......
...@@ -9,6 +9,6 @@ template("monochrome_repack_locales") { ...@@ -9,6 +9,6 @@ template("monochrome_repack_locales") {
chrome_repack_locales(target_name) { chrome_repack_locales(target_name) {
forward_variables_from(invoker, "*") forward_variables_from(invoker, "*")
additional_source_patterns = webview_repack_locales_source_patterns additional_source_patterns = webview_repack_locales_source_patterns
additional_deps = webview_repack_locales_deps deps = webview_repack_locales_deps
} }
} }
...@@ -7,44 +7,29 @@ import("//build/config/features.gni") ...@@ -7,44 +7,29 @@ import("//build/config/features.gni")
import("//build/config/ui.gni") import("//build/config/ui.gni")
import("//tools/grit/repack.gni") import("//tools/grit/repack.gni")
# Arguments: # Wraps repack_locales(), setting the source_patterns and deps required for
# Chrome.
# #
# locale # Extra Parameters:
# Internal name of locale. e.g. "pt-BR"
# #
# output # additional_source_patterns [optional]
# Output file name. # Extra source_patterns for repack_locales().
# template("chrome_repack_locales") {
# visibility repack_locales(target_name) {
# Normal meaning. forward_variables_from(invoker, "*", [ "additional_source_patterns" ])
#
# additional_source_patterns # Each input pak file should also have a deps line.
# The pattern of additional pak files which need repacked, the name of source_patterns = [
# pak always ends with '_${locale}.pak' e.g. foo_zh-CN.pak, since the "${root_gen_dir}/chrome/generated_resources_",
# locale is argument of template, the sources in this list should be "${root_gen_dir}/chrome/locale_settings_",
# the file name without '_${locale}.pak', tempate expands sources to "${root_gen_dir}/chrome/platform_locale_settings_",
# the full name, e.g "${root_gen_dir}/components/strings/components_locale_settings_",
# ${root_gen_dir}/foo expands to ${root_gen_dir}/foo_zh-CN.pak "${root_gen_dir}/components/strings/components_strings_",
# when locale is zh-CN.
#
# additional_deps
# The corresponding deps of additonal_source_patterns.
#
template("_repack_one_locale") {
locale = invoker.locale
repack(target_name) {
visibility = invoker.visibility
# Each input pak file should also have a deps line for completeness.
sources = [
"${root_gen_dir}/chrome/generated_resources_${locale}.pak",
"${root_gen_dir}/chrome/locale_settings_${locale}.pak",
"${root_gen_dir}/chrome/platform_locale_settings_${locale}.pak",
"${root_gen_dir}/components/strings/components_locale_settings_${locale}.pak",
"${root_gen_dir}/components/strings/components_strings_${locale}.pak",
] ]
deps = [ if (!defined(deps)) {
deps = []
}
deps += [
"//chrome/app:generated_resources", "//chrome/app:generated_resources",
"//chrome/app/resources:locale_settings", "//chrome/app/resources:locale_settings",
"//chrome/app/resources:platform_locale_settings", "//chrome/app/resources:platform_locale_settings",
...@@ -52,21 +37,14 @@ template("_repack_one_locale") { ...@@ -52,21 +37,14 @@ template("_repack_one_locale") {
"//components/strings:components_strings", "//components/strings:components_strings",
] ]
if (defined(invoker.additional_source_patterns)) {
sources += process_file_template(invoker.additional_source_patterns,
[ "{{source}}_${locale}.pak" ])
deps += invoker.additional_deps
}
if (use_ash) { if (use_ash) {
sources += source_patterns += [ "${root_gen_dir}/ash/common/strings/ash_strings_" ]
[ "${root_gen_dir}/ash/common/strings/ash_strings_${locale}.pak" ]
deps += [ "//ash/common/strings" ] deps += [ "//ash/common/strings" ]
} }
if (is_chromeos) { if (is_chromeos) {
sources += [ source_patterns += [
"${root_gen_dir}/remoting/resources/${locale}.pak", "${root_gen_dir}/remoting/resources/",
"${root_gen_dir}/ui/chromeos/strings/ui_chromeos_strings_${locale}.pak", "${root_gen_dir}/ui/chromeos/strings/ui_chromeos_strings_",
] ]
deps += [ deps += [
"//remoting/resources", "//remoting/resources",
...@@ -74,12 +52,12 @@ template("_repack_one_locale") { ...@@ -74,12 +52,12 @@ template("_repack_one_locale") {
] ]
} }
if (!is_ios) { if (!is_ios) {
sources += [ source_patterns += [
"${root_gen_dir}/content/app/strings/content_strings_${locale}.pak", "${root_gen_dir}/content/app/strings/content_strings_",
"${root_gen_dir}/device/bluetooth/strings/bluetooth_strings_${locale}.pak", "${root_gen_dir}/device/bluetooth/strings/bluetooth_strings_",
"${root_gen_dir}/third_party/libaddressinput/address_input_strings_${locale}.pak", "${root_gen_dir}/third_party/libaddressinput/address_input_strings_",
"${root_gen_dir}/ui/strings/app_locale_settings_${locale}.pak", "${root_gen_dir}/ui/strings/app_locale_settings_",
"${root_gen_dir}/ui/strings/ui_strings_${locale}.pak", "${root_gen_dir}/ui/strings/ui_strings_",
] ]
deps += [ deps += [
"//content/app/strings", "//content/app/strings",
...@@ -90,27 +68,27 @@ template("_repack_one_locale") { ...@@ -90,27 +68,27 @@ template("_repack_one_locale") {
] ]
} }
if (enable_extensions) { if (enable_extensions) {
sources += [ source_patterns += [
# TODO(jamescook): When Android stops building extensions code move # TODO(jamescook): When Android stops building extensions code move
# this to the OS != 'ios' and OS != 'android' section. # this to the OS != 'ios' and OS != 'android' section.
"${root_gen_dir}/extensions/strings/extensions_strings_${locale}.pak", "${root_gen_dir}/extensions/strings/extensions_strings_",
] ]
deps += [ "//extensions/strings" ] deps += [ "//extensions/strings" ]
} }
if (is_chrome_branded) { if (is_chrome_branded) {
sources += [ source_patterns += [
"${root_gen_dir}/chrome/google_chrome_strings_${locale}.pak", "${root_gen_dir}/chrome/google_chrome_strings_",
"${root_gen_dir}/components/strings/components_google_chrome_strings_${locale}.pak", "${root_gen_dir}/components/strings/components_google_chrome_strings_",
] ]
deps += [ deps += [
"//chrome/app:google_chrome_strings", "//chrome/app:google_chrome_strings",
"//components/strings:components_google_chrome_strings", "//components/strings:components_google_chrome_strings",
] ]
} else { } else {
sources += [ source_patterns += [
"${root_gen_dir}/chrome/chromium_strings_${locale}.pak", "${root_gen_dir}/chrome/chromium_strings_",
"${root_gen_dir}/components/strings/components_chromium_strings_${locale}.pak", "${root_gen_dir}/components/strings/components_chromium_strings_",
] ]
deps += [ deps += [
"//chrome/app:chromium_strings", "//chrome/app:chromium_strings",
...@@ -118,93 +96,16 @@ template("_repack_one_locale") { ...@@ -118,93 +96,16 @@ template("_repack_one_locale") {
] ]
} }
if (enable_resource_whitelist_generation) { if (defined(invoker.additional_source_patterns)) {
repack_whitelist = "$root_gen_dir/chrome/resource_whitelist.txt" source_patterns += invoker.additional_source_patterns
deps += [ "//chrome:resource_whitelist" ]
}
output = invoker.output
} }
}
# Creates an action to call the repack_locales script.
#
# The GYP version generates the locales in the "gen" directory and then copies
# it to the root build directory. This isn't easy to express in a GN copy
# rule since the files on Mac have a complex structure. So we generate the
# files into the final place and skip the "gen" directory.
#
# This template uses GN's looping constructs to avoid the complex call to
# chrome/tools/build/repack_locales.py which wraps the repack commands in the
# GYP build.
#
# Arguments
#
# input_locales
# List of locale names to use as inputs.
#
# output_locales
# A list containing the corresponding output names for each of the
# input names. Mac uses different names in some cases.
#
# visibility
#
# additional_source_patterns
# Pass to template("_repack_one_locale")
#
# additional_deps
# Pass to template("_repack_one_locale")
#
# output_dir
# this is used to override default output dir.
#
template("chrome_repack_locales") {
# This is the name of the group below that will collect all the invidual
# locale targets. External targets will depend on this.
group_target_name = target_name
# GN's subscript is too stupid to do invoker.output_locales[foo] so we need
# to make a copy and do output_locales[foo].
output_locales = invoker.output_locales
# Collects all targets the loop generates.
locale_targets = []
# This loop iterates over the input locales and also keeps a counter so it if (!defined(output_dir)) {
# can simultaneously iterate over the output locales (using GN's very if (is_mac || is_ios) {
# limited looping capabilities). output_dir = "${root_gen_dir}/repack/locales"
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_one_locale(current_name) {
visibility = [ ":$group_target_name" ]
locale = input_locale
# Compute the output name. Mac uses a different location.
if (defined(invoker.output_dir)) {
output = "${invoker.output_dir}/${output_locale}.pak"
} else if (is_mac || is_ios) {
output = "${root_gen_dir}/repack/locales/${output_locale}.pak"
} else { } else {
output = "${root_out_dir}/locales/${output_locale}.pak" output_dir = "${root_out_dir}/locales"
} }
if (defined(invoker.additional_source_patterns)) {
additional_source_patterns = invoker.additional_source_patterns
additional_deps = invoker.additional_deps
} }
} }
current_index = current_index + 1
}
# The group that external targets depend on which collects all deps.
group(group_target_name) {
forward_variables_from(invoker, [ "visibility" ])
public_deps = locale_targets
}
} }
...@@ -39,7 +39,7 @@ ios_chrome_repack_all_scales("repack_scalable_resources") { ...@@ -39,7 +39,7 @@ ios_chrome_repack_all_scales("repack_scalable_resources") {
] ]
} }
ios_repack("repack_unscaled_resources") { repack("repack_unscaled_resources") {
visibility = [ ":packed_resources" ] visibility = [ ":packed_resources" ]
sources = [ sources = [
"$root_gen_dir/components/components_resources.pak", "$root_gen_dir/components/components_resources.pak",
...@@ -56,5 +56,5 @@ ios_repack("repack_unscaled_resources") { ...@@ -56,5 +56,5 @@ ios_repack("repack_unscaled_resources") {
"//ui/resources", "//ui/resources",
] ]
output = "$target_gen_dir/resources.pak" output = "$target_gen_dir/resources.pak"
bundle_output = "{{bundle_resources_dir}}/{{source_file_part}}" copy_data_to_bundle = true
} }
...@@ -5,93 +5,20 @@ ...@@ -5,93 +5,20 @@
import("//tools/grit/repack.gni") import("//tools/grit/repack.gni")
import("//build/config/chrome_build.gni") import("//build/config/chrome_build.gni")
# Template to repack resources and copy them to the application bundles. # Wraps repack_locales(), setting the source_patterns and deps required for
# # Chrome.
# Arguments # Generates a collection of bundle_data targets.
# template("ios_chrome_repack_locales") {
# deps repack_locales(target_name) {
# list of strings corresponding to target labels. forward_variables_from(invoker, "*")
# source_patterns = [
# sources "${root_gen_dir}/components/strings/components_${branding_path_component}_strings_",
# list of strings corresponding to path to resources pak to pack. "${root_gen_dir}/components/strings/components_locale_settings_",
# "${root_gen_dir}/components/strings/components_strings_",
# output "${root_gen_dir}/ios/chrome/ios_${branding_path_component}_strings_",
# string, path of the packed resources. "${root_gen_dir}/ios/chrome/ios_strings_",
# "${root_gen_dir}/ui/strings/app_locale_settings_",
# bundle_output "${root_gen_dir}/ui/strings/ui_strings_",
# string, path of the packed resources in the bundle.
#
# Generates a bundle_data target for convenience.
template("ios_repack") {
assert(defined(invoker.deps), "deps must be defined for $target_name")
assert(defined(invoker.sources), "sources must be defined for $target_name")
assert(defined(invoker.output), "output must be defined for $target_name")
assert(defined(invoker.bundle_output),
"bundle_output must be defined for $target_name")
_target_name = target_name
repack("${_target_name}_pack") {
forward_variables_from(invoker, [ "testonly" ])
visibility = [ ":${_target_name}" ]
sources = invoker.sources
output = invoker.output
deps = invoker.deps
}
bundle_data(_target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
public_deps = [
":${_target_name}_pack",
]
sources = [
invoker.output,
]
outputs = [
invoker.bundle_output,
]
}
}
# Template to repack all resources for a given locale.
#
# Arguments
#
# input_locale
# string, name of the locale to pack.
#
# output_locale
# string, name of the locale (may be different from input_locale
# as iOS and Chrome not use the same convention for naming locales
# with country variant).
#
# Generates a bundle_data target for convenience.
template("_ios_chrome_repack_one_locale") {
assert(defined(invoker.input_locale),
"input_locale must be defined for ${target_name}")
assert(defined(invoker.output_locale),
"output_locale must be defined for ${target_name}")
ios_repack(target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
sources = [
"${root_gen_dir}/components/strings/components_${branding_path_component}_strings_${invoker.input_locale}.pak",
"${root_gen_dir}/components/strings/components_locale_settings_${invoker.input_locale}.pak",
"${root_gen_dir}/components/strings/components_strings_${invoker.input_locale}.pak",
"${root_gen_dir}/ios/chrome/ios_${branding_path_component}_strings_${invoker.input_locale}.pak",
"${root_gen_dir}/ios/chrome/ios_strings_${invoker.input_locale}.pak",
"${root_gen_dir}/ui/strings/app_locale_settings_${invoker.input_locale}.pak",
"${root_gen_dir}/ui/strings/ui_strings_${invoker.input_locale}.pak",
] ]
deps = [ deps = [
...@@ -104,60 +31,7 @@ template("_ios_chrome_repack_one_locale") { ...@@ -104,60 +31,7 @@ template("_ios_chrome_repack_one_locale") {
"//ui/strings:ui_strings", "//ui/strings:ui_strings",
] ]
output = "${target_gen_dir}/${invoker.output_locale}.lproj/locale.pak" copy_data_to_bundle = true
bundle_output = "{{bundle_resources_dir}}/${invoker.output_locale}.lproj" +
"/{{source_file_part}}"
}
}
# Template to repack all resources for all locales.
#
# Arguments
#
# input_locales
# list of strings corresponding to all locales to pack.
#
# output_locales
# list of strings corresponding to all locales to pack (may be
# different from input_locales as iOS and Chrome do not use the
# same convention for naming locales with country variant).
#
# Must be the same length as input_locales.
#
# Generates a collection of bundle_data targets for convenience.
template("ios_chrome_repack_locales") {
assert(defined(invoker.input_locales),
"input_locales must be defined for ${target_name}")
assert(defined(invoker.output_locales),
"output_locales must be defined for ${target_name}")
_target_name = target_name
_locale_targets = []
_output_locales = invoker.output_locales
_current_index = 0
foreach(_input_locale, invoker.input_locales) {
_output_locale = _output_locales[_current_index]
_locale_targets += [ ":${_target_name}_${_input_locale}" ]
_ios_chrome_repack_one_locale("${_target_name}_${_input_locale}") {
forward_variables_from(invoker, [ "testonly" ])
visibility = [ ":${_target_name}" ]
input_locale = _input_locale
output_locale = _output_locale
}
_current_index = _current_index + 1
}
group(_target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
public_deps = _locale_targets
} }
} }
...@@ -172,7 +46,7 @@ template("ios_chrome_repack_locales") { ...@@ -172,7 +46,7 @@ template("ios_chrome_repack_locales") {
template("_ios_chrome_repack_one_scale") { template("_ios_chrome_repack_one_scale") {
assert(defined(invoker.scale), "scale must be defined for ${target_name}") assert(defined(invoker.scale), "scale must be defined for ${target_name}")
ios_repack(target_name) { repack(target_name) {
forward_variables_from(invoker, forward_variables_from(invoker,
[ [
"testonly", "testonly",
...@@ -191,7 +65,7 @@ template("_ios_chrome_repack_one_scale") { ...@@ -191,7 +65,7 @@ template("_ios_chrome_repack_one_scale") {
] ]
output = "$target_gen_dir/chrome_${invoker.scale}_percent.pak" output = "$target_gen_dir/chrome_${invoker.scale}_percent.pak"
bundle_output = "{{bundle_resources_dir}}/{{source_file_part}}" copy_data_to_bundle = true
} }
} }
......
...@@ -4,122 +4,24 @@ ...@@ -4,122 +4,24 @@
import("//tools/grit/repack.gni") import("//tools/grit/repack.gni")
# Pack all resources for an application extension for a given locale. # Pack all resources for an application extension for all locales.
# #
# Arguments: # Arguments (in addition to those from repack_locales):
# #
# extension [required] # extension [required]
# name of the application extension. # name of the application extension.
# #
# input_locale [required] template("extension_repack_all_locales") {
# name of the locale to pack. # Wraps repack_locales(), setting the source_patterns and deps required for
# # Chrome.
# output_locale [required] # Generates a collection of bundle_data targets.
# name of the locale (may be different from input_locale as iOS repack_locales(target_name) {
# and Chrome does not use the same convention for naming locales forward_variables_from(invoker, "*", [ "extension" ])
# with country variants).
#
# copy_data_to_bundle [required]
# controls whether bundle_data targets are defined to copy the repacked
# data into the final bundle.
#
# visibility [optional]
# usual meaning.
#
template("_extension_repack_one_locale") {
assert(defined(invoker.extension), "Need extension for $target_name")
assert(defined(invoker.input_locale), "Need input_locale for $target_name")
assert(defined(invoker.output_locale), "Need output_locale for $target_name")
if (invoker.copy_data_to_bundle) {
_target_type = "repack_and_bundle"
} else {
_target_type = "repack"
}
target(_target_type, target_name) { source_patterns = [ "$root_gen_dir/ios/${invoker.extension}/ios_${invoker.extension}_strings_" ]
forward_variables_from(invoker, [ "visibility" ])
deps = [ deps = [
"//ios/chrome/${invoker.extension}/strings", "//ios/chrome/${invoker.extension}/strings",
] ]
sources = [
"$root_gen_dir/ios/${invoker.extension}/" +
"ios_${invoker.extension}_strings_${invoker.input_locale}.pak",
]
output = "$target_gen_dir/${invoker.output_locale}.lproj/locale.pak"
if (invoker.copy_data_to_bundle) {
bundle_output = "{{bundle_resources_dir}}/" +
"${invoker.output_locale}.lproj/locale.pak"
}
}
}
# Pack all resources for an application extension for all locales.
#
# Arguments:
#
# extension [required]
# name of the application extension.
#
# input_locales [required]
# list of all locales to pack.
#
# output_locales [required]
# list of all locales in application bundle (may differ from input
# locales as iOS and Chrome does not use the same convention for
# naming locales with country variants).
#
# Must be the same length as input_locales.
#
# copy_data_to_bundle [optional]
# controls whether bundle_data targets are defined to copy the repacked
# data into the final bundle (defaults to true if not defined).
#
# visibility [optional]
# usual meaning.
#
template("extension_repack_all_locales") {
assert(defined(invoker.extension), "Need extension for $target_name")
assert(defined(invoker.input_locales), "Need input_locales for $target_name")
assert(defined(invoker.output_locales),
"Need output_locales for $target_name")
_target_name = target_name
_copy_data_to_bundle = true
if (defined(invoker.copy_data_to_bundle)) {
_copy_data_to_bundle = invoker.copy_data_to_bundle
}
# TODO(614747): GN parser does not grok invoker.output_locales[foo]. Use a
# local variables to workaround this issue until the issue is fixed.
_current_locale = 0
_output_locales = invoker.output_locales
# Collect all locale targets to avoid looping twice over the locales.
_locale_targets = []
foreach(_input_locale, invoker.input_locales) {
_output_locale = _output_locales[_current_locale]
_locale_target = _target_name + "_$_input_locale"
_extension_repack_one_locale(_locale_target) {
visibility = [ ":$_target_name" ]
input_locale = _input_locale
output_locale = _output_locale
extension = invoker.extension
copy_data_to_bundle = _copy_data_to_bundle
}
_locale_targets += [ ":$_locale_target" ]
_current_locale = _current_locale + 1
}
group(_target_name) {
forward_variables_from(invoker, [ "visibility" ])
public_deps = _locale_targets
} }
} }
...@@ -12,7 +12,6 @@ group("resources") { ...@@ -12,7 +12,6 @@ group("resources") {
} }
extension_repack_all_locales("packed_resources") { extension_repack_all_locales("packed_resources") {
copy_data_to_bundle = false
extension = "share_extension" extension = "share_extension"
input_locales = ios_packed_locales input_locales = ios_packed_locales
output_locales = ios_packed_locales_as_mac_outputs output_locales = ios_packed_locales_as_mac_outputs
......
...@@ -15,4 +15,5 @@ extension_repack_all_locales("packed_resources") { ...@@ -15,4 +15,5 @@ extension_repack_all_locales("packed_resources") {
extension = "today_extension" extension = "today_extension"
input_locales = ios_packed_locales input_locales = ios_packed_locales
output_locales = ios_packed_locales_as_mac_outputs output_locales = ios_packed_locales_as_mac_outputs
copy_data_to_bundle = true
} }
...@@ -14,7 +14,7 @@ mojom("mojo_bindings") { ...@@ -14,7 +14,7 @@ mojom("mojo_bindings") {
use_new_wrapper_types = false use_new_wrapper_types = false
} }
repack_and_bundle("packed_resources") { repack("packed_resources") {
testonly = true testonly = true
sources = [ sources = [
"$root_gen_dir/ios/web/ios_web_resources.pak", "$root_gen_dir/ios/web/ios_web_resources.pak",
...@@ -25,7 +25,7 @@ repack_and_bundle("packed_resources") { ...@@ -25,7 +25,7 @@ repack_and_bundle("packed_resources") {
"//ios/web:resources", "//ios/web:resources",
] ]
output = "$target_gen_dir/resources.pak" output = "$target_gen_dir/resources.pak"
bundle_output = "{{bundle_resources_dir}}/{{source_file_part}}" copy_data_to_bundle = true
} }
grit("resources") { grit("resources") {
......
...@@ -13,12 +13,26 @@ import("//tools/grit/grit_rule.gni") ...@@ -13,12 +13,26 @@ import("//tools/grit/grit_rule.gni")
# output [required] # output [required]
# File name (single string) of the output file. # File name (single string) of the output file.
# #
# copy_data_to_bundle [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] # deps [optional]
# public_deps [optional] # public_deps [optional]
# visibility [optional] # visibility [optional]
# Normal meaning. # Normal meaning.
template("repack") { template("repack") {
action(target_name) { _copy_data_to_bundle =
defined(invoker.copy_data_to_bundle) && invoker.copy_data_to_bundle
_repack_target_name = target_name
if (_copy_data_to_bundle) {
_repack_target_name = "${target_name}__repack"
}
action(_repack_target_name) {
forward_variables_from(invoker, forward_variables_from(invoker,
[ [
"deps", "deps",
...@@ -26,6 +40,9 @@ template("repack") { ...@@ -26,6 +40,9 @@ template("repack") {
"testonly", "testonly",
"visibility", "visibility",
]) ])
if (defined(visibility) && _copy_data_to_bundle) {
visibility += [ ":${invoker.target_name}" ]
}
assert(defined(invoker.sources), "Need sources for $target_name") assert(defined(invoker.sources), "Need sources for $target_name")
assert(defined(invoker.output), "Need output for $target_name") assert(defined(invoker.output), "Need output for $target_name")
...@@ -46,63 +63,124 @@ template("repack") { ...@@ -46,63 +63,124 @@ template("repack") {
args += [ rebase_path(invoker.output, root_build_dir) ] args += [ rebase_path(invoker.output, root_build_dir) ]
args += rebase_path(invoker.sources, root_build_dir) args += rebase_path(invoker.sources, root_build_dir)
} }
if (_copy_data_to_bundle) {
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 # Repacks a set of .pak files for each locale.
# to move them to the application bundle. This is mostly useful on iOS.
# #
# Parameters: # Parameters:
# sources [required]
# List of pak files that need to be combined.
# #
# output [required] # input_locales [required]
# File name (single string) of the output file. # List of locale names to use as inputs.
# #
# bundle_output [optional] # output_locales [required]
# Path of the file in the application bundle, defaults to # A list containing the corresponding output names for each of the
# {{bundle_resources_dir}}/{{source_file_part}} if omitted. # input names. Mac and iOS use different names in some cases.
#
# 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] # deps [optional]
# visibility [optional] # visibility [optional]
# testonly [optional]
# copy_data_to_bundle [optional]
# repack_whitelist [optional]
# Normal meaning. # Normal meaning.
template("repack_and_bundle") { template("repack_locales") {
assert(defined(invoker.bundle_output), "Need bundle_output for $target_name") # GN can't handle invoker.output_locales[foo] (http://crbug.com/614747).
_output_locales = invoker.output_locales
if (defined(invoker.output_dir)) {
_output_dir = invoker.output_dir
} else {
if (is_ios) {
_output_dir = "$target_gen_dir"
} else {
_output_dir = "$target_gen_dir/$target_name"
}
}
# Collects all targets the loop generates.
_locale_targets = []
_repack_target_name = target_name + "_repack" # This loop iterates over the input locales and also keeps a counter so it
_bundle_target_name = target_name # 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]
repack(_repack_target_name) { # Compute the name of the target for the current file. Save it for the deps.
visibility = [ ":$_bundle_target_name" ] _current_name = "${target_name}_${_input_locale}"
_locale_targets += [ ":$_current_name" ]
repack(_current_name) {
forward_variables_from(invoker, forward_variables_from(invoker,
[ [
"copy_data_to_bundle",
"bundle_output",
"deps", "deps",
"output", "repack_whitelist",
"sources",
"testonly", "testonly",
]) ])
visibility = [ ":${invoker.target_name}" ]
if (is_ios) {
output = "$_output_dir/${_output_locale}.lproj/locale.pak"
if (defined(copy_data_to_bundle) && copy_data_to_bundle) {
bundle_output =
"{{bundle_resources_dir}}/${_output_locale}.lproj/locale.pak"
}
} 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, forward_variables_from(invoker,
[ [
"testonly",
"visibility", "visibility",
"testonly",
]) ])
public_deps = _locale_targets
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}}",
]
}
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment