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
This commit is contained in:
Gurpreet Singh
2023-03-27 15:52:55 +00:00
parent aec473404b
commit 7719a9790a
2 changed files with 44 additions and 2 deletions

View File

@@ -472,7 +472,8 @@ java_sdk_library_import {{
@staticmethod @staticmethod
def does_sdk_library_support_latest_api(sdk_library): 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 False
return True return True
@@ -503,6 +504,10 @@ java_sdk_library_import {{
target_dict[sdk_library][scope][target] = scope_json[target] target_dict[sdk_library][scope][target] = scope_json[target]
target_paths.append(scope_json["latest_api"]) target_paths.append(scope_json["latest_api"])
target_paths.append(scope_json["latest_removed_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 return target_paths, target_dict
@@ -560,6 +565,7 @@ java_sdk_library_import {{
with open( with open(
sdk_api_diff_file, "w", sdk_api_diff_file, "w",
encoding="utf8") as sdk_api_diff_file_object: encoding="utf8") as sdk_api_diff_file_object:
last_finalized_version_set = set()
for sdk_library in target_dict[sdk_info_file]: for sdk_library in target_dict[sdk_info_file]:
for scope in target_dict[sdk_info_file][sdk_library]: for scope in target_dict[sdk_info_file][sdk_library]:
scope_json = target_dict[sdk_info_file][sdk_library][scope] scope_json = target_dict[sdk_info_file][sdk_library][scope]
@@ -575,6 +581,33 @@ java_sdk_library_import {{
sdk_zip_file, removed_api, sdk_zip_file, removed_api,
latest_removed_api, snapshots_dir) 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( gantry_metadata_dict["api_diff_file"] = sdk_api_diff_file.rsplit(
"/", 1)[-1] "/", 1)[-1]
gantry_metadata_dict["api_diff_file_size"] = os.path.getsize( gantry_metadata_dict["api_diff_file_size"] = os.path.getsize(

View File

@@ -130,7 +130,11 @@ class FakeSnapshotBuilder(mm.SnapshotBuilder):
for target_path in target_paths: for target_path in target_paths:
os.makedirs(os.path.split(target_path)[0]) 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 return target_dict
@@ -343,6 +347,11 @@ class TestProduceDist(unittest.TestCase):
5, 5,
msg="The module extension version does not match the expected value." 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): def create_build_number_file(self):
soong_dir = os.path.join(self.tmp_out_dir, "soong") soong_dir = os.path.join(self.tmp_out_dir, "soong")