Skip to content

Commit 505f5e7

Browse files
committed
Reorganize the contents of $BUILD_TMP
In preparation for building the toolchain on the host, check for existence of a stamp file before executing a build step and create such file after the build step succeedes. Define the subdirectories of $BUILD_TMP to be used by its sub-processes in the main build-all.sh script. Improve the diagnostic messages.
1 parent 37bdc20 commit 505f5e7

6 files changed

Lines changed: 55 additions & 19 deletions

File tree

scripts/build-all.sh

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#!/usr/bin/env sh
2-
set -xe
2+
set -e
33

44
# This script invokes all other build-*.sh scripts.
55
# Inside the container, it is called by build-in-docker.sh.
66
# FIXME: Add another entry point script to perform build directly on host.
77

8+
set -x
89
cd "$(dirname "$0")"
910
. "$REPO_ROOT/config"
1011
. ./global-vars
12+
set +x
1113

1214
write_clang_config_files() {
1315
cat > "$INSTALL_DIR/bin/aarch64-unknown-linux-pauthtest.cfg" <<EOF
@@ -20,19 +22,63 @@ $EXTRA_FLAGS_MUSL
2022
EOF
2123
}
2224

25+
# Usage: try_build <stamp-prefix> <command line...>
26+
# Note: CROSS_TARGET is added to the stamp file name.
27+
#
28+
# Try performing the build step:
29+
# * skip this step if the stamp file already exists
30+
# * create the stamp file if the build step succeeded
31+
# * print an error to the user if the build step failed
32+
#
33+
# The primary goal of this function is to improve usability of restarting
34+
# partially successful builds performed on the host. Note that no directories
35+
# are removed in case of an error to minimize the amount of "rm -rf" calls
36+
# performed on the host and to simplify the debugging of build errors.
37+
try_build() {
38+
local stamp_prefix="$1"
39+
shift 1
40+
41+
local build_dir="${BUILD_TMP}/${stamp_prefix}-${CROSS_TARGET}"
42+
43+
local stamp_file_name="${build_dir}.stamp"
44+
if [ -f "$stamp_file_name" ]; then
45+
echo "Stamp found, skipping '$*'."
46+
return
47+
fi
48+
49+
if [ -d "$build_dir" ]; then
50+
echo "Incomplete build directory is found at $build_dir." 1>&2
51+
exit 1
52+
fi
53+
54+
# Try performing the build step.
55+
# On error, print a message to the user instead on exiting due to 'set -e'.
56+
57+
export BUILD_DIR="$build_dir" # Used by called subprocess.
58+
echo "Executing: $*"
59+
if "$@"; then
60+
touch "$stamp_file_name"
61+
else
62+
echo "Execution of '$stamp_prefix' step for '$CROSS_TARGET' failed." 1>&2
63+
echo "Please remove incomplete build at '$BUILD_DIR' before restarting the build." 1>&2
64+
exit 1
65+
fi
66+
}
67+
2368
build_target_libs() {
2469
export CROSS_TARGET
2570
export TARGET_PREFIX="$INSTALL_DIR/$CROSS_TARGET/usr"
26-
./create-symlinks.sh
27-
./build-linux-header.sh
28-
LIBC_STARTFILE_STAGE=1 ./build-musl.sh
29-
COMPILER_RT_BUILD=builtins ./build-compiler-rt.sh
30-
./build-musl.sh
31-
./build-runtimes.sh
32-
COMPILER_RT_BUILD=full ./build-compiler-rt.sh
71+
echo "Building runtime libs in $TARGET_PREFIX..."
72+
try_build symlinks ./create-symlinks.sh
73+
try_build linux-headers ./build-linux-header.sh
74+
LIBC_STARTFILE_STAGE=1 try_build musl-startfiles ./build-musl.sh
75+
COMPILER_RT_BUILD=builtins try_build compiler-rt-builtins ./build-compiler-rt.sh
76+
try_build musl-full ./build-musl.sh
77+
try_build runtimes ./build-runtimes.sh
78+
COMPILER_RT_BUILD=full try_build compiler-rt-full ./build-compiler-rt.sh
3379
}
3480

35-
./build-llvm.sh
81+
CROSS_TARGET="all" try_build llvm ./build-llvm.sh
3682

3783
write_clang_config_files
3884
CROSS_TARGET="aarch64-linux-pauthtest" build_target_libs

scripts/build-compiler-rt.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ cd "$(dirname "$0")"
44
. "$REPO_ROOT/config"
55
. ./global-vars
66

7-
BUILD_DIR="${BUILD_TMP}/compiler-rt-${COMPILER_RT_BUILD}-${CROSS_TARGET}"
8-
97
COMPILER_RT_INSTALL_PREFIX="$("$INSTALL_DIR/bin/clang" --print-resource-dir)"
108

119
# Assertion: COMPILER_RT_INSTALL_PREFIX should be under INSTALL_DIR.

scripts/build-linux-header.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ KERNEL_ARCH=arm64
88
TARBALL_BASENAME="linux-$LINUX_KERNEL_VERSION.tar.xz"
99
TARBALL_PATH="$SRC_DIR/$TARBALL_BASENAME"
1010

11-
BUILD_DIR="$BUILD_TMP/linux-headers-${CROSS_TARGET}"
12-
1311
mkdir "$BUILD_DIR"
1412
tar -axf "$TARBALL_PATH" -C "$BUILD_DIR" --strip 1
1513
mkdir "$BUILD_DIR/build-$KERNEL_ARCH"

scripts/build-llvm.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ cd "$(dirname "$0")"
44
. "$REPO_ROOT/config"
55
. ./global-vars
66

7-
BUILD_DIR="$BUILD_TMP/llvm"
8-
97
cmake \
108
-S "$LLVM_SOURCE_DIR/llvm" \
119
-B "$BUILD_DIR" \

scripts/build-musl.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ cd "$(dirname "$0")"
44
. "$REPO_ROOT/config"
55
. ./global-vars
66

7-
BUILD_DIR="${BUILD_TMP}/musl-${CROSS_TARGET}"
8-
[ ! -n "$LIBC_STARTFILE_STAGE" ] && BUILD_DIR="$BUILD_DIR-full"
97
mkdir "$BUILD_DIR"
108
cd "$BUILD_DIR"
119

scripts/build-runtimes.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ cd "$(dirname "$0")"
44
. "$REPO_ROOT/config"
55
. ./global-vars
66

7-
BUILD_DIR="$BUILD_TMP/runtimes-${CROSS_TARGET}"
8-
97
if [ -d "$TARGET_PREFIX/include/c++" ]; then
108
echo "ERROR: The destination directory already exists: $TARGET_PREFIX/include/c++" 1>&2
119
exit 1

0 commit comments

Comments
 (0)