The Meson Build System http://mesonbuild.com/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
892 B

10 years ago
#!/usr/bin/env python3
import sys, os, subprocess
def generate(infile, outfile, fallback):
workdir = os.path.split(infile)[0]
if workdir == '':
workdir = '.'
version = fallback
try:
p = subprocess.Popen(['git', 'describe'], cwd=workdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdo, _) = p.communicate()
if p.returncode == 0:
version = stdo.decode().strip()
except:
pass
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:
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)