diff options
author | Davide Beatrici <git@davidebeatrici.dev> | 2021-01-08 01:19:25 +0300 |
---|---|---|
committer | Davide Beatrici <git@davidebeatrici.dev> | 2021-01-08 01:19:25 +0300 |
commit | d8a5133b090cbffd920a861bb3ca787a8f524998 (patch) | |
tree | 5c97c260738c27bf9994bf1e6ba75c191471853d /scripts | |
parent | 27471118b58e281d305cc95eda8a262dbbd19bd5 (diff) |
BUILD(versioning): Implement "--project" option in mumble-version.py
The option tells the script to print only the project version, i.e. "1.4.0".
This commit also makes the "--newline" argument an option and changes some text, for consistency.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/mumble-version.py | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/scripts/mumble-version.py b/scripts/mumble-version.py index c4a5ee8a7..a52ec42aa 100755 --- a/scripts/mumble-version.py +++ b/scripts/mumble-version.py @@ -57,6 +57,7 @@ from __future__ import (unicode_literals, print_function, division) +import argparse import os import platform import subprocess @@ -72,11 +73,11 @@ def cmd(args): p = subprocess.Popen(args, shell=shell, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() if p.returncode != 0: - raise Exception('cmd: {0} failed with status {1}: {2}'.format(args, p.returncode, stderr)) + raise Exception('cmd(): {0} failed with status {1}: {2}'.format(args, p.returncode, stderr)) return stdout.decode('utf-8') # Reads the version from CMakeLists.txt -def readMumbleVersion(): +def readProjectVersion(): sourceTreeRoot = strip(cmd(['git', 'rev-parse', '--show-toplevel'])) version = None @@ -88,11 +89,31 @@ def readMumbleVersion(): line = line[0 : line.find('.${BUILD_NUMBER}"')].strip() version = line break + if version is None: - raise Exception('unable to read version from CMakeLists.txt') + raise Exception('Unable to read version from CMakeLists.txt') + + if len(version) == 0 or not '.' in version: + raise Exception('Bad version: "{0}"'.format(version)) + return version def main(): + parser = argparse.ArgumentParser() + parser.add_argument('-n', '--newline', action = "store_true", help = 'Break line after printing version') + parser.add_argument('-p', '--project', action = "store_true", help = 'Print CMake project version') + args = parser.parse_args() + + if args.newline: + end = None + else: + end = '' + + if args.project: + projectVersion = readProjectVersion() + print(projectVersion, end = end) + return + # Get all tags associated with the latest commit latestCommitTags = [x for x in cmd(['git', 'tag', '--points-at', 'HEAD']).split("\n") if x] @@ -112,17 +133,11 @@ def main(): # Get the hash of the most recent commit (shortened) latestCommitHash = cmd(['git', 'rev-parse', '--short' , 'HEAD']).strip() - # Get the Mumble version that is set in the CMakeLists.txt file - mumblePriVersion = readMumbleVersion() - if len(mumblePriVersion) == 0 or not '.' in mumblePriVersion: - raise Exception('bad mumblePriVersion: "{0}"'.format(mumblePriVersion)) + projectVersion = readProjectVersion() - version = '{0}~{1}~g{2}~snapshot'.format(mumblePriVersion, latestCommitDate, latestCommitHash) + version = '{0}~{1}~g{2}~snapshot'.format(projectVersion, latestCommitDate, latestCommitHash) - end = '' - if '--newline' in sys.argv: - end = None - print(version, end=end) + print(version, end = end) if __name__ == '__main__': main() |