Consolidate build target collection
Move build target collection to `atest_main` that contains other logic
for determining build targets.
Test: m atest && atest-dev atest_unittests --host
Change-Id: I8e35d20bfa9258cd760b07b1f76e026ba87dbcdb
diff --git a/atest/atest_main.py b/atest/atest_main.py
index 24f25c7..e2b6c72 100755
--- a/atest/atest_main.py
+++ b/atest/atest_main.py
@@ -984,6 +984,13 @@
return False
+def _gather_build_targets(test_infos):
+ targets = set()
+ for t_info in test_infos:
+ targets |= t_info.build_targets
+ return targets
+
+
# pylint: disable=too-many-statements
# pylint: disable=too-many-branches
# pylint: disable=too-many-return-statements
@@ -1074,7 +1081,8 @@
if proc_idx and not atest_utils.has_index_files():
proc_idx.join()
find_start = time.time()
- build_targets, test_infos = translator.translate(args)
+ test_infos = translator.translate(args)
+ build_targets = _gather_build_targets(test_infos)
given_amount = len(args.serial) if args.serial else 0
required_amount = get_device_count_config(test_infos, mod_info)
args.device_count_config = required_amount
diff --git a/atest/cli_translator.py b/atest/cli_translator.py
index 9c53853..2fc22b1 100644
--- a/atest/cli_translator.py
+++ b/atest/cli_translator.py
@@ -535,12 +535,6 @@
return tests, all_tests
- def _gather_build_targets(self, test_infos):
- targets = set()
- for t_info in test_infos:
- targets |= t_info.build_targets
- return targets
-
def _get_test_mapping_tests(self, args, exit_if_no_test_found=True):
"""Find the tests in TEST_MAPPING files.
@@ -715,13 +709,12 @@
result=int(finished_time))
for t_info in test_infos:
logging.debug('%s\n', t_info)
- build_targets = self._gather_build_targets(test_infos)
if not self._bazel_mode:
if host_unit_tests or self._has_host_unit_test(tests):
msg = (r"It is recommended to run host unit tests with "
r"--bazel-mode.")
atest_utils.colorful_print(msg, constants.YELLOW)
- return build_targets, test_infos
+ return test_infos
# TODO: (b/265359291) Raise Exception when the brackets are not in pair.
diff --git a/atest/cli_translator_unittest.py b/atest/cli_translator_unittest.py
index a1b8871..4b61f58 100755
--- a/atest/cli_translator_unittest.py
+++ b/atest/cli_translator_unittest.py
@@ -259,9 +259,11 @@
host_unit_tests.return_value = False
self.args.tests = [uc.CLASS_NAME]
self.args.host_unit_test_only = False
- targets, test_infos = self.ctr.translate(self.args)
+ test_infos = self.ctr.translate(self.args)
unittest_utils.assert_strict_equal(
- self, targets, uc.CLASS_BUILD_TARGETS)
+ self,
+ _gather_build_targets(test_infos),
+ uc.CLASS_BUILD_TARGETS)
unittest_utils.assert_strict_equal(self, test_infos, {uc.CLASS_INFO})
@mock.patch.object(test_finder_utils, 'find_host_unit_tests',
@@ -275,9 +277,11 @@
host_unit_tests.return_value = []
self.args.tests = [uc.MODULE_NAME, uc.CLASS_NAME]
self.args.host_unit_test_only = False
- targets, test_infos = self.ctr.translate(self.args)
+ test_infos = self.ctr.translate(self.args)
unittest_utils.assert_strict_equal(
- self, targets, uc.MODULE_CLASS_COMBINED_BUILD_TARGETS)
+ self,
+ _gather_build_targets(test_infos),
+ uc.MODULE_CLASS_COMBINED_BUILD_TARGETS)
unittest_utils.assert_strict_equal(self, test_infos, {uc.MODULE_INFO,
uc.CLASS_INFO})
@@ -297,9 +301,11 @@
self.args.host = False
self.args.host_unit_test_only = False
host_unit_tests.return_value = False
- targets, test_infos = self.ctr.translate(self.args)
+ test_infos = self.ctr.translate(self.args)
unittest_utils.assert_strict_equal(
- self, targets, uc.MODULE_CLASS_COMBINED_BUILD_TARGETS)
+ self,
+ _gather_build_targets(test_infos),
+ uc.MODULE_CLASS_COMBINED_BUILD_TARGETS)
unittest_utils.assert_strict_equal(self, test_infos, {uc.MODULE_INFO,
uc.CLASS_INFO})
@@ -317,9 +323,11 @@
self.args.test_mapping = True
self.args.host = False
host_unit_tests.return_value = False
- targets, test_infos = self.ctr.translate(self.args)
+ test_infos = self.ctr.translate(self.args)
unittest_utils.assert_strict_equal(
- self, targets, uc.MODULE_CLASS_COMBINED_BUILD_TARGETS)
+ self,
+ _gather_build_targets(test_infos),
+ uc.MODULE_CLASS_COMBINED_BUILD_TARGETS)
unittest_utils.assert_strict_equal(self, test_infos, {uc.MODULE_INFO,
uc.CLASS_INFO})
@@ -471,7 +479,7 @@
self.args.tests = []
self.args.host = False
self.args.host_unit_test_only = False
- _, test_infos = self.ctr.translate(self.args)
+ test_infos = self.ctr.translate(self.args)
unittest_utils.assert_strict_equal(self,
test_infos,
{uc.MODULE_INFO,
@@ -499,7 +507,7 @@
self.args.host = False
self.args.test_mapping = True
self.args.host_unit_test_only = False
- _, test_infos = self.ctr.translate(self.args)
+ test_infos = self.ctr.translate(self.args)
unittest_utils.assert_strict_equal(
self,
test_infos,
@@ -553,3 +561,10 @@
if __name__ == '__main__':
unittest.main()
+
+
+def _gather_build_targets(test_infos):
+ targets = set()
+ for t_info in test_infos:
+ targets |= t_info.build_targets
+ return targets