22export LC_ALL=C
33set -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
4549fi
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+
5055if ! git diff-index --quiet HEAD -- && [ -z " $FORCE_DIRTY_WORKTREE " ]; then
5156cat << EOF
5257ERR: 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
6166EOF
6267exit 1
63- else
64- GIT_COMMIT=$( git rev-parse --short=12 HEAD)
6568fi
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)
7277export 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#
8285distsrc_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
106109done
107110exit 1
108111else
109-
110112 mkdir -p " $DISTSRC_BASE "
111113fi
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
117119for host in $HOSTS ; do
@@ -129,7 +131,7 @@ for host in $HOSTS; do
129131done
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
218229cat << 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 " ) '
228239EOF
229240
230241 # Run the build script 'contrib/guix/libexec/build.sh' in the build
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
0 commit comments