1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-11-05 09:50:11 +00:00
jfa-go/version.py
Harvey Tindall 72cf3e2240
add external/internal data options
"make all" will build with internal data, whereas "make debug"/"make
all-external" will make an external "data/" directory.
2021-02-12 14:32:48 +00:00

28 lines
689 B
Python

import subprocess
import sys
try:
version = sys.argv[1].replace('v', '')
except IndexError:
version = "git"
if version == "auto":
try:
version = subprocess.check_output("git describe --exact-match HEAD".split()).decode("utf-8").rstrip().replace('v', '')
except subprocess.CalledProcessError as e:
if e.returncode == 128:
version = "git"
commit = subprocess.check_output("git rev-parse --short HEAD".split()).decode("utf-8").rstrip()
file = f'package main; const VERSION = "{version}"; const COMMIT = "{commit}";'
try:
writeto = sys.argv[2]
except IndexError:
writeto = "version.go"
with open(writeto, 'w') as f:
f.write(file)