summaryrefslogtreecommitdiffstats
path: root/tools/meson-vcs-tag.sh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
commit55944e5e40b1be2afc4855d8d2baf4b73d1876b5 (patch)
tree33f869f55a1b149e9b7c2b7e201867ca5dd52992 /tools/meson-vcs-tag.sh
parentInitial commit. (diff)
downloadsystemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.tar.xz
systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.zip
Adding upstream version 255.4.upstream/255.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/meson-vcs-tag.sh')
-rwxr-xr-xtools/meson-vcs-tag.sh33
1 files changed, 33 insertions, 0 deletions
diff --git a/tools/meson-vcs-tag.sh b/tools/meson-vcs-tag.sh
new file mode 100755
index 0000000..4a8dc89
--- /dev/null
+++ b/tools/meson-vcs-tag.sh
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+set -u
+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.
+
+ c=''
+ if [ -e "${dir}/.git" ]; then
+ c="$(git -C "$dir" describe --abbrev=7 --dirty=^ 2>/dev/null)"
+ if [ -z "$c" ]; then
+ # This call might still fail with permission issues
+ suffix="$(git -C "$dir" describe --always --abbrev=7 --dirty=^ 2>/dev/null)"
+ [ -n "$suffix" ] && c="${fallback}-${suffix}"
+ fi
+ fi
+ [ -z "$c" ] && c="${fallback}"
+ echo "$c" | sed 's/^v//; s/-rc/~rc/'
+fi