Skip to content

Commit 7f401c9

Browse files
committed
guix: Adapt guix-build to prelude, restructure hier
1 parent 4eccf06 commit 7f401c9

File tree

2 files changed

+44
-32
lines changed

2 files changed

+44
-32
lines changed

contrib/guix/guix-build

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@
22
export LC_ALL=C
33
set -e -o pipefail
44

5+
# Source the common prelude, which:
6+
# 1. Checks if we're at the top directory of the Bitcoin Core repository
7+
# 2. Defines a few common functions and variables
8+
#
9+
# shellcheck source=libexec/prelude.bash
10+
source "$(dirname "${BASH_SOURCE[0]}")/libexec/prelude.bash"
11+
12+
513
###################
6-
## Sanity Checks ##
14+
## SANITY CHECKS ##
715
###################
816

917
################
10-
# Check 1: Make sure that we can invoke required tools
18+
# Required non-builtin commands should be invokable
1119
################
12-
for cmd in git make guix cat mkdir curl; 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
20+
21+
check_tools cat mkdir make git guix
1822

1923
################
20-
# Check 2: Make sure GUIX_BUILD_OPTIONS is empty
24+
# GUIX_BUILD_OPTIONS should be empty
2125
################
2226
#
2327
# GUIX_BUILD_OPTIONS is an environment variable recognized by guix commands that
@@ -45,8 +49,9 @@ exit 1
4549
fi
4650

4751
################
48-
# Check 3: Make sure that we're not in a dirty worktree
52+
# The git worktree should not be dirty
4953
################
54+
5055
if ! git diff-index --quiet HEAD -- && [ -z "$FORCE_DIRTY_WORKTREE" ]; then
5156
cat << EOF
5257
ERR: The current git worktree is dirty, which may lead to broken builds.
@@ -60,27 +65,25 @@ Hint: To make your git worktree clean, You may want to:
6065
using a dirty worktree
6166
EOF
6267
exit 1
63-
else
64-
GIT_COMMIT=$(git rev-parse --short=12 HEAD)
6568
fi
6669

70+
mkdir -p "$VERSION_BASE"
71+
6772
################
68-
# Check 4: Make sure that build directories do not exist
73+
# Build directories should not exist
6974
################
7075

7176
# Default to building for all supported HOSTs (overridable by environment)
7277
export HOSTS="${HOSTS:-x86_64-linux-gnu arm-linux-gnueabihf aarch64-linux-gnu riscv64-linux-gnu powerpc64-linux-gnu powerpc64le-linux-gnu
7378
x86_64-w64-mingw32
7479
x86_64-apple-darwin18}"
7580

76-
DISTSRC_BASE="${DISTSRC_BASE:-${PWD}}"
77-
7881
# Usage: distsrc_for_host HOST
7982
#
8083
# HOST: The current platform triple we're building for
8184
#
8285
distsrc_for_host() {
83-
echo "${DISTSRC_BASE}/distsrc-${GIT_COMMIT}-${1}"
86+
echo "${DISTSRC_BASE}/distsrc-${VERSION}-${1}"
8487
}
8588

8689
# Accumulate a list of build directories that already exist...
@@ -106,12 +109,11 @@ for host in $hosts_distsrc_exists; do
106109
done
107110
exit 1
108111
else
109-
110112
mkdir -p "$DISTSRC_BASE"
111113
fi
112114

113115
################
114-
# Check 5: When building for darwin, make sure that the macOS SDK exists
116+
# When building for darwin, the macOS SDK should exists
115117
################
116118

117119
for host in $HOSTS; do
@@ -129,7 +131,7 @@ for host in $HOSTS; do
129131
done
130132

131133
#########
132-
# Setup #
134+
# SETUP #
133135
#########
134136

135137
# Determine the maximum number of jobs to run simultaneously (overridable by
@@ -172,11 +174,20 @@ time-machine() {
172174
}
173175

174176
# Make sure an output directory exists for our builds
175-
OUTDIR="${OUTDIR:-${PWD}/output}"
176-
[ -e "$OUTDIR" ] || mkdir -p "$OUTDIR"
177+
OUTDIR_BASE="${OUTDIR_BASE:-${VERSION_BASE}/output}"
178+
mkdir -p "$OUTDIR_BASE"
179+
180+
# Usage: outdir_for_host HOST
181+
#
182+
# HOST: The current platform triple we're building for
183+
#
184+
outdir_for_host() {
185+
echo "${OUTDIR_BASE}/${1}"
186+
}
187+
177188

178189
#########
179-
# Build #
190+
# BUILD #
180191
#########
181192

