Commit d27f7a4d authored by Senthil Kumaran S's avatar Senthil Kumaran S
Browse files

Fix for Debian reproducible builds.

See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=844103

Change-Id: Ifa1652c9ba095b32b353dcdea26303afe161861c
parent 3e8dbfec
......@@ -37,6 +37,46 @@ def version_tag():
from that.
:return: a version string based on the tag and short hash
"""
tag_name = None
if os.path.exists("./.git/"):
tag_list = [
'git', 'for-each-ref', '--sort=taggerdate', '--format',
"'%(refname)'", 'refs/tags',
]
hash_list = ['git', 'log', '-n', '1']
tag_hash_list = ['git', 'rev-list']
clone_data = subprocess.check_output(hash_list).strip().decode('utf-8')
commits = clone_data.split('\n')
clone_hash = commits[0].replace('commit ', '')[:8]
tag_data = subprocess.check_output(tag_list).strip().decode('utf-8')
tags = tag_data.split('\n')
if len(tags) < 2:
return clone_hash
tag_line = str(tags[len(tags) - 1]).replace('\'', '').strip()
tag_name = tag_line.split("/")[2]
tag_hash_list.append(tag_name)
tag_hash = subprocess.check_output(tag_hash_list).strip().decode('utf-8')
tags = tag_hash.split('\n')
tag_hash = tags[0][:8]
if tag_hash == clone_hash:
return tag_name
else:
# tag, month end and release are now out of sync.
# use the rev-list count to always ensure that we are building
# a newer version to cope with date changes at month end.
# use short git hash for reference.
dev_stamp = ['git', 'rev-list', '--count', 'HEAD']
dev_count = subprocess.check_output(dev_stamp).strip().decode('utf-8')
dev_short = ['git', 'rev-parse', '--short', 'HEAD']
dev_hash = subprocess.check_output(dev_short).strip().decode('utf-8')
return "%s+%s.%s" % (tag_name, dev_count, dev_hash)
if not tag_name and os.path.exists('debian/changelog'):
deb_version = subprocess.check_output(('dpkg-parsechangelog',
'--show-field',
'Version')).strip().decode(
'utf-8')
# example version returned would be '2016.11'
return deb_version.split('-')[0]
if not os.path.exists("./.git/"):
base = os.path.basename(os.getcwd())
name_list = ['grep', 'name=', 'setup.py']
......@@ -44,37 +84,6 @@ def version_tag():
name_data = name_data.replace("name=\'", '')
name_data = name_data.replace("\',", '')
return base.replace("%s-" % name_data, '')
tag_list = [
'git', 'for-each-ref', '--sort=taggerdate', '--format',
"'%(refname)'", 'refs/tags',
]
hash_list = ['git', 'log', '-n', '1']
tag_hash_list = ['git', 'rev-list']
clone_data = subprocess.check_output(hash_list).strip().decode('utf-8')
commits = clone_data.split('\n')
clone_hash = commits[0].replace('commit ', '')[:8]
tag_data = subprocess.check_output(tag_list).strip().decode('utf-8')
tags = tag_data.split('\n')
if len(tags) < 2:
return clone_hash
tag_line = str(tags[len(tags) - 1]).replace('\'', '').strip()
tag_name = tag_line.split("/")[2]
tag_hash_list.append(tag_name)
tag_hash = subprocess.check_output(tag_hash_list).strip().decode('utf-8')
tags = tag_hash.split('\n')
tag_hash = tags[0][:8]
if tag_hash == clone_hash:
return tag_name
else:
# tag, month end and release are now out of sync.
# use the rev-list count to always ensure that we are building
# a newer version to cope with date changes at month end.
# use short git hash for reference.
dev_stamp = ['git', 'rev-list', '--count', 'HEAD']
dev_count = subprocess.check_output(dev_stamp).strip().decode('utf-8')
dev_short = ['git', 'rev-parse', '--short', 'HEAD']
dev_hash = subprocess.check_output(dev_short).strip().decode('utf-8')
return "%s+%s.%s" % (tag_name, dev_count, dev_hash)
def main():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment