From 1dc5d47653c319bc148175ce85b3b19b65952851 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Thu, 20 Jul 2017 23:51:16 -0700 Subject: [PATCH] Look for non-existent files listed in avb_vbmeta_args. In BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS, if we have defined "--include_descriptors_from_image" with an image file whose path points to source tree, add_img_to_target_files.py or sign_target_files_apks.py may fail to find the file. Because these scripts may run without a source tree, by taking target_files.zip as the only input. This CL scans additional locations in the input target_files.zip to find those missing files in avb_vbmeta_args. As long as the files are included in the target_files.zip, they get a second chance to be found. Bug: 63910867 Test: As follows: 1. Setup BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS with a local file path; 2. Remove the local file; 3. sign_target_files_apks.py fails without this CL; 4. sign_target_files_apks.py works. Change-Id: I3c58f80a5535db02b74cfe40d0c0beff72587cf8 --- tools/releasetools/add_img_to_target_files.py | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tools/releasetools/add_img_to_target_files.py b/tools/releasetools/add_img_to_target_files.py index 4a85496aea..cf78d5ee61 100755 --- a/tools/releasetools/add_img_to_target_files.py +++ b/tools/releasetools/add_img_to_target_files.py @@ -377,7 +377,27 @@ def AddVBMeta(output_zip, boot_img_path, system_img_path, vendor_img_path, args = OPTIONS.info_dict.get("avb_vbmeta_args") if args and args.strip(): - cmd.extend(shlex.split(args)) + split_args = shlex.split(args) + for index, arg in enumerate(split_args[:-1]): + # Sanity check that the image file exists. Some images might be defined + # as a path relative to source tree, which may not be available at the + # same location when running this script (we have the input target_files + # zip only). For such cases, we additionally scan other locations (e.g. + # IMAGES/, RADIO/, etc) before bailing out. + if arg == '--include_descriptors_from_image': + image_path = split_args[index + 1] + if os.path.exists(image_path): + continue + found = False + for dir in ['IMAGES', 'RADIO', 'VENDOR_IMAGES', 'PREBUILT_IMAGES']: + alt_path = os.path.join( + OPTIONS.input_tmp, dir, os.path.basename(image_path)) + if os.path.exists(alt_path): + split_args[index + 1] = alt_path + found = True + break + assert found, 'failed to find %s' % (image_path,) + cmd.extend(split_args) p = common.Run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p.communicate()