From: Kirill Isakov Date: Thu, 31 Mar 2022 05:32:56 +0000 (+0600) Subject: Fall back to VERSION file if .git is not present X-Git-Url: http://tinc-vpn.org/git/browse?p=tinc;a=commitdiff_plain;h=ee988a6e3758994cb0552ef17f872e2530e7ceff Fall back to VERSION file if .git is not present https://github.com/gsliepen/tinc/issues/358 --- diff --git a/VERSION b/VERSION new file mode 100644 index 00000000..c0540cbd --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.1pre18 diff --git a/version.py b/version.py index ff491bb5..e9419a03 100755 --- a/version.py +++ b/version.py @@ -1,12 +1,17 @@ #!/usr/bin/env python3 -from sys import argv, exit +from os import path, environ +from sys import argv, stderr import subprocess as subp prefix = "release-" +source_root = path.dirname(path.realpath(__file__)) +source_root = environ.get("MESON_SOURCE_ROOT", source_root) cmd = [ "git", + "--git-dir", + path.join(source_root, ".git"), "describe", "--always", "--tags", @@ -19,8 +24,13 @@ if "short" in argv: result = subp.run(cmd, stdout=subp.PIPE, encoding="utf-8") version = result.stdout -if not result.returncode and version and version.startswith(prefix): +if result.returncode or not version: + try: + with open(path.join(source_root, "VERSION"), "r") as f: + version = f.read().strip() + except OSError as e: + print("could not read version from file", e, file=stderr) +elif version.startswith(prefix): version = version[len(prefix):].strip() print(version if version else "unknown", end="") -exit(not version)