]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
meson: Decouple the version tag from the vcs tag 31352/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 16 Feb 2024 15:58:58 +0000 (16:58 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 21 Feb 2024 13:01:25 +0000 (14:01 +0100)
Let's split off a new vcs-tag option from version-tag that configures whether
the current commit should be appended to the version tag. Doing this saves
us from having to fiddle around with generating git versions in packaging
specs and instead let's meson do it for us, even if we pass in a custom
version tag.

With this approach there's no more need for tools/meson-vcs-tag.sh so
we remove it.

meson.build
meson_options.txt
src/boot/efi/meson.build
src/version/version.h.in
tools/meson-vcs-tag.sh [deleted file]

index 1c583027f2fc674087d2bd9d8e7658be3a4dc2e3..4d1ee361e56face0da9b293f8c471d7d3cbecc53 100644 (file)
@@ -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 == ''
index b51af01721d419633afce4ed4e1a59bca508b3cf..4dea1a8bf31a7669033afbe7179367fbea1f002b 100644 (file)
@@ -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')
index 2e22bdf57fe3068fe824e95792e1ce1c18b8965e..b5d4e9630320cfbbf8c2028bf4d52ea388bcb585 100644 (file)
@@ -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')
index 083779aab0ec560b29262809f698b617fbfa1f35..01ff697434eb3699a2878eb235a3f7a41a3e59cc 100644 (file)
@@ -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 (executable)
index 16cf110..0000000
+++ /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