From e98427ac3f2caa107862ec476bec6bc2c08cbbb1 Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Fri, 7 Dec 2018 10:08:27 -0800 Subject: [PATCH] Don't build super image if source images are missing For some internal branches, vendor.img isn't built, so there is no need to build super image / super split images there. Test: remove vendor.img and VENDOR/ from target_files_intermediates, then run add_img_to_target_files Fixes: 120634805 Change-Id: I2834a27ce232538f203733c204dd257279c789fc --- tools/releasetools/add_img_to_target_files.py | 11 ++++++----- tools/releasetools/build_super_image.py | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/tools/releasetools/add_img_to_target_files.py b/tools/releasetools/add_img_to_target_files.py index 669d87b697..1872a58127 100755 --- a/tools/releasetools/add_img_to_target_files.py +++ b/tools/releasetools/add_img_to_target_files.py @@ -657,12 +657,13 @@ def AddSuperSplit(output_zip): """Create split super_*.img and store it in output_zip.""" outdir = os.path.join(OPTIONS.input_tmp, "OTA") - build_super_image.BuildSuperImage(OPTIONS.input_tmp, outdir) + built = build_super_image.BuildSuperImage(OPTIONS.input_tmp, outdir) - for dev in OPTIONS.info_dict['super_block_devices'].strip().split(): - img = OutputFile(output_zip, OPTIONS.input_tmp, "OTA", - "super_" + dev + ".img") - img.Write() + if built: + for dev in OPTIONS.info_dict['super_block_devices'].strip().split(): + img = OutputFile(output_zip, OPTIONS.input_tmp, "OTA", + "super_" + dev + ".img") + img.Write() def ReplaceUpdatedFiles(zip_filename, files_list): diff --git a/tools/releasetools/build_super_image.py b/tools/releasetools/build_super_image.py index 6efd3f45b6..e8730ae19a 100755 --- a/tools/releasetools/build_super_image.py +++ b/tools/releasetools/build_super_image.py @@ -138,14 +138,25 @@ def BuildSuperImageFromDict(info_dict, output): else: logger.info("Done writing image %s", output) + return True + def BuildSuperImageFromExtractedTargetFiles(inp, out): info_dict = common.LoadInfoDict(inp) partition_list = shlex.split( info_dict.get("dynamic_partition_list", "").strip()) + missing_images = [] for partition in partition_list: - info_dict["{}_image".format(partition)] = os.path.join( - inp, "IMAGES", "{}.img".format(partition)) + image_path = os.path.join(inp, "IMAGES", "{}.img".format(partition)) + if not os.path.isfile(image_path): + missing_images.append(image_path) + else: + info_dict["{}_image".format(partition)] = image_path + if missing_images: + logger.warning("Skip building super image because the following " + "images are missing from target files:\n%s", + "\n".join(missing_images)) + return False return BuildSuperImageFromDict(info_dict, out)