#!/bin/sh # gen_version.sh -- write OpenPuck/git_version.h with build provenance for the WebUSB panel: # - semantic version (when OPK_BUILD_VERSION is set, or HEAD has a semver tag), # - git short hash, # - dirty flag. # Run this BEFORE `arduino-cli compile` (it's a no-op to re-run). The generated header is git-ignored, so # generating it never itself marks the tree dirty. set -e cd "$(dirname "$0")" HASH=$(git rev-parse --short=8 HEAD 2>/dev/null || echo unknown) VERSION="${OPK_BUILD_VERSION:-}" if [ -z "$VERSION" ]; then VERSION="$( git tag --points-at HEAD 2>/dev/null \ | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' \ | sort -V \ | tail -n1 || true )" fi # Dirty = any tracked change OR untracked file (porcelain is empty only on a clean tree). git_version.h is # git-ignored so it doesn't count. if [ -z "$(git status --porcelain 2>/dev/null)" ]; then DIRTY=0; else DIRTY=1; fi cat > OpenPuck/git_version.h <