diff options
author | Yuval Peress <peress@chromium.org> | 2021-06-23 22:51:54 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-06-24 17:32:29 +0000 |
commit | 46481b71d4d9a7d0f0830794fb84900e8cfd3d7a (patch) | |
tree | 33cbb199d82de97a243d95f5186dbf2649034f57 | |
parent | 0250c5d2866b425bf2f808daa82d600ef4694dd2 (diff) | |
download | chrome-ec-46481b71d4d9a7d0f0830794fb84900e8cfd3d7a.tar.gz |
zmake: Add ability to print compatible zephyr versions
This simple subcommand in zmake prints the compatible Zephyr
versions for the project. It will be used in the zephyr
ebuild to set the correct zephyr-base and modules directories.
BRANCH=none
BUG=b:190731415, b:191892353
TEST=zmake print-versions zephyr/projects/volteer/volteer
TEST=added unit tests
Change-Id: If597035f71cca1e90c9402dbdb0e5e558e1e0892
Signed-off-by: Yuval Peress <peress@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2984298
Reviewed-by: Simon Glass <sjg@chromium.org>
Commit-Queue: Simon Glass <sjg@chromium.org>
-rw-r--r-- | zephyr/zmake/tests/test_print_versions.py | 37 | ||||
-rw-r--r-- | zephyr/zmake/zmake/__main__.py | 4 | ||||
-rw-r--r-- | zephyr/zmake/zmake/zmake.py | 7 |
3 files changed, 48 insertions, 0 deletions
diff --git a/zephyr/zmake/tests/test_print_versions.py b/zephyr/zmake/tests/test_print_versions.py new file mode 100644 index 0000000000..0e7df2f3a0 --- /dev/null +++ b/zephyr/zmake/tests/test_print_versions.py @@ -0,0 +1,37 @@ +# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import pathlib +import tempfile +import zmake.zmake as zm + + +def generate_zmake_yaml(dest, versions): + with open(dest, 'w') as f: + f.write('board: test\n') + f.write('output-type: elf\n') + f.write('toolchain: llvm\n') + f.write('supported-zephyr-versions:\n') + for version in versions: + f.write(' - {}\n'.format(version)) + + +def test_single_version(capsys): + with tempfile.TemporaryDirectory() as temp_dir_name: + generate_zmake_yaml(pathlib.Path(temp_dir_name) / 'zmake.yaml', + ['v2.5']) + zm.Zmake().print_versions(temp_dir_name) + captured = capsys.readouterr().out.splitlines() + assert captured == ['v2.5'] + + +def test_multiple_versions(capsys): + with tempfile.TemporaryDirectory() as temp_dir_name: + generate_zmake_yaml(pathlib.Path(temp_dir_name) / 'zmake.yaml', + ['v2.5', 'v2.6']) + zm.Zmake().print_versions(temp_dir_name) + captured = capsys.readouterr().out.splitlines() + # Compare the sorted lists since we don't guarantee anything about the + # print order + assert sorted(captured) == sorted(['v2.5', 'v2.6']) diff --git a/zephyr/zmake/zmake/__main__.py b/zephyr/zmake/zmake/__main__.py index 942fb1ea0d..45712cc591 100644 --- a/zephyr/zmake/zmake/__main__.py +++ b/zephyr/zmake/zmake/__main__.py @@ -85,6 +85,10 @@ def main(argv=None): sub = parser.add_subparsers(dest='subcommand', help='Subcommand') sub.required = True + print_versions = sub.add_parser('print-versions') + print_versions.add_argument('project_dir', type=pathlib.Path, + help='Path to the project to build') + configure = sub.add_parser('configure') configure.add_argument( '--ignore-unsupported-zephyr-version', action='store_true', diff --git a/zephyr/zmake/zmake/zmake.py b/zephyr/zmake/zmake/zmake.py index e0a2debf59..e102e865a1 100644 --- a/zephyr/zmake/zmake/zmake.py +++ b/zephyr/zmake/zmake/zmake.py @@ -192,6 +192,13 @@ class Zmake: return util.locate_zephyr_base(self.checkout, version) + def print_versions(self, project_dir): + """Print all the supported versions for a project directory""" + project = zmake.project.Project(pathlib.Path(project_dir)) + supported_versions = project.config.supported_zephyr_versions + for version in supported_versions: + print('v{}.{}'.format(*version[:2])) + def configure(self, project_dir, build_dir=None, toolchain=None, ignore_unsupported_zephyr_version=False, build_after_configure=False, test_after_configure=False, |