]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
meson: Bring back use of vcs_tag
authorJan Janssen <medhefgo@web.de>
Fri, 25 Aug 2023 11:07:55 +0000 (13:07 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 26 Aug 2023 04:53:42 +0000 (13:53 +0900)
The use of vcs_tag was dropped in #28567, which results in builds having
stale version information once new commit are made.

This also fixes a case where CI builds would have no version information
because they are checked out without any tags for git-describe to use.

Additionally, use `--git-dir` now, as that particular issues seems to
have been fixed by now.

meson.build
src/boot/efi/meson.build
src/fundamental/sbat.h

index 7d08c0f852b020a0f286b4b6b9075d20c13b28a7..52e3ebad34fa82284c979c99077c671fb2d66c77 100644 (file)
@@ -1808,29 +1808,31 @@ xml_helper_py = find_program('tools/xml_helper.py')
 ############################################################
 
 version_tag = get_option('version-tag')
-if version_tag == ''
-        # 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 git.found() and fs.exists(project_source_root / '.git')
-                # Apparently git describe has a bug where it always considers the work-tree dirty when
-                # invoked with --git-dir (even though 'git status' is happy). Work around this issue by
-                # cd-ing to the source directory.
-                version_tag = run_command(
-                        sh, '-c',
-                        'cd "$MESON_SOURCE_ROOT"; git describe --abbrev=7 --dirty=^ 2>/dev/null | sed "s/^v//; s/-rc/~rc/"',
-                        check : true,
-                ).stdout().strip()
-        else
-                version_tag = meson.project_version()
-        endif
+# 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 version_tag == '' and git.found() and fs.exists(project_source_root / '.git')
+        version_h = vcs_tag(
+                input : 'src/version/version.h.in',
+                output : 'version.h',
+                # If the working tree has no tags (CI builds), the first git-describe will fail
+                # and we fall back to project_version-commitid instead.
+                # TODO: Use 'sh' variable with meson >= 0.63.0
+                command: ['sh',
+                          '-euc',
+                          '''git -C "$1" describe --abbrev=7 --dirty=^ 2>/dev/null ||
+                                echo "$2-$(git -C "$1" describe --always --abbrev=7)" |
+                                sed 's/^v//; s/-rc/~rc/' ''',
+                          '_',
+                          project_source_root,
+                          meson.project_version()])
+else
+        vcs_data = configuration_data()
+        vcs_data.set('VCS_TAG', version_tag == '' ? meson.project_version() : version_tag)
+        version_h = configure_file(configuration : vcs_data,
+                                   input : 'src/version/version.h.in',
+                                   output : 'version.h')
 endif
 
-vcs_data = configuration_data()
-vcs_data.set('VCS_TAG', version_tag)
-version_h = configure_file(configuration : vcs_data,
-                           input : 'src/version/version.h.in',
-                           output : 'version.h')
-
 versiondep = declare_dependency(
         sources : version_h,
         include_directories : include_directories('.'),
index e35ab91402a1773ce6d06b2781247d14435b4b0c..0effa90c159cbb0ce1e720aab1704c8e8b396ad7 100644 (file)
@@ -92,9 +92,11 @@ elif get_option('sbat-distro') != ''
 
         pkgver = get_option('sbat-distro-version')
         if pkgver == ''
-                pkgver = version_tag
+                # This is determined during build, not configuration, so we can't display it yet.
+                efi_conf.set('SBAT_DISTRO_VERSION', 'GIT_VERSION')
+        else
+                efi_conf.set_quoted('SBAT_DISTRO_VERSION', pkgver)
         endif
-        efi_conf.set_quoted('SBAT_DISTRO_VERSION', pkgver)
 endif
 
 summary({'UEFI architectures' : efi_arch + (efi_arch_alt == '' ? '' : ', ' + efi_arch_alt)},
index b3c09dcb4c332e2cd0d774f8545ebbd51f4232d7..e3198287ba7438b7f14bf7e57a94cfcbcd380539 100644 (file)
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #ifdef SBAT_DISTRO
+#  include "version.h"
 #  define SBAT_SECTION_TEXT \
         "sbat,1,SBAT Version,sbat,1,https://github.com/rhboot/shim/blob/main/SBAT.md\n" \
         SBAT_PROJECT ",1,The systemd Developers," SBAT_PROJECT "," PROJECT_VERSION "," PROJECT_URL "\n" \