make_chroot: manually build host toolchain packages in order
To workaround race conditions where we build & install a package that
is actively being used by other packages we're building (e.g. we run
the assembler while building gcc while also building & installing the
assembler in parallel), pull some of the critical packages out so we
can run them in a specific order.
For now we build binutils & the C library in serial. The other libs
and compilers don't directly depend on each other, so they can still
build in parallel.
This might slow the build down overall slightly, but we probably don't
run as slow in practice because we don't see large packages (e.g. gcc)
failing to build and then needing to be retried.
BUG=chromium:715788
TEST=bootstrapping sdk still works
Change-Id: I5d52d1660662957daf10f4ba6b0d116a788dff21
Reviewed-on: https://chromium-review.googlesource.com/c/1387715
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/sdk_lib/make_chroot.sh b/sdk_lib/make_chroot.sh
index 2159532..e955d76 100755
--- a/sdk_lib/make_chroot.sh
+++ b/sdk_lib/make_chroot.sh
@@ -611,7 +611,11 @@
early_enter_chroot ${EMERGE_CMD} -uNv ${USEPKG} --select ${EMERGE_JOBS} \
sys-apps/sandbox '>=sys-devel/patch-2.7' sys-devel/automake sys-devel/bison
-
+# Now that many of the fundamental packages should be in a good state, update
+# the host toolchain. We have to do this step by step ourselves to avoid races
+# when building tools that are actively used (e.g. updating the assembler while
+# also compiling other packages that use the assembler).
+# https://crbug.com/715788
info "Updating host toolchain"
if [[ ! -e "${FLAGS_chroot}/usr/bin/crossdev" ]]; then
early_enter_chroot $EMERGE_CMD -uNv crossdev
@@ -620,6 +624,16 @@
if [[ "${FLAGS_usepkg}" == "${FLAGS_FALSE}" ]]; then
TOOLCHAIN_ARGS+=( --nousepkg )
fi
+# First the low level compiler tools. These should be fairly independent of
+# the C library, so we can do it first.
+early_enter_chroot ${EMERGE_CMD} -uNv ${EMERGE_JOBS} \
+ sys-devel/binutils
+# Next the C library. The compilers often use newer features, but the C library
+# is often designed to work with older compilers.
+early_enter_chroot ${EMERGE_CMD} -uNv ${EMERGE_JOBS} \
+ sys-kernel/linux-headers sys-libs/glibc
+# Now we can let the rest of the compiler packages build in parallel as they
+# don't generally rely on each other.
# Note: early_enter_chroot executes as root.
early_enter_chroot "${CHROOT_TRUNK_DIR}/chromite/bin/cros_setup_toolchains" \
--hostonly "${TOOLCHAIN_ARGS[@]}"