From 7719a9790afb89cca5d7b342865b284d4bc0e79a Mon Sep 17 00:00:00 2001 From: Gurpreet Singh Date: Mon, 27 Mar 2023 15:52:55 +0000 Subject: [PATCH] Add last finalized version to metadata file. This CL builds the .latest.version target which contains the last finalized version. This version is read and populated inside the metadata file. The CL also verifies whether all the java sdk libraries under a module, which has been finalized atleast once, have the same extension version. Bug: 242316893 Test: atest --host mainline_modules_sdks_test --no-bazel-mode Change-Id: I94acf448b25d76c45a4bfd3d54fc276e2f01c7cc --- build/mainline_modules_sdks.py | 35 ++++++++++++++++++++++++++++- build/mainline_modules_sdks_test.py | 11 ++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/build/mainline_modules_sdks.py b/build/mainline_modules_sdks.py index da84cfc..81e06fa 100755 --- a/build/mainline_modules_sdks.py +++ b/build/mainline_modules_sdks.py @@ -472,7 +472,8 @@ java_sdk_library_import {{ @staticmethod def does_sdk_library_support_latest_api(sdk_library): - if sdk_library == "conscrypt.module.platform.api": + if sdk_library == "conscrypt.module.platform.api" or \ + sdk_library == "conscrypt.module.intra.core.api": return False return True @@ -503,6 +504,10 @@ java_sdk_library_import {{ target_dict[sdk_library][scope][target] = scope_json[target] target_paths.append(scope_json["latest_api"]) target_paths.append(scope_json["latest_removed_api"]) + target_paths.append(scope_json["latest_api"] + .replace(".latest", ".latest.extension_version")) + target_paths.append(scope_json["latest_removed_api"] + .replace(".latest", ".latest.extension_version")) return target_paths, target_dict @@ -560,6 +565,7 @@ java_sdk_library_import {{ with open( sdk_api_diff_file, "w", encoding="utf8") as sdk_api_diff_file_object: + last_finalized_version_set = set() for sdk_library in target_dict[sdk_info_file]: for scope in target_dict[sdk_info_file][sdk_library]: scope_json = target_dict[sdk_info_file][sdk_library][scope] @@ -575,6 +581,33 @@ java_sdk_library_import {{ sdk_zip_file, removed_api, latest_removed_api, snapshots_dir) + def read_extension_version(target): + extension_target = target.replace( + ".latest", ".latest.extension_version") + with open( + extension_target, "r", encoding="utf8") as file: + version = int(file.read()) + # version equal to -1 means "not an extension version". + if version != -1: + last_finalized_version_set.add(version) + + read_extension_version(scope_json["latest_api"]) + read_extension_version(scope_json["latest_removed_api"]) + + if len(last_finalized_version_set) == 0: + # Either there is no java sdk library or all java sdk libraries + # have not been finalized in sdk extensions yet and hence have + # last finalized version set as -1. + gantry_metadata_dict["last_finalized_version"] = -1 + elif len(last_finalized_version_set) == 1: + # All java sdk library extension version match. + gantry_metadata_dict["last_finalized_version"] =\ + last_finalized_version_set.pop() + else: + # Fail the build + raise ValueError( + "Not all sdk libraries finalized with the same version.\n") + gantry_metadata_dict["api_diff_file"] = sdk_api_diff_file.rsplit( "/", 1)[-1] gantry_metadata_dict["api_diff_file_size"] = os.path.getsize( diff --git a/build/mainline_modules_sdks_test.py b/build/mainline_modules_sdks_test.py index 2131a60..35d27ea 100644 --- a/build/mainline_modules_sdks_test.py +++ b/build/mainline_modules_sdks_test.py @@ -130,7 +130,11 @@ class FakeSnapshotBuilder(mm.SnapshotBuilder): for target_path in target_paths: os.makedirs(os.path.split(target_path)[0]) - self.write_data_to_file(target_path, "") + if ".latest.extension_version" in target_path: + self.write_data_to_file( + target_path, str(self.get_module_extension_version())) + else: + self.write_data_to_file(target_path, "") return target_dict @@ -343,6 +347,11 @@ class TestProduceDist(unittest.TestCase): 5, msg="The module extension version does not match the expected value." ) + self.assertEqual( + json_data["last_finalized_version"], + 5, + msg="The last finalized version does not match the expected value." + ) def create_build_number_file(self): soong_dir = os.path.join(self.tmp_out_dir, "soong")