add BuildContext class and fix enabled features
Add a BuildContext class to simplify parsing the build context dict, and
fix the parsing of enabledBuildFeatures, which was being parsed as a
list of strings when it's actually a list of dicts like:
[{'name': '<feature_name>'}]
Test: atest build_test_suites_test
Bug: 361605425
Change-Id: I6424c444daf1582e92313c39f43207cb274aa78f
diff --git a/ci/build_test_suites.py b/ci/build_test_suites.py
index deb1f1d..402880c 100644
--- a/ci/build_test_suites.py
+++ b/ci/build_test_suites.py
@@ -24,6 +24,7 @@
import subprocess
import sys
from typing import Callable
+from build_context import BuildContext
import optimized_targets
@@ -53,18 +54,9 @@
any output zip files needed by the build.
"""
- _DOWNLOAD_OPTS = {
- 'test-config-only-zip',
- 'test-zip-file-filter',
- 'extra-host-shared-lib-zip',
- 'sandbox-tests-zips',
- 'additional-files-filter',
- 'cts-package-name',
- }
-
def __init__(
self,
- build_context: dict[str, any],
+ build_context: BuildContext,
args: argparse.Namespace,
target_optimizations: dict[str, optimized_targets.OptimizedBuildTarget],
):
@@ -74,18 +66,15 @@
def create_build_plan(self):
- if 'optimized_build' not in self.build_context.get(
- 'enabledBuildFeatures', []
- ):
+ if 'optimized_build' not in self.build_context.enabled_build_features:
return BuildPlan(set(self.args.extra_targets), set())
build_targets = set()
packaging_functions = set()
- self.file_download_options = self._aggregate_file_download_options()
for target in self.args.extra_targets:
if self._unused_target_exclusion_enabled(
target
- ) and not self._build_target_used(target):
+ ) and not self.build_context.build_target_used(target):
continue
target_optimizer_getter = self.target_optimizations.get(target, None)
@@ -102,34 +91,11 @@
return BuildPlan(build_targets, packaging_functions)
def _unused_target_exclusion_enabled(self, target: str) -> bool:
- return f'{target}_unused_exclusion' in self.build_context.get(
- 'enabledBuildFeatures', []
+ return (
+ f'{target}_unused_exclusion'
+ in self.build_context.enabled_build_features
)
- def _build_target_used(self, target: str) -> bool:
- """Determines whether this target's outputs are used by the test configurations listed in the build context."""
- # For all of a targets' outputs, check if any of the regexes used by tests
- # to download artifacts would match it. If any of them do then this target
- # is necessary.
- regex = r'\b(%s)\b' % re.escape(target)
- return any(re.search(regex, opt) for opt in self.file_download_options)
-
- def _aggregate_file_download_options(self) -> set[str]:
- """Lists out all test config options to specify targets to download.
-
- These come in the form of regexes.
- """
- all_options = set()
- for test_info in self._get_test_infos():
- for opt in test_info.get('extraOptions', []):
- # check the known list of options for downloading files.
- if opt.get('key') in self._DOWNLOAD_OPTS:
- all_options.update(opt.get('values', []))
- return all_options
-
- def _get_test_infos(self):
- return self.build_context.get('testContext', dict()).get('testInfos', [])
-
@dataclass(frozen=True)
class BuildPlan:
@@ -148,7 +114,7 @@
"""
args = parse_args(argv)
check_required_env()
- build_context = load_build_context()
+ build_context = BuildContext(load_build_context())
build_planner = BuildPlanner(
build_context, args, optimized_targets.OPTIMIZED_BUILD_TARGETS
)