Skip to content

Commit

Permalink
Reland "Android: Update bundletool version to 0.9.0."
Browse files Browse the repository at this point in the history
Original commit 56e27b2.

bundletool build-apks system modes now require a device spec. This CL
adds a device spec that contains the locales that should be
present in system images.

Change-Id: Ia956ea961fdf207af481a504351e469e18ecd0c3
Bug: 945418
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1542218
Commit-Queue: Eric Stevenson <estevenson@chromium.org>
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#645765}
  • Loading branch information
Eric Stevenson authored and Commit Bot committed Mar 29, 2019
1 parent cfd9be4 commit a522e05
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 33 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ deps = {
'packages': [
{
'package': 'chromium/third_party/android_tools_bundletool',
'version': 'GpDcZ4f-UcI4u6Kk7Ud-vtiLMltFr8vW63-NThsB5tEC',
'version': 'Z272op8PxTBt5cUJ8aE0NXam_SO7tp-0T0R1woZ0XN0C',
},
],
'condition': 'checkout_android',
Expand Down
17 changes: 11 additions & 6 deletions build/android/apk_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ def install(device):
# keystore_path: Path to keystore file.
# keystore_password: Password for the keystore file.
# keystore_alias: Signing key name alias within the keystore file.
# system_image_locales: List of Chromium locales to include in system .apks.
BundleGenerationInfo = collections.namedtuple(
'BundleGenerationInfo',
'bundle_path,bundle_apks_path,aapt2_path,keystore_path,keystore_password,'
'keystore_alias')
'keystore_alias,system_image_locales')


def _GenerateBundleApks(info,
Expand All @@ -117,6 +118,7 @@ def _GenerateBundleApks(info,
info.keystore_path,
info.keystore_password,
info.keystore_alias,
system_image_locales=info.system_image_locales,
mode=mode,
minimal=minimal,
minimal_sdk_version=minimal_sdk_version)
Expand Down Expand Up @@ -1564,10 +1566,10 @@ def Run(output_directory, apk_path, incremental_json, command_line_flags_file,
_RunInternal(parser, output_directory=output_directory)


def RunForBundle(output_directory, bundle_path, bundle_apks_path,
aapt2_path, keystore_path, keystore_password,
keystore_alias, package_name, command_line_flags_file,
proguard_mapping_path, target_cpu):
def RunForBundle(output_directory, bundle_path, bundle_apks_path, aapt2_path,
keystore_path, keystore_password, keystore_alias, package_name,
command_line_flags_file, proguard_mapping_path, target_cpu,
system_image_locales):
"""Entry point for generated app bundle wrapper scripts.
Args:
Expand All @@ -1584,6 +1586,8 @@ def RunForBundle(output_directory, bundle_path, bundle_apks_path,
proguard_mapping_path: Input path to the Proguard mapping file, used to
deobfuscate Java stack traces.
target_cpu: Chromium target CPU name, used by the 'gdb' command.
system_image_locales: List of Chromium locales that should be included in
system image APKs.
"""
constants.SetOutputDirectory(output_directory)
devil_chromium.Initialize(output_directory=output_directory)
Expand All @@ -1593,7 +1597,8 @@ def RunForBundle(output_directory, bundle_path, bundle_apks_path,
aapt2_path=aapt2_path,
keystore_path=keystore_path,
keystore_password=keystore_password,
keystore_alias=keystore_alias)
keystore_alias=keystore_alias,
system_image_locales=system_image_locales)

parser = argparse.ArgumentParser()
parser.set_defaults(
Expand Down
2 changes: 1 addition & 1 deletion build/android/gyp/bundletool.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
__file__, '..', '..', '..', '..', 'third_party', 'android_build_tools',
'bundletool'))

BUNDLETOOL_VERSION = '0.8.0'
BUNDLETOOL_VERSION = '0.9.0'

