]> git.ipfire.org Git - people/ms/ipfire-2.x.git/commitdiff
make.sh: Refactor the toolchain extraction
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 5 Jul 2024 08:58:46 +0000 (08:58 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 8 Jul 2024 15:39:43 +0000 (15:39 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
make.sh

diff --git a/make.sh b/make.sh
index 39e1b7c5710cb09c6961b54a88c51131d2fa45dc..fd2cc72975d2f38f62ecc9f85b16759b7896ca42 100755 (executable)
--- a/make.sh
+++ b/make.sh
@@ -965,6 +965,32 @@ update_contributors() {
        return 0
 }
 
+# Extracts the toolchain
+extract_toolchain() {
+       local toolchain="${1}"
+
+       local build_dir="${BUILD_DIR#${BASEDIR}/}"
+       local log_dir="${LOG_DIR#${BASEDIR}/}"
+
+       local args=(
+               # Extract
+               "ax"
+
+               # The file to extract
+               "-f" "${toolchain}"
+
+               # The destination
+               "-C" "${BASEDIR}"
+
+               # Transform any older toolchains
+               "--transform" "s@^build/@${build_dir}/@"
+               "--transform" "s@^log/@${log_dir}/@"
+       )
+
+       # Extract the toolchain
+       tar "${args[@]}" || return $?
+}
+
 buildtoolchain() {
        local gcc=$(type -p gcc)
        if [ -z "${gcc}" ]; then
@@ -1880,6 +1906,9 @@ LOGFILE="${LOG_DIR}/_build.preparation.log"
 # Ensure the log directory exists
 mkdir -p "${LOG_DIR}"
 
+# Path to the toolchain
+readonly TOOLCHAIN="${CACHE_DIR}/toolchains/${SNAME}-${VERSION}-toolchain-${TOOLCHAINVER}-${BUILD_ARCH}.tar.zst"
+
 # See what we're supposed to do
 case "$1" in
 build)
@@ -1888,25 +1917,25 @@ build)
        # Launch in a new namespace
        exec_in_namespace "$@"
 
-       PACKAGE="$BASEDIR/cache/toolchains/$SNAME-$VERSION-toolchain-$TOOLCHAINVER-${BUILD_ARCH}.tar.zst"
-       #only restore on a clean disk
-       if [ ! -e "${BASEDIR}/build${TOOLS_DIR}/.toolchain-successful" ]; then
-               if [ ! -n "$PACKAGE" ]; then
-                       print_build_stage "Full toolchain compilation"
-                       prepareenv
-                       buildtoolchain
-               else
-                       PACKAGENAME=${PACKAGE%.tar.zst}
+       # Prepare the environment
+       prepareenv
+
+       # Check if the toolchain is available
+       if [ ! -e "${BUILD_DIR}${TOOLS_DIR}/.toolchain-successful" ]; then
+               # If we have the toolchain available, we extract it into the build environment
+               if [ -r "${TOOLCHAIN}" ]; then
                        print_build_stage "Packaged toolchain compilation"
-                       if [ `b2sum $PACKAGE | awk '{print $1}'` == `cat $PACKAGENAME.b2 | awk '{print $1}'` ]; then
-                               zstd -d < "${PACKAGE}" | tar x
-                               prepareenv
-                       else
-                               exiterror "$PACKAGENAME BLAKE2 checksum did not match, check downloaded package"
+
+                       # Extract the toolchain
+                       if ! extract_toolchain "${TOOLCHAIN}"; then
+                               exiterror "Failed extracting the toolchain"
                        fi
+
+               # Otherwise perform a full toolchain compilation
+               else
+                       print_build_stage "Full toolchain compilation"
+                       buildtoolchain
                fi
-       else
-               prepareenv
        fi
 
        print_build_stage "Building LFS"