aboutsummaryrefslogtreecommitdiffstats
path: root/meson/test cases/common/65 build always/version_gen.py
diff options
context:
space:
mode:
Diffstat (limited to 'meson/test cases/common/65 build always/version_gen.py')
-rwxr-xr-xmeson/test cases/common/65 build always/version_gen.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/meson/test cases/common/65 build always/version_gen.py b/meson/test cases/common/65 build always/version_gen.py
new file mode 100755
index 000000000..fbe2df93f
--- /dev/null
+++ b/meson/test cases/common/65 build always/version_gen.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+
+import sys, os, subprocess
+
+def generate(infile, outfile, fallback):
+ workdir = os.path.split(infile)[0]
+ if workdir == '':
+ workdir = '.'
+ try:
+ version = subprocess.check_output(['git', 'describe'], cwd=workdir).decode().strip()
+ except (subprocess.CalledProcessError, OSError, UnicodeDecodeError):
+ version = fallback
+ with open(infile) as f:
+ newdata = f.read().replace('@VERSION@', version)
+ try:
+ with open(outfile) as f:
+ olddata = f.read()
+ if olddata == newdata:
+ return
+ except OSError:
+ pass
+ with open(outfile, 'w') as f:
+ f.write(newdata)
+
+if __name__ == '__main__':
+ infile = sys.argv[1]
+ outfile = sys.argv[2]
+ fallback = sys.argv[3]
+ generate(infile, outfile, fallback)