From ea43db77ffee2d2be816d50e2a9fd62bb9205d75 Mon Sep 17 00:00:00 2001 From: Timo Sairiala Date: Wed, 31 Jul 2024 16:06:02 +0300 Subject: [PATCH] add git top info --- Tools/generate_basic_build_info.sh | 5 +++++ src/lib/version/px_update_git_header.py | 11 +++++++++++ src/lib/version/version.c | 5 +++++ src/lib/version/version.h | 6 ++++++ 4 files changed, 27 insertions(+) diff --git a/Tools/generate_basic_build_info.sh b/Tools/generate_basic_build_info.sh index 8838aeef4516..e12f4924d69c 100755 --- a/Tools/generate_basic_build_info.sh +++ b/Tools/generate_basic_build_info.sh @@ -16,7 +16,11 @@ if [ -z "${1:-}" ]; then fi repo=$(basename `git rev-parse --show-toplevel`) +# short sha for compatibility sha=$(git rev-parse --short HEAD) +# separate px4_sha for long sha +px4_sha=$(git rev-parse HEAD) + # github variables are set only in github if [ -z "${GITHUB_SERVER_URL:-}" ] || [ -z "${GITHUB_REPOSITORY:-}" ] || [ -z "${GITHUB_RUN_ID:-}" ]; then build_url="undefined" @@ -28,6 +32,7 @@ fi declare -A build_info build_info["reponame"]=${repo} build_info["sha"]=${sha} +build_info["px4_firmware_sha"]=${px4_sha} build_info["build_url"]=${build_url} # loop thru associative array and print key value pairs diff --git a/src/lib/version/px_update_git_header.py b/src/lib/version/px_update_git_header.py index 61e42865ef60..1fd9ca21d658 100755 --- a/src/lib/version/px_update_git_header.py +++ b/src/lib/version/px_update_git_header.py @@ -107,6 +107,16 @@ if not tag_or_branch.startswith('release-'): tag_or_branch = 'master' +# count commits since last tag +# git log --oneline $(git describe --tags --abbrev=0)..HEAD | wc -l +# this has to be ran with shell=True because if uses $() subshell +try: + git_tag_top = subprocess.check_output('git log --oneline $(git describe --tags --abbrev=0)..HEAD | wc -l', + shell=True, + stderr=subprocess.STDOUT).decode('utf-8').strip() +except: + git_tag_top = 0 + # build timestamp in epoch format build_timestamp = subprocess.check_output('date -u +%s'.split(), stderr=subprocess.STDOUT).decode('utf-8').strip() @@ -119,6 +129,7 @@ #define PX4_GIT_OEM_VERSION_STR "{oem_tag}" #define PX4_GIT_TAG_OR_BRANCH_NAME "{tag_or_branch}" // special variable: git tag, release or master branch +#define PX4_GIT_VERSION_TOP {git_tag_top} #define PX4_BUILD_TIME {build_timestamp} """ diff --git a/src/lib/version/version.c b/src/lib/version/version.c index 6c49e1fd8d04..ea214611d57e 100644 --- a/src/lib/version/version.c +++ b/src/lib/version/version.c @@ -242,6 +242,11 @@ uint32_t px4_firmware_vendor_version(void) return version_tag_to_vendor_version_number(PX4_GIT_TAG_STR); } +uint32_t px4_firmware_git_top_number(void) +{ + return PX4_GIT_VERSION_TOP; +} + const char *px4_firmware_git_branch(void) { return PX4_GIT_BRANCH_NAME; diff --git a/src/lib/version/version.h b/src/lib/version/version.h index d6cb16310e05..f5b7cc2a22eb 100644 --- a/src/lib/version/version.h +++ b/src/lib/version/version.h @@ -141,6 +141,12 @@ __EXPORT uint32_t version_tag_to_vendor_version_number(const char *tag); */ __EXPORT uint32_t px4_firmware_vendor_version(void); +/** + * get the PX4 Firmware vendor version git tag top number + * @return number of git commits after git tag + */ +__EXPORT uint32_t px4_firmware_git_top_number(void); + /** * get the board version (last 8 bytes should be silicon ID, if any) */