turbo-editors/turbo-rustpublic Fork 0
v1.0.1
Commits
Clone
git clone https://git.rickub.com/turbo-editors/turbo-rust.git
git clone ssh://git@rickub.com/turbo-editors/turbo-rust.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

📦 Turbo Rust 713ea5c · on v1.0.1 · k33g · 10h ago
check-version.sh · 72 lines · 2.4 KBBash Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
#
# Check that a freshly built binary reports the version the build meant to put
# into it.
#
#   scripts/check-version.sh bin/turbo-rust v0.2.0 88a4c38
#   scripts/check-version.sh bin/turbo-rust            # unstamped build
#
# Linker flags are a string: a typo in one produces a binary that builds, links
# and runs, and quietly reports the wrong version — or "unknown". Nothing but
# running the binary catches that, so the build runs it.
#
# With a version to expect, the reported number must **equal** it. A substring
# test is not enough: "0.2.0" is a substring of "10.2.0" and of a commit hash
# that happens to contain it, and the case this exists to catch is a stamp that
# is nearly right.
#
# With no version to expect — a build outside a git checkout, where there is
# nothing to describe — the only claim left is that some source named it, so
# "unknown" is the failure.

set -euo pipefail

if [ $# -lt 1 ]; then
	echo "usage: $0 <binary> [expected-version] [expected-commit]" >&2
	exit 2
fi

readonly BINARY="$1"
readonly EXPECTED_VERSION="${2:-}"
readonly EXPECTED_COMMIT="${3:-}"

if [ ! -x "${BINARY}" ]; then
	echo "check-version: ${BINARY} is not an executable file" >&2
	exit 1
fi

if ! reported="$("${BINARY}" -version 2>&1)"; then
	echo "check-version: ${BINARY} does not run:" >&2
	echo "${reported}" >&2
	exit 1
fi

# The binary prints "<Name> <number>" or "<Name> <number> (<commit>, built …)",
# so the number is the last field before the parenthesis, if there is one. The
# name is two words in every editor built on turbo-core and one word in some
# future one, which is why it is read from the right rather than the left.
head="${reported%% (*}"
number="${head##* }"

if [ -n "${EXPECTED_VERSION}" ]; then
	# The version package drops the leading v of a tag: the tag is v0.2.0 and
	# what a person reads is 0.2.0.
	want="${EXPECTED_VERSION#v}"
	if [ "${number}" != "${want}" ]; then
		echo "check-version: the build meant to stamp ${want} and the binary reports ${number}" >&2
		echo "  ${reported}" >&2
		exit 1
	fi
elif [ "${number}" = "unknown" ]; then
	echo "check-version: the binary cannot name its own version" >&2
	echo "  ${reported}" >&2
	exit 1
fi

if [ -n "${EXPECTED_COMMIT}" ] && [ "${reported}" = "${reported#*"${EXPECTED_COMMIT}"}" ]; then
	echo "check-version: the build meant to stamp commit ${EXPECTED_COMMIT} and the binary reports:" >&2
	echo "  ${reported}" >&2
	exit 1
fi

echo "${reported}"