Merge commit '66b8b530187b129934a685bf0c4349eef00e4b0c' from

oc-mr1-dev-plus-aosp-without-vendor into stage-aosp-master.

Change-Id: I7594bb72dd7e847292eb502edd918e41318aac29
Merged-In: Ide82473d358719f7e01cd2a4a85db954f3722f14
This commit is contained in:
Xin Li
2017-11-14 11:36:22 -08:00
64 changed files with 1069 additions and 248 deletions

View File

@@ -18,6 +18,7 @@ import copy
import errno
import getopt
import getpass
import gzip
import imp
import os
import platform
@@ -557,6 +558,13 @@ def GetBootableImage(name, prebuilt_name, unpack_dir, tree_subdir,
return None
def Gunzip(in_filename, out_filename):
"""Gunzip the given gzip compressed file to a given output file.
"""
with gzip.open(in_filename, "rb") as in_file, open(out_filename, "wb") as out_file:
shutil.copyfileobj(in_file, out_file)
def UnzipTemp(filename, pattern=None):
"""Unzip the given archive into a temporary directory and return the name.
@@ -762,16 +770,34 @@ def CheckSize(data, target, info_dict):
def ReadApkCerts(tf_zip):
"""Given a target_files ZipFile, parse the META/apkcerts.txt file
and return a {package: cert} dict."""
and return a tuple with the following elements: (1) a dictionary that maps
packages to certs (based on the "certificate" and "private_key" attributes
in the file. (2) A string representing the extension of compressed APKs in
the target files (e.g ".gz" ".bro")."""
certmap = {}
compressed_extension = None
# META/apkcerts.txt contains the info for _all_ the packages known at build
# time. Filter out the ones that are not installed.
installed_files = set()
for name in tf_zip.namelist():
basename = os.path.basename(name)
if basename:
installed_files.add(basename)
for line in tf_zip.read("META/apkcerts.txt").split("\n"):
line = line.strip()
if not line:
continue
m = re.match(r'^name="(.*)"\s+certificate="(.*)"\s+'
r'private_key="(.*)"$', line)
m = re.match(r'^name="(?P<NAME>.*)"\s+certificate="(?P<CERT>.*)"\s+'
r'private_key="(?P<PRIVKEY>.*?)"(\s+compressed="(?P<COMPRESSED>.*)")?$',
line)
if m:
name, cert, privkey = m.groups()
matches = m.groupdict()
cert = matches["CERT"]
privkey = matches["PRIVKEY"]
name = matches["NAME"]
this_compressed_extension = matches["COMPRESSED"]
public_key_suffix_len = len(OPTIONS.public_key_suffix)
private_key_suffix_len = len(OPTIONS.private_key_suffix)
if cert in SPECIAL_CERT_STRINGS and not privkey:
@@ -782,7 +808,22 @@ def ReadApkCerts(tf_zip):
certmap[name] = cert[:-public_key_suffix_len]
else:
raise ValueError("failed to parse line from apkcerts.txt:\n" + line)
return certmap
if this_compressed_extension:
# Only count the installed files.
filename = name + '.' + this_compressed_extension
if filename not in installed_files:
continue
# Make sure that all the values in the compression map have the same
# extension. We don't support multiple compression methods in the same
# system image.
if compressed_extension:
if this_compressed_extension != compressed_extension:
raise ValueError("multiple compressed extensions : %s vs %s",
(compressed_extension, this_compressed_extension))
else:
compressed_extension = this_compressed_extension
return (certmap, ("." + compressed_extension) if compressed_extension else None)
COMMON_DOCSTRING = """