Derive meson version via python3, not sh.

This commit is contained in:
Bartosz Taudul
2026-08-27 17:20:55 +02:00
parent 5ed42cfc6d
commit 32aa7ee1f5
3 changed files with 24 additions and 22 deletions

23
extra/tracy-version.py Executable file
View File

@@ -0,0 +1,23 @@
#!/usr/bin/env python3
# Derive the project version from the single source of truth:
# public/common/TracyVersion.hpp. Prints X.Y.Z, exits nonzero on failure.
import re
import sys
header = sys.argv[1]
try:
with open(header, encoding='utf-8') as f:
text = f.read()
except OSError as exc:
print('tracy-version: cannot read %s: %s' % (header, exc), file=sys.stderr)
sys.exit(1)
numbers = {}
for name in ('Major', 'Minor', 'Patch'):
match = re.search(r'%s\s*=\s*(\d+)' % name, text)
if not match:
print('tracy-version: could not parse version from %s' % header, file=sys.stderr)
sys.exit(1)
numbers[name] = match.group(1)
print('%s.%s.%s' % (numbers['Major'], numbers['Minor'], numbers['Patch']))

View File

@@ -1,21 +0,0 @@
#!/bin/sh
# Derive the project version from the single source of truth:
# public/common/TracyVersion.hpp. Prints X.Y.Z, exits nonzero on failure.
header="$1"
[ -r "$header" ] || {
echo "tracy-version: cannot read $header" >&2
exit 1
}
major=$(sed -n 's/.*Major = \([0-9][0-9]*\).*/\1/p' "$header")
minor=$(sed -n 's/.*Minor = \([0-9][0-9]*\).*/\1/p' "$header")
patch=$(sed -n 's/.*Patch = \([0-9][0-9]*\).*/\1/p' "$header")
if [ -n "$major" ] && [ -n "$minor" ] && [ -n "$patch" ]; then
printf '%s.%s.%s\n' "$major" "$minor" "$patch"
else
echo "tracy-version: could not parse version from $header" >&2
exit 1
fi

View File

@@ -1,4 +1,4 @@
project('tracy', ['cpp'], version: run_command('sh', files('extra/tracy-version.sh'), 'public/common/TracyVersion.hpp', check: true).stdout().strip(), meson_version: '>=1.3.0', default_options : ['cpp_std=c++11'])
project('tracy', ['cpp'], version: run_command(find_program('python3'), files('extra/tracy-version.py'), 'public/common/TracyVersion.hpp', check: true).stdout().strip(), meson_version: '>=1.3.0', default_options : ['cpp_std=c++11'])
# internal compiler flags
tracy_compile_args = []