BUNDLETOOL_JAR_PATH = os.path.join(
BUNDLETOOL_DIR, 'bundletool-all-%s.jar' % BUNDLETOOL_VERSION)
Expand Down
22 changes: 22 additions & 0 deletions build/android/gyp/create_app_bundle_minimal_apks.pydeps
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Generated by running:
# build/print_python_deps.py --root build/android/gyp --output build/android/gyp/create_app_bundle_minimal_apks.pydeps build/android/gyp/create_app_bundle_minimal_apks.py
../../../third_party/jinja2/__init__.py
../../../third_party/jinja2/_compat.py
../../../third_party/jinja2/bccache.py
../../../third_party/jinja2/compiler.py
../../../third_party/jinja2/defaults.py
../../../third_party/jinja2/environment.py
../../../third_party/jinja2/exceptions.py
../../../third_party/jinja2/filters.py
../../../third_party/jinja2/idtracking.py
../../../third_party/jinja2/lexer.py
../../../third_party/jinja2/loaders.py
../../../third_party/jinja2/nodes.py
../../../third_party/jinja2/optimizer.py
../../../third_party/jinja2/parser.py
../../../third_party/jinja2/runtime.py
../../../third_party/jinja2/tests.py
../../../third_party/jinja2/utils.py
../../../third_party/jinja2/visitor.py
../../../third_party/markupsafe/__init__.py
../../../third_party/markupsafe/_compat.py
../../../third_party/markupsafe/_native.py
../../gn_helpers.py
../pylib/__init__.py
../pylib/utils/__init__.py
Expand All @@ -9,3 +30,4 @@ create_app_bundle_minimal_apks.py
util/__init__.py
util/build_utils.py
util/md5_check.py
util/resource_utils.py
42 changes: 29 additions & 13 deletions build/android/gyp/create_bundle_wrapper_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def main():
package_name=${PACKAGE_NAME},
command_line_flags_file=${FLAGS_FILE},
proguard_mapping_path=resolve(${MAPPING_PATH}),
target_cpu=${TARGET_CPU})
target_cpu=${TARGET_CPU},
system_image_locales=${SYSTEM_IMAGE_LOCALES})
if __name__ == '__main__':
sys.exit(main())
Expand All @@ -64,6 +65,7 @@ def main(args):
parser.add_argument('--command-line-flags-file')
parser.add_argument('--proguard-mapping-path')
parser.add_argument('--target-cpu')
parser.add_argument('--system-image-locales')
args = parser.parse_args(args)

def relativize(path):
Expand All @@ -77,18 +79,32 @@ def relativize(path):

