From b1173f1f623d13f4a3d7070af2113e7396615ae6 Mon Sep 17 00:00:00 2001 From: James Goppert Date: Fri, 13 Jan 2017 03:00:56 -0500 Subject: [PATCH] Fix cmake version detection from git tag. --- CMakeLists.txt | 4 ++-- Tools/tag_to_version.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 Tools/tag_to_version.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 546318cffc..79bd84a6fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,7 +244,7 @@ endif() # version info from git execute_process( - COMMAND Tools/tag_to_version.py ${PX4_SOURCE_DIR} + COMMAND Tools/tag_to_version.py --root ${PX4_SOURCE_DIR} OUTPUT_VARIABLE version WORKING_DIRECTORY ${PX4_SOURCE_DIR} ) @@ -255,7 +255,7 @@ execute_process( WORKING_DIRECTORY ${PX4_SOURCE_DIR} ) set(package-contact "px4users@googlegroups.com") -message(STATUS "PX4 VERSION: ${version}") +message(STATUS "VERSION: ${version}") #============================================================================= # find programs and packages diff --git a/Tools/tag_to_version.py b/Tools/tag_to_version.py new file mode 100644 index 0000000000..fe597ac71d --- /dev/null +++ b/Tools/tag_to_version.py @@ -0,0 +1,17 @@ +import subprocess +import os +import argparse + +p = argparse.ArgumentParser('finds major minor patch version from git tag') +p.add_argument('--root', help="root of git repo", default=".") +args = p.parse_args() +os.chdir(args.root) +p= subprocess.Popen( + 'git describe --always --tags'.split(), + stdout=subprocess.PIPE, stderr=subprocess.PIPE) +stdout, stderr = p.communicate() +res = stdout.split('-')[0].split('.') +major = res[0].replace('v','') +minor = res[1] +patch = res[2] +print("{:s}.{:s}.{:s}".format(major, minor, patch))