diff --git a/cmake/common/px4_base.cmake b/cmake/common/px4_base.cmake index a6d74b4d58c..0783dc6d19c 100644 --- a/cmake/common/px4_base.cmake +++ b/cmake/common/px4_base.cmake @@ -765,6 +765,13 @@ function(px4_create_git_hash_header) ONE_VALUE HEADER REQUIRED HEADER ARGN ${ARGN}) + execute_process( + COMMAND git describe --tags + OUTPUT_VARIABLE git_tag + OUTPUT_STRIP_TRAILING_WHITESPACE + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + ) + message(STATUS "GIT_TAG = ${git_tag}") execute_process( COMMAND git rev-parse HEAD OUTPUT_VARIABLE git_desc diff --git a/cmake/templates/build_git_version.h.in b/cmake/templates/build_git_version.h.in index 83c59c37d9d..99b35517432 100644 --- a/cmake/templates/build_git_version.h.in +++ b/cmake/templates/build_git_version.h.in @@ -2,3 +2,4 @@ /* Do not edit! */ #define PX4_GIT_VERSION_STR "@git_desc@" #define PX4_GIT_VERSION_BINARY 0x@git_desc_short@ +#define PX4_GIT_TAG_STR "@git_tag@" diff --git a/src/modules/systemlib/git_version.h b/src/modules/systemlib/git_version.h index f9bc3cbedd9..d3a5cb15367 100644 --- a/src/modules/systemlib/git_version.h +++ b/src/modules/systemlib/git_version.h @@ -47,5 +47,10 @@ __BEGIN_DECLS __EXPORT extern const char *px4_git_version; __EXPORT extern const uint64_t px4_git_version_binary; +__EXPORT extern const char *px4_git_tag; +__EXPORT extern const char *os_git_tag; +__EXPORT extern const uint32_t px4_board_version; + +__EXPORT uint32_t version_tag_to_number(const char* tag); __END_DECLS diff --git a/src/systemcmds/ver/ver.c b/src/systemcmds/ver/ver.c index 28cd9886278..7afc33fb792 100644 --- a/src/systemcmds/ver/ver.c +++ b/src/systemcmds/ver/ver.c @@ -60,6 +60,48 @@ static const char mcu_uid_str[] = "uid"; const char *px4_git_version = PX4_GIT_VERSION_STR; const uint64_t px4_git_version_binary = PX4_GIT_VERSION_BINARY; +const char *px4_git_tag = PX4_GIT_TAG_STR; + +#if defined(__PX4_NUTTX) +__EXPORT const char *os_git_tag = "6.27"; +__EXPORT const uint32_t px4_board_version = CONFIG_CDCACM_PRODUCTID; +#else +__EXPORT const char *os_git_tag = ""; +__EXPORT const uint32_t px4_board_version = 1; +#endif + +/** + * Convert a version tag string to a number + */ +uint32_t version_tag_to_number(const char* tag) +{ + uint32_t ver = 0; + unsigned len = strlen(tag); + unsigned mag = 1; + bool dotparsed = false; + + for (int i = len - 1; i >= 0; i--) { + if (tag[i] >= '0' && tag[i] <= '9') { + unsigned number = tag[i] - '0'; + + ver += number * mag; + mag *= 10; + } else if (tag[i] == '.') { + continue; + } else if (ver > 100 && dotparsed) { + /* this is a full version and we have enough digits */ + return ver; + } else if (tag[i] != 'v') { + /* reset, because we don't have a full tag but + * are seeing non-numeric characters again + */ + ver = 0; + mag = 1; + } + } + + return ver; +} static void usage(const char *reason) { @@ -109,6 +151,9 @@ int ver_main(int argc, char *argv[]) if (show_all || !strncmp(argv[1], sz_ver_git_str, sizeof(sz_ver_git_str))) { printf("FW git-hash: %s\n", px4_git_version); + printf("FW version: %s (%u)\n", px4_git_tag, version_tag_to_number(px4_git_tag)); + /* middleware is currently the same thing as firmware, so not printing yet */ + printf("OS version: %s (%u)\n", os_git_tag, version_tag_to_number(os_git_tag)); ret = 0; }