Browse Source

isar-bootstrap: Add host architecture support

Add HOST_* definitions and recipe to generate
ISAR boostrap with the host architecture.
Add corresponding options to setup_root_file_system().
Generate reprepro config for host distro
if it doesn't exist.

Signed-off-by: Alexander Smirnov <asmirnov@ilbers.de>
Signed-off-by: Maxim Yu. Osipov <mosipov@ilbers.de>
Alexander Smirnov 7 năm trước cách đây
mục cha
commit
895ab88b51

+ 20 - 2
meta/classes/isar-bootstrap-helper.bbclass

@@ -7,6 +7,18 @@
 
 IMAGE_TRANSIENT_PACKAGES ??= ""
 
+def get_deb_host_arch():
+    import subprocess
+    arch =  subprocess.check_output(['/usr/bin/dpkg-architecture', '-q', 'DEB_HOST_ARCH'], universal_newlines=True)
+    return str.splitlines(arch)[0]
+
+#Debian Distribution for SDK host
+HOST_DISTRO ?= "debian-stretch"
+#Determine SDK host architecture if not explicitly set
+HOST_ARCH ?= "${@get_deb_host_arch()}"
+
+HOST_DISTRO_APT_SOURCES += "conf/distro/${HOST_DISTRO}.list"
+
 def reverse_bb_array(d, varname):
     array = d.getVar(varname, True)
     if array is None:
@@ -14,13 +26,18 @@ def reverse_bb_array(d, varname):
     array = reversed(array.split())
     return " ".join(i for i in array)
 
+
 setup_root_file_system() {
     CLEAN=""
     FSTAB=""
+    ROOTFS_ARCH="${DISTRO_ARCH}"
+    ROOTFS_DISTRO="${DISTRO}"
     while true; do
         case "$1" in
         --clean) CLEAN=1 ;;
         --fstab) FSTAB=$2; shift ;;
+        --host-arch) ROOTFS_ARCH=${HOST_ARCH} ;;
+        --host-distro) ROOTFS_DISTRO=${HOST_DISTRO} ;;
         -*) bbfatal "$0: invalid option specified: $1" ;;
         *) break ;;
         esac
