[v6,02/11] meta: Add debrepo bbclass handling base-apt prefetching

Message ID 20240314073047.29465-3-ubely@ilbers.de
State Superseded, archived
Headers show
Series Improving base-apt usage | expand

Commit Message

Uladzimir Bely March 14, 2024, 7:27 a.m. UTC
This class uses 'scripts/debrepo' python script to prefetch given
packages or sources to local base-apt repository.

Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
---
 RECIPE-API-CHANGELOG.md      |  9 ++++
 meta/classes/debrepo.bbclass | 81 ++++++++++++++++++++++++++++++++++++
 meta/conf/bitbake.conf       |  5 +++
 3 files changed, 95 insertions(+)
 create mode 100644 meta/classes/debrepo.bbclass

Patch

diff --git a/RECIPE-API-CHANGELOG.md b/RECIPE-API-CHANGELOG.md
index 2da7968d..cb466eb7 100644
--- a/RECIPE-API-CHANGELOG.md
+++ b/RECIPE-API-CHANGELOG.md
@@ -572,3 +572,12 @@  the module build recipe.
 Remove all uses of the function deb_compat. The functionality was replaced with
 a dependency to the package debhelper-compat.
 
+### "Prefetch" mode for base-apt
+
+Originally, `base-apt` repo is created only during second build when variable
+ISAR_USE_CACHED_BASE_REPO is set. The repo is populated with every package that
+took part in the first build and was cached in DL_DIR.
+
+New ISAR_PREFETCH_BASE_APT variable changes the way `base-apt` is populated.
+Packages added to the repo before running any task that need them. Separate
+`debrepo` script is used for populating base-apt repo.
diff --git a/meta/classes/debrepo.bbclass b/meta/classes/debrepo.bbclass
new file mode 100644
index 00000000..6c135ef2
--- /dev/null
+++ b/meta/classes/debrepo.bbclass
@@ -0,0 +1,81 @@ 
+# This software is a part of Isar.
+# Copyright (C) 2024 ilbers GmbH
+#
+# SPDX-License-Identifier: MIT
+
+DEBREPO_WORKDIR ?= "${DEBREPO_TARGET_DIR}"
+
+debrepo_update_apt_source_list() {
+    [ "${ISAR_PREFETCH_BASE_APT}" != "1" ] && return
+
+    chroot_dir=${1}
+    apt_list=${2}
+
+    flock -x "${REPO_BASE_DIR}/repo.lock" -c "
+        sudo -E chroot ${chroot_dir} /usr/bin/apt-get update \
+            -o Dir::Etc::SourceList=\"sources.list.d/${apt_list}.list\" \
+            -o Dir::Etc::SourceParts=\"-\" \
+            -o APT::Get::List-Cleanup=\"0\"
+    "
+}
+
+debrepo_add_packages() {
+    [ "${ISAR_PREFETCH_BASE_APT}" != "1" ] && return
+    [ "${ISAR_USE_CACHED_BASE_REPO}" = "1" ] && return
+
+    args=""
+    if [ "${1}" = "--srcmode" ]; then
+        args="${args} --srcmode"
+        shift
+    fi
+
+    if [ "${1}" = "--isarapt" ]; then
+        args="${args} --extrarepo=${REPO_ISAR_DIR}/${DISTRO}"
+        shift
+    fi
+
+    workdir="${1}"
+    args="${args} ${2}"
+
+    if [ -n "${GNUPGHOME}" ]; then
+        export GNUPGHOME="${GNUPGHOME}"
+    fi
+
+    flock -x "${workdir}/repo.lock" -c "
+        ${SCRIPTSDIR}/debrepo \
+            --workdir=\"${workdir}\" \
+            ${args}
+        "
+}
+
+debrepo_handle_controlfile() {
+    [ "${ISAR_PREFETCH_BASE_APT}" != "1" ] && return
+    [ "${ISAR_USE_CACHED_BASE_REPO}" = "1" ] && return
+
+    control_file="${1}"
+    args=""
+
+    build_arch=${DISTRO_ARCH}
+    if [ "${ISAR_CROSS_COMPILE}" = "1" ]; then
+        build_arch=${HOST_ARCH}
+    fi
+    if [ "${PACKAGE_ARCH}" != "${build_arch}" ]; then
+        args="--crossbuild \
+            crossbuild-essential-${PACKAGE_ARCH}:${build_arch} \
+            dose-distcheck:${build_arch} \
+            libc-dev:${PACKAGE_ARCH} \
+            libstdc++-dev:${PACKAGE_ARCH} \
+        "
+    fi
+
+    if [ -n "${GNUPGHOME}" ]; then
+        export GNUPGHOME="${GNUPGHOME}"
+    fi
+
+    flock -x "${DEBREPO_WORKDIR}/repo.lock" -c "
+        ${SCRIPTSDIR}/debrepo \
+            --workdir=\"${DEBREPO_WORKDIR}\" \
+            --controlfile=\"${control_file}\" \
+            ${args}
+    "
+}
diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
index 91c5c815..1bff8c8e 100644
--- a/meta/conf/bitbake.conf
+++ b/meta/conf/bitbake.conf
@@ -69,6 +69,11 @@  KERNEL_FILE:mipsel ?= "vmlinux"
 KERNEL_FILE:riscv64 ?= "vmlinux"
 KERNEL_FILE:arm64 ?= "vmlinux"
 
+# debrepo config
+DEBREPO_DIR = "${TOPDIR}/debrepo"
+DEBREPO_HOST_DIR = "${DEBREPO_DIR}/${HOST_DISTRO}-${HOST_ARCH}_${DISTRO}-${DISTRO_ARCH}"
+DEBREPO_TARGET_DIR = "${DEBREPO_DIR}/${DISTRO}-${DISTRO_ARCH}"
+
 MACHINEOVERRIDES ?= "${MACHINE}"
 DISTROOVERRIDES ?= "${DISTRO}"
 OVERRIDES = "${PACKAGE_ARCH}:${MACHINEOVERRIDES}:${DISTROOVERRIDES}:${BASE_DISTRO_CODENAME}:forcevariable"