2021-08-26 16:44:02 +00:00
|
|
|
#!/usr/bin/python3
|
2015-12-21 23:10:17 +00:00
|
|
|
#
|
|
|
|
# Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
|
|
|
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()
|
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
|
|
|
|
|
|
|
|
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()
|
2016-02-10 00:21:55 +00:00
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
version_hash = 'unknown-version'
|
|
|
|
|
2015-12-21 23:10:17 +00:00
|
|
|
if version_tag:
|
2020-06-02 07:22:36 +00:00
|
|
|
print('{0}-{1}'.format(version_tag, version_hash))
|
2015-12-21 23:10:17 +00:00
|
|
|
else:
|
2021-08-26 16:44:02 +00:00
|
|
|
print(version_hash)
|