diff options
author | Jack Rosenthal <jrosenth@chromium.org> | 2021-02-09 14:34:34 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-02-10 17:33:42 +0000 |
commit | 38f35d6ca279effd22261b534e92c311bf3ac31e (patch) | |
tree | c953f02a624d791a01e8126e9b98c806da18c05f /zephyr | |
parent | fbdf09e8672aa541f1f6d150691f921784b58761 (diff) | |
download | chrome-ec-38f35d6ca279effd22261b534e92c311bf3ac31e.tar.gz |
zepyhr: zmake: add a function to read zephyr version from $ZEPHYR_BASE
This will be used to read the version from a non-CrOS checked-out
zephyr base.
BUG=b:179813084
BRANCH=none
TEST=provided unit tests
Signed-off-by: Jack Rosenthal <jrosenth@chromium.org>
Change-Id: Id6c3bdebbc5273df767f23115f00f2dac794e3a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2685474
Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'zephyr')
-rw-r--r-- | zephyr/zmake/tests/test_util.py | 16 | ||||
-rw-r--r-- | zephyr/zmake/zmake/util.py | 22 |
2 files changed, 38 insertions, 0 deletions
diff --git a/zephyr/zmake/tests/test_util.py b/zephyr/zmake/tests/test_util.py index 4d6c64f1e5..7ce11fbda5 100644 --- a/zephyr/zmake/tests/test_util.py +++ b/zephyr/zmake/tests/test_util.py @@ -53,3 +53,19 @@ def test_resolve_build_dir_from_project(platform_ec_subdir, project_subdir): project_dir=project_dir, build_dir=None) assert build_dir == platform_ec_dir / 'build' / project_subdir + + +version_integers = st.integers(min_value=0) +version_tuples = st.tuples(version_integers, version_integers, version_integers) + + +@hypothesis.given(version_tuples) +def test_read_zephyr_version(version_tuple): + with tempfile.TemporaryDirectory() as zephyr_base: + with open(pathlib.Path(zephyr_base) / 'VERSION', 'w') as f: + for name, value in zip(('VERSION_MAJOR', 'VERSION_MINOR', + 'PATCHLEVEL'), + version_tuple): + f.write('{} = {}\n'.format(name, value)) + + assert util.read_zephyr_version(zephyr_base) == version_tuple diff --git a/zephyr/zmake/zmake/util.py b/zephyr/zmake/zmake/util.py index 03bf580617..946fd41521 100644 --- a/zephyr/zmake/zmake/util.py +++ b/zephyr/zmake/zmake/util.py @@ -107,6 +107,28 @@ def parse_zephyr_version(version_string): return tuple(int(x) for x in match.groups() if x is not None) +def read_zephyr_version(zephyr_base): + """Read the Zephyr version from a Zephyr OS checkout. + + Args: + zephyr_base: path to the Zephyr OS repository. + + Returns: + A 3-tuple of the version number (major, minor, patchset). + """ + version_file = pathlib.Path(zephyr_base) / 'VERSION' + + file_vars = {} + with open(version_file) as f: + for line in f: + key, sep, value = line.partition('=') + file_vars[key.strip()] = value.strip() + + return (int(file_vars['VERSION_MAJOR']), + int(file_vars['VERSION_MINOR']), + int(file_vars['PATCHLEVEL'])) + + def repr_command(argv): """Represent an argument array as a string. |