binman: Add a way to obtain the version

Add a -V option which shows the version number of binman. For now this
just uses a local 'version' file. Once the tool is packaged in some way
we can figure out an approach that suits.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2021-11-23 11:03:42 -07:00
parent 650e5de7d4
commit c475decf59
3 changed files with 67 additions and 0 deletions

View File

@@ -16,6 +16,8 @@ import os
from patman import tools
from patman import tout
OUR_PATH = os.path.dirname(os.path.realpath(__file__))
# Map an dtb etype to its expected filename
DTB_TYPE_FNAME = {
'u-boot-spl-dtb': 'spl/u-boot-spl.dtb',
@@ -515,3 +517,19 @@ def TimingShow():
for name, seconds in duration.items():
print('%10s: %10.1fms' % (name, seconds * 1000))
def GetVersion(path=OUR_PATH):
"""Get the version string for binman
Args:
path: Path to 'version' file
Returns:
str: String version, e.g. 'v2021.10'
"""
version_fname = os.path.join(path, 'version')
if os.path.exists(version_fname):
version = tools.ReadFile(version_fname, binary=False)
else:
version = '(unreleased)'
return version