From cea5cd210e5c0251025e5125215fa1fab1d18dfb Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Tue, 21 Mar 2017 14:44:27 -0700 Subject: [PATCH] Speed up non-AB ota_from_target_files in the build system We've just created the target files package and still have the extracted directory, so pass that to ota_from_target_files so that it doesn't have to re-extract what we just compressed. This saves a little bit of time -- for bullhead-userdebug on internal master, this brings the time to build an OTA from ~340s -> ~310s. Much of the time is still spent generating and signing the OTA. Test: lunch bullhead-userdebug; m -j otapackage Test: bullhead-ota-*.zip is identical before/after Change-Id: Ib51cf6b02123e9c49280e9957c6590645470a52c --- core/Makefile | 1 + tools/releasetools/ota_from_target_files.py | 28 +++++++++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/core/Makefile b/core/Makefile index cf0aa4a429..886ee17d04 100644 --- a/core/Makefile +++ b/core/Makefile @@ -2200,6 +2200,7 @@ $(INTERNAL_OTA_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) \ $(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH MKBOOTIMG=$(MKBOOTIMG) \ ./build/tools/releasetools/ota_from_target_files -v \ --block \ + --extracted_input_target_files $(patsubst %.zip,%,$(BUILT_TARGET_FILES_PACKAGE)) \ -p $(HOST_OUT) \ -k $(KEY_CERT_PAIR) \ $(if $(OEM_OTA_CONFIG), -o $(OEM_OTA_CONFIG)) \ diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py index 8222377df3..c3f063fcc8 100755 --- a/tools/releasetools/ota_from_target_files.py +++ b/tools/releasetools/ota_from_target_files.py @@ -1235,6 +1235,8 @@ def main(argv): OPTIONS.payload_signer = a elif o == "--payload_signer_args": OPTIONS.payload_signer_args = shlex.split(a) + elif o == "--extracted_input_target_files": + OPTIONS.extracted_input = a else: return False return True @@ -1265,6 +1267,7 @@ def main(argv): "log_diff=", "payload_signer=", "payload_signer_args=", + "extracted_input_target_files=", ], extra_option_handler=option_handler) if len(args) != 2: @@ -1287,9 +1290,12 @@ def main(argv): # Load the dict file from the zip directly to have a peek at the OTA type. # For packages using A/B update, unzipping is not needed. - input_zip = zipfile.ZipFile(args[0], "r") - OPTIONS.info_dict = common.LoadInfoDict(input_zip) - common.ZipClose(input_zip) + if OPTIONS.extracted_input is not None: + OPTIONS.info_dict = common.LoadInfoDict(OPTIONS.extracted_input, OPTIONS.extracted_input) + else: + input_zip = zipfile.ZipFile(args[0], "r") + OPTIONS.info_dict = common.LoadInfoDict(input_zip) + common.ZipClose(input_zip) ab_update = OPTIONS.info_dict.get("ab_update") == "true" @@ -1319,12 +1325,18 @@ def main(argv): if OPTIONS.extra_script is not None: OPTIONS.extra_script = open(OPTIONS.extra_script).read() - print("unzipping target target-files...") - OPTIONS.input_tmp, input_zip = common.UnzipTemp( - args[0], UNZIP_PATTERN) + if OPTIONS.extracted_input is not None: + OPTIONS.input_tmp = OPTIONS.extracted_input + OPTIONS.target_tmp = OPTIONS.input_tmp + OPTIONS.info_dict = common.LoadInfoDict(OPTIONS.input_tmp, OPTIONS.input_tmp) + input_zip = zipfile.ZipFile(args[0], "r") + else: + print("unzipping target target-files...") + OPTIONS.input_tmp, input_zip = common.UnzipTemp( + args[0], UNZIP_PATTERN) - OPTIONS.target_tmp = OPTIONS.input_tmp - OPTIONS.info_dict = common.LoadInfoDict(input_zip, OPTIONS.target_tmp) + OPTIONS.target_tmp = OPTIONS.input_tmp + OPTIONS.info_dict = common.LoadInfoDict(input_zip, OPTIONS.target_tmp) if OPTIONS.verbose: print("--- target info ---")