Pass BuildRelease to apply and _apply_transformation methods am: 3f18d87e1a

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

Change-Id: I67551cdf3829ae9c1fb4faeeb8a321c4c75729e4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Zhi Dou
2023-03-24 13:28:35 +00:00
committed by Automerger Merge Worker
2 changed files with 27 additions and 23 deletions

View File

@@ -72,12 +72,12 @@ class FileTransformation:
# The path of the file within the SDK snapshot zip file. # The path of the file within the SDK snapshot zip file.
path: str path: str
def apply(self, producer, path): def apply(self, producer, path, build_release):
"""Apply the transformation to the path; changing it in place.""" """Apply the transformation to the path; changing it in place."""
with open(path, "r+", encoding="utf8") as file: 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. """Apply the transformation to the file.
The file has been opened in read/write mode so the implementation of 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. # The line containing the prefer property.
PREFER_LINE = " prefer: false," PREFER_LINE = " prefer: false,"
def _apply_transformation(self, producer, file): def _apply_transformation(self, producer, file, build_release):
raise NotImplementedError raise NotImplementedError
@@ -117,11 +117,11 @@ class SoongConfigBoilerplateInserter(SoongConfigVarTransformation):
def config_module_type(self, module_type): def config_module_type(self, module_type):
return self.configModuleTypePrefix + module_type return self.configModuleTypePrefix + module_type
def apply(self, producer, path): def apply(self, producer, path, build_release):
with open(path, "r+", encoding="utf8") as file: 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):
# TODO(b/174997203): Remove this when we have a proper way to control # TODO(b/174997203): Remove this when we have a proper way to control
# prefer flags in Mainline modules. # prefer flags in Mainline modules.
@@ -228,7 +228,7 @@ soong_config_module_type {{
@dataclasses.dataclass(frozen=True) @dataclasses.dataclass(frozen=True)
class UseSourceConfigVarTransformation(SoongConfigVarTransformation): class UseSourceConfigVarTransformation(SoongConfigVarTransformation):
def _apply_transformation(self, producer, file): def _apply_transformation(self, producer, file, build_release):
lines = [] lines = []
for line in file: for line in file:
line = line.rstrip("\n") line = line.rstrip("\n")
@@ -1271,9 +1271,11 @@ class SdkDistProducer:
sdk_path = sdk_snapshot_zip_file(snapshots_dir, sdk) sdk_path = sdk_snapshot_zip_file(snapshots_dir, sdk)
sdk_type = sdk_type_from_name(sdk) sdk_type = sdk_type_from_name(sdk)
transformations = module.transformations(build_release, sdk_type) 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. """Copy the sdk snapshot zip file to a dist directory.
If no transformations are provided then this simply copies the show sdk If no transformations are provided then this simply copies the show sdk
@@ -1281,7 +1283,8 @@ class SdkDistProducer:
provided then the files to be transformed are extracted from the provided then the files to be transformed are extracted from the
snapshot zip file, they are transformed to files in a separate directory 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 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) os.makedirs(sdk_dist_dir, exist_ok=True)
dest_sdk_zip = os.path.join(sdk_dist_dir, os.path.basename(src_sdk_zip)) dest_sdk_zip = os.path.join(sdk_dist_dir, os.path.basename(src_sdk_zip))
@@ -1304,7 +1307,7 @@ class SdkDistProducer:
extract_matching_files_from_zip(src_sdk_zip, tmp_dir, pattern) extract_matching_files_from_zip(src_sdk_zip, tmp_dir, pattern)
# Apply the transformations to the extracted files in situ. # 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 # Replace the original entries in the zip with the transformed
# files. # files.
@@ -1358,7 +1361,7 @@ def copy_zip_and_replace(producer, src_zip_path, dest_zip_path, src_dir, paths):
cwd=src_dir) cwd=src_dir)
def apply_transformations(producer, tmp_dir, transformations): def apply_transformations(producer, tmp_dir, transformations, build_release):
for transformation in transformations: for transformation in transformations:
path = os.path.join(tmp_dir, transformation.path) path = os.path.join(tmp_dir, transformation.path)
@@ -1366,7 +1369,7 @@ def apply_transformations(producer, tmp_dir, transformations):
modified = os.path.getmtime(path) modified = os.path.getmtime(path)
# Transform the file. # 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 # Reset the timestamp of the file to the original timestamp before the
# transformation was applied. # transformation was applied.

View File

@@ -438,7 +438,7 @@ def read_test_data(relative_path):
class TestAndroidBpTransformations(unittest.TestCase): class TestAndroidBpTransformations(unittest.TestCase):
def apply_transformations(self, src, transformations, expected): def apply_transformations(self, src, transformations, build_release, expected):
producer = mm.SdkDistProducer( producer = mm.SdkDistProducer(
subprocess_runner=mock.Mock(mm.SubprocessRunner), subprocess_runner=mock.Mock(mm.SubprocessRunner),
snapshot_builder=mock.Mock(mm.SnapshotBuilder), snapshot_builder=mock.Mock(mm.SnapshotBuilder),
@@ -450,7 +450,8 @@ class TestAndroidBpTransformations(unittest.TestCase):
with open(path, "w", encoding="utf8") as f: with open(path, "w", encoding="utf8") as f:
f.write(src) f.write(src)
mm.apply_transformations(producer, tmp_dir, transformations) mm.apply_transformations(
producer, tmp_dir, transformations, build_release)
with open(path, "r", encoding="utf8") as f: with open(path, "r", encoding="utf8") as f:
result = f.read() result = f.read()
@@ -471,7 +472,7 @@ class TestAndroidBpTransformations(unittest.TestCase):
module = MAINLINE_MODULES_BY_APEX["com.android.ipsec"] module = MAINLINE_MODULES_BY_APEX["com.android.ipsec"]
transformations = module.transformations(mm.S, mm.Sdk) transformations = module.transformations(mm.S, mm.Sdk)
self.apply_transformations(src, transformations, expected) self.apply_transformations(src, transformations, mm.S, expected)
def test_common_mainline_module_tiramisu(self): def test_common_mainline_module_tiramisu(self):
"""Tests the transformations applied to a common mainline sdk on T. """Tests the transformations applied to a common mainline sdk on T.
@@ -486,7 +487,7 @@ class TestAndroidBpTransformations(unittest.TestCase):
module = MAINLINE_MODULES_BY_APEX["com.android.ipsec"] module = MAINLINE_MODULES_BY_APEX["com.android.ipsec"]
transformations = module.transformations(mm.Tiramisu, mm.Sdk) transformations = module.transformations(mm.Tiramisu, mm.Sdk)
self.apply_transformations(src, transformations, expected) self.apply_transformations(src, transformations, mm.Tiramisu, expected)
def test_optional_mainline_module(self): def test_optional_mainline_module(self):
"""Tests the transformations applied to an optional mainline sdk on S. """Tests the transformations applied to an optional mainline sdk on S.
@@ -502,7 +503,7 @@ class TestAndroidBpTransformations(unittest.TestCase):
module = MAINLINE_MODULES_BY_APEX["com.android.wifi"] module = MAINLINE_MODULES_BY_APEX["com.android.wifi"]
transformations = module.transformations(mm.S, mm.Sdk) transformations = module.transformations(mm.S, mm.Sdk)
self.apply_transformations(src, transformations, expected) self.apply_transformations(src, transformations, mm.S, expected)
def test_optional_mainline_module_tiramisu(self): def test_optional_mainline_module_tiramisu(self):
"""Tests the transformations applied to an optional mainline sdk on T. """Tests the transformations applied to an optional mainline sdk on T.
@@ -517,7 +518,7 @@ class TestAndroidBpTransformations(unittest.TestCase):
module = MAINLINE_MODULES_BY_APEX["com.android.wifi"] module = MAINLINE_MODULES_BY_APEX["com.android.wifi"]
transformations = module.transformations(mm.Tiramisu, mm.Sdk) transformations = module.transformations(mm.Tiramisu, mm.Sdk)
self.apply_transformations(src, transformations, expected) self.apply_transformations(src, transformations, mm.Tiramisu, expected)
def test_art(self): def test_art(self):
"""Tests the transformations applied to a the ART mainline module. """Tests the transformations applied to a the ART mainline module.
@@ -533,7 +534,7 @@ class TestAndroidBpTransformations(unittest.TestCase):
module = MAINLINE_MODULES_BY_APEX["com.android.art"] module = MAINLINE_MODULES_BY_APEX["com.android.art"]
transformations = module.transformations(mm.S, mm.Sdk) transformations = module.transformations(mm.S, mm.Sdk)
self.apply_transformations(src, transformations, expected) self.apply_transformations(src, transformations, mm.S, expected)
def test_art_module_exports(self): def test_art_module_exports(self):
"""Tests the transformations applied to a the ART mainline module. """Tests the transformations applied to a the ART mainline module.
@@ -549,7 +550,7 @@ class TestAndroidBpTransformations(unittest.TestCase):
module = MAINLINE_MODULES_BY_APEX["com.android.art"] module = MAINLINE_MODULES_BY_APEX["com.android.art"]
transformations = module.transformations(mm.S, mm.HostExports) transformations = module.transformations(mm.S, mm.HostExports)
self.apply_transformations(src, transformations, expected) self.apply_transformations(src, transformations, mm.S, expected)
def test_r_build(self): def test_r_build(self):
"""Tests the transformations that are applied for the R build. """Tests the transformations that are applied for the R build.
@@ -567,7 +568,7 @@ class TestAndroidBpTransformations(unittest.TestCase):
module = MAINLINE_MODULES_BY_APEX["com.android.ipsec"] module = MAINLINE_MODULES_BY_APEX["com.android.ipsec"]
transformations = module.transformations(mm.R, mm.Sdk) transformations = module.transformations(mm.R, mm.Sdk)
self.apply_transformations(src, transformations, expected) self.apply_transformations(src, transformations, mm.R, expected)
class TestFilterModules(unittest.TestCase): class TestFilterModules(unittest.TestCase):