tarball: capture Git version

Commit 92dae88f62 (tarball: remove redundant "version" file,
2026-01-12) committed to using Cargo.toml as single source of truth
for our version string.

This works fine for tarballs built from a tag, but those built from
an arbitrary Git commit will show a misleading version ("4.3.3"
instead of something like "4.3.3-190-g460081725b5-dirty").

Fix this by copying the Git version to the tarball's Cargo.{toml,lock}.

It's not clear if we really need this (it's only for nightly builds)
so we might end up reverting this.

Ref: https://matrix.to/#/!YLTeaulxSDauOOxBoR:matrix.org/$BdRagDGCV-8yVjBs0i3QyWUdBK820vTmjuSBqgpsuJY

Note that OBS builds are probably still broken from 081c469f6f
(tarball: include .cargo/config.toml again, 2026-01-13); see
https://github.com/fish-shell/fish-shell/pull/12292#discussion_r2694000477
This commit is contained in:
Johannes Altmanninger
2026-02-01 19:20:21 +11:00
parent bb7dce941a
commit 73e3b47ebd

View File

@@ -16,11 +16,40 @@ VERSION=$(build_tools/git_version_gen.sh)
prefix=fish-$VERSION
path=${FISH_ARTEFACT_PATH:-~/fish_built}/$prefix.tar.xz
tmpdir=$(mktemp -d)
manifest=$tmpdir/Cargo.toml
lockfile=$tmpdir/Cargo.lock
sed "s/^version = \".*\"\$/version = \"$VERSION\"/g" Cargo.toml \
>"$manifest"
awk -v version=$VERSION '
/^name = "fish"$/ { ok=1 }
ok == 1 && /^version = ".*"$/ {
ok = 2;
$0 = "version = \"" version "\"";
}
{print}
' \
Cargo.lock >"$lockfile"
for ext in toml lock; do
if cmp Cargo.$ext "$tmpdir/Cargo.$ext" >/dev/null; then
echo >&2 "failed to update Cargo.$ext version?"
exit 1
fi
done
git archive \
--prefix="$prefix/" \
--add-virtual-file="$prefix/Cargo.toml:$(cat "$manifest")" \
--add-virtual-file="$prefix/Cargo.lock:$(cat "$lockfile")" \
HEAD "$@" |
xz >"$path"
rm "$manifest"
rm "$lockfile"
rmdir "$tmpdir"
# Output what we did, and the sha256 hash
echo "Tarball written to $path"
openssl dgst -sha256 "$path"