gen_version.sh 880 B

1234567891011121314151617181920
  1. #!/bin/sh
  2. # gen_version.sh -- write OpenPuck/git_version.h with the current git short hash + dirty flag, for the build
  3. # provenance shown in the WebUSB panel. Run this BEFORE `arduino-cli compile` (it's a no-op to re-run). The
  4. # generated header is git-ignored, so generating it never itself marks the tree dirty.
  5. set -e
  6. cd "$(dirname "$0")"
  7. HASH=$(git rev-parse --short=8 HEAD 2>/dev/null || echo unknown)
  8. # Dirty = any tracked change OR untracked file (porcelain is empty only on a clean tree). git_version.h is
  9. # git-ignored so it doesn't count.
  10. if [ -z "$(git status --porcelain 2>/dev/null)" ]; then DIRTY=0; else DIRTY=1; fi
  11. cat > OpenPuck/git_version.h <<EOF
  12. // AUTO-GENERATED by gen_version.sh -- do not edit, do not commit (git-ignored).
  13. #pragma once
  14. #define OPK_GIT_HASH "$HASH"
  15. #define OPK_GIT_DIRTY $DIRTY
  16. EOF
  17. echo "OpenPuck/git_version.h: hash=$HASH dirty=$DIRTY"