From 1a71ac07adafebe7e0074f92d049f72968ca2d47 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 11 Sep 2023 16:46:04 +0200 Subject: [PATCH] meson: restore tools/meson-vcs-tag.sh MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This conceptually reverts e95acdfe1d3a790e18617bb992a712b34f41800d, but the actual contents of the script are taken from the command invocation in meson with all the updates that happened in the meantime. One small change is that I replaced () by {}: this avoids one subprocess spawn. People were worried about the cost of vcs_tag(), and this microoptimization may help a bit. I measured the speed on machine, and noop rebuilds are still about 100–120 ms. The logic is entirely moved to the script. This makes the meson config simpler and also makes it easier to use it externally. The script is needed for in-place rpm builds, see README.build-in-place.md [1], where it is invoked from the spec file to determine the project version. [1] https://src.fedoraproject.org/rpms/systemd/blob/rawhide/f/README.build-in-place.md --- meson.build | 19 +++---------------- tools/meson-vcs-tag.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 16 deletions(-) create mode 100755 tools/meson-vcs-tag.sh diff --git a/meson.build b/meson.build index 807858c4a49..702eaaf652e 100644 --- a/meson.build +++ b/meson.build @@ -1808,26 +1808,13 @@ xml_helper_py = find_program('tools/xml_helper.py') ############################################################ version_tag = get_option('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 version_tag == '' and git.found() and fs.exists(project_source_root / '.git') - # If the working tree has no tags (CI builds), the first git-describe will fail - # and we fall back to project_version-commitid instead. - version_cmd = '''(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/' ''' -else - version_cmd = '''echo "$2" ''' -endif - version_h = vcs_tag( input : 'src/version/version.h.in', output : 'version.h', - # TODO: Use 'sh' variable with meson >= 0.63.0 - command: ['sh', '-euc', version_cmd, - '_', + command: [project_source_root / 'tools/meson-vcs-tag.sh', project_source_root, - version_tag == '' ? meson.project_version() : version_tag, + meson.project_version(), + version_tag, ]) shared_lib_tag = get_option('shared-lib-tag') diff --git a/tools/meson-vcs-tag.sh b/tools/meson-vcs-tag.sh new file mode 100755 index 00000000000..65564bba853 --- /dev/null +++ b/tools/meson-vcs-tag.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later + +set -eu +set -o pipefail + +dir="${1:?}" +fallback="${2:?}" +version_tag="$3" + +if [ -n "${version_tag}" ]; then + # If -Dversion_tag= was used, just use that without further changes. + echo "${version_tag}" +else + # 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. + if [ -e "${dir}/.git" ]; then + c="$(git -C "$dir" describe --abbrev=7 --dirty=^ 2>/dev/null || + echo "${fallback}-$(git -C "$dir" describe --always --abbrev=7)")" + else + c="${fallback}" + fi + echo "$c" | sed 's/^v//; s/-rc/~rc/' +fi -- 2.47.3