Make vcs-tag do something useful for non-developer mode as well
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 19 Jul 2024 11:05:11 +0000 (13:05 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 24 Jul 2024 12:26:49 +0000 (14:26 +0200)
When building packages of arbitrary commits of systemd-stable,
distributors might want to include a git sha of the exact commit
they're on. Let's extend vcs-tag a little to make this possible.

If we're on a commit matching a tag, don't generate a git sha at all.
If we're not on a commit matching a tag, generate a vcs tag as usually.
However, if we're not in developer mode, don't append a '^' if the tree
is dirty to accomodate package builds applying various patches to the
tree which shouldn't be considered as "dirty" edits.

(cherry picked from commit 944faf65986f36d7ed3a4ba5cb4cc763011f0f77)

meson.build
tools/vcs-tag.sh [new file with mode: 0755]

index bb0348e729637d52b1adc5c182b9f5e5b2228b22..0548e2e31d56c0ccca6d015e4e0e5835c7030115 100644 (file)
@@ -1995,14 +1995,11 @@ endif
 conf.set_quoted('VERSION_TAG', version_tag)
 
 vcs_tag = get_option('vcs-tag')
-command = ['sh', '-c',
-           vcs_tag and fs.exists(project_source_root / '.git') ?
-                   'echo "-g$(git -C . describe --abbrev=7 --match="" --always --dirty=^)"' : ':']
 version_h = vcs_tag(
         input : 'src/version/version.h.in',
         output : 'version.h',
         fallback : '',
-        command : command,
+        command : [vcs_tag ? 'tools/vcs-tag.sh' : 'true', get_option('mode')],
 )
 
 shared_lib_tag = get_option('shared-lib-tag')
diff --git a/tools/vcs-tag.sh b/tools/vcs-tag.sh
new file mode 100755 (executable)
index 0000000..5da39cc
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+set -e
+
+MODE="$1"
+
+if ! [[ -d .git ]] || git describe --tags --exact-match &>/dev/null; then
+    exit 0
+fi
+
+if [[ "$MODE" == "developer" ]]; then
+    DIRTY="--dirty=^"
+else
+    DIRTY=""
+fi
+
+echo "-g$(git describe --abbrev=7 --match="" --always $DIRTY)"