From 33771550cfc31d250b88a2deef528cacb8434961 Mon Sep 17 00:00:00 2001 From: OrangePi CM5 Builder Date: Thu, 9 Apr 2026 18:35:23 +0800 Subject: [PATCH] build: bootstrap missing sources even with IGNORE_UPDATES - If IGNORE_UPDATES=yes, still fetch kernel/u-boot/ATF once when local trees are missing\n- fetch_from_repo: fallback to upstream GitHub when mirror lacks requested ref; disable partial-clone settings --- scripts/general.sh | 37 +++++++++++++++++++++++++++++++++++++ scripts/main.sh | 23 +++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/scripts/general.sh b/scripts/general.sh index 84ed0a6bdd9d..a03cb01d0378 100755 --- a/scripts/general.sh +++ b/scripts/general.sh @@ -500,6 +500,7 @@ fetch_from_repo() local dir=$2 local ref=$3 local ref_subdir=$4 + local upstream_url=$1 # Set GitHub mirror before anything else touches $url url=${url//'https://github.com/'/$GITHUB_SOURCE'/'} @@ -555,6 +556,18 @@ fetch_from_repo() offline=false fi + # If this repo was left in a partial-clone state (e.g. filter=blob:none), + # checkouts can degrade into extremely slow per-blob fetches. + # Disable it to ensure reliable, reasonably fast builds. + if [[ "$(git config --bool --get remote.origin.promisor 2>/dev/null)" == "true" || \ + -n "$(git config --get remote.origin.partialclonefilter 2>/dev/null)" || \ + -n "$(git config --get extensions.partialclone 2>/dev/null)" ]]; then + display_alert "Disabling partial clone settings" "${workdir}" "wrn" + git config --unset-all remote.origin.promisor >/dev/null 2>&1 || true + git config --unset-all remote.origin.partialclonefilter >/dev/null 2>&1 || true + git config --unset-all extensions.partialclone >/dev/null 2>&1 || true + fi + local changed=false # when we work offline we simply return the sources to their original state @@ -567,14 +580,32 @@ fetch_from_repo() # TODO: grep refs/heads/$name local remote_hash remote_hash=$(improved_git ls-remote -h "${url}" "$ref_name" | head -1 | cut -f1) + if [[ -z $remote_hash && $url != "$upstream_url" ]]; then + display_alert "Mirror missing ref; falling back" "$ref_name" "wrn" + url="$upstream_url" + git remote set-url origin "${url}" >/dev/null 2>&1 || true + remote_hash=$(improved_git ls-remote -h "${url}" "$ref_name" | head -1 | cut -f1) + fi [[ -z $local_hash || "${local_hash}" != "${remote_hash}" ]] && changed=true ;; tag) local remote_hash remote_hash=$(improved_git ls-remote -t "${url}" "$ref_name" | cut -f1) + if [[ -z $remote_hash && $url != "$upstream_url" ]]; then + display_alert "Mirror missing tag; falling back" "$ref_name" "wrn" + url="$upstream_url" + git remote set-url origin "${url}" >/dev/null 2>&1 || true + remote_hash=$(improved_git ls-remote -t "${url}" "$ref_name" | cut -f1) + fi if [[ -z $local_hash || "${local_hash}" != "${remote_hash}" ]]; then remote_hash=$(improved_git ls-remote -t "${url}" "$ref_name^{}" | cut -f1) + if [[ -z $remote_hash && $url != "$upstream_url" ]]; then + display_alert "Mirror missing tag deref; falling back" "$ref_name" "wrn" + url="$upstream_url" + git remote set-url origin "${url}" >/dev/null 2>&1 || true + remote_hash=$(improved_git ls-remote -t "${url}" "$ref_name^{}" | cut -f1) + fi [[ -z $remote_hash || "${local_hash}" != "${remote_hash}" ]] && changed=true fi ;; @@ -582,6 +613,12 @@ fetch_from_repo() head) local remote_hash remote_hash=$(improved_git ls-remote "${url}" HEAD | cut -f1) + if [[ -z $remote_hash && $url != "$upstream_url" ]]; then + display_alert "Mirror missing HEAD; falling back" "HEAD" "wrn" + url="$upstream_url" + git remote set-url origin "${url}" >/dev/null 2>&1 || true + remote_hash=$(improved_git ls-remote "${url}" HEAD | cut -f1) + fi [[ -z $local_hash || "${local_hash}" != "${remote_hash}" ]] && changed=true ;; diff --git a/scripts/main.sh b/scripts/main.sh index 08e3033eff42..1363128a4ddd 100755 --- a/scripts/main.sh +++ b/scripts/main.sh @@ -446,7 +446,9 @@ prepare_host # fetch_from_repo + # ignore updates help on building all images - for internal purposes +# When IGNORE_UPDATES=yes, still fetch once if required sources are missing. if [[ ${IGNORE_UPDATES} != yes ]]; then display_alert "Downloading sources" "" "info" @@ -583,6 +585,27 @@ if [[ $BUILD_OPT == u-boot || $BUILD_OPT == image ]]; then display_alert "File name" "${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb" "info" fi fi + +else + + # IGNORE_UPDATES=yes: prefer local trees, but bootstrap missing sources to avoid hard failures. + # Kernel: if the tree isn't populated, it will be missing the top-level Makefile. + if [[ $BUILD_OPT =~ kernel|image && ! -f "${LINUXSOURCEDIR}/Makefile" ]]; then + display_alert "Kernel sources missing; downloading once" "(IGNORE_UPDATES=yes)" "wrn" + fetch_from_repo "$KERNELSOURCE" "$KERNELDIR" "$KERNELBRANCH" "yes" + fi + + # U-Boot/ATF are required for image builds; fetch once if missing. + if [[ $BOARDFAMILY != "cix" && $BUILD_OPT =~ u-boot|image && ! -f "${BOOTSOURCEDIR}/Makefile" ]]; then + display_alert "U-Boot sources missing; downloading once" "(IGNORE_UPDATES=yes)" "wrn" + fetch_from_repo "$BOOTSOURCE" "$BOOTDIR" "$BOOTBRANCH" "yes" + fi + + if [[ -n ${ATFSOURCE} && $BUILD_OPT =~ u-boot|image && ! -f "${EXTER}/cache/sources/${ATFSOURCEDIR}/Makefile" ]]; then + display_alert "ATF sources missing; downloading once" "(IGNORE_UPDATES=yes)" "wrn" + fetch_from_repo "$ATFSOURCE" "${EXTER}/cache/sources/$ATFDIR" "$ATFBRANCH" "yes" + fi + fi # Compile kernel if packed .deb does not exist or use the one from Orange Pi