From e17874960f466705ff18ab4cfa4f0407e6a94e4d Mon Sep 17 00:00:00 2001 From: Thomas Gazagnaire Date: Tue, 23 Jun 2026 11:26:24 -0700 Subject: [PATCH] Stamp version.h from $SOLO5_VERSION for tarball pins gen_version_h.sh needs a version when .git is absent. Today the only fallback is version.h.distrib from a `make distrib` release tarball; an opam tarball pin (or any exported git snapshot) has neither a Git tree nor a .distrib, so the build fails. Add $SOLO5_VERSION as a third source, after git describe and version.h.distrib, and pass it from the opam files as %{version}% so a tarball pin builds. --- opam/solo5-cross-aarch64.opam | 4 ++-- opam/solo5.opam | 4 ++-- scripts/gen_version_h.sh | 29 +++++++++++++++-------------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/opam/solo5-cross-aarch64.opam b/opam/solo5-cross-aarch64.opam index 515035d67..66c58e87e 100644 --- a/opam/solo5-cross-aarch64.opam +++ b/opam/solo5-cross-aarch64.opam @@ -11,9 +11,9 @@ license: "ISC" dev-repo: "git+https://github.com/solo5/solo5.git" build: [ ["env" "TARGET_CC=aarch64-linux-gnu-gcc" "TARGET_LD=aarch64-linux-gnu-ld" "TARGET_OBJCOPY=aarch64-linux-gnu-objcopy" "./configure.sh" "--prefix=%{prefix}%"] - [make "V=1"] + ["env" "SOLO5_VERSION=%{version}%" make "V=1"] ] -install: [make "V=1" "install-toolchain"] +install: ["env" "SOLO5_VERSION=%{version}%" make "V=1" "install-toolchain"] depends: [ "conf-pkg-config" {build & os = "linux"} "conf-libseccomp" {build & os = "linux"} diff --git a/opam/solo5.opam b/opam/solo5.opam index 4c2d0b259..5f41d2228 100644 --- a/opam/solo5.opam +++ b/opam/solo5.opam @@ -11,9 +11,9 @@ license: "ISC" dev-repo: "git+https://github.com/solo5/solo5.git" build: [ ["./configure.sh" "--prefix=%{prefix}%"] - [make "V=1"] + ["env" "SOLO5_VERSION=%{version}%" make "V=1"] ] -install: [make "V=1" "install"] +install: ["env" "SOLO5_VERSION=%{version}%" make "V=1" "install"] depends: [ "conf-pkg-config" {build & os = "linux"} "conf-libseccomp" {build & os = "linux"} diff --git a/scripts/gen_version_h.sh b/scripts/gen_version_h.sh index d0a5ffaec..e7d64ed51 100755 --- a/scripts/gen_version_h.sh +++ b/scripts/gen_version_h.sh @@ -10,34 +10,35 @@ die () [ $# -ne 1 ] && exit 1 VERSION_H="$1" -# If we are being run from a release tarball, then a version.h.distrib must -# be present, and we always use that as our source of truth. Allow ./.git -# to be a file to support git worktrees. -if [ ! -d "./.git" -a ! -f "./.git" ]; then - if [ ! -f "${VERSION_H}.distrib" ]; then - die "${VERSION_H}.distrib: Not found, and we are not in a Git tree" - fi +# Determine the version, in order of precedence: +# 1. "git describe" in a real checkout (allow ./.git to be a file for worktrees) +# 2. version.h.distrib shipped in a release tarball +# 3. $SOLO5_VERSION for an exported snapshot (e.g. an opam tarball pin) that has +# neither a Git tree nor a version.h.distrib +if [ -d "./.git" -o -f "./.git" ]; then + VERSION="$(git -C . describe --dirty --tags --always)" || + die "Could not determine Git version" +elif [ -f "${VERSION_H}.distrib" ]; then cp "${VERSION_H}.distrib" "${VERSION_H}" || die exit 0 +elif [ -n "${SOLO5_VERSION}" ]; then + VERSION="${SOLO5_VERSION}" +else + die "not a Git tree, ${VERSION_H}.distrib not found, and SOLO5_VERSION unset" fi -# Otherwise, use "git describe" to get the exact version of this tree, and -# generate a version.h from it. -GIT_VERSION="$(git -C . describe --dirty --tags --always)" || - die "Could not determine Git version" - cat <${VERSION_H}.tmp || die /* Automatically generated, do not edit */ #ifndef __VERSION_H__ #define __VERSION_H__ -#define SOLO5_VERSION "${GIT_VERSION}" +#define SOLO5_VERSION "${VERSION}" #endif EOM -# Only touch the target file if it does not exist yet or Git version differs. +# Only touch the target file if it does not exist yet or the version differs. if [ -f ${VERSION_H} ] && diff -q ${VERSION_H} ${VERSION_H}.tmp >/dev/null; then rm ${VERSION_H}.tmp || die else