mirror of
https://github.com/AdaCore/Certyflie.git
synced 2026-02-12 12:27:35 -08:00
Some people prefer to use git (easy possible by using git-hg) therefor make the version-scripts git-aware. To not change the view of the version string(s), the version when using git still looks the same as if mercury is used (and not like a standard git-version).
80 lines
2.2 KiB
Python
80 lines
2.2 KiB
Python
#!/usr/bin/env python
|
|
|
|
import sys
|
|
import subprocess
|
|
import os
|
|
|
|
|
|
version = { }
|
|
|
|
header = """/* This file is automatically generated by {0}!
|
|
* Do not edit manually, any manual change will be overwritten.
|
|
*/
|
|
"""
|
|
|
|
if len(sys.argv)<3:
|
|
print("Usage:")
|
|
print(" {0} <infile> <outfile>".format(sys.argv[0]))
|
|
sys.exit(1)
|
|
|
|
#Get the build repos information
|
|
if os.path.isdir(".git"):
|
|
# git
|
|
revision = subprocess.check_output(["git", "rev-parse", "HEAD"]).strip()
|
|
|
|
version['revision'] = revision[0:12]
|
|
version['irevision0'] = "0x" + revision[0:8]
|
|
version['irevision1'] = "0x" + revision[8:12]
|
|
|
|
identify = subprocess.check_output(["git", "describe", "--abbrev=12", "--tags", "HEAD"])
|
|
identify = identify.split('-')
|
|
|
|
if len(identify) > 2:
|
|
version['local_revision'] = identify[len(identify)-2] + '+'
|
|
else:
|
|
version['local_revision'] = '0'
|
|
|
|
version['tag'] = identify[0]
|
|
for x in range(1, len(identify)-2):
|
|
version['tag'] += '-'
|
|
version['tag'] += identify[x]
|
|
|
|
branch = subprocess.check_output(["git", "branch", "--contains"])[2:].strip()
|
|
version['branch'] = branch
|
|
|
|
subprocess.call(["git", "update-index", "-q", "--refresh"])
|
|
changes = subprocess.check_output(["git", "diff-index", "--name-only", "HEAD", "--"]).strip()
|
|
if len(changes):
|
|
version['modified'] = 'true'
|
|
else:
|
|
version['modified'] = 'false'
|
|
else:
|
|
# mercury
|
|
identify = subprocess.check_output(["hg", "identify", "-nitb"])
|
|
identify = identify.split()
|
|
version['revision'] = identify[0]
|
|
version['irevision0'] = "0x" + identify[0][0:8]
|
|
version['irevision1'] = "0x" + identify[0][8:12]
|
|
version['local_revision'] = identify[1]
|
|
version['branch'] = identify[2]
|
|
if len(identify)>3:
|
|
version['tag'] = identify[3]
|
|
else:
|
|
version['tag'] = ""
|
|
|
|
try:
|
|
version['local_revision'].index('+')
|
|
version['modified'] = 'true'
|
|
except Exception:
|
|
version['modified'] = 'false'
|
|
|
|
#Apply information to the file template
|
|
infile = open(sys.argv[1], 'r')
|
|
outfile = open(sys.argv[2], 'w')
|
|
|
|
outfile.write(header.format(sys.argv[0], sys.argv[1]))
|
|
outfile.write(infile.read().format(**version))
|
|
|
|
infile.close()
|
|
outfile.close()
|