3 """Print current tinc version for using in build scripts.
5 First try to determine the latest version using git tags. If this fails (because
6 the .git directory is missing, git is not installed, or for some other reason),
7 fall back to using the VERSION file. If it is not present or could not be read,
11 from os import path, environ
12 from sys import argv, stderr
13 import subprocess as subp
17 SOURCE_ROOT = path.dirname(path.realpath(__file__))
18 SOURCE_ROOT = environ.get("MESON_SOURCE_ROOT", SOURCE_ROOT)
23 path.join(SOURCE_ROOT, ".git"),
27 "--match=" + PREFIX + "*",
31 cmd.append("--abbrev=0")
33 version: T.Optional[str] = None
36 result = subp.run(cmd, stdout=subp.PIPE, encoding="utf-8", check=False)
37 if not result.returncode:
38 version = result.stdout
39 except FileNotFoundError:
44 with open(path.join(SOURCE_ROOT, "VERSION"), "r", encoding="utf-8") as f:
45 version = f.read().strip()
47 print("could not read version from file", e, file=stderr)
48 elif version.startswith(PREFIX):
49 version = version[len(PREFIX) :].strip()
51 print(version if version else "unknown", end="")