Commit 7c1fd7c2 authored by Peter Wen's avatar Peter Wen Committed by Commit Bot

Android: Make apks files hermetic

Since bundletool does not produce hermetic zip files (apks files),
extract and re-zip so builds become deterministic again. Also localize
temp file/dir usage as much as possible.

Add .apks as a valid build artifact extension.

Fixed: 1008664
Change-Id: I72b237e49670c83c1aa48aa06795fb6d72dd43ba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1877150
Auto-Submit: Peter Wen <wnwen@chromium.org>
Reviewed-by: default avatarTakuto Ikuta <tikuta@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Commit-Queue: Peter Wen <wnwen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709005}
parent b39afd5a
...@@ -94,28 +94,36 @@ def GenerateBundleApks(bundle_path, ...@@ -94,28 +94,36 @@ def GenerateBundleApks(bundle_path,
def rebuild(): def rebuild():
logging.info('Building %s', bundle_apks_path) logging.info('Building %s', bundle_apks_path)
with tempfile.NamedTemporaryFile(suffix='.json') as spec_file, \ with tempfile.NamedTemporaryFile(suffix='.apks') as tmp_apks_file:
build_utils.AtomicOutput(bundle_apks_path, only_if_changed=False) as f:
cmd_args = [ cmd_args = [
'build-apks', 'build-apks',
'--aapt2=%s' % aapt2_path, '--aapt2=%s' % aapt2_path,
'--output=%s' % f.name, '--output=%s' % tmp_apks_file.name,
'--bundle=%s' % bundle_path, '--bundle=%s' % bundle_path,
'--ks=%s' % keystore_path, '--ks=%s' % keystore_path,
'--ks-pass=pass:%s' % keystore_password, '--ks-pass=pass:%s' % keystore_password,
'--ks-key-alias=%s' % keystore_alias, '--ks-key-alias=%s' % keystore_alias,
'--overwrite', '--overwrite',
] ]
if device_spec:
json.dump(device_spec, spec_file)
spec_file.flush()
cmd_args += ['--device-spec=' + spec_file.name]
if mode is not None: if mode is not None:
if mode not in BUILD_APKS_MODES: if mode not in BUILD_APKS_MODES:
raise Exception('Invalid mode parameter %s (should be in %s)' % raise Exception('Invalid mode parameter %s (should be in %s)' %
(mode, BUILD_APKS_MODES)) (mode, BUILD_APKS_MODES))
cmd_args += ['--mode=' + mode] cmd_args += ['--mode=' + mode]
bundletool.RunBundleTool(cmd_args)
with tempfile.NamedTemporaryFile(suffix='.json') as spec_file:
if device_spec:
json.dump(device_spec, spec_file)
spec_file.flush()
cmd_args += ['--device-spec=' + spec_file.name]
bundletool.RunBundleTool(cmd_args)
# Make the resulting .apks file hermetic.
with build_utils.TempDir() as temp_dir, \
build_utils.AtomicOutput(bundle_apks_path, only_if_changed=False) as f:
files = build_utils.ExtractAll(tmp_apks_file.name, temp_dir)
build_utils.DoZip(files, f, base_dir=temp_dir)
if check_for_noop: if check_for_noop:
# NOTE: BUNDLETOOL_JAR_PATH is added to input_strings, rather than # NOTE: BUNDLETOOL_JAR_PATH is added to input_strings, rather than
......
...@@ -29,6 +29,7 @@ def get_files_to_compare(build_dir, recursive=False): ...@@ -29,6 +29,7 @@ def get_files_to_compare(build_dir, recursive=False):
allowed = frozenset(( allowed = frozenset((
'.aab', '.aab',
'.apk', '.apk',
'.apks',
'.app', '.app',
'.bin', # V8 snapshot file snapshot_blob.bin '.bin', # V8 snapshot file snapshot_blob.bin
'.dll', '.dll',
......
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