Fix incorrect cherry pick

Change https://r.android.com/2507369 accidentally reverted some of the
changes from https://r.android.com/2507370 and that broke the script.
Unfortunately, that was not picked up by TH.

This change reapplies those changes.

Test: atest mainline_modules_sdks_test --host
      packages/modules/common/build/mainline_modules_sdks.sh
Bug: 254111089
Bug: 275471775
Merged-In: I94989519011e31c7db33656c6730c4f8fd5e0a4f
Change-Id: I42f9cdc7ada0ec9cafbfc381db67e4942a29421a
This commit is contained in:
Zhi Dou
2023-03-22 20:30:42 +00:00
committed by Paul Duffin
parent 7c3ab89443
commit 02c84ac56b

View File

@@ -72,12 +72,12 @@ class FileTransformation:
# The path of the file within the SDK snapshot zip file.
path: str
def apply(self, producer, path):
def apply(self, producer, path, build_release):
"""Apply the transformation to the path; changing it in place."""
with open(path, "r+", encoding="utf8") as file:
self._apply_transformation(producer, file)
self._apply_transformation(producer, file, build_release)
def _apply_transformation(self, producer, file):
def _apply_transformation(self, producer, file, build_release):
"""Apply the transformation to the file.
The file has been opened in read/write mode so the implementation of
@@ -96,7 +96,7 @@ class SoongConfigVarTransformation(FileTransformation):
# The line containing the prefer property.
PREFER_LINE = " prefer: false,"
def _apply_transformation(self, producer, file):
def _apply_transformation(self, producer, file, build_release):
raise NotImplementedError
@@ -224,7 +224,7 @@ soong_config_module_type {{
@dataclasses.dataclass(frozen=True)
class UseSourceConfigVarTransformation(SoongConfigVarTransformation):
def _apply_transformation(self, producer, file):
def _apply_transformation(self, producer, file, build_release):
lines = []
for line in file:
line = line.rstrip("\n")
@@ -1261,9 +1261,11 @@ class SdkDistProducer:
sdk_path = sdk_snapshot_zip_file(snapshots_dir, sdk)
sdk_type = sdk_type_from_name(sdk)
transformations = module.transformations(build_release, sdk_type)
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
@@ -1271,7 +1273,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))
@@ -1294,7 +1297,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.
@@ -1348,7 +1351,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)
@@ -1356,7 +1359,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.