summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meson.build28
-rw-r--r--meson_options.txt4
-rw-r--r--src/boot/efi/meson.build1
-rw-r--r--src/version/version.h.in2
-rwxr-xr-xtools/meson-vcs-tag.sh42
5 files changed, 26 insertions, 51 deletions
diff --git a/meson.build b/meson.build
index 1c583027f2..4d1ee361e5 100644
--- a/meson.build
+++ b/meson.build
@@ -1853,13 +1853,27 @@ xml_helper_py = find_program('tools/xml_helper.py')
#####################################################################
version_tag = get_option('version-tag')
-version_h = vcs_tag(
- input : 'src/version/version.h.in',
- output : 'version.h',
- command: [project_source_root / 'tools/meson-vcs-tag.sh',
- project_source_root,
- version_tag,
- ])
+if version_tag == ''
+ version_tag = meson.project_version()
+endif
+
+conf.set_quoted('VERSION_TAG', version_tag)
+
+vcs_tag = get_option('vcs-tag')
+if vcs_tag and fs.is_dir(project_source_root / '.git')
+ version_h = vcs_tag(
+ input : 'src/version/version.h.in',
+ output : 'version.h',
+ fallback : '',
+ command : ['sh', '-c', 'echo "-g$(git -C . describe --abbrev=7 --match="" --always --dirty=^)"'],
+ )
+else
+ version_h = configure_file(
+ input : 'src/version/version.h.in',
+ output : 'version.h',
+ configuration : configuration_data({'VCS_TAG' : ''}),
+ )
+endif
shared_lib_tag = get_option('shared-lib-tag')
if shared_lib_tag == ''
diff --git a/meson_options.txt b/meson_options.txt
index b51af01721..4dea1a8bf3 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -2,9 +2,11 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
option('version-tag', type : 'string',
- description : 'override the git version string')
+ description : 'set the extended version string (defaults to project version)')
option('shared-lib-tag', type : 'string',
description : 'override the private shared library version tag (defaults to project version)')
+option('vcs-tag', type : 'boolean', value : true,
+ description : 'append current git commit to version output when git information is available')
option('mode', type : 'combo', choices : ['developer', 'release'],
description : 'autoenable features suitable for systemd development/release builds')
diff --git a/src/boot/efi/meson.build b/src/boot/efi/meson.build
index 2e22bdf57f..b5d4e96303 100644
--- a/src/boot/efi/meson.build
+++ b/src/boot/efi/meson.build
@@ -68,6 +68,7 @@ if meson.is_cross_build() and get_option('sbat-distro') == 'auto'
elif get_option('sbat-distro') != ''
efi_conf.set_quoted('SBAT_PROJECT', meson.project_name())
efi_conf.set_quoted('PROJECT_VERSION', meson.project_version().split('~')[0])
+ efi_conf.set_quoted('VERSION_TAG', version_tag)
efi_conf.set('PROJECT_URL', conf.get('PROJECT_URL'))
if get_option('sbat-distro-generation') < 1
error('SBAT Distro Generation must be a positive integer')
diff --git a/src/version/version.h.in b/src/version/version.h.in
index 083779aab0..01ff697434 100644
--- a/src/version/version.h.in
+++ b/src/version/version.h.in
@@ -7,4 +7,4 @@
* - where a simplified machine-parsable form is more useful, for example
* pkgconfig files and version information written to binary files.
*/
-#define GIT_VERSION "@VCS_TAG@"
+#define GIT_VERSION VERSION_TAG "@VCS_TAG@"
diff --git a/tools/meson-vcs-tag.sh b/tools/meson-vcs-tag.sh
deleted file mode 100755
index 16cf11007d..0000000000
--- a/tools/meson-vcs-tag.sh
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/usr/bin/env bash
-# SPDX-License-Identifier: LGPL-2.1-or-later
-
-set -u
-set -o pipefail
-
-dir="${1:-.}"
-version_tag="${2:-}"
-
-if [ -n "${version_tag}" ]; then
- # If -Dversion_tag= was used, just use that without further changes.
- echo "${version_tag}"
-else
- read -r project_version <"${dir}/meson.version"
-
- # Check that we have either .git/ (a normal clone) or a .git file (a work-tree)
- # and that we don't get confused if a tarball is extracted in a higher-level
- # git repository.
- #
- # If the working tree has no tags (CI builds), the first git-describe will fail
- # and we fall back to project_version-commitid instead.
-
- c=''
- if [ -e "${dir}/.git" ]; then
- c="$(git -C "$dir" describe --abbrev=7 --dirty=^ 2>/dev/null)"
- if [ -n "$c" ]; then
- # git describe uses the most recent tag. However, for development versions (e.g. v256~devel), the
- # most recent tag will be v255 as there is no tag for development versions. To deal with this, we
- # replace the tag with the project version instead.
- c="${project_version}-${c#*-}"
- else
- # This call might still fail with permission issues
- suffix="$(git -C "$dir" describe --always --abbrev=7 --dirty=^ 2>/dev/null)"
- [ -n "$suffix" ] && c="${project_version}-${suffix}"
- fi
- fi
- [ -z "$c" ] && c="${project_version}"
- # Replace any hyphens with carets which are allowed in versions by pacman whereas hyphens are not. Git
- # versions with carets will also sort higher than their non-git version counterpart both in pacman
- # versioning and in version format specification versioning.
- echo "$c" | sed 's/^v//; s/-/^/g'
-fi