with open(args.script_output_path, 'w') as script:
script_dict = {
'WRAPPED_SCRIPT_DIR': repr(wrapped_script_dir),
'OUTPUT_DIR': repr(relativize('.')),
'BUNDLE_PATH': repr(relativize(args.bundle_path)),
'BUNDLE_APKS_PATH': repr(relativize(args.bundle_apks_path)),
'PACKAGE_NAME': repr(args.package_name),
'AAPT2_PATH': repr(relativize(args.aapt2_path)),
'KEYSTORE_PATH': repr(relativize(args.keystore_path)),
'KEYSTORE_PASSWORD': repr(args.keystore_password),
'KEY_NAME': repr(args.key_name),
'MAPPING_PATH': repr(relativize(args.proguard_mapping_path)),
'FLAGS_FILE': repr(args.command_line_flags_file),
'TARGET_CPU': repr(args.target_cpu),
'WRAPPED_SCRIPT_DIR':
repr(wrapped_script_dir),
'OUTPUT_DIR':
repr(relativize('.')),
'BUNDLE_PATH':
repr(relativize(args.bundle_path)),
'BUNDLE_APKS_PATH':
repr(relativize(args.bundle_apks_path)),
'PACKAGE_NAME':
repr(args.package_name),
'AAPT2_PATH':
repr(relativize(args.aapt2_path)),
'KEYSTORE_PATH':
repr(relativize(args.keystore_path)),
'KEYSTORE_PASSWORD':
repr(args.keystore_password),
'KEY_NAME':
repr(args.key_name),
'MAPPING_PATH':
repr(relativize(args.proguard_mapping_path)),
'FLAGS_FILE':
repr(args.command_line_flags_file),
'TARGET_CPU':
repr(args.target_cpu),
'SYSTEM_IMAGE_LOCALES':
repr(build_utils.ParseGnList(args.system_image_locales)),
}
script.write(SCRIPT_TEMPLATE.substitute(script_dict))
os.chmod(args.script_output_path, 0750)
Expand Down
22 changes: 22 additions & 0 deletions build/android/gyp/create_bundle_wrapper_script.pydeps
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@
../../../third_party/catapult/devil/devil/utils/watchdog_timer.py
../../../third_party/catapult/devil/devil/utils/zip_utils.py
../../../third_party/catapult/third_party/zipfile/zipfile_2_7_13.py
../../../third_party/jinja2/__init__.py
../../../third_party/jinja2/_compat.py
../../../third_party/jinja2/bccache.py
../../../third_party/jinja2/compiler.py
../../../third_party/jinja2/defaults.py
../../../third_party/jinja2/environment.py
../../../third_party/jinja2/exceptions.py
../../../third_party/jinja2/filters.py
../../../third_party/jinja2/idtracking.py
../../../third_party/jinja2/lexer.py
../../../third_party/jinja2/loaders.py
../../../third_party/jinja2/nodes.py
../../../third_party/jinja2/optimizer.py
../../../third_party/jinja2/parser.py
../../../third_party/jinja2/runtime.py
../../../third_party/jinja2/tests.py
../../../third_party/jinja2/utils.py
../../../third_party/jinja2/visitor.py
../../../third_party/markupsafe/__init__.py
../../../third_party/markupsafe/_compat.py
../../../third_party/markupsafe/_native.py
../../gn_helpers.py
../apk_operations.py
../devil_chromium.py
Expand All @@ -78,3 +99,4 @@ create_bundle_wrapper_script.py
util/__init__.py
util/build_utils.py
util/md5_check.py
util/resource_utils.py
31 changes: 23 additions & 8 deletions build/android/pylib/utils/app_bundle_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,24 @@

from util import build_utils
from util import md5_check
from util import resource_utils
import bundletool

# List of valid modes for GenerateBundleApks()
BUILD_APKS_MODES = ('default', 'universal', 'system', 'system_compressed')
_SYSTEM_MODES = ('system_compressed', 'system')

_ALL_ABIS = ['armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64']


def _CreateMinimalDeviceSpec(bundle_path, sdk_version):
def _CreateDeviceSpec(bundle_path, sdk_version, locales):
# Could also use "bundletool dump resources", but reading directly is faster.
if not sdk_version:
with zipfile.ZipFile(bundle_path) as f:
manifest_data = f.read('base/manifest/AndroidManifest.xml')
sdk_version = int(
re.search(r'minSdkVersion.*?(\d+)', manifest_data).group(1))

# Measure with one language split installed. Use Hindi because it is popular.
# resource_size.py looks for splits/base-hi.apk.
# Note: English is always included since it's in base-master.apk.
locales = ['hi']
# Setting sdkVersion=minSdkVersion prevents multiple per-minSdkVersion .apk
# files from being created within the .apks file.
return {
Expand All @@ -53,7 +51,8 @@ def GenerateBundleApks(bundle_path,
mode=None,
minimal=False,
minimal_sdk_version=None,
check_for_noop=True):
check_for_noop=True,
system_image_locales=None):
"""Generate an .apks archive from a an app bundle if needed.
Args:
Expand All @@ -66,12 +65,28 @@ def GenerateBundleApks(bundle_path,
keystore_alias: Keystore signing key alias.
mode: Build mode, which must be either None or one of BUILD_APKS_MODES.
minimal: Create the minimal set of apks possible (english-only).
minimal_sdk_version: When minimal=True, use this sdkVersion.
minimal_sdk_version: Use this sdkVersion when |minimal| or
|system_image_locales| args are present.
check_for_noop: Use md5_check to short-circuit when inputs have not changed.
system_image_locales: Locales to package in the APK when mode is "system"
or "system_compressed".
"""
device_spec = None
if minimal:
device_spec = _CreateMinimalDeviceSpec(bundle_path, minimal_sdk_version)
# Measure with one language split installed. Use Hindi because it is
# popular. resource_size.py looks for splits/base-hi.apk.
# Note: English is always included since it's in base-master.apk.
device_spec = _CreateDeviceSpec(bundle_path, minimal_sdk_version, ['hi'])
elif mode in _SYSTEM_MODES:
if not system_image_locales:
raise Exception('system modes require system_image_locales')
# Bundletool doesn't seem to understand device specs with locales in the
# form of "<lang>-r<region>", so just provide the language code instead.
locales = [
resource_utils.ToAndroidLocaleName(l).split('-')[0]
for l in system_image_locales
]
device_spec = _CreateDeviceSpec(bundle_path, minimal_sdk_version, locales)

def rebuild():
logging.info('Building %s', bundle_apks_path)
Expand Down
8 changes: 8 additions & 0 deletions build/config/android/rules.gni
Original file line number Diff line number Diff line change
Expand Up @@ -4052,6 +4052,9 @@ if (enable_java_templates) {
# such that they are extracted upon install. Libraries prefixed with
# "crazy." are never compressed.
#
# system_image_locale_whitelist: List of locales that should be included
# on system APKs generated from this bundle.
#
# Example:
# android_app_bundle("chrome_public_bundle") {
# base_module_target = "//chrome/android:chrome_public_apk"
Expand Down Expand Up @@ -4423,6 +4426,11 @@ if (enable_java_templates) {
"--key-name",
_keystore_name,
]
if (defined(invoker.system_image_locale_whitelist)) {
args += [
"--system-image-locales=${invoker.system_image_locale_whitelist}",
]
}
if (defined(invoker.command_line_flags_file)) {
args += [
"--command-line-flags-file",
Expand Down
2 changes: 2 additions & 0 deletions chrome/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2142,6 +2142,8 @@ template("monochrome_public_bundle_tmpl") {
bundle_name = _bundle_name
base_module_target = ":$_base_module_target_name"
command_line_flags_file = "chrome-command-line"
system_image_locale_whitelist = locales - android_chrome_omitted_locales

if (!is_java_debug) {
proguard_enabled = true
proguard_android_sdk_dep = webview_framework_dep
Expand Down
2 changes: 1 addition & 1 deletion third_party/android_build_tools/bundletool/README.chromium
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Name: Android SDK bundletool
Short Name: bundletool
Version: 0.8.0
Version: 0.9.0
License: Apache Version 2.0
License File: NOT_SHIPPED
Security Critical: No
Expand Down
6 changes: 3 additions & 3 deletions third_party/android_build_tools/bundletool/cipd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
# Remember to increment the versions for the commands in this comment block.
# Before creating a new CIPD package run the following to make sure the tag you
# are adding does not already exist (otherwise you break the build):
# cipd describe chromium/third_party/android_tools_bundletool -version "version:0.8.0-cr0"
# cipd describe chromium/third_party/android_tools_bundletool -version "version:0.9.0-cr0"
# To create CIPD package run the following command.
# cipd create --pkg-def cipd.yaml -tag version:0.8.0-cr0
# cipd create --pkg-def cipd.yaml -tag version:0.9.0-cr0
package: chromium/third_party/android_tools_bundletool
description: Android SDK tool to manage App Bundles
data:
- file: bundletool-all-0.8.0.jar
- file: bundletool-all-0.9.0.jar

0 comments on commit a522e05

Please sign in to comment.