Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9fb42b34 authored by Jackeagle's avatar Jackeagle
Browse files

kernel: run initial repo init from outside the Android tree



When repo init runs from inside the Android tree (which the kernel dir
is nested under), repo walks up and finds the Android .repo checkout,
reusing it instead of creating a new kernel checkout. Previous attempts
to fix this by copying .repo/repo or passing --repo-dir failed because
it is main.py itself (not the launcher) that walks up looking for a
valid .repo with manifests.git.

Fix by running the initial repo init from a temp dir outside the Android
tree where there is no parent .repo to find. The resulting .repo (with
a proper manifests.git) is then moved into the kernel dir. All internal
paths inside .repo are relative, so the move is safe.

On subsequent runs manifests.git already exists in the kernel dir, so
the regular repo init from inside the tree finds the kernel checkout
correctly without walking up.

Signed-off-by: default avatarJackeagle <jackeagle102@gmail.com>
parent 3cc44d52
Loading
Loading
Loading
Loading
+39 −19
Original line number Diff line number Diff line
@@ -943,6 +943,18 @@ function build_kernel() {

    local KERNEL_BUILD_TOP="${ANDROID_BUILD_TOP}/out-kernel/${target_kernel_source}"

    local target_kernel_manifest=$(echo android_kernel_${target_kernel_source}_manifest | tr / _)
    local repo_init_args=("-b" "${lineage_version}")
    if [ -n "${LINEAGE_MIRROR}" ]; then
        repo_init_args+=("--reference" "${LINEAGE_MIRROR}")
    fi
    if [ -n "${REPO_VERSION}" ]; then
        repo_init_args+=("--repo-rev" "${REPO_VERSION}")
    fi
    if [ -f "${ANDROID_BUILD_TOP}/.repo/local_manifests/proprietary_gitlab.xml" ]; then
        repo_init_args+=("-g" "default,-darwin,-muppets,muppets_${LINEAGE_BUILD}")
    fi

    # Make sure we have the kernel source folder structure in place.
    # Check for manifests.git specifically — a previous failed run may have
    # left .repo/ with only a TRACE_FILE, causing the old .repo/ check to
@@ -950,13 +962,31 @@ function build_kernel() {
    if [ ! -d "${KERNEL_BUILD_TOP}/.repo/manifests.git" ]; then
        echo "Kernel source ${KERNEL_BUILD_TOP} is missing, preparing folder structure"

        # Copy .repo/repo from Android tree to allow nested `repo init`.
        # With .repo/repo/main.py present, _FindRepo() finds the local checkout
        # instead of walking up to the parent Android tree. repo init then
        # creates manifests.git fresh from the kernel manifest URL.
        mkdir -p "${KERNEL_BUILD_TOP}/.repo"
        rm -rf "${KERNEL_BUILD_TOP}/.repo/repo"
        cp -R "${ANDROID_BUILD_TOP}/.repo/repo" "${KERNEL_BUILD_TOP}/.repo/repo"
        # Run repo init from a temp dir OUTSIDE the Android tree.
        # When called from inside the tree, repo walks up and reuses
        # the Android .repo checkout instead of creating a new one.
        # By initializing outside, repo has no parent .repo to find.
        # We then move the result into the kernel dir.
        local _tmpdir=$(mktemp -d)
        mkdir -p "${_tmpdir}/.repo"
        cp -R "${ANDROID_BUILD_TOP}/.repo/repo" "${_tmpdir}/.repo/repo"

        pushd "${_tmpdir}" > /dev/null
        yes | repo init -u "https://github.com/LineageOS/${target_kernel_manifest}.git" ${repo_init_args[@]} || [ $? -eq 141 ]
        if [ $? -ne 0 ]; then
            echo "Kernel source repo init failed"
            popd > /dev/null
            rm -rf "${_tmpdir}"
            return 1
        fi
        popd > /dev/null

        # Move the initialized .repo to kernel dir (all internal paths
        # are relative so the move is safe)
        mkdir -p "${KERNEL_BUILD_TOP}"
        rm -rf "${KERNEL_BUILD_TOP}/.repo"
        mv "${_tmpdir}/.repo" "${KERNEL_BUILD_TOP}/.repo"
        rm -rf "${_tmpdir}"

        # Allow custom .repo/project-objects dir
        if [ -n "${KERNEL_REPO_PROJECT_OBJECTS_DIR}" ]; then
@@ -982,18 +1012,8 @@ function build_kernel() {
    pushd "${KERNEL_BUILD_TOP}" > /dev/null
    if [[ "${SKIP_KERNEL_SYNC}" != "true" && "${SKIP_KERNEL_SYNC}" != "1" ]]; then
        echo "Syncing ${KERNEL_BUILD_TOP}"
        local target_kernel_manifest=$(echo android_kernel_${target_kernel_source}_manifest | tr / _)
        local repo_init_args=("-b" "${lineage_version}")
        if [ -n "${LINEAGE_MIRROR}" ]; then
            repo_init_args+=("--reference" "${LINEAGE_MIRROR}")
        fi
        if [ -n "${REPO_VERSION}" ]; then
            repo_init_args+=("--repo-rev" "${REPO_VERSION}")
        fi
        if [ -f "${ANDROID_BUILD_TOP}/.repo/local_manifests/proprietary_gitlab.xml" ]; then
            repo_init_args+=("-g" "default,-darwin,-muppets,muppets_${LINEAGE_BUILD}")
        fi

        # On subsequent runs manifests.git exists so repo finds the
        # kernel checkout without walking up to the Android tree.
        yes | repo init -u https://github.com/LineageOS/${target_kernel_manifest}.git ${repo_init_args[@]} || [ $? -eq 141 ]
        if [ $? -ne 0 ]; then
            echo "Kernel source repo init failed"