[RFC,2/2] buildchroot: Add provision to specify apt preferences

Message ID 20211129145241.2932943-3-Vijaikumar_Kanagarajan@mentor.com
State RFC
Headers show
Series Buildchroot non-determinism | expand

Commit Message

Vijai Kumar K Nov. 29, 2021, 4:52 a.m. UTC
Add provision to set apt preferences for buildchroot-host and target.

Signed-off-by: Vijai Kumar K <Vijaikumar_Kanagarajan@mentor.com>
---
 .../buildchroot/buildchroot.inc               | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)

Patch

diff --git a/meta/recipes-devtools/buildchroot/buildchroot.inc b/meta/recipes-devtools/buildchroot/buildchroot.inc
index 726c7bb..fd06b80 100644
--- a/meta/recipes-devtools/buildchroot/buildchroot.inc
+++ b/meta/recipes-devtools/buildchroot/buildchroot.inc
@@ -50,6 +50,36 @@  rootfs_do_mounts_append() {
 EOSUDO
 }
 
+BUILDCHROOT_VARS_PREFIX ?= "${@'BUILDCHROOT_HOST_' if d.getVar('BOOTSTRAP_VARIANT') == 'HOST' else 'BUILDCHROOT_TARGET_'}"
+python() {
+    distro_apt_preferences = d.getVar(d.getVar("BUILDCHROOT_VARS_PREFIX") + "APT_PREFERENCES", True) or ""
+    for file in distro_apt_preferences.split():
+        d.appendVar("SRC_URI", " file://%s" % bb.parse.resolve_file(file, d))
+}
+
+APTPREFS = "${WORKDIR}/apt-preferences"
+
+do_buildchroot_prepare[vardeps] += " \
+    APTPREFS \
+    ${BUILDCHROOT_VARS_PREFIX}_APT_PREFERENCES \
+    "
+
+python do_buildchroot_prepare() {
+    apt_preferences_out = d.getVar("APTPREFS", True)
+    apt_preferences_list = (
+        d.getVar(d.getVar("BUILDCHROOT_VARS_PREFIX") + "APT_PREFERENCES", True) or ""
+    ).split()
+    aggregate_files(d, apt_preferences_list, apt_preferences_out)
+}
+addtask buildchroot_prepare before do_rootfs_install after do_unpack
+
+ROOTFS_CONFIGURE_COMMAND += "buildchroot_configure_preferences"
+buildchroot_configure_preferences() {
+    sudo install -v -m644 "${APTPREFS}" \
+                         "${BUILDCHROOT_DIR}/etc/apt/preferences.d/buildchroot"
+}
+
+
 ROOTFS_POSTPROCESS_COMMAND =+ "buildchroot_install_files"
 buildchroot_install_files() {
     sudo mkdir -p "${BUILDCHROOT_DIR}/home/builder"