Commit d6c25a7f authored by agrieve's avatar agrieve Committed by Commit bot

Revert of 🍵 Refactor the various locale_paks() templates to be more shared...

Revert of 🍵 Refactor the various locale_paks() templates to be more shared (patchset #7 id:120001 of https://codereview.chromium.org/2320883006/ )

Reason for revert:
gn gen fails when enable_resource_whitelist_generation=true

Original issue's description:
> Refactor the various locale_paks() templates to be more shared
>
> Main motivation for this is to more easily add per-target
> repack_whitelist.
>
> BUG=645716
>
> Committed: https://crrev.com/61973f5b2e2d7cf070c89043768b4a3e0025b19a
> Cr-Commit-Position: refs/heads/master@{#418327}

TBR=michaelbai@chromium.org,thakis@chromium.org,sdefresne@chromium.org,estevenson@chromium.org,rsesek@chromium.org,brettw@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=645716

Review-Url: https://codereview.chromium.org/2340673002
Cr-Commit-Position: refs/heads/master@{#418418}
parent b5aa9139
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# 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("webview_repack_locales_list.gni")
# Wraps repack_locales(), setting the source_patterns and deps required for
# Chrome.
template("webview_repack_locales") {
repack_locales(target_name) {
forward_variables_from(invoker, "*")
# Arguments:
#
# locale
# Internal name of locale. e.g. "pt-BR"
#
# 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
# webview_repack_locales_source_patterns, so it is also included in
# Monochrome.
source_patterns = [
"${root_gen_dir}/android_webview/components_strings_",
"${root_gen_dir}/content/app/strings/content_strings_",
"${root_gen_dir}/ui/strings/app_locale_settings_",
# Each input pak file should also have a deps line for completeness.
sources = [
"${root_gen_dir}/android_webview/components_strings_${locale}.pak",
"${root_gen_dir}/content/app/strings/content_strings_${locale}.pak",
"${root_gen_dir}/ui/strings/app_locale_settings_${locale}.pak",
]
deps = [
"//android_webview:generate_components_strings",
"//content/app/strings",
"//ui/strings:app_locale_settings",
]
source_patterns += webview_repack_locales_source_patterns
sources += process_file_template(webview_repack_locales_source_patterns,
[ "{{source}}_${locale}.pak" ])
deps += webview_repack_locales_deps
output_dir = "$root_out_dir/android_webview/locales"
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.
#
# 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 @@
# For how to add pattern, see additional_source_patterns argument of
# _repack_one_locale in chrome/chrome_repack_locales.gni.
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" ]
......@@ -1481,11 +1481,6 @@ chrome_repack_locales("repack_locales_pack") {
} else {
output_locales = locales
}
if (enable_resource_whitelist_generation) {
repack_whitelist = android_resource_whitelist
deps += [ "//chrome:resource_whitelist" ]
}
}
chrome_repack_locales("repack_pseudo_locales_pack") {
......@@ -1498,11 +1493,6 @@ chrome_repack_locales("repack_pseudo_locales_pack") {
} else {
output_locales = [ "fake-bidi" ]
}
if (enable_resource_whitelist_generation) {
repack_whitelist = android_resource_whitelist
deps += [ "//chrome:resource_whitelist" ]
}
}
# Generates a rule to repack a set of resources, substituting a given string
......
......@@ -9,6 +9,6 @@ template("monochrome_repack_locales") {
chrome_repack_locales(target_name) {
forward_variables_from(invoker, "*")
additional_source_patterns = webview_repack_locales_source_patterns
deps = webview_repack_locales_deps
additional_deps = webview_repack_locales_deps
}
}
......@@ -7,29 +7,44 @@ import("//build/config/features.gni")
import("//build/config/ui.gni")
import("//tools/grit/repack.gni")
# Wraps repack_locales(), setting the source_patterns and deps required for
# Chrome.
# Arguments:
#
# Extra Parameters:
# locale
# Internal name of locale. e.g. "pt-BR"
#
# additional_source_patterns [optional]
# Extra source_patterns for repack_locales().
template("chrome_repack_locales") {
repack_locales(target_name) {
forward_variables_from(invoker, "*", [ "additional_source_patterns" ])
# Each input pak file should also have a deps line.
source_patterns = [
"${root_gen_dir}/chrome/generated_resources_",
"${root_gen_dir}/chrome/locale_settings_",
"${root_gen_dir}/chrome/platform_locale_settings_",
"${root_gen_dir}/components/strings/components_locale_settings_",
"${root_gen_dir}/components/strings/components_strings_",
# output
# Output file name.
#
# visibility
# Normal meaning.
#
# additional_source_patterns
# The pattern of additional pak files which need repacked, the name of
# pak always ends with '_${locale}.pak' e.g. foo_zh-CN.pak, since the
# locale is argument of template, the sources in this list should be
# the file name without '_${locale}.pak', tempate expands sources to
# the full name, e.g
# ${root_gen_dir}/foo expands to ${root_gen_dir}/foo_zh-CN.pak
# 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",
]
if (!defined(deps)) {
deps = []
}
deps += [
deps = [
"//chrome/app:generated_resources",
"//chrome/app/resources:locale_settings",
"//chrome/app/resources:platform_locale_settings",
......@@ -37,14 +52,21 @@ template("chrome_repack_locales") {
"//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) {
source_patterns += [ "${root_gen_dir}/ash/common/strings/ash_strings_" ]
sources +=
[ "${root_gen_dir}/ash/common/strings/ash_strings_${locale}.pak" ]
deps += [ "//ash/common/strings" ]
}
if (is_chromeos) {
source_patterns += [
"${root_gen_dir}/remoting/resources/",
"${root_gen_dir}/ui/chromeos/strings/ui_chromeos_strings_",
sources += [
"${root_gen_dir}/remoting/resources/${locale}.pak",
"${root_gen_dir}/ui/chromeos/strings/ui_chromeos_strings_${locale}.pak",
]
deps += [
"//remoting/resources",
......@@ -52,12 +74,12 @@ template("chrome_repack_locales") {
]
}
if (!is_ios) {
source_patterns += [
"${root_gen_dir}/content/app/strings/content_strings_",
"${root_gen_dir}/device/bluetooth/strings/bluetooth_strings_",
"${root_gen_dir}/third_party/libaddressinput/address_input_strings_",
"${root_gen_dir}/ui/strings/app_locale_settings_",
"${root_gen_dir}/ui/strings/ui_strings_",
sources += [
"${root_gen_dir}/content/app/strings/content_strings_${locale}.pak",
"${root_gen_dir}/device/bluetooth/strings/bluetooth_strings_${locale}.pak",
"${root_gen_dir}/third_party/libaddressinput/address_input_strings_${locale}.pak",
"${root_gen_dir}/ui/strings/app_locale_settings_${locale}.pak",
"${root_gen_dir}/ui/strings/ui_strings_${locale}.pak",
]
deps += [
"//content/app/strings",
......@@ -68,27 +90,27 @@ template("chrome_repack_locales") {
]
}
if (enable_extensions) {
source_patterns += [
sources += [
# TODO(jamescook): When Android stops building extensions code move
# this to the OS != 'ios' and OS != 'android' section.
"${root_gen_dir}/extensions/strings/extensions_strings_",
"${root_gen_dir}/extensions/strings/extensions_strings_${locale}.pak",
]
deps += [ "//extensions/strings" ]
}
if (is_chrome_branded) {
source_patterns += [
"${root_gen_dir}/chrome/google_chrome_strings_",
"${root_gen_dir}/components/strings/components_google_chrome_strings_",
sources += [
"${root_gen_dir}/chrome/google_chrome_strings_${locale}.pak",
"${root_gen_dir}/components/strings/components_google_chrome_strings_${locale}.pak",
]
deps += [
"//chrome/app:google_chrome_strings",
"//components/strings:components_google_chrome_strings",
]
} else {
source_patterns += [
"${root_gen_dir}/chrome/chromium_strings_",
"${root_gen_dir}/components/strings/components_chromium_strings_",
sources += [
"${root_gen_dir}/chrome/chromium_strings_${locale}.pak",
"${root_gen_dir}/components/strings/components_chromium_strings_${locale}.pak",
]
deps += [
"//chrome/app:chromium_strings",
......@@ -96,16 +118,93 @@ template("chrome_repack_locales") {
]
}
if (defined(invoker.additional_source_patterns)) {
source_patterns += invoker.additional_source_patterns
if (enable_resource_whitelist_generation) {
repack_whitelist = "$root_gen_dir/chrome/resource_whitelist.txt"
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
if (!defined(output_dir)) {
if (is_mac || is_ios) {
output_dir = "${root_gen_dir}/repack/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
# 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 {
output_dir = "${root_out_dir}/locales"
output = "${root_out_dir}/locales/${output_locale}.pak"
}
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") {
]
}
repack("repack_unscaled_resources") {
ios_repack("repack_unscaled_resources") {
visibility = [ ":packed_resources" ]
sources = [
"$root_gen_dir/components/components_resources.pak",
......@@ -56,5 +56,5 @@ repack("repack_unscaled_resources") {
"//ui/resources",
]
output = "$target_gen_dir/resources.pak"
copy_data_to_bundle = true
bundle_output = "{{bundle_resources_dir}}/{{source_file_part}}"
}
......@@ -5,20 +5,93 @@
import("//tools/grit/repack.gni")
import("//build/config/chrome_build.gni")
# Wraps repack_locales(), setting the source_patterns and deps required for
# Chrome.
# Generates a collection of bundle_data targets.
template("ios_chrome_repack_locales") {
repack_locales(target_name) {
forward_variables_from(invoker, "*")
source_patterns = [
"${root_gen_dir}/components/strings/components_${branding_path_component}_strings_",
"${root_gen_dir}/components/strings/components_locale_settings_",
"${root_gen_dir}/components/strings/components_strings_",
"${root_gen_dir}/ios/chrome/ios_${branding_path_component}_strings_",
"${root_gen_dir}/ios/chrome/ios_strings_",
"${root_gen_dir}/ui/strings/app_locale_settings_",
"${root_gen_dir}/ui/strings/ui_strings_",
# Template to repack resources and copy them to the application bundles.
#
# Arguments
#
# deps
# list of strings corresponding to target labels.
#
# sources
# list of strings corresponding to path to resources pak to pack.
#
# output
# string, path of the packed resources.
#
# bundle_output
# 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 = [
......@@ -31,7 +104,60 @@ template("ios_chrome_repack_locales") {
"//ui/strings:ui_strings",
]
copy_data_to_bundle = true
output = "${target_gen_dir}/${invoker.output_locale}.lproj/locale.pak"
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
}
}
......@@ -46,7 +172,7 @@ template("ios_chrome_repack_locales") {
template("_ios_chrome_repack_one_scale") {
assert(defined(invoker.scale), "scale must be defined for ${target_name}")
repack(target_name) {
ios_repack(target_name) {
forward_variables_from(invoker,
[
"testonly",
......@@ -65,7 +191,7 @@ template("_ios_chrome_repack_one_scale") {
]
output = "$target_gen_dir/chrome_${invoker.scale}_percent.pak"
copy_data_to_bundle = true
bundle_output = "{{bundle_resources_dir}}/{{source_file_part}}"
}
}
......
......@@ -4,24 +4,122 @@
import("//tools/grit/repack.gni")
# Pack all resources for an application extension for all locales.
# Pack all resources for an application extension for a given locale.
#
# Arguments (in addition to those from repack_locales):
# Arguments:
#
# extension [required]
# name of the application extension.
#
template("extension_repack_all_locales") {
# Wraps repack_locales(), setting the source_patterns and deps required for
# Chrome.
# Generates a collection of bundle_data targets.
repack_locales(target_name) {
forward_variables_from(invoker, "*", [ "extension" ])
# input_locale [required]
# name of the locale to pack.
#
# output_locale [required]
# name of the locale (may be different from input_locale as iOS
# and Chrome does not use the same convention for naming locales
# 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"
}
source_patterns = [ "$root_gen_dir/ios/${invoker.extension}/ios_${invoker.extension}_strings_" ]
target(_target_type, target_name) {
forward_variables_from(invoker, [ "visibility" ])
deps = [
"//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,6 +12,7 @@ group("resources") {
}
extension_repack_all_locales("packed_resources") {
copy_data_to_bundle = false
extension = "share_extension"
input_locales = ios_packed_locales
output_locales = ios_packed_locales_as_mac_outputs
......
......@@ -15,5 +15,4 @@ extension_repack_all_locales("packed_resources") {
extension = "today_extension"
input_locales = ios_packed_locales
output_locales = ios_packed_locales_as_mac_outputs
copy_data_to_bundle = true
}
......@@ -14,7 +14,7 @@ mojom("mojo_bindings") {
use_new_wrapper_types = false
}
repack("packed_resources") {
repack_and_bundle("packed_resources") {
testonly = true
sources = [
"$root_gen_dir/ios/web/ios_web_resources.pak",
......@@ -25,7 +25,7 @@ repack("packed_resources") {
"//ios/web:resources",
]
output = "$target_gen_dir/resources.pak"
copy_data_to_bundle = true
bundle_output = "{{bundle_resources_dir}}/{{source_file_part}}"
}
grit("resources") {
......
......@@ -13,26 +13,12 @@ import("//tools/grit/grit_rule.gni")
# output [required]
# 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]
# public_deps [optional]
# visibility [optional]
# Normal meaning.
template("repack") {
_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) {
action(target_name) {
forward_variables_from(invoker,
[
"deps",
......@@ -40,9 +26,6 @@ template("repack") {
"testonly",
"visibility",
])
if (defined(visibility) && _copy_data_to_bundle) {
visibility += [ ":${invoker.target_name}" ]
}
assert(defined(invoker.sources), "Need sources for $target_name")
assert(defined(invoker.output), "Need output for $target_name")
......@@ -63,119 +46,63 @@ template("repack") {
args += [ rebase_path(invoker.output, 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}}",
]
}
}
}
}
# Repacks a set of .pak files for each locale.
# This template combines repacking resources and defining a bundle_data target
# to move them to the application bundle. This is mostly useful on iOS.
#
# Parameters:
# sources [required]
# List of pak files that need to be combined.
#
# input_locales [required]
# List of locale names to use as inputs.
#
# output_locales [required]
# A list containing the corresponding output names for each of the
# 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 [required]
# File name (single string) of the output file.
#
# output_dir [optional]
# Directory in which to put all pak files.
# bundle_output [optional]
# Path of the file in the application bundle, defaults to
# {{bundle_resources_dir}}/{{source_file_part}} if omitted.
#
# deps [optional]
# visibility [optional]
# testonly [optional]
# copy_data_to_bundle [optional]
# repack_whitelist [optional]
# Normal meaning.
template("repack_locales") {
# GN can't handle invoker.output_locales[foo] (http://crbug.com/614747).
_output_locales = invoker.output_locales
_output_dir = "$target_gen_dir/$target_name"
if (defined(invoker.output_dir)) {
_output_dir = invoker.output_dir
}
# 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" ]
template("repack_and_bundle") {
assert(defined(invoker.bundle_output), "Need bundle_output for $target_name")
repack(_current_name) {
forward_variables_from(invoker,
[
"copy_data_to_bundle",
"bundle_output",
"deps",
"repack_whitelist",
"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" ]
}
}
_repack_target_name = target_name + "_repack"
_bundle_target_name = target_name
_current_index = _current_index + 1
repack(_repack_target_name) {
visibility = [ ":$_bundle_target_name" ]
forward_variables_from(invoker,
[
"deps",
"output",
"sources",
"testonly",
])
}
# The group that external targets depend on which collects all deps.
group(target_name) {
bundle_data(_bundle_target_name) {
forward_variables_from(invoker,
[
"visibility",
"testonly",
"visibility",
])
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