182193
# Function to be called when building for host ${1} and the user interrupts the
@@ -216,15 +227,15 @@ for host in $HOSTS; do
216227

217228
# shellcheck disable=SC2030
218229
cat << EOF
219-
INFO: Building commit ${GIT_COMMIT:?not set} for platform triple ${HOST:?not set}:
230+
INFO: Building ${VERSION:?not set} for platform triple ${HOST:?not set}:
220231
...using reference timestamp: ${SOURCE_DATE_EPOCH:?not set}
221232
...running at most ${JOBS:?not set} jobs
222233
...from worktree directory: '${PWD}'
223234
...bind-mounted in container to: '/bitcoin'
224235
...in build directory: '$(distsrc_for_host "$HOST")'
225236
...bind-mounted in container to: '$(DISTSRC_BASE=/distsrc-base && distsrc_for_host "$HOST")'
226-
...outputting in: '${OUTDIR:?not set}'
227-
...bind-mounted in container to: '/outdir'
237+
...outdirting in: '$(outdir_for_host "$HOST")'
238+
...bind-mounted in container to: '$(OUTDIR_BASE=/outdir-base && outdir_for_host "$HOST")'
228239
EOF
229240

230241
# Run the build script 'contrib/guix/libexec/build.sh' in the build
@@ -299,7 +310,7 @@ EOF
299310
--no-cwd \
300311
--share="$PWD"=/bitcoin \
301312
--share="$DISTSRC_BASE"=/distsrc-base \
302-
--share="$OUTDIR"=/outdir \
313+
--share="$OUTDIR_BASE"=/outdir-base \
303314
--expose="$(git rev-parse --git-common-dir)" \
304315
${SOURCES_PATH:+--share="$SOURCES_PATH"} \
305316
${BASE_CACHE:+--share="$BASE_CACHE"} \
@@ -309,14 +320,16 @@ EOF
309320
${SUBSTITUTE_URLS:+--substitute-urls="$SUBSTITUTE_URLS"} \
310321
${ADDITIONAL_GUIX_COMMON_FLAGS} ${ADDITIONAL_GUIX_ENVIRONMENT_FLAGS} \
311322
-- env HOST="$host" \
323+
DISTNAME="$DISTNAME" \
312324
JOBS="$JOBS" \
313325
SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:?unable to determine value}" \
314326
${V:+V=1} \
315327
${SOURCES_PATH:+SOURCES_PATH="$SOURCES_PATH"} \
316328
${BASE_CACHE:+BASE_CACHE="$BASE_CACHE"} \
317329
${SDK_PATH:+SDK_PATH="$SDK_PATH"} \
318330
DISTSRC="$(DISTSRC_BASE=/distsrc-base && distsrc_for_host "$HOST")" \
319-
OUTDIR=/outdir \
331+
OUTDIR="$(OUTDIR_BASE=/outdir-base && outdir_for_host "$HOST")" \
332+
DIST_ARCHIVE_BASE=/outdir-base/dist-archive \
320333
bash -c "cd /bitcoin && bash contrib/guix/libexec/build.sh"
321334
)
322335

contrib/guix/libexec/build.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ fi
2424
# Check that required environment variables are set
2525
cat << EOF
2626
Required environment variables as seen inside the container:
27+
DIST_ARCHIVE_BASE: ${DIST_ARCHIVE_BASE:?not set}
28+
DISTNAME: ${DISTNAME:?not set}
2729
HOST: ${HOST:?not set}
2830
SOURCE_DATE_EPOCH: ${SOURCE_DATE_EPOCH:?not set}
2931
JOBS: ${JOBS:?not set}
@@ -198,11 +200,7 @@ make -C depends --jobs="$JOBS" HOST="$HOST" \
198200
# Source Tarball Building #
199201
###########################
200202

201-
# Define DISTNAME variable.
202-
# shellcheck source=contrib/gitian-descriptors/assign_DISTNAME
203-
source contrib/gitian-descriptors/assign_DISTNAME
204-
205-
GIT_ARCHIVE="${OUTDIR}/src/${DISTNAME}.tar.gz"
203+
GIT_ARCHIVE="${DIST_ARCHIVE_BASE}/${DISTNAME}.tar.gz"
206204

207205
# Create the source tarball if not already there
208206
if [ ! -e "$GIT_ARCHIVE" ]; then
@@ -275,6 +273,7 @@ mkdir -p "$DISTSRC"
275273
# version symbols for Linux distro back-compatibility.
276274
make -C src --jobs=1 check-symbols ${V:+V=1}
277275

276+
mkdir -p ${OUTDIR}
278277
# Make the os-specific installers
279278
case "$HOST" in
280279
*mingw*)

0 commit comments

Comments
 (0)