Created
November 15, 2024 15:01
-
-
Save LeSpocky/5e6ce2214925ebc3487c46edccaf9ab2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ptxd_lib_git_bsp_ver() | |
{ | |
local git_ver | |
local sed_ver | |
local dbg_sfx='' | |
git_ver="$(git -C "${PTXDIST_WORKSPACE}" describe --tags --dirty='+' --always)" || | |
ptxd_bailout 'git describe failed!' | |
# for correct version sort replace the dash before an RC suffix | |
# with a tilde. | |
# format of `git describe` is thankfully quite strict and more | |
# or less easy to match, so just some examples: | |
# | |
# v2023.06.3 -> v2023.06.3 (*not* changed) | |
# v2023.06.3+ -> v2023.06.3+ (*not* changed) | |
# v2023.06.3-18-g6923926 -> v2023.06.3-18-g6923926 (*not* changed) | |
# v2023.06.3-18-g6923926+ -> v2023.06.3-18-g6923926+ (*not* changed) | |
# v2023.06.6-RC2 -> v2023.06.6~RC2 | |
# v2023.06.6-RC2-3-g49c5fd0 -> v2023.06.6~RC2-3-g49c5fd0 | |
# v2023.06.6-RC2-3-g49c5fd0+ -> v2023.06.6~RC2-3-g49c5fd0+ | |
# | |
# note: everything before the first matched '-' is printed by | |
# sed as is, no need to match that separately | |
# shellcheck disable=SC2001 | |
sed_ver="$(echo "${git_ver}" | | |
sed -e 's/-\([rR][cC][[:digit:]]\+\)\(-[[:digit:]]\+-g[[:xdigit:]]\+\)\?\(+\)\?$/~\1\2\3/')" || | |
# |\_______________________/\__________________________________/\_____/| |\____/ | |
# | | | | | | | | |
# | `-- the trailing e.g. 'RC1' of our tag | | | | `-- match groups 1 to 3 | |
# `-- the '-' dash we to replace | | | `-- the '~' we want instead | |
# git describe's number of commits and abbrev hash (optional) --' | `-- match EOL | |
# `-- '+' from --dirty='+' (optional) | |
ptxd_bailout 'replacing -RCx with ~RCx failed!' | |
if ptxd_get_ptxconf PTXCONF_TTBUILD_DEBUG_SUPPORT > /dev/null | |
then | |
dbg_sfx='-Debug' | |
fi | |
echo "${sed_ver}${dbg_sfx}" | |
} | |
export -f ptxd_lib_git_bsp_ver |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment