2021-08-26 16:44:02 +00:00
|
|
|
#!/usr/bin/python3
|
2015-12-21 23:10:17 +00:00
|
|
|
#
|
2023-12-01 17:32:19 +00:00
|
|
|
# Copyright 2015 Google LLC. All rights reserved.
|
2015-12-21 23:10:17 +00:00
|
|
|
#
|
|
|
|
# Use of this source code is governed by a BSD-style
|
|
|
|
# license that can be found in the LICENSE file or at
|
|
|
|
# https://developers.google.com/open-source/licenses/bsd
|
|
|
|
"""This script is used to generate version string for packager."""
|
|
|
|
|
|
|
|
import subprocess
|
2024-03-12 20:09:38 +00:00
|
|
|
import sys
|
2015-12-21 23:10:17 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2016-02-10 00:21:55 +00:00
|
|
|
try:
|
2021-06-18 19:23:22 +00:00
|
|
|
version_tag = subprocess.check_output('git tag --points-at HEAD',
|
2021-08-26 16:44:02 +00:00
|
|
|
stderr=subprocess.STDOUT, shell=True).decode().rstrip()
|
2024-03-12 20:09:38 +00:00
|
|
|
if version_tag:
|
|
|
|
print('Found version tag: {}'.format(version_tag), file=sys.stderr)
|
|
|
|
else:
|
|
|
|
print('Cannot find version tag!', file=sys.stderr)
|
2016-02-10 00:21:55 +00:00
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
# git tag --points-at is not supported in old versions of git. Just ignore
|
|
|
|
# version_tag in this case.
|
|
|
|
version_tag = None
|
2024-03-12 20:09:38 +00:00
|
|
|
print('Old version of git, cannot determine version tag!', file=sys.stderr)
|
2016-02-10 00:21:55 +00:00
|
|
|
|
|
|
|
try:
|
2021-06-18 19:23:22 +00:00
|
|
|
version_hash = subprocess.check_output('git rev-parse --short HEAD',
|
2021-08-26 16:44:02 +00:00
|
|
|
stderr=subprocess.STDOUT, shell=True).decode().rstrip()
|
2024-03-12 20:09:38 +00:00
|
|
|
print('Version hash: {}'.format(version_hash), file=sys.stderr)
|
2016-02-10 00:21:55 +00:00
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
version_hash = 'unknown-version'
|
2024-03-12 20:09:38 +00:00
|
|
|
print('Cannot find version hasah!', file=sys.stderr)
|
2016-02-10 00:21:55 +00:00
|
|
|
|
2015-12-21 23:10:17 +00:00
|
|
|
if version_tag:
|
2024-03-12 20:09:38 +00:00
|
|
|
output = '{0}-{1}'.format(version_tag, version_hash)
|
2015-12-21 23:10:17 +00:00
|
|
|
else:
|
2024-03-12 20:09:38 +00:00
|
|
|
output = version_hash
|
|
|
|
|
|
|
|
# Final debug message, mirroring what is used to generate the source file:
|
|
|
|
print('Final output: {}'.format(output), file=sys.stderr)
|
|
|
|
|
|
|
|
# Actually used to generate the source file:
|
|
|
|
print(output)
|