diff options
author | Jeremy Bettis <jbettis@google.com> | 2021-03-30 14:34:16 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-03-31 18:58:26 +0000 |
commit | 9b918d35a2a5573405250e1dfeef084f40ef0c99 (patch) | |
tree | c2e1eec258d694f63570b6c2505c22a65d559e9b | |
parent | 68da2a47999aa5f2a6398bbadebc0b859bce63f3 (diff) | |
download | chrome-ec-9b918d35a2a5573405250e1dfeef084f40ef0c99.tar.gz |
zephyr: Add find_projects() to zmake.project.
A new generator function which searches subdirectories for zmake
projects.
BUG=b:183007888
TEST=zmake testall
BRANCH=none
Signed-off-by: Jeremy Bettis <jbettis@google.com>
Change-Id: Iceca946a12e0e64a46c5994366734addb3e24cb2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2795931
Commit-Queue: Jack Rosenthal <jrosenth@chromium.org>
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Tested-by: Jack Rosenthal <jrosenth@chromium.org>
-rw-r--r-- | zephyr/zmake/tests/test_project.py | 38 | ||||
-rw-r--r-- | zephyr/zmake/zmake/project.py | 17 | ||||
-rw-r--r-- | zephyr/zmake/zmake/zmake.py | 19 |
3 files changed, 62 insertions, 12 deletions
diff --git a/zephyr/zmake/tests/test_project.py b/zephyr/zmake/tests/test_project.py index 9b5cd8fe35..732e397354 100644 --- a/zephyr/zmake/tests/test_project.py +++ b/zephyr/zmake/tests/test_project.py @@ -124,3 +124,41 @@ def test_prune_modules_unavailable(): 'modules': ['hal_stm32', 'cmsis']}) as project: with pytest.raises(KeyError): project.prune_modules(module_paths) + + +def test_find_projects_empty(tmp_path): + """Test the find_projects method when there are no projects.""" + projects = list(zmake.project.find_projects(tmp_path)) + assert len(projects) == 0 + + +YAML_FILE = """ +supported-zephyr-versions: + - v2.5 +toolchain: coreboot-sdk +output-type: npcx +""" + + +def test_find_projects(tmp_path): + """Test the find_projects method when there are projects.""" + dir = tmp_path.joinpath('one') + dir.mkdir() + dir.joinpath('zmake.yaml').write_text("board: one\n" + YAML_FILE) + tmp_path.joinpath('two').mkdir() + dir = tmp_path.joinpath('two/a') + dir.mkdir() + dir.joinpath('zmake.yaml').write_text( + "board: twoa\nis-test: true\n" + YAML_FILE) + dir = tmp_path.joinpath('two/b') + dir.mkdir() + dir.joinpath('zmake.yaml').write_text("board: twob\n" + YAML_FILE) + projects = list(zmake.project.find_projects(tmp_path)) + projects.sort(key=lambda x: x.project_dir) + assert len(projects) == 3 + assert projects[0].project_dir == tmp_path.joinpath('one') + assert projects[1].project_dir == tmp_path.joinpath('two/a') + assert projects[2].project_dir == tmp_path.joinpath('two/b') + assert not projects[0].config.is_test + assert projects[1].config.is_test + assert not projects[2].config.is_test diff --git a/zephyr/zmake/zmake/project.py b/zephyr/zmake/zmake/project.py index a7e2fec20e..f7e085cb1e 100644 --- a/zephyr/zmake/zmake/project.py +++ b/zephyr/zmake/zmake/project.py @@ -3,7 +3,10 @@ # found in the LICENSE file. """Module for project config wrapper object.""" +import logging +import pathlib import warnings + import yaml # The version of jsonschema in the chroot has a bunch of @@ -33,6 +36,20 @@ def module_dts_overlay_name(modpath, board_name): board_name) +def find_projects(root_dir): + """Finds all zmake projects in root_dir. + + Args: + root_dir: the root dir as a pathlib.Path object + + Yields: + Project: The next project found. + """ + logging.info('Finding zmake targets under \'%s\'.', root_dir) + for path in pathlib.Path(root_dir).rglob('zmake.yaml'): + yield Project(path.parent) + + class ProjectConfig: """An object wrapping zmake.yaml.""" validator = jsonschema.Draft7Validator diff --git a/zephyr/zmake/zmake/zmake.py b/zephyr/zmake/zmake/zmake.py index 51897f0cd4..865e477698 100644 --- a/zephyr/zmake/zmake/zmake.py +++ b/zephyr/zmake/zmake/zmake.py @@ -383,25 +383,20 @@ class Zmake: def testall(self, fail_fast=False): """Test all the valid test targets""" - root_dirs = [self.module_paths['ec'] / 'zephyr'] - project_dirs = [] - for root_dir in root_dirs: - self.logger.info('Finding zmake target under \'%s\'.', root_dir) - for path in pathlib.Path(root_dir).rglob('zmake.yaml'): - project_dirs.append(path.parent) - executor = zmake.multiproc.Executor(fail_fast=fail_fast) tmp_dirs = [] - for project_dir in project_dirs: - is_test = zmake.project.Project(project_dir).config.is_test + for project in zmake.project.find_projects( + self.module_paths['ec'] / 'zephyr'): + is_test = project.config.is_test temp_build_dir = tempfile.mkdtemp( - suffix='-{}'.format(os.path.basename(project_dir.as_posix())), - prefix='zbuild-') + suffix='-{}'.format(os.path.basename( + project.project_dir.as_posix())), + prefix='zbuild-') tmp_dirs.append(temp_build_dir) # Configure and run the test. executor.append( func=lambda: self.configure( - project_dir=pathlib.Path(project_dir), + project_dir=project.project_dir, build_dir=pathlib.Path(temp_build_dir), build_after_configure=True, test_after_configure=is_test)) |