From c78b611e48fbfb6963a300c7f0b35b0dded5f4cf Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Fri, 25 Aug 2023 13:07:55 +0200 Subject: [PATCH] meson: Bring back use of vcs_tag 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 | 44 +++++++++++++++++++++------------------- src/boot/efi/meson.build | 6 ++++-- src/fundamental/sbat.h | 1 + 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/meson.build b/meson.build index 7d08c0f852b..52e3ebad34f 100644 --- a/meson.build +++ b/meson.build @@ -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('.'), diff --git a/src/boot/efi/meson.build b/src/boot/efi/meson.build index e35ab91402a..0effa90c159 100644 --- a/src/boot/efi/meson.build +++ b/src/boot/efi/meson.build @@ -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)}, diff --git a/src/fundamental/sbat.h b/src/fundamental/sbat.h index b3c09dcb4c3..e3198287ba7 100644 --- a/src/fundamental/sbat.h +++ b/src/fundamental/sbat.h @@ -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" \