Decouple population of the dist dir from the SnapshotBuilder
Previously, the code for populating the dist directory, e.g.
populate_dist and create_legacy_dist_structures assumed that the sdk
snapshot files they needed could be found in the directory referenced
by SnapshotBuilder.mainline_sdks_dir. This change removes that
assumption and instead passes the snapshot_dirs directory into the
populate_dist method and uses it in the create_legacy_dist_structures
function.
This refactoring is needed to allow a follow up change to construct a
set of sdk snapshot files in a different directory while still using
the populate_dist method to copy them into the correct location in the
dist directory.
Bug: 218685706
Test: atest --host mainline_modules_sdks_test
packages/modules/common/build/mainline_modules_sdks.sh
pyformat -s 4 --force_quote_type double -i build/mainline_modules_sdks*.py
/usr/bin/pylint --rcfile $ANDROID_BUILD_TOP/tools/repohooks/tools/pylintrc build/mainline_modules_sdks*.py
Change-Id: I9fb659df28d7688b3f081bf84f5fae8ee85dc534
This commit is contained in:
@@ -197,6 +197,11 @@ class SubprocessRunner:
|
||||
*args, check=True, stdout=self.stdout, stderr=self.stderr, **kwargs)
|
||||
|
||||
|
||||
def sdk_snapshot_zip_file(snapshots_dir, sdk_name, sdk_version):
|
||||
"""Get the path to the sdk snapshot zip file."""
|
||||
return os.path.join(snapshots_dir, f"{sdk_name}-{sdk_version}.zip")
|
||||
|
||||
|
||||
@dataclasses.dataclass()
|
||||
class SnapshotBuilder:
|
||||
"""Builds sdk snapshots"""
|
||||
@@ -207,13 +212,16 @@ class SnapshotBuilder:
|
||||
# The OUT_DIR environment variable.
|
||||
out_dir: str
|
||||
|
||||
def get_mainline_sdks_path(self):
|
||||
"""Get the path to the Soong mainline-sdks directory"""
|
||||
return os.path.join(self.out_dir, "soong/mainline-sdks")
|
||||
# The out/soong/mainline-sdks directory.
|
||||
mainline_sdks_dir: str = ""
|
||||
|
||||
def __post_init__(self):
|
||||
self.mainline_sdks_dir = os.path.join(self.out_dir,
|
||||
"soong/mainline-sdks")
|
||||
|
||||
def get_sdk_path(self, sdk_name, sdk_version):
|
||||
"""Get the path to the sdk snapshot zip file produced by soong"""
|
||||
return os.path.join(self.get_mainline_sdks_path(),
|
||||
return os.path.join(self.mainline_sdks_dir,
|
||||
f"{sdk_name}-{sdk_version}.zip")
|
||||
|
||||
def build_snapshots(self, build_release, sdk_versions, modules):
|
||||
@@ -222,7 +230,7 @@ class SnapshotBuilder:
|
||||
# Compute the paths to all the Soong generated sdk snapshot files
|
||||
# required by this script.
|
||||
paths = [
|
||||
self.get_sdk_path(sdk, sdk_version)
|
||||
sdk_snapshot_zip_file(self.mainline_sdks_dir, sdk, sdk_version)
|
||||
for module in modules
|
||||
for sdk in module.sdks
|
||||
]
|
||||
@@ -261,6 +269,7 @@ class SnapshotBuilder:
|
||||
env = os.environ.copy()
|
||||
env.update(extraEnv)
|
||||
self.subprocess_runner.run(cmd, env=env)
|
||||
return self.mainline_sdks_dir
|
||||
|
||||
|
||||
# A list of the sdk versions to build. Usually just current but can include a
|
||||
@@ -353,7 +362,8 @@ def create_legacy_dist_structures(build_release: BuildRelease,
|
||||
producer: "SdkDistProducer",
|
||||
modules: List["MainlineModule"]):
|
||||
"""Creates legacy file structures."""
|
||||
producer.produce_dist_for_build_release(build_release, modules)
|
||||
snapshots_dir = producer.produce_dist_for_build_release(
|
||||
build_release, modules)
|
||||
|
||||
# Create the out/dist/mainline-sdks/stubs structure.
|
||||
# TODO(b/199759953): Remove stubs once it is no longer used by gantry.
|
||||
@@ -369,8 +379,7 @@ def create_legacy_dist_structures(build_release: BuildRelease,
|
||||
# If the sdk's name ends with -sdk then extract sdk library
|
||||
# related files from its zip file.
|
||||
if sdk.endswith("-sdk"):
|
||||
sdk_file = producer.snapshot_builder.get_sdk_path(
|
||||
sdk, "current")
|
||||
sdk_file = sdk_snapshot_zip_file(snapshots_dir, sdk, "current")
|
||||
extract_matching_files_from_zip(sdk_file, dest_dir,
|
||||
sdk_library_files_pattern())
|
||||
|
||||
@@ -596,11 +605,13 @@ class SdkDistProducer:
|
||||
|
||||
def produce_dist_for_build_release(self, build_release, modules):
|
||||
sdk_versions = build_release.sdk_versions
|
||||
self.snapshot_builder.build_snapshots(build_release, sdk_versions,
|
||||
modules)
|
||||
self.populate_dist(build_release, sdk_versions, modules)
|
||||
snapshots_dir = self.snapshot_builder.build_snapshots(
|
||||
build_release, sdk_versions, modules)
|
||||
self.populate_dist(build_release, sdk_versions, modules, snapshots_dir)
|
||||
return snapshots_dir
|
||||
|
||||
def populate_dist(self, build_release, sdk_versions, modules):
|
||||
def populate_dist(self, build_release, sdk_versions, modules,
|
||||
snapshots_dir):
|
||||
build_release_dist_dir = os.path.join(self.mainline_sdks_dir,
|
||||
build_release.sub_dir)
|
||||
|
||||
@@ -618,8 +629,8 @@ class SdkDistProducer:
|
||||
|
||||
sdk_dist_dir = os.path.join(build_release_dist_dir,
|
||||
sdk_version, apex, subdir)
|
||||
sdk_path = self.snapshot_builder.get_sdk_path(
|
||||
sdk, sdk_version)
|
||||
sdk_path = sdk_snapshot_zip_file(snapshots_dir, sdk,
|
||||
sdk_version)
|
||||
self.dist_sdk_snapshot_zip(sdk_path, sdk_dist_dir,
|
||||
module.transformations())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user