From 39d6c59698b34866f1ef30199fdfc4f513c1ef90 Mon Sep 17 00:00:00 2001 From: Zhi Dou Date: Wed, 29 Mar 2023 20:45:48 +0000 Subject: Manually resolve conflict for cherry pick Original chagne ag/22203161 Ignore-AOSP-First: Only for cherry pickig Test: vendor/google/build/mainline_modules_sdks.sh --build_go_sdk Bug: 275368353 (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:6fdb801b081966f98adfe78a8476b582df3de1af) Merged-In: Ie8a79f9d641a24df73742841a9010ab66c974136 Change-Id: Ie8a79f9d641a24df73742841a9010ab66c974136 --- build/mainline_modules_sdks.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/build/mainline_modules_sdks.py b/build/mainline_modules_sdks.py index e4a5b24d..091453ac 100755 --- a/build/mainline_modules_sdks.py +++ b/build/mainline_modules_sdks.py @@ -71,9 +71,9 @@ class FileTransformation: # The path of the file within the SDK snapshot zip file. path: str - def apply(self, producer, path): - """Apply the transformation to the src_path to produce the dest_path.""" - raise NotImplementedError + def apply(self, producer, path, build_release): + with open(path, "r+", encoding="utf8") as file: + self._apply_transformation(producer, file, build_release) @dataclasses.dataclass(frozen=True) @@ -94,11 +94,10 @@ class SoongConfigBoilerplateInserter(FileTransformation): # The prefix to use for the soong config module types. configModuleTypePrefix: str - def apply(self, producer, path): - with open(path, "r+", encoding="utf8") as file: - self._apply_transformation(producer, file) + def config_module_type(self, module_type): + return self.configModuleTypePrefix + module_type - def _apply_transformation(self, producer, file): + def _apply_transformation(self, producer, file, build_release): # TODO(b/174997203): Remove this when we have a proper way to control # prefer flags in Mainline modules. @@ -783,6 +782,9 @@ class MainlineModule: # Defaults to the last part of the apex name. short_name: str = "" + # Additional transformations + additional_transformations: list[FileTransformation] = None + def __post_init__(self): # If short_name is not set then set it to the last component of the apex # name. @@ -822,6 +824,10 @@ class MainlineModule: configModuleTypePrefix=config_module_type_prefix, configBpDefFile=config_bp_def_file) transformations.append(inserter) + + if self.additional_transformations and build_release > R: + transformations.extend(self.additional_transformations) + return transformations def is_required_for(self, target_build_release): @@ -1179,9 +1185,11 @@ class SdkDistProducer: sdk_dist_subdir = os.path.join(sdk_dist_dir, module.apex, subdir) sdk_path = sdk_snapshot_zip_file(snapshots_dir, sdk, sdk_version) transformations = module.transformations(build_release) - self.dist_sdk_snapshot_zip(sdk_path, sdk_dist_subdir, transformations) + self.dist_sdk_snapshot_zip( + build_release, sdk_path, sdk_dist_subdir, transformations) - def dist_sdk_snapshot_zip(self, src_sdk_zip, sdk_dist_dir, transformations): + def dist_sdk_snapshot_zip( + self, build_release, src_sdk_zip, sdk_dist_dir, transformations): """Copy the sdk snapshot zip file to a dist directory. If no transformations are provided then this simply copies the show sdk @@ -1189,7 +1197,8 @@ class SdkDistProducer: provided then the files to be transformed are extracted from the snapshot zip file, they are transformed to files in a separate directory and then a new zip file is created in the dist directory with the - original files replaced by the newly transformed files. + original files replaced by the newly transformed files. build_release is + provided for transformations if it is needed. """ os.makedirs(sdk_dist_dir, exist_ok=True) dest_sdk_zip = os.path.join(sdk_dist_dir, os.path.basename(src_sdk_zip)) @@ -1212,7 +1221,7 @@ class SdkDistProducer: extract_matching_files_from_zip(src_sdk_zip, tmp_dir, pattern) # Apply the transformations to the extracted files in situ. - apply_transformations(self, tmp_dir, transformations) + apply_transformations(self, tmp_dir, transformations, build_release) # Replace the original entries in the zip with the transformed # files. @@ -1266,7 +1275,7 @@ def copy_zip_and_replace(producer, src_zip_path, dest_zip_path, src_dir, paths): cwd=src_dir) -def apply_transformations(producer, tmp_dir, transformations): +def apply_transformations(producer, tmp_dir, transformations, build_release): for transformation in transformations: path = os.path.join(tmp_dir, transformation.path) @@ -1274,7 +1283,7 @@ def apply_transformations(producer, tmp_dir, transformations): modified = os.path.getmtime(path) # Transform the file. - transformation.apply(producer, path) + transformation.apply(producer, path, build_release) # Reset the timestamp of the file to the original timestamp before the # transformation was applied. -- cgit v1.2.3