meson: Really fix git version parsing
The previous attempt to fix git version parsing in commitd34cefad17
("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:
parent
ac7511dc4c
commit
4cd9cb4a90
2 changed files with 26 additions and 11 deletions
29
meson.build
29
meson.build
|
@ -11,15 +11,19 @@ project('libcamera', 'c', 'cpp',
|
|||
license : 'LGPL 2.1+')
|
||||
|
||||
# Generate version information. The libcamera_git_version variable contains the
|
||||
# full version with git patch count and SHA1 (e.g. 1.2.3+211-c94a24f4), while
|
||||
# the libcamera_version variable contains the major.minor.patch (e.g. 1.2.3)
|
||||
# only. If the source tree isn't under git control, or if it matches the last
|
||||
# git version tag, the build metadata (e.g. +211-c94a24f4) is omitted from
|
||||
# libcamera_git_version.
|
||||
# full version with build metadata (patch count and SHA1, e.g.
|
||||
# 1.2.3+211-c94a24f4), while the libcamera_version variable contains the
|
||||
# major.minor.patch (e.g. 1.2.3) only.
|
||||
#
|
||||
# If the source tree matches the last git version tag, the build metadata
|
||||
# (e.g. +211-c94a24f4) is omitted from libcamera_git_version.
|
||||
libcamera_git_version = run_command('utils/gen-version.sh',
|
||||
meson.project_build_root(),
|
||||
meson.project_source_root(),
|
||||
check: false).stdout().strip()
|
||||
|
||||
# If the source tree isn't under git control, set libcamera_git_version to the
|
||||
# meson project version.
|
||||
if libcamera_git_version == ''
|
||||
libcamera_git_version = meson.project_version()
|
||||
endif
|
||||
|
@ -31,7 +35,7 @@ project_version = meson.project_version().split('+')[0]
|
|||
# meson.project_version() could leave the project in a mis-described state.
|
||||
# Produce a warning in this event, and fix to a best effort.
|
||||
if libcamera_version != project_version
|
||||
warning('The sources disagree about the version: '
|
||||
warning('The sources and meson.build disagree about the version: '
|
||||
+ libcamera_version + ' != ' + project_version)
|
||||
|
||||
summary({'libcamera git version' : libcamera_git_version,
|
||||
|
@ -39,13 +43,16 @@ if libcamera_version != project_version
|
|||
},
|
||||
bool_yn : true, section : 'Versions')
|
||||
|
||||
# Replace the version components reported by git with the release version,
|
||||
# but keep all trailing information supplied by git.
|
||||
libcamera_git_version = (project_version + '+' +
|
||||
libcamera_git_version.split('+')[1])
|
||||
# Re-run gen-version.sh to replace the git version (major.minor.patch) with
|
||||
# the meson project version. The build metadata provided by git are kept.
|
||||
libcamera_git_version = run_command('utils/gen-version.sh',
|
||||
meson.project_build_root(),
|
||||
meson.project_source_root(),
|
||||
project_version,
|
||||
check: false).stdout().strip()
|
||||
libcamera_version = project_version
|
||||
|
||||
# Append a marker to show we have modified this version string
|
||||
# Append a marker to show we have modified this version string.
|
||||
libcamera_git_version += '-nvm'
|
||||
endif
|
||||
|
||||
|
|
|
@ -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-)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue