Code refactoring to build targets in a separate method.

The build_snapshot method is creating a list of targets and building
them by calling soong.
The code sets some environment variables and builds the targets. This
code can be made reusable by putting it into a separate method and
passing the list of targets to be built. This will avoid code
redundancy.

Bug: 230609867
Test: The code builds on the intellij and successfully builds all the
targets passed to this newly added method.

Change-Id: I22566ca438b2da0cf832416466f4e3affb1c976e
This commit is contained in:
Gurpreet Singh
2022-06-08 12:05:00 +00:00
parent cdbe3e48aa
commit d7a929c3e2

View File

@@ -246,17 +246,7 @@ class SnapshotBuilder:
return os.path.join(self.mainline_sdks_dir,
f"{sdk_name}-{sdk_version}.zip")
def build_snapshots(self, build_release, sdk_versions, modules):
# Build the SDKs once for each version.
for sdk_version in sdk_versions:
# Compute the paths to all the Soong generated sdk snapshot files
# required by this script.
paths = [
sdk_snapshot_zip_file(self.mainline_sdks_dir, sdk, sdk_version)
for module in modules
for sdk in module.sdks
]
def build_target_paths(self, build_release, sdk_version, target_paths):
# Extra environment variables to pass to the build process.
extraEnv = {
# TODO(ngeoffray): remove SOONG_ALLOW_MISSING_DEPENDENCIES, but
@@ -276,8 +266,7 @@ class SnapshotBuilder:
# This MUST be identical to the TARGET_BUILD_VARIANT used to build
# the corresponding APEXes otherwise it could result in different
# hidden API flags, see http://b/202398851#comment29 for more info.
target_build_variant = os.environ.get("TARGET_BUILD_VARIANT",
"user")
target_build_variant = os.environ.get("TARGET_BUILD_VARIANT", "user")
cmd = [
"build/soong/soong_ui.bash",
"--make-mode",
@@ -286,11 +275,24 @@ class SnapshotBuilder:
"TARGET_PRODUCT=mainline_sdk",
"MODULE_BUILD_FROM_SOURCE=true",
"out/soong/apex/depsinfo/new-allowed-deps.txt.check",
] + paths
] + target_paths
print_command(extraEnv, cmd)
env = os.environ.copy()
env.update(extraEnv)
self.subprocess_runner.run(cmd, env=env)
def build_snapshots(self, build_release, sdk_versions, modules):
# Build the SDKs once for each version.
for sdk_version in sdk_versions:
# Compute the paths to all the Soong generated sdk snapshot files
# required by this script.
paths = [
sdk_snapshot_zip_file(self.mainline_sdks_dir, sdk, sdk_version)
for module in modules
for sdk in module.sdks
]
self.build_target_paths(build_release, sdk_version, paths)
return self.mainline_sdks_dir
def build_snapshots_for_build_r(self, build_release, sdk_versions, modules):