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):
if args.bundle:
# if merging a bundle we must ignore the bundle specific
# proto files as they will always be different.
ignores += ['BundleConfig.pb', 'native.pb', 'resources.pb']
ignores += ['BundleConfig.pb', 'native.pb']
dcmp = filecmp.dircmp(
tmp_dir_64,
......
......@@ -22,7 +22,6 @@ import re
import shutil
import subprocess
import sys
import tempfile
import textwrap
import zipfile
from xml.etree import ElementTree
......@@ -911,14 +910,19 @@ def main(args):
args = build_utils.ExpandFileArgs(args)
options = _ParseArgs(args)
path = options.arsc_path or options.proto_path
debug_temp_resources_dir = os.environ.get(_ENV_DEBUG_VARIABLE)
if debug_temp_resources_dir:
debug_temp_resources_dir = os.path.join(debug_temp_resources_dir,
os.path.basename(options.arsc_path))
build_utils.DeleteDirectory(debug_temp_resources_dir)
build_utils.MakeDirectory(debug_temp_resources_dir)
path = os.path.join(debug_temp_resources_dir, os.path.basename(path))
build_utils.DeleteDirectory(path)
else:
# 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)
# If --shared-resources-whitelist is used, the all resources listed in
......
......@@ -675,12 +675,13 @@ class _ResourceBuildContext(object):
temp_dir: Optional root build directory path. If None, a temporary
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."""
# The top-level temporary directory.
if temp_dir:
self.temp_dir = temp_dir
self.remove_on_exit = False
self.remove_on_exit = not keep_files
else:
self.temp_dir = tempfile.mkdtemp()
self.remove_on_exit = True
......@@ -714,10 +715,10 @@ class _ResourceBuildContext(object):
@contextlib.contextmanager
def BuildContext(temp_dir=None):
def BuildContext(temp_dir=None, keep_files=False):
"""Generator for a _ResourceBuildContext instance."""
try:
context = _ResourceBuildContext(temp_dir)
context = _ResourceBuildContext(temp_dir, keep_files)
yield context
finally:
context.Close()
......
......@@ -16,8 +16,6 @@
# TODO(thakis): Move android det bots to use two distinct build dirs,
# https://crbug.com/899438
'android': [
# https://crbug.com/939984
'apks/ChromeModernPublic.aab',
],
'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