Allow "optimize_for" param for bundletool.

TBR=agrieve@chromium.org

Bug: 1123319
Change-Id: Ib60d02dd820e2f60a9ab6b7f9f0380b4af839d02
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2390863
Commit-Queue: Ben Mason <benmason@chromium.org>
Reviewed-by: Ben Mason <benmason@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803947}
GitOrigin-RevId: a270ae9a2998a3f3031e8e2af3fe69a5a33852ce
This commit is contained in:
Ben Mason 2020-09-02 19:11:26 +00:00 коммит произвёл Copybara-Service
Родитель c8b72be369
Коммит 01f9622579
2 изменённых файлов: 25 добавлений и 4 удалений

Просмотреть файл

@ -96,7 +96,8 @@ def _GenerateBundleApks(info,
output_path=None,
minimal=False,
minimal_sdk_version=None,
mode=None):
mode=None,
optimize_for=None):
"""Generate an .apks archive from a bundle on demand.
Args:
@ -105,6 +106,8 @@ def _GenerateBundleApks(info,
minimal: Create the minimal set of apks possible (english-only).
minimal_sdk_version: When minimal=True, use this sdkVersion.
mode: Build mode, either None, or one of app_bundle_utils.BUILD_APKS_MODES.
optimize_for: Override split config, either None, or one of
app_bundle_utils.OPTIMIZE_FOR_OPTIONS.
"""
logging.info('Generating .apks file')
app_bundle_utils.GenerateBundleApks(
@ -118,7 +121,8 @@ def _GenerateBundleApks(info,
system_image_locales=info.system_image_locales,
mode=mode,
minimal=minimal,
minimal_sdk_version=minimal_sdk_version)
minimal_sdk_version=minimal_sdk_version,
optimize_for=optimize_for)
def _InstallBundle(devices, apk_helper_instance, package_name,
@ -1732,6 +1736,10 @@ class _BuildBundleApks(_Command):
'single universal APK, "system" generates an archive with a system '
'image APK, while "system_compressed" generates a compressed system '
'APK, with an additional stub APK for the system image.')
group.add_argument(
'--optimize-for',
choices=app_bundle_utils.OPTIMIZE_FOR_OPTIONS,
help='Override split configuration.')
def Run(self):
_GenerateBundleApks(
@ -1739,7 +1747,8 @@ class _BuildBundleApks(_Command):
output_path=self.args.output_apks,
minimal=self.args.minimal,
minimal_sdk_version=self.args.sdk_version,
mode=self.args.build_mode)
mode=self.args.build_mode,
optimize_for=self.args.optimize_for)
class _ManifestCommand(_Command):

Просмотреть файл

@ -18,6 +18,8 @@ import bundletool
# List of valid modes for GenerateBundleApks()
BUILD_APKS_MODES = ('default', 'universal', 'system', 'system_compressed')
OPTIMIZE_FOR_OPTIONS = ('ABI', 'SCREEN_DENSITY', 'LANGUAGE',
'TEXTURE_COMPRESSION_FORMAT')
_SYSTEM_MODES = ('system_compressed', 'system')
_ALL_ABIS = ['armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64']
@ -50,7 +52,8 @@ def GenerateBundleApks(bundle_path,
minimal=False,
minimal_sdk_version=None,
check_for_noop=True,
system_image_locales=None):
system_image_locales=None,
optimize_for=None):
"""Generate an .apks archive from a an app bundle if needed.
Args:
@ -68,6 +71,8 @@ def GenerateBundleApks(bundle_path,
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".
optimize_for: Overrides split configuration, which must be None or
one of OPTIMIZE_FOR_OPTIONS.
"""
device_spec = None
if minimal_sdk_version:
@ -110,6 +115,13 @@ def GenerateBundleApks(bundle_path,
(mode, BUILD_APKS_MODES))
cmd_args += ['--mode=' + mode]
if optimize_for:
if optimize_for not in OPTIMIZE_FOR_OPTIONS:
raise Exception('Invalid optimize_for parameter %s '
'(should be in %s)' %
(mode, OPTIMIZE_FOR_OPTIONS))
cmd_args += ['--optimize-for=' + optimize_for]
with tempfile.NamedTemporaryFile(suffix='.json') as spec_file:
if device_spec:
json.dump(device_spec, spec_file)