@@ -33,7 +50,7 @@ setup_root_file_system() {
     CLEAN_FILES="${ROOTFSDIR}/etc/hostname ${ROOTFSDIR}/etc/resolv.conf"
 
     sudo cp -Trpfx \
-        "${DEPLOY_DIR_IMAGE}/isar-bootstrap-${DISTRO}-${DISTRO_ARCH}/" \
+        "${DEPLOY_DIR_IMAGE}/isar-bootstrap-$ROOTFS_DISTRO-$ROOTFS_ARCH/" \
         "$ROOTFSDIR"
     [ -n "${FSTAB}" ] && cat ${FSTAB} | sudo tee "$ROOTFSDIR/etc/fstab"
 
@@ -43,7 +60,8 @@ setup_root_file_system() {
     echo "Package: *\nPin: release n=${DEBDISTRONAME}\nPin-Priority: 1000" | \
         sudo tee "$ROOTFSDIR/etc/apt/preferences.d/isar" >/dev/null
 
-    sudo mount --bind ${DEPLOY_DIR_APT}/${DISTRO} $ROOTFSDIR/isar-apt
+    sudo mount --bind ${DEPLOY_DIR_APT}/${ROOTFS_DISTRO} $ROOTFSDIR/isar-apt
+
     sudo mount -t devtmpfs -o mode=0755,nosuid devtmpfs $ROOTFSDIR/dev
     sudo mount -t proc none $ROOTFSDIR/proc
 

+ 75 - 0
meta/recipes-core/isar-bootstrap/isar-bootstrap-host.bb

@@ -0,0 +1,75 @@
+# Minimal host Debian root file system
+#
+# This software is a part of ISAR.
+# Copyright (c) Siemens AG, 2018
+#
+# SPDX-License-Identifier: MIT
+
+Description = "Minimal host Debian root file system"
+
+WORKDIR = "${TMPDIR}/work/${DISTRO}-${DISTRO_ARCH}/${PN}-${HOST_DISTRO}-${HOST_ARCH}"
+
+include isar-bootstrap.inc
+inherit isar-bootstrap-helper
+
+do_generate_keyring[stamp-extra-info] = "${HOST_DISTRO}-${HOST_ARCH}"
+
+do_apt_config_prepare[stamp-extra-info] = "${HOST_DISTRO}-${HOST_ARCH}"
+do_apt_config_prepare[dirs] = "${WORKDIR}"
+do_apt_config_prepare[vardeps] += "\
+                                   APTPREFS \
+                                   HOST_DISTRO_APT_PREFERENCES \
+                                   DEBDISTRONAME \
+                                   APTSRCS \
+                                   HOST_DISTRO_APT_SOURCES \
+                                  "
+python do_apt_config_prepare() {
+    apt_preferences_out = d.getVar("APTPREFS", True)
+    apt_preferences_list = (d.getVar("HOST_DISTRO_APT_PREFERENCES", True) or ""
+                           ).split()
+    aggregate_files(d, apt_preferences_list, apt_preferences_out)
+
+    apt_sources_out = d.getVar("APTSRCS", True)
+    apt_sources_list = (d.getVar("HOST_DISTRO_APT_SOURCES", True) or "").split()
+
+    aggregate_aptsources_list(d, apt_sources_list, apt_sources_out)
+}
+addtask apt_config_prepare before do_build after do_unpack
+
+do_apt_config_install[stamp-extra-info] = "${HOST_DISTRO}-${HOST_ARCH}"
+
+
+do_bootstrap[stamp-extra-info] = "${HOST_DISTRO}-${HOST_ARCH}"
+do_bootstrap[vardeps] += "HOST_DISTRO_APT_SOURCES"
+do_bootstrap[vardeps] += "DISTRO_APT_PREMIRRORS"
+do_bootstrap() {
+    if [ -e "${ROOTFSDIR}" ]; then
+       sudo umount -l "${ROOTFSDIR}/dev" || true
+       sudo umount -l "${ROOTFSDIR}/proc" || true
+       sudo rm -rf "${ROOTFSDIR}"
+    fi
+    E="${@bb.utils.export_proxies(d)}"
+    sudo -E "${DEBOOTSTRAP}" --verbose \
+                             --variant=minbase \
+                             --include=locales \
+                             ${@get_distro_components_argument(d, True)} \
+                             ${DEBOOTSTRAP_KEYRING} \
+                             "${@get_distro_suite(d, True)}" \
+                             "${ROOTFSDIR}" \
+                             "${@get_distro_source(d, True)}"
+}
+addtask bootstrap before do_build after do_generate_keyring
+
+do_deploy[stamp-extra-info] = "${HOST_DISTRO}-${HOST_ARCH}"
+do_deploy[dirs] = "${DEPLOY_DIR_IMAGE}"
+do_deploy() {
+    ln -Tfsr "${ROOTFSDIR}" "${DEPLOY_DIR_IMAGE}/isar-bootstrap-${HOST_DISTRO}-${HOST_ARCH}"
+}
+addtask deploy before do_build after do_apt_update
+
+do_apt_update[stamp-extra-info] = "${HOST_DISTRO}-${HOST_ARCH}"
+
+CLEANFUNCS = "clean_deploy"
+clean_deploy() {
+     rm -f "${DEPLOY_DIR_IMAGE}/isar-bootstrap}-${HOST_DISTRO}-${HOST_ARCH}"
+}

+ 31 - 0
meta/recipes-devtools/isar-apt/isar-apt-host.bb

@@ -0,0 +1,31 @@
+# This software is a part of ISAR.
+# Copyright (C) 2015-2018 ilbers GmbH
+
+inherit isar-bootstrap-helper
+
+SRC_URI = "file://distributions.in"
+
+CACHE_CONF_DIR = "${DEPLOY_DIR_APT}/${HOST_DISTRO}/conf"
+do_cache_config[dirs] = "${CACHE_CONF_DIR}"
+do_cache_config[stamp-extra-info] = "${HOST_DISTRO}"
+do_cache_config[lockfiles] = "${DEPLOY_DIR_APT}/isar.lock"
+
+# Generate reprepro config for current host distro if it doesn't exist. Once it's
+# generated, this task should do nothing.
+do_cache_config() {
+    if [ ! -e "${CACHE_CONF_DIR}/distributions" ]; then
+        sed -e "s#{DISTRO_NAME}#"${DEBDISTRONAME}"#g" \
+            ${WORKDIR}/distributions.in > ${CACHE_CONF_DIR}/distributions
+    fi
+
+    path_cache="${DEPLOY_DIR_APT}/${HOST_DISTRO}"
+    path_databases="${DEPLOY_DIR_DB}/${HOST_DISTRO}"
+
+    if [ ! -d "${path_databases}" ]; then
+        reprepro -b ${path_cache} \
+                 --dbdir ${path_databases} \
+                 export ${DEBDISTRONAME}
+    fi
+}
+
+addtask cache_config after do_unpack