armbian/lib/functions/compilation/kernel-git.sh
Igor Velkov 6c036dbaf6 git: try other kernel remotes when one does not answer or lacks the ref
Each git source is a single URL: if it does not answer, the build fails,
even though the same kernel refs sit on several remotes. A mirror lagging
behind a fresh tag fails the same way.

git_remote_candidates() lists, for a kernel remote, the mirrors of the
same tree: torvalds on kernel.org and GitHub, stable on kernel.org and
googlesource, led by MAINLINE_KERNEL_SOURCE. For tags it adds the other
tree too, as both carry the mainline tags; same-named branches differ
between the trees. Any other source keeps only its own URL. Tag and
branch resolution ask them in turn, and move on when a remote does not
answer or answers without the ref. fetch_from_repo() starts with the
remote that had the tag, and moves to the next remote once improved_git
gives up. The Makefile is read from the remote that answered.

A branch tip can differ from the commit the build was versioned with: a
mirror can lag, and the versioned SHA1 is memoized (an hour by default).
The kernel passes KERNEL_GIT_SHA1 as GIT_EXPECTED_SHA1: a tree at another
commit is no cache hit, a fetch is kept only if that commit is present
afterwards, and that commit is checked out instead of the fetched tip.
Submodule fetches clear it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 02:56:23 +03:00

32 lines
1.1 KiB
Bash

#!/usr/bin/env bash
#
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (c) 2013-2026 Igor Pecovnik, igor@armbian.com
#
# This file is a part of the Armbian Build Framework
# https://github.com/armbian/build/
function kernel_prepare_git() {
[[ "${KERNELSOURCE}" == 'none' ]] && return 0 # do nothing if no kernel source... but again, why were we called then?
# validate kernel_git_bare_tree is set
if [[ -z "${kernel_git_bare_tree}" ]]; then
exit_with_error "kernel_git_bare_tree is not set"
fi
display_alert "Downloading sources" "kernel" "git"
GIT_FIXED_WORKDIR="${LINUXSOURCEDIR}" \
GIT_EXPECTED_SHA1="${KERNEL_GIT_SHA1:-}" \
GIT_BARE_REPO_FOR_WORKTREE="${kernel_git_bare_tree}" \
GIT_BARE_REPO_INITIAL_BRANCH="master" \
fetch_from_repo "${KERNELSOURCE}" "kernel:${KERNEL_MAJOR_MINOR}" "${KERNELBRANCH}" "yes"
# second parameter, "dir", is ignored, since we've passed GIT_FIXED_WORKDIR
}
function kernel_cleanup_bundle_artifacts() {
[[ -z "${git_bundles_dir}" ]] && exit_with_error "git_bundles_dir is not set"
git_oras_tree_cleanup_bundles "Kernel" "${git_bundles_dir}"
}