Skip to content

Commit

Permalink
core: Add release version number to version string
Browse files Browse the repository at this point in the history
Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
  • Loading branch information
naushir committed Sep 26, 2024
1 parent cea7388 commit 9f7ddec
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
2 changes: 1 addition & 1 deletion core/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if fs.is_file(dist_version_file)
version_cmd += fs.read(dist_version_file)
endif

version_cpp = vcs_tag(command : version_cmd,
version_cpp = vcs_tag(command : [version_cmd, meson.project_version()],
replace_string: '@VER@',
input : 'version.cpp.in',
output : 'version.cpp',
Expand Down
68 changes: 36 additions & 32 deletions utils/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,46 @@
digits = 12


def generate_version():
def generate_version(git_sha):
if git_sha is None:
# Check if this is a git directory
r = subprocess.run(['git', 'rev-parse', '--git-dir'],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, text=True)
if r.returncode:
raise RuntimeError('Invalid git directory!')

# Get commit id
r = subprocess.run(['git', 'rev-parse', '--verify', 'HEAD'],
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True)
if r.returncode:
raise RuntimeError('Invalid git commit!')

commit = r.stdout.strip('\n')[0:digits] + '-intree'

# Check dirty status
r = subprocess.run(['git', 'diff-index', '--quiet', 'HEAD'],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, text=True)
if r.returncode:
commit = commit + '-dirty'
else:
commit = git_sha.lower().strip()
if any(c not in hexdigits for c in commit):
raise RuntimeError('Invalid git sha!')

commit = commit[0:digits]

return commit


if __name__ == "__main__":
try:
if len(sys.argv) == 1:
# Check if this is a git directory
r = subprocess.run(['git', 'rev-parse', '--git-dir'],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, text=True)
if r.returncode:
raise RuntimeError('Invalid git directory!')

# Get commit id
r = subprocess.run(['git', 'rev-parse', '--verify', 'HEAD'],
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True)
if r.returncode:
raise RuntimeError('Invalid git commit!')

commit = r.stdout.strip('\n')[0:digits] + '-intree'

# Check dirty status
r = subprocess.run(['git', 'diff-index', '--quiet', 'HEAD'],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, text=True)
if r.returncode:
commit = commit + '-dirty'
else:
commit = sys.argv[1].lower().strip()
if any(c not in hexdigits for c in commit):
raise RuntimeError('Invalid git sha!')

commit = commit[0:digits]
rpicam_apps_ver = '0.0.0' if len(sys.argv) < 2 else sys.argv[1]
git_sha = None if len(sys.argv) < 3 else sys.argv[2]
commit = generate_version(git_sha)

except RuntimeError as e:
print(f'ERR: {e}', file=sys.stderr)
commit = '0' * digits + '-invalid'

finally:
print(f'{commit} {datetime.now().strftime("%d-%m-%Y (%H:%M:%S)")}', end="")


if __name__ == "__main__":
generate_version()
print(f'v{rpicam_apps_ver}-{commit} {datetime.now().strftime("%d-%m-%Y (%H:%M:%S)")}', end="")

0 comments on commit 9f7ddec

Please sign in to comment.