From b3805c1d357a9bef0317630a4b2463d4c3f90b0d Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 18 Mar 2022 16:57:40 +0000 Subject: [PATCH] mainline_modules_sdks.py: Optimize snapshot build order Previously, the snapshots would be built in the order in which the build releases were defined. This change groups the snapshots with the same build environment and builds them in sequence in order to minimize the regeneration of the ninja files. The test revealed that the produce_bundled_dist_for_build_release method would call build_snapshots even if there were no bundled snapshots needed which was a waste so that was also optimized as part of this change. 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: I5bb8d864a50318b4b5390a8e5a3601aa33c18fef --- build/mainline_modules_sdks.py | 18 +++++++++++++----- build/mainline_modules_sdks_test.py | 23 +++++++++++------------ 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/build/mainline_modules_sdks.py b/build/mainline_modules_sdks.py index c0135ec..43bb832 100755 --- a/build/mainline_modules_sdks.py +++ b/build/mainline_modules_sdks.py @@ -28,6 +28,7 @@ import subprocess import sys import tempfile import typing +from collections import defaultdict from typing import Callable, List import zipfile @@ -848,7 +849,14 @@ class SdkDistProducer: # Prepare the dist directory for the sdks. self.prepare() + # Group build releases so that those with the same Soong environment are + # run consecutively to avoid having to regenerate ninja files. + grouped_by_env = defaultdict(list) for build_release in build_releases: + grouped_by_env[str(build_release.soong_env)].append(build_release) + ordered = [br for _, group in grouped_by_env.items() for br in group] + + for build_release in ordered: # Only build modules that are required for this build release. filtered_modules = [ m for m in modules if m.is_required_for(build_release) @@ -883,11 +891,11 @@ class SdkDistProducer: def produce_bundled_dist_for_build_release(self, build_release, modules): modules = [m for m in modules if m.is_bundled()] - sdk_versions = build_release.sdk_versions - snapshots_dir = self.snapshot_builder.build_snapshots( - build_release, sdk_versions, modules) - self.populate_bundled_dist(build_release, modules, snapshots_dir) - return snapshots_dir + if modules: + sdk_versions = build_release.sdk_versions + snapshots_dir = self.snapshot_builder.build_snapshots( + build_release, sdk_versions, modules) + self.populate_bundled_dist(build_release, modules, snapshots_dir) def populate_unbundled_dist(self, build_release, sdk_versions, modules, snapshots_dir): diff --git a/build/mainline_modules_sdks_test.py b/build/mainline_modules_sdks_test.py index 6ab8f28..6b77e14 100644 --- a/build/mainline_modules_sdks_test.py +++ b/build/mainline_modules_sdks_test.py @@ -300,17 +300,6 @@ class TestProduceDist(unittest.TestCase): ["current"], ["com.android.ipsec", "com.google.android.wifi"], ), - ( - "S", - { - "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": "S" - }, - ["current"], - [ - "com.android.art", "com.android.ipsec", - "com.google.android.wifi" - ], - ), ( "latest", {}, @@ -320,7 +309,6 @@ class TestProduceDist(unittest.TestCase): "com.google.android.wifi" ], ), - ('latest', {}, ['current'], []), ( "legacy", {}, @@ -330,6 +318,17 @@ class TestProduceDist(unittest.TestCase): "com.google.android.wifi" ], ), + ( + "S", + { + "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": "S" + }, + ["current"], + [ + "com.android.art", "com.android.ipsec", + "com.google.android.wifi" + ], + ), ], snapshot_builder.snapshots)