Create metadata json file for each module am: 653f881161

Original change: https://android-review.googlesource.com/c/platform/packages/modules/common/+/2304275

Change-Id: Ibe5e456ddab06776ebd075811cfb7037074b5f07
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Gurpreet Singh
2023-03-23 10:56:15 +00:00
committed by Automerger Merge Worker
2 changed files with 87 additions and 11 deletions

View File

@@ -288,6 +288,12 @@ def sdk_snapshot_api_diff_file(snapshots_dir, sdk_name):
return os.path.join(snapshots_dir, f"{sdk_name}-{SDK_VERSION}-api-diff.txt")
def sdk_snapshot_gantry_metadata_json_file(snapshots_dir, sdk_name):
"""Get the path to the sdk snapshot gantry metadata json file."""
return os.path.join(snapshots_dir,
f"{sdk_name}-{SDK_VERSION}-gantry-metadata.json")
# The default time to use in zip entries. Ideally, this should be the same as is
# used by soong_zip and ziptime but there is no strict need for that to be the
# case. What matters is this is a fixed time so that the contents of zip files
@@ -541,8 +547,10 @@ java_sdk_library_import {{
capture_output=True).stdout.decode("utf-8")
file_object.write(diff)
def create_snapshot_api_diff(self, sdk, target_dict, snapshots_dir):
"""Creates api diff files for each module sdk.
def create_snapshot_gantry_metadata_and_api_diff(self, sdk, target_dict,
snapshots_dir,
module_extension_version):
"""Creates gantry metadata and api diff files for each module sdk.
For each module sdk, the scope targets are obtained for each java sdk
library and the api diff files are generated by performing a diff
@@ -551,6 +559,8 @@ java_sdk_library_import {{
sdk_info_file = sdk_snapshot_info_file(snapshots_dir, sdk)
sdk_zip_file = sdk_snapshot_zip_file(snapshots_dir, sdk)
sdk_api_diff_file = sdk_snapshot_api_diff_file(snapshots_dir, sdk)
gantry_metadata_dict = {}
with open(
sdk_api_diff_file, "w",
encoding="utf8") as sdk_api_diff_file_object:
@@ -569,14 +579,39 @@ java_sdk_library_import {{
sdk_zip_file, removed_api,
latest_removed_api, snapshots_dir)
def build_snapshot_api_diff(self, modules, target_dict, snapshots_dir):
"""For each module sdk, create the api diff file."""
gantry_metadata_dict["api_diff_file"] = sdk_api_diff_file.rsplit(
"/", 1)[-1]
gantry_metadata_dict["api_diff_file_size"] = os.path.getsize(
sdk_api_diff_file)
gantry_metadata_dict[
"module_extension_version"] = module_extension_version
sdk_metadata_json_file = sdk_snapshot_gantry_metadata_json_file(
snapshots_dir, sdk)
gantry_metadata_json_object = json.dumps(gantry_metadata_dict, indent=4)
with open(sdk_metadata_json_file,
"w") as gantry_metadata_json_file_object:
gantry_metadata_json_file_object.write(gantry_metadata_json_object)
def get_module_extension_version(self):
return int(
subprocess.run([
"build/soong/soong_ui.bash", "--dumpvar-mode",
"PLATFORM_SDK_EXTENSION_VERSION"
],
capture_output=True).stdout.decode("utf-8").strip())
def build_snapshot_gantry_metadata_and_api_diff(self, modules, target_dict,
snapshots_dir):
"""For each module sdk, create the metadata and api diff file."""
module_extension_version = self.get_module_extension_version()
for module in modules:
for sdk in module.sdks:
sdk_type = sdk_type_from_name(sdk)
if not sdk_type.providesApis:
continue
self.create_snapshot_api_diff(sdk, target_dict, snapshots_dir)
self.create_snapshot_gantry_metadata_and_api_diff(
sdk, target_dict, snapshots_dir, module_extension_version)
# The sdk version to build
@@ -1152,7 +1187,7 @@ class SdkDistProducer:
if build_release == LATEST:
target_dict = self.snapshot_builder.build_sdk_scope_targets(
build_release, modules)
self.snapshot_builder.build_snapshot_api_diff(
self.snapshot_builder.build_snapshot_gantry_metadata_and_api_diff(
modules, target_dict, snapshots_dir)
self.populate_unbundled_dist(build_release, modules, snapshots_dir)
return snapshots_dir
@@ -1164,18 +1199,26 @@ class SdkDistProducer:
build_release, modules)
self.populate_bundled_dist(build_release, modules, snapshots_dir)
def dist_sdk_snapshot_api_diff(self, sdk_dist_dir, sdk, module,
snapshots_dir):
def dist_sdk_snapshot_gantry_metadata_and_api_diff(self, sdk_dist_dir, sdk,
module, snapshots_dir):
"""Copy the sdk snapshot api diff file to a dist directory."""
sdk_type = sdk_type_from_name(sdk)
if not sdk_type.providesApis:
return
sdk_dist_subdir = os.path.join(sdk_dist_dir, module.apex, "sdk")
sdk_dist_module_subdir = os.path.join(sdk_dist_dir, module.apex)
sdk_dist_subdir = os.path.join(sdk_dist_module_subdir, "sdk")
os.makedirs(sdk_dist_subdir, exist_ok=True)
sdk_api_diff_path = sdk_snapshot_api_diff_file(snapshots_dir, sdk)
shutil.copy(sdk_api_diff_path, sdk_dist_subdir)
sdk_gantry_metadata_json_path = sdk_snapshot_gantry_metadata_json_file(
snapshots_dir, sdk)
sdk_dist_gantry_metadata_json_path = os.path.join(
sdk_dist_module_subdir, "gantry-metadata.json")
shutil.copy(sdk_gantry_metadata_json_path,
sdk_dist_gantry_metadata_json_path)
def populate_unbundled_dist(self, build_release, modules, snapshots_dir):
build_release_dist_dir = os.path.join(self.mainline_sdks_dir,
build_release.sub_dir)
@@ -1183,8 +1226,8 @@ class SdkDistProducer:
for sdk in module.sdks:
sdk_dist_dir = os.path.join(build_release_dist_dir, SDK_VERSION)
if build_release == LATEST:
self.dist_sdk_snapshot_api_diff(sdk_dist_dir, sdk, module,
snapshots_dir)
self.dist_sdk_snapshot_gantry_metadata_and_api_diff(
sdk_dist_dir, sdk, module, snapshots_dir)
self.populate_dist_snapshot(build_release, module, sdk,
sdk_dist_dir, snapshots_dir)