aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-03-30 01:17:07 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-03-30 01:17:07 +0000
commita4d2678bdc38dbdd76d1f433a37e0df4d25427e0 (patch)
treee0939bb11053d66af643c71d4108f00c7e42251d
parentff114fbba854919bcae821ab992d3b504a5872c7 (diff)
parent39d6c59698b34866f1ef30199fdfc4f513c1ef90 (diff)
downloadcommon-android13-mainline-go-odp-release.tar.gz
Merge cherrypicks of ['googleplex-android-review.googlesource.com/22341745'] into mainline-go-odp-release.aml_go_odp_330913000android13-mainline-go-odp-release
Change-Id: I792de1654cb9fa9dcba8e751a1f98b9196dfeb63
-rwxr-xr-xbuild/mainline_modules_sdks.py35
1 files 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.