diff --git a/copy-builtin b/copy-builtin index eaffbd2d26ec..1dcfcb961ee8 100755 --- a/copy-builtin +++ b/copy-builtin @@ -30,7 +30,7 @@ then fi make clean || true -scripts/make_gitrev.sh +scripts/make_gitrev.sh || true rm -rf "$KERNEL_DIR/include/zfs" "$KERNEL_DIR/fs/zfs" cp --recursive include "$KERNEL_DIR/include/zfs" diff --git a/scripts/make_gitrev.sh b/scripts/make_gitrev.sh index 04be09595ccc..f6631e3c3b4b 100755 --- a/scripts/make_gitrev.sh +++ b/scripts/make_gitrev.sh @@ -26,29 +26,19 @@ # `configure` is run. # -BASE_DIR=$(dirname "$0") +set -e -u -file=${BASE_DIR}/../include/zfs_gitrev.h +cleanup() { + ZFS_GIT_REV=${ZFS_GIT_REV:-"unknown"} + cat << EOF > "$(dirname "$0")"/../include/zfs_gitrev.h +#define ZFS_META_GITREV "${ZFS_GIT_REV}" +EOF +} +trap cleanup EXIT -# -# Set default file contents in case we bail. -# -rm -f "$file" -# shellcheck disable=SC2039 -/bin/echo -e "#define\tZFS_META_GITREV \"unknown\"" >>"$file" - -# # Check if git is installed and we are in a git repo. -# -git rev-parse --git-dir > /dev/null 2>&1 || exit - -# +git rev-parse --git-dir > /dev/null 2>&1 # Check if there are uncommitted changes -# -git diff-index --quiet HEAD || exit - -rev=$(git describe 2>/dev/null) || exit - -rm -f "$file" -# shellcheck disable=SC2039 -/bin/echo -e "#define\tZFS_META_GITREV \"${rev}\"" >>"$file" +git diff-index --quiet HEAD +# Get the git current git revision +ZFS_GIT_REV=$(git describe 2>/dev/null)