aboutsummaryrefslogtreecommitdiff
path: root/contrib/guix
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2020-12-21 14:02:00 -0500
committerCarl Dong <contact@carldong.me>2021-01-08 11:40:01 -0500
commitd27ff8b86aa66acec63b5713912bd4ad9470e66f (patch)
tree4b1f973a3aaa6b5444bf8b87e3161dcdb637ddad /contrib/guix
parent57f95331464f097261c63fd1b6040536c58a03fa (diff)
guix: Add more sanity checks to guix-build.sh
Diffstat (limited to 'contrib/guix')
-rwxr-xr-xcontrib/guix/guix-build.sh34
1 files changed, 34 insertions, 0 deletions
diff --git a/contrib/guix/guix-build.sh b/contrib/guix/guix-build.sh
index b956be6579..9ce0c7e18c 100755
--- a/contrib/guix/guix-build.sh
+++ b/contrib/guix/guix-build.sh
@@ -6,6 +6,20 @@ set -e -o pipefail
## Sanity Checks ##
###################
+################
+# Check 1: Make sure that we can invoke required tools
+################
+for cmd in git make guix cat mkdir; do
+ if ! command -v "$cmd" > /dev/null 2>&1; then
+ echo "ERR: This script requires that '$cmd' is installed and available in your \$PATH"
+ exit 1
+ fi
+done
+
+################
+# Check 2: Make sure GUIX_BUILD_OPTIONS is empty
+################
+#
# GUIX_BUILD_OPTIONS is an environment variable recognized by guix commands that
# can perform builds. This seems like what we want instead of
# ADDITIONAL_GUIX_COMMON_FLAGS, but the value of GUIX_BUILD_OPTIONS is actually
@@ -30,6 +44,26 @@ EOF
exit 1
fi
+################
+# Check 3: Make sure that we're not in a dirty worktree
+################
+if ! git diff-index --quiet HEAD -- && [ -z "$FORCE_DIRTY_WORKTREE" ]; then
+cat << EOF
+ERR: The current git worktree is dirty, which may lead to broken builds.
+
+ Aborting...
+
+Hint: To make your git worktree clean, You may want to:
+ 1. Commit your changes,
+ 2. Stash your changes, or
+ 3. Set the 'FORCE_DIRTY_WORKTREE' environment variable if you insist on
+ using a dirty worktree
+EOF
+exit 1
+else
+ GIT_COMMIT=$(git rev-parse --short=12 HEAD)
+fi
+
#########
# Setup #
#########