Skip to content

Commit 2f9d1fd

Browse files
committed
guix: Move DISTSRC determination to guix-build.sh
1 parent 0b7cd07 commit 2f9d1fd

File tree

2 files changed

+50
-12
lines changed

2 files changed

+50
-12
lines changed

contrib/guix/guix-build.sh

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,50 @@ else
6464
GIT_COMMIT=$(git rev-parse --short=12 HEAD)
6565
fi
6666

67+
################
68+
# Check 4: Make sure that build directories do no exist
69+
################
70+
71+
# Default to building for all supported HOSTs (overridable by environment)
72+
export HOSTS="${HOSTS:-x86_64-linux-gnu arm-linux-gnueabihf aarch64-linux-gnu riscv64-linux-gnu
73+
x86_64-w64-mingw32}"
74+
75+
DISTSRC_BASE="${DISTSRC_BASE:-${PWD}}"
76+
77+
# Usage: distsrc_for_host HOST
78+
#
79+
# HOST: The current platform triple we're building for
80+
#
81+
distsrc_for_host() {
82+
echo "${DISTSRC_BASE}/distsrc-${GIT_COMMIT}-${1}"
83+
}
84+
85+
# Accumulate a list of build directories that already exist...
86+
hosts_distsrc_exists=""
87+
for host in $HOSTS; do
88+
if [ -e "$(distsrc_for_host "$host")" ]; then
89+
hosts_distsrc_exists+=" ${host}"
90+
fi
91+
done
92+
93+
if [ -n "$hosts_distsrc_exists" ]; then
94+
# ...so that we can print them out nicely in an error message
95+
cat << EOF
96+
ERR: Build directories for this commit already exist for the following platform
97+
triples you're attempting to build, probably because of previous builds.
98+
Please remove, or otherwise deal with them prior to starting another build.
99+
100+
Aborting...
101+
102+
EOF
103+
for host in $hosts_distsrc_exists; do
104+
echo " ${host} '$(distsrc_for_host "$host")'"
105+
done
106+
exit 1
107+
else
108+
mkdir -p "$DISTSRC_BASE"
109+
fi
110+
67111
#########
68112
# Setup #
69113
#########
@@ -116,9 +160,9 @@ and untracked files and directories will be wiped, allowing you to start anew.
116160
EOF
117161
}
118162

119-
# Deterministically build Bitcoin Core for HOSTs (overridable by environment)
163+
# Deterministically build Bitcoin Core
120164
# shellcheck disable=SC2153
121-
for host in ${HOSTS=x86_64-linux-gnu arm-linux-gnueabihf aarch64-linux-gnu riscv64-linux-gnu x86_64-w64-mingw32}; do
165+
for host in $HOSTS; do
122166

123167
# Display proper warning when the user interrupts the build
124168
trap 'int_trap ${host}' INT
@@ -187,12 +231,13 @@ for host in ${HOSTS=x86_64-linux-gnu arm-linux-gnueabihf aarch64-linux-gnu riscv
187231
# Please read the README.md in the same directory as this file for
188232
# more information.
189233
#
190-
# shellcheck disable=SC2086
234+
# shellcheck disable=SC2086,SC2031
191235
time-machine environment --manifest="${PWD}/contrib/guix/manifest.scm" \
192236
--container \
193237
--pure \
194238
--no-cwd \
195239
--share="$PWD"=/bitcoin \
240+
--share="$DISTSRC_BASE"=/distsrc-base \
196241
--share="$OUTDIR"=/outdir \
197242
--expose="$(git rev-parse --git-common-dir)" \
198243
${SOURCES_PATH:+--share="$SOURCES_PATH"} \
@@ -204,6 +249,7 @@ for host in ${HOSTS=x86_64-linux-gnu arm-linux-gnueabihf aarch64-linux-gnu riscv
204249
SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:?unable to determine value}" \
205250
${V:+V=1} \
206251
${SOURCES_PATH:+SOURCES_PATH="$SOURCES_PATH"} \
252+
DISTSRC="$(DISTSRC_BASE=/distsrc-base && distsrc_for_host "$HOST")" \
207253
OUTDIR=/outdir \
208254
bash -c "cd /bitcoin && bash contrib/guix/libexec/build.sh"
209255
)

contrib/guix/libexec/build.sh

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ echo "At most ${MAX_JOBS:?not set} jobs will run at once..."
2323
# $HOSTs after successfully building.
2424
BASEPREFIX="${PWD}/depends"
2525

26-
# Setup the directory where our Bitcoin Core build for HOST will occur
27-
DISTSRC="${DISTSRC:-${PWD}/distsrc-${HOST}}"
28-
if [ -e "$DISTSRC" ]; then
29-
echo "DISTSRC directory '${DISTSRC}' exists, probably because of previous builds... Aborting..."
30-
exit 1
31-
else
32-
mkdir -p "$DISTSRC"
33-
fi
34-
3526
# Given a package name and an output name, return the path of that output in our
3627
# current guix environment
3728
store_path() {
@@ -185,6 +176,7 @@ esac
185176

186177
# Make $HOST-specific native binaries from depends available in $PATH
187178
export PATH="${BASEPREFIX}/${HOST}/native/bin:${PATH}"
179+
mkdir -p "$DISTSRC"
188180
(
189181
cd "$DISTSRC"
190182

0 commit comments

Comments
 (0)