2015-12-21 23:10:17 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
|
|
|
# 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."""
|
|
|
|
|
2020-06-02 07:22:36 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2015-12-21 23:10:17 +00:00
|
|
|
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',
|
2020-03-13 16:22:12 +00:00
|
|
|
stderr=subprocess.STDOUT, shell=True).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',
|
2020-03-13 16:22:12 +00:00
|
|
|
stderr=subprocess.STDOUT, shell=True).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:
|
2020-06-02 07:22:36 +00:00
|
|
|
print(version_hash)
|