Files
panopainter/scripts/pre-build.py

48 lines
1.7 KiB
Python

from subprocess import Popen, PIPE, check_output
from tempfile import mkstemp
from shutil import move
from os import remove, close
import re, subprocess, sys
branch = check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).rstrip().decode("utf-8")
shorthash = check_output(["git", "log", "--pretty=format:%h", "-n 1"]).rstrip().decode("utf-8")
revcount = len(check_output(["git", "log", "--oneline"]).split(b'\n')) - 1
tag = check_output(["git", "describe", "--tags", "--abbrev=0"]).rstrip().decode("utf-8")
config = sys.argv[1]
version = "%s.%d (%s-%s-%s)" % (tag, revcount, shorthash, branch, config)
version_number = "%s.%d" % (tag, revcount)
print("Compiling version: %s" % version)
version_gen_h = '// AUTO GENERATED FILE - DON\'T MODIFY\n'
version_gen_h += '#define PP_VERSION_NUMBER_STRING "%s"\n' % version_number
version_gen_h += '#define PP_VERSION_STRING "%s"\n' % version
version_gen_h += '#define PP_RC_BUILD_VERSION %s,0\n' % version_number.replace('.',',')
version_gen_h += '#define PP_RC_BUILD_VERSION_STRING "%s\\0"\n' % version
version_gen_h += '#define PP_RC_PRODUCT_VERSION %s,0,0\n' % tag.replace('.',',')
version_gen_h += '#define PP_RC_PRODUCT_VERSION_STRING "%s\\0"\n' % tag
f = open("engine/version.gen.h", "w")
f.write(version_gen_h)
"""
file_path = "Setup\\Product.wxs";
#Create temp file
fh, abs_path = mkstemp()
regex = re.compile(r'Version="\d+\.\d+\.\d+\.\d+"')
with open(abs_path,'w') as new_file:
with open(file_path) as old_file:
for line in old_file:
new_line = regex.sub('Version="%s"' % version, line)
new_file.write(new_line)
close(fh)
#Remove original file
remove(file_path)
#Move new file
move(abs_path, file_path)
"""
exit(0)