]> git.ipfire.org Git - thirdparty/systemd.git/blame - tools/meson-vcs-tag.sh
man/systemd-sysext.xml: document mutable extensions
[thirdparty/systemd.git] / tools / meson-vcs-tag.sh
CommitLineData
1a71ac07
ZJS
1#!/usr/bin/env bash
2# SPDX-License-Identifier: LGPL-2.1-or-later
3
725e6468 4set -u
1a71ac07
ZJS
5set -o pipefail
6
ea2a57be
DDM
7dir="${1:-.}"
8version_tag="${2:-}"
1a71ac07
ZJS
9
10if [ -n "${version_tag}" ]; then
11 # If -Dversion_tag= was used, just use that without further changes.
12 echo "${version_tag}"
13else
ea2a57be
DDM
14 read -r project_version <"${dir}/meson.version"
15
1a71ac07
ZJS
16 # Check that we have either .git/ (a normal clone) or a .git file (a work-tree)
17 # and that we don't get confused if a tarball is extracted in a higher-level
18 # git repository.
19 #
20 # If the working tree has no tags (CI builds), the first git-describe will fail
21 # and we fall back to project_version-commitid instead.
725e6468
ZJS
22
23 c=''
1a71ac07 24 if [ -e "${dir}/.git" ]; then
725e6468 25 c="$(git -C "$dir" describe --abbrev=7 --dirty=^ 2>/dev/null)"
ea2a57be
DDM
26 if [ -n "$c" ]; then
27 # git describe uses the most recent tag. However, for development versions (e.g. v256~devel), the
28 # most recent tag will be v255 as there is no tag for development versions. To deal with this, we
29 # replace the tag with the project version instead.
30 c="${project_version}-${c#*-}"
31 else
725e6468
ZJS
32 # This call might still fail with permission issues
33 suffix="$(git -C "$dir" describe --always --abbrev=7 --dirty=^ 2>/dev/null)"
ea2a57be 34 [ -n "$suffix" ] && c="${project_version}-${suffix}"
725e6468 35 fi
1a71ac07 36 fi
ea2a57be 37 [ -z "$c" ] && c="${project_version}"
6d55e3a3
DDM
38 # Replace any hyphens with carets which are allowed in versions by pacman whereas hyphens are not. Git
39 # versions with carets will also sort higher than their non-git version counterpart both in pacman
dbb9a6ad 40 # versioning and in version format specification versioning.
6d55e3a3 41 echo "$c" | sed 's/^v//; s/-/^/g'
1a71ac07 42fi