meson: Really fix git version parsing

The previous attempt to fix git version parsing in commit d34cefad17
("meson: Fix git version parsing") was too naive, and didn't take into
account cases where the libcamera git version contains no or multiple
'+' signs.

Fixing this is more complex than a one-liner change, as meson doesn't
support Python-style slicing of arrays or a length method on strings.
The simplest and most versatile option is to patch the version string in
the gen-version.sh script. Do so, and clarify the comments related to
version handling in meson.build.

Fixes: d34cefad17 ("meson: Fix git version parsing")
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
This commit is contained in:
Laurent Pinchart 2023-03-22 18:35:59 +02:00
parent ac7511dc4c
commit 4cd9cb4a90
2 changed files with 26 additions and 11 deletions

View file

@ -5,6 +5,7 @@
build_dir="$1"
src_dir="$2"
project_version="$3"
# If .tarball-version exists, output the version string from the file and exit.
# This file is auto-generated on a 'meson dist' command from the run-dist.sh
@ -43,6 +44,13 @@ then
fi
git diff-index --quiet HEAD || version="$version-dirty ($(date --iso-8601=seconds))"
# If a project version is provided, use it to replace the version number.
if [ -n "$project_version" ]
then
version=$(echo "$version" | sed -e 's/^[^-]*-//')
version="v$project_version-$version"
fi
# Replace first '-' with a '+' to denote build metadata, strip the 'g' in from
# of the git SHA1 and remove the initial 'v'.
version=$(echo "$version" | sed -e 's/-/+/' | sed -e 's/-g/-/' | cut -c 2-)