Skip to content

Commit

Permalink
version: add git top info
Browse files Browse the repository at this point in the history
Generate PX4_GIT_VERSION_TOP define in build time to get
count of commits on top of last tag.
This info is used for FC-OTA update mechanism.
  • Loading branch information
TimoSairiala authored and jnippula committed Aug 23, 2024
1 parent 3496d25 commit 173baf4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Tools/generate_basic_build_info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/lib/version/px_update_git_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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}
"""

Expand Down
5 changes: 5 additions & 0 deletions src/lib/version/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/lib/version/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand Down

0 comments on commit 173baf4

Please sign in to comment.