Commit 5308435f authored by Peter Wen's avatar Peter Wen Committed by Commit Bot

Android: Use a deterministic tmpdir for resources

Some generated .pb files embed the absolute path of a bundle's resources
and cause the resulting .aab file to be non-deterministic due to these
resources being stored in a temp directory. Make an explicitly named
temp directory as a sibling directory to the output so that the
resulting .aab is deterministic.

An upstream fix is tracked in b/131222965.

Tbr: ntfschr@chromium.org for android_webview/tools/apk_merger.py
Bug: 939984
Change-Id: I80a8bb082393ede4f92bf70a4857de994363567a
Fixed: 939984
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1891433
Commit-Queue: Peter Wen <wnwen@chromium.org>
Reviewed-by: default avatarBen Mason <benmason@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Reviewed-by: default avatarEric Stevenson <estevenson@chromium.org>
Auto-Submit: Peter Wen <wnwen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712146}
parent 4a870319
...@@ -181,7 +181,7 @@ def MergeApk(args, tmp_apk, tmp_dir_32, tmp_dir_64): ...@@ -181,7 +181,7 @@ def MergeApk(args, tmp_apk, tmp_dir_32, tmp_dir_64):
if args.bundle: if args.bundle:
# if merging a bundle we must ignore the bundle specific # if merging a bundle we must ignore the bundle specific
# proto files as they will always be different. # proto files as they will always be different.
ignores += ['BundleConfig.pb', 'native.pb', 'resources.pb'] ignores += ['BundleConfig.pb', 'native.pb']
dcmp = filecmp.dircmp( dcmp = filecmp.dircmp(
tmp_dir_64, tmp_dir_64,
......
...@@ -22,7 +22,6 @@ import re ...@@ -22,7 +22,6 @@ import re
import shutil import shutil
import subprocess import subprocess
import sys import sys
import tempfile
import textwrap import textwrap
import zipfile import zipfile
from xml.etree import ElementTree from xml.etree import ElementTree
...@@ -911,14 +910,19 @@ def main(args): ...@@ -911,14 +910,19 @@ def main(args):
args = build_utils.ExpandFileArgs(args) args = build_utils.ExpandFileArgs(args)
options = _ParseArgs(args) options = _ParseArgs(args)
path = options.arsc_path or options.proto_path
debug_temp_resources_dir = os.environ.get(_ENV_DEBUG_VARIABLE) debug_temp_resources_dir = os.environ.get(_ENV_DEBUG_VARIABLE)
if debug_temp_resources_dir: if debug_temp_resources_dir:
debug_temp_resources_dir = os.path.join(debug_temp_resources_dir, path = os.path.join(debug_temp_resources_dir, os.path.basename(path))
os.path.basename(options.arsc_path)) build_utils.DeleteDirectory(path)
build_utils.DeleteDirectory(debug_temp_resources_dir) else:
build_utils.MakeDirectory(debug_temp_resources_dir) # Use a deterministic temp directory since .pb files embed the absolute
# path of resources: crbug.com/939984
path = path + '.tmpdir'
build_utils.MakeDirectory(path)
with resource_utils.BuildContext(debug_temp_resources_dir) as build: with resource_utils.BuildContext(
temp_dir=path, keep_files=bool(debug_temp_resources_dir)) as build:
manifest_package_name = _PackageApk(options, build) manifest_package_name = _PackageApk(options, build)
# If --shared-resources-whitelist is used, the all resources listed in # If --shared-resources-whitelist is used, the all resources listed in
......
...@@ -675,12 +675,13 @@ class _ResourceBuildContext(object): ...@@ -675,12 +675,13 @@ class _ResourceBuildContext(object):
temp_dir: Optional root build directory path. If None, a temporary temp_dir: Optional root build directory path. If None, a temporary
directory will be created, and removed in Close(). directory will be created, and removed in Close().
""" """
def __init__(self, temp_dir=None):
def __init__(self, temp_dir=None, keep_files=False):
"""Initialized the context.""" """Initialized the context."""
# The top-level temporary directory. # The top-level temporary directory.
if temp_dir: if temp_dir:
self.temp_dir = temp_dir self.temp_dir = temp_dir
self.remove_on_exit = False self.remove_on_exit = not keep_files
else: else:
self.temp_dir = tempfile.mkdtemp() self.temp_dir = tempfile.mkdtemp()
self.remove_on_exit = True self.remove_on_exit = True
...@@ -714,10 +715,10 @@ class _ResourceBuildContext(object): ...@@ -714,10 +715,10 @@ class _ResourceBuildContext(object):
@contextlib.contextmanager @contextlib.contextmanager
def BuildContext(temp_dir=None): def BuildContext(temp_dir=None, keep_files=False):
"""Generator for a _ResourceBuildContext instance.""" """Generator for a _ResourceBuildContext instance."""
try: try:
context = _ResourceBuildContext(temp_dir) context = _ResourceBuildContext(temp_dir, keep_files)
yield context yield context
finally: finally:
context.Close() context.Close()
......
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
# TODO(thakis): Move android det bots to use two distinct build dirs, # TODO(thakis): Move android det bots to use two distinct build dirs,
# https://crbug.com/899438 # https://crbug.com/899438
'android': [ 'android': [
# https://crbug.com/939984
'apks/ChromeModernPublic.aab',
], ],
'fuchsia': [ 'fuchsia': [
......
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