diff options
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. |