version.py 572 B

123456789101112131415161718192021222324
  1. #!/usr/bin/env python3
  2. """Print current tinc version for using in build scripts."""
  3. from os import path, environ
  4. import subprocess as subp
  5. PREFIX = "release-"
  6. SOURCE_ROOT = path.dirname(path.realpath(__file__))
  7. SOURCE_ROOT = environ.get("MESON_SOURCE_ROOT", SOURCE_ROOT)
  8. cmd = [
  9. "git",
  10. "--git-dir",
  11. path.join(SOURCE_ROOT, ".git"),
  12. "describe",
  13. "--always",
  14. "--tags",
  15. "--match=" + PREFIX + "*",
  16. ]
  17. result = subp.run(cmd, stdout=subp.PIPE, encoding="utf-8", check=True)
  18. version = result.stdout.strip().replace("release-", "", 1)
  19. print(version)