From b4b07aba7dbcef7177f19482067efc6fab3aefc4 Mon Sep 17 00:00:00 2001 From: Daniel Norman Date: Wed, 17 Feb 2021 13:22:21 -0800 Subject: [PATCH] Returns empty apex_infos if the apex target dir does not exist. This is needed for partial builds that do not have the apex directory in their target files package. Test: build target files for a partial vendor-only build. Change-Id: I076bfbd1a81cccddcef795f5edeaf2b51538cdec --- tools/releasetools/add_img_to_target_files.py | 4 ++-- tools/releasetools/apex_utils.py | 7 ++++++- tools/releasetools/test_ota_from_target_files.py | 6 +++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/tools/releasetools/add_img_to_target_files.py b/tools/releasetools/add_img_to_target_files.py index 7839b471f5..5f9f19a6da 100644 --- a/tools/releasetools/add_img_to_target_files.py +++ b/tools/releasetools/add_img_to_target_files.py @@ -64,7 +64,7 @@ import sparse_img import verity_utils import ota_metadata_pb2 -from apex_utils import GetApexInfoFromTargetFiles +from apex_utils import GetSystemApexInfoFromTargetFiles if sys.hexversion < 0x02070000: print("Python 2.7 or newer is required.", file=sys.stderr) @@ -757,7 +757,7 @@ def HasPartition(partition_name): "{}.img".format(partition_name)))) def AddApexInfo(output_zip): - apex_infos = GetApexInfoFromTargetFiles(OPTIONS.input_tmp) + apex_infos = GetSystemApexInfoFromTargetFiles(OPTIONS.input_tmp) apex_metadata_proto = ota_metadata_pb2.ApexMetadata() apex_metadata_proto.apex_info.extend(apex_infos) apex_info_bytes = apex_metadata_proto.SerializeToString() diff --git a/tools/releasetools/apex_utils.py b/tools/releasetools/apex_utils.py index 644b92a574..1c88053454 100644 --- a/tools/releasetools/apex_utils.py +++ b/tools/releasetools/apex_utils.py @@ -516,7 +516,7 @@ def SignApex(avbtool, apex_data, payload_key, container_key, container_pw, raise ApexInfoError( 'Failed to get type for {}:\n{}'.format(apex_file, e)) -def GetApexInfoFromTargetFiles(input_file): +def GetSystemApexInfoFromTargetFiles(input_file): """ Get information about system APEX stored in the input_file zip @@ -538,6 +538,11 @@ def GetApexInfoFromTargetFiles(input_file): tmp_dir = UnzipTemp(input_file, ["SYSTEM/apex/*"]) target_dir = os.path.join(tmp_dir, "SYSTEM/apex/") + # Partial target-files packages for vendor-only builds may not contain + # a system apex directory. + if not os.path.exists(target_dir): + return [] + apex_infos = [] debugfs_path = "debugfs" diff --git a/tools/releasetools/test_ota_from_target_files.py b/tools/releasetools/test_ota_from_target_files.py index b556b3a8e8..82669088e8 100644 --- a/tools/releasetools/test_ota_from_target_files.py +++ b/tools/releasetools/test_ota_from_target_files.py @@ -33,7 +33,7 @@ from ota_from_target_files import ( GetTargetFilesZipWithoutPostinstallConfig, Payload, PayloadSigner, POSTINSTALL_CONFIG, StreamingPropertyFiles, AB_PARTITIONS) -from apex_utils import GetApexInfoFromTargetFiles +from apex_utils import GetSystemApexInfoFromTargetFiles from test_utils import PropertyFilesTestCase @@ -281,9 +281,9 @@ class OtaFromTargetFilesTest(test_utils.ReleaseToolsTestCase): metadata) @test_utils.SkipIfExternalToolsUnavailable() - def test_GetApexInfoFromTargetFiles(self): + def test_GetSystemApexInfoFromTargetFiles(self): target_files = construct_target_files(compressedApex=True) - apex_infos = GetApexInfoFromTargetFiles(target_files) + apex_infos = GetSystemApexInfoFromTargetFiles(target_files) self.assertEqual(len(apex_infos), 1) self.assertEqual(apex_infos[0].package_name, "com.android.apex.compressed") self.assertEqual(apex_infos[0].version, 1)