singe/util/singeBinary.py

33 lines
1.4 KiB
Python

# The Singe the util scripts run: the one the default preset (linux-x86_64) leaves in .builddir,
# named for the version in CMakeLists.txt exactly as the build names it. Looking it up by name
# rather than taking the first Singe in a folder means a binary an older version or another preset
# left behind is never the one recorded with: sorted, Singe-v3.00- comes before Singe-v3.00b1-.
# Run as a script it prints the path, for the shell scripts: BIN=$(python3 util/singeBinary.py)
import os
import re
REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
def singeBinary():
path = os.path.join(REPO, ".builddir", "Singe-v%s-Linux-x86_64" % singeVersion())
if not os.access(path, os.X_OK):
raise SystemExit("no %s; build the linux-x86_64 preset first" % os.path.relpath(path, REPO))
return path
def singeVersion():
# The four numbers of the project() line: patch 1 means a beta and tweak says which, so
# 3.00.1.2 is 3.00b2, as CMakeLists.txt makes SINGE_VERSION_FULL.
text = open(os.path.join(REPO, "CMakeLists.txt"), encoding="utf-8").read()
found = re.search(r"^project\(singe2 VERSION (\d+)\.(\d+)\.(\d+)\.(\d+)", text, re.M)
if not found:
raise SystemExit("CMakeLists.txt has no four-number project() version")
major, minor, patch, tweak = found.groups()
if patch == "1":
return "%s.%sb%s" % (major, minor, tweak)
return "%s.%s" % (major, minor)
if __name__ == "__main__":
print(singeBinary())