2
2
export LC_ALL=C
3
3
set -e -o pipefail
4
4
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
+
5
13
# ##################
6
- # # Sanity Checks ##
14
+ # # SANITY CHECKS ##
7
15
# ##################
8
16
9
17
# ###############
10
- # Check 1: Make sure that we can invoke required tools
18
+ # Required non-builtin commands should be invokable
11
19
# ###############
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
18
22
19
23
# ###############
20
- # Check 2: Make sure GUIX_BUILD_OPTIONS is empty
24
+ # GUIX_BUILD_OPTIONS should be empty
21
25
# ###############
22
26
#
23
27
# GUIX_BUILD_OPTIONS is an environment variable recognized by guix commands that
45
49
fi
46
50
47
51
# ###############
48
- # Check 3: Make sure that we're not in a dirty worktree
52
+ # The git worktree should not be dirty
49
53
# ###############
54
+
50
55
if ! git diff-index --quiet HEAD -- && [ -z " $FORCE_DIRTY_WORKTREE " ]; then
51
56
cat << EOF
52
57
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:
60
65
using a dirty worktree
61
66
EOF
62
67
exit 1
63
- else
64
- GIT_COMMIT=$( git rev-parse --short=12 HEAD)
65
68
fi
66
69
70
+ mkdir -p " $VERSION_BASE "
71
+
67
72
# ###############
68
- # Check 4: Make sure that build directories do not exist
73
+ # Build directories should not exist
69
74
# ###############
70
75
71
76
# Default to building for all supported HOSTs (overridable by environment)
72
77
export HOSTS=" ${HOSTS:- x86_64-linux-gnu arm-linux-gnueabihf aarch64-linux-gnu riscv64-linux-gnu powerpc64-linux-gnu powerpc64le-linux-gnu
73
78
x86_64-w64-mingw32
74
79
x86_64-apple-darwin18} "
75
80
76
- DISTSRC_BASE=" ${DISTSRC_BASE:- ${PWD} } "
77
-
78
81
# Usage: distsrc_for_host HOST
79
82
#
80
83
# HOST: The current platform triple we're building for
81
84
#
82
85
distsrc_for_host () {
83
- echo " ${DISTSRC_BASE} /distsrc-${GIT_COMMIT } -${1} "
86
+ echo " ${DISTSRC_BASE} /distsrc-${VERSION } -${1} "
84
87
}
85
88
86
89
# Accumulate a list of build directories that already exist...
@@ -106,12 +109,11 @@ for host in $hosts_distsrc_exists; do
106
109
done
107
110
exit 1
108
111
else
109
-
110
112
mkdir -p " $DISTSRC_BASE "
111
113
fi
112
114
113
115
# ###############
114
- # Check 5: When building for darwin, make sure that the macOS SDK exists
116
+ # When building for darwin, the macOS SDK should exists
115
117
# ###############
116
118
117
119
for host in $HOSTS ; do
@@ -129,7 +131,7 @@ for host in $HOSTS; do
129
131
done
130
132
131
133
# ########
132
- # Setup #
134
+ # SETUP #
133
135
# ########
134
136
135
137
# Determine the maximum number of jobs to run simultaneously (overridable by
@@ -172,11 +174,20 @@ time-machine() {
172
174
}
173
175
174
176
# 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
+
177
188
178
189
# ########
179
- # Build #
190
+ # BUILD #
180
191
# ########
181
192
182
193
# Function to be called when building for host ${1} and the user interrupts the
@@ -216,15 +227,15 @@ for host in $HOSTS; do
216
227
217
228
# shellcheck disable=SC2030
218
229
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} :
220
231
...using reference timestamp: ${SOURCE_DATE_EPOCH:? not set}
221
232
...running at most ${JOBS:? not set} jobs
222
233
...from worktree directory: '${PWD} '
223
234
...bind-mounted in container to: '/bitcoin'
224
235
...in build directory: '$( distsrc_for_host " $HOST " ) '
225
236
...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 " ) '
228
239
EOF
229
240
230
241
# Run the build script 'contrib/guix/libexec/build.sh' in the build
299
310
--no-cwd \
300
311
--share=" $PWD " =/bitcoin \
301
312
--share=" $DISTSRC_BASE " =/distsrc-base \
302
- --share=" $OUTDIR " =/outdir \
313
+ --share=" $OUTDIR_BASE " =/outdir-base \
303
314
--expose=" $( git rev-parse --git-common-dir) " \
304
315
${SOURCES_PATH: +--share=" $SOURCES_PATH " } \
305
316
${BASE_CACHE: +--share=" $BASE_CACHE " } \
@@ -309,14 +320,16 @@ EOF
309
320
${SUBSTITUTE_URLS: +--substitute-urls=" $SUBSTITUTE_URLS " } \
310
321
${ADDITIONAL_GUIX_COMMON_FLAGS} ${ADDITIONAL_GUIX_ENVIRONMENT_FLAGS} \
311
322
-- env HOST=" $host " \
323
+ DISTNAME=" $DISTNAME " \
312
324
JOBS=" $JOBS " \
313
325
SOURCE_DATE_EPOCH=" ${SOURCE_DATE_EPOCH:? unable to determine value} " \
314
326
${V: +V=1} \
315
327
${SOURCES_PATH: +SOURCES_PATH=" $SOURCES_PATH " } \
316
328
${BASE_CACHE: +BASE_CACHE=" $BASE_CACHE " } \
317
329
${SDK_PATH: +SDK_PATH=" $SDK_PATH " } \
318
330
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 \
320
333
bash -c " cd /bitcoin && bash contrib/guix/libexec/build.sh"
321
334
)
322
335
0 commit comments