turbo-editors/turbo-rustpublic Fork 0
v1.0.2
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.

check-version.sh · 72 lines · 2.4 KBBash Blame HistoryRaw
📦 Turbo Rust 713ea5c k33g 11h ago1#!/usr/bin/env bash
2#
3# Check that a freshly built binary reports the version the build meant to put
4# into it.
5#
6# scripts/check-version.sh bin/turbo-rust v0.2.0 88a4c38
7# scripts/check-version.sh bin/turbo-rust # unstamped build
8#
9# Linker flags are a string: a typo in one produces a binary that builds, links
10# and runs, and quietly reports the wrong version — or "unknown". Nothing but
11# running the binary catches that, so the build runs it.
12#
13# With a version to expect, the reported number must **equal** it. A substring
14# test is not enough: "0.2.0" is a substring of "10.2.0" and of a commit hash
15# that happens to contain it, and the case this exists to catch is a stamp that
16# is nearly right.
17#
18# With no version to expect — a build outside a git checkout, where there is
19# nothing to describe — the only claim left is that some source named it, so
20# "unknown" is the failure.
21
22set -euo pipefail
23
24if [ $# -lt 1 ]; then
25 echo "usage: $0 <binary> [expected-version] [expected-commit]" >&2
26 exit 2
27fi
28
29readonly BINARY="$1"
30readonly EXPECTED_VERSION="${2:-}"
31readonly EXPECTED_COMMIT="${3:-}"
32
33if [ ! -x "${BINARY}" ]; then
34 echo "check-version: ${BINARY} is not an executable file" >&2
35 exit 1
36fi
37
38if ! reported="$("${BINARY}" -version 2>&1)"; then
39 echo "check-version: ${BINARY} does not run:" >&2
40 echo "${reported}" >&2
41 exit 1
42fi
43
44# The binary prints "<Name> <number>" or "<Name> <number> (<commit>, built …)",
45# so the number is the last field before the parenthesis, if there is one. The
46# name is two words in every editor built on turbo-core and one word in some
47# future one, which is why it is read from the right rather than the left.
48head="${reported%% (*}"
49number="${head##* }"
50
51if [ -n "${EXPECTED_VERSION}" ]; then
52 # The version package drops the leading v of a tag: the tag is v0.2.0 and
53 # what a person reads is 0.2.0.
54 want="${EXPECTED_VERSION#v}"
55 if [ "${number}" != "${want}" ]; then
56 echo "check-version: the build meant to stamp ${want} and the binary reports ${number}" >&2
57 echo " ${reported}" >&2
58 exit 1
59 fi
60elif [ "${number}" = "unknown" ]; then
61 echo "check-version: the binary cannot name its own version" >&2
62 echo " ${reported}" >&2
63 exit 1
64fi
65
66if [ -n "${EXPECTED_COMMIT}" ] && [ "${reported}" = "${reported#*"${EXPECTED_COMMIT}"}" ]; then
67 echo "check-version: the build meant to stamp commit ${EXPECTED_COMMIT} and the binary reports:" >&2
68 echo " ${reported}" >&2
69 exit 1
70fi
71
72echo "${reported}"