creates a header file with upto date git info
This commit is contained in:
parent
90e44e5d19
commit
a0075d4bb3
47
git_build_info.sh
Executable file
47
git_build_info.sh
Executable file
@ -0,0 +1,47 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# --- Date / time (no spaces/colons) ---
|
||||||
|
DATESTAMP=$(date +"%Y%m%d_%H%M%S")
|
||||||
|
|
||||||
|
# --- Git info (with fallbacks if not a git repo) ---
|
||||||
|
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||||
|
GITHASH=$(git rev-parse --short HEAD 2>/dev/null || echo "no-git")
|
||||||
|
BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "no-branch")
|
||||||
|
REPO_PATH=$(git rev-parse --show-toplevel 2>/dev/null || echo ".")
|
||||||
|
REPO_NAME=$(basename "$REPO_PATH")
|
||||||
|
REMOTE_URL=$(git remote get-url origin 2>/dev/null || echo "no-remote")
|
||||||
|
else
|
||||||
|
GITHASH="no-git"
|
||||||
|
BRANCH="no-branch"
|
||||||
|
REPO_NAME="no-repo"
|
||||||
|
REMOTE_URL="unknown"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- Host and user ---
|
||||||
|
HOSTNAME=$(hostname)
|
||||||
|
USER_NAME=${USER:-unknown}
|
||||||
|
|
||||||
|
# --- Where to put the header (CubeIDE default) ---
|
||||||
|
OUT_DIR="." # "Core/Inc"
|
||||||
|
OUT_FILE="${OUT_DIR}/build_info.h"
|
||||||
|
|
||||||
|
mkdir -p "$OUT_DIR"
|
||||||
|
|
||||||
|
cat <<EOF > "$OUT_FILE"
|
||||||
|
/* Auto-generated: DO NOT EDIT */
|
||||||
|
#ifndef BUILD_INFO_H
|
||||||
|
#define BUILD_INFO_H
|
||||||
|
|
||||||
|
#define BUILD_DATE "${DATESTAMP}"
|
||||||
|
#define BUILD_GIT_HASH "${GITHASH}"
|
||||||
|
#define BUILD_BRANCH "${BRANCH}"
|
||||||
|
#define BUILD_REPO "${REPO_NAME}"
|
||||||
|
#define BUILD_HOST "${HOSTNAME}"
|
||||||
|
#define BUILD_USER "${USER_NAME}"
|
||||||
|
#define REMOTE_URL "${REMOTE_URL}"
|
||||||
|
|
||||||
|
#endif /* BUILD_INFO_H */
|
||||||
|
EOF
|
||||||
|
|
||||||
|
echo "Generated ${OUT_FILE}"
|
||||||
|
cat ${OUT_FILE}
|
||||||
Loading…
Reference in New Issue
Block a user