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.
30 lines
824 B
30 lines
824 B
8 years ago
|
#!/usr/bin/env python3
|
||
10 years ago
|
|
||
|
import sys, os, subprocess
|
||
|
|
||
|
def generate(infile, outfile, fallback):
|
||
|
workdir = os.path.split(infile)[0]
|
||
|
if workdir == '':
|
||
|
workdir = '.'
|
||
10 years ago
|
try:
|
||
7 years ago
|
version = subprocess.check_output(['git', 'describe'], cwd=workdir).decode().strip()
|
||
7 years ago
|
except (subprocess.CalledProcessError, OSError, UnicodeDecodeError):
|
||
7 years ago
|
version = fallback
|
||
8 years ago
|
with open(infile) as f:
|
||
|
newdata = f.read().replace('@VERSION@', version)
|
||
10 years ago
|
try:
|
||
8 years ago
|
with open(outfile) as f:
|
||
|
olddata = f.read()
|
||
10 years ago
|
if olddata == newdata:
|
||
|
return
|
||
7 years ago
|
except OSError:
|
||
10 years ago
|
pass
|
||
8 years ago
|
with open(outfile, 'w') as f:
|
||
|
f.write(newdata)
|
||
10 years ago
|
|
||
|
if __name__ == '__main__':
|
||
|
infile = sys.argv[1]
|
||
|
outfile = sys.argv[2]
|
||
|
fallback = sys.argv[3]
|
||
|
generate(infile, outfile, fallback)
|