Skip to content

Commit d27ff8b

Browse files
committed
guix: Add more sanity checks to guix-build.sh
1 parent 57f9533 commit d27ff8b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

contrib/guix/guix-build.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ set -e -o pipefail
66
## Sanity Checks ##
77
###################
88

9+
################
10+
# Check 1: Make sure that we can invoke required tools
11+
################
12+
for cmd in git make guix cat mkdir; do
13+
if ! command -v "$cmd" > /dev/null 2>&1; then
14+
echo "ERR: This script requires that '$cmd' is installed and available in your \$PATH"
15+
exit 1
16+
fi
17+
done
18+
19+
################
20+
# Check 2: Make sure GUIX_BUILD_OPTIONS is empty
21+
################
22+
#
923
# GUIX_BUILD_OPTIONS is an environment variable recognized by guix commands that
1024
# can perform builds. This seems like what we want instead of
1125
# ADDITIONAL_GUIX_COMMON_FLAGS, but the value of GUIX_BUILD_OPTIONS is actually
@@ -30,6 +44,26 @@ EOF
3044
exit 1
3145
fi
3246

47+
################
48+
# Check 3: Make sure that we're not in a dirty worktree
49+
################
50+
if ! git diff-index --quiet HEAD -- && [ -z "$FORCE_DIRTY_WORKTREE" ]; then
51+
cat << EOF
52+
ERR: The current git worktree is dirty, which may lead to broken builds.
53+
54+
Aborting...
55+
56+
Hint: To make your git worktree clean, You may want to:
57+
1. Commit your changes,
58+
2. Stash your changes, or
59+
3. Set the 'FORCE_DIRTY_WORKTREE' environment variable if you insist on
60+
using a dirty worktree
61+
EOF
62+
exit 1
63+
else
64+
GIT_COMMIT=$(git rev-parse --short=12 HEAD)
65+
fi
66+
3367
#########
3468
# Setup #
3569
#########

0 commit comments

Comments
 (0)