[v2,2/7] image: refactor SDK

Message ID 20220405132431.2895832-3-adriaan.schmidt@siemens.com
State Superseded, archived
Headers show
Series imagetypes | expand

Commit Message

Schmidt, Adriaan April 5, 2022, 5:24 a.m. UTC
- turn the image-sdk-extension into an image recipe variant (requires
  renaming of the class to `sdk` to use BBCLASSEXTEND).
- put the logic from sdkchroot into that variant
- turn the remainder of sdkcroot into the package sdk-files that
  that is then installed into SDKs

API change: SDK_FORMATS now has the same semantics (and knows the same
    formats) as IMAGE_FSTYPES. Because there is no image type to generate
    tar.xz images, for now the default SDK_FORMAT is `targz-img`.

NOTE: this patch does not work stand-alone. It requires changes to the
    way image types are handled.

Signed-off-by: Adriaan Schmidt <adriaan.schmidt@siemens.com>
---
 meta/classes/image-sdk-extension.bbclass      |  87 -----------
 meta/classes/image.bbclass                    |   2 +-
 meta/classes/sdk.bbclass                      | 137 ++++++++++++++++++
 .../{sdkchroot => sdk-files}/files/README.sdk |   0
 .../files/configscript.sh                     |   0
 .../files/gcc-sysroot-wrapper.sh              |   0
 .../files/relocate-sdk.sh                     |   0
 meta/recipes-devtools/sdk-files/sdk-files.bb  |  26 ++++
 meta/recipes-devtools/sdkchroot/sdkchroot.bb  |  78 ----------
 9 files changed, 164 insertions(+), 166 deletions(-)
 delete mode 100644 meta/classes/image-sdk-extension.bbclass
 create mode 100644 meta/classes/sdk.bbclass
 rename meta/recipes-devtools/{sdkchroot => sdk-files}/files/README.sdk (100%)
 rename meta/recipes-devtools/{sdkchroot => sdk-files}/files/configscript.sh (100%)
 rename meta/recipes-devtools/{sdkchroot => sdk-files}/files/gcc-sysroot-wrapper.sh (100%)
 rename meta/recipes-devtools/{sdkchroot => sdk-files}/files/relocate-sdk.sh (100%)
 create mode 100644 meta/recipes-devtools/sdk-files/sdk-files.bb
 delete mode 100644 meta/recipes-devtools/sdkchroot/sdkchroot.bb

Patch

diff --git a/meta/classes/image-sdk-extension.bbclass b/meta/classes/image-sdk-extension.bbclass
deleted file mode 100644
index 052c1b58..00000000
--- a/meta/classes/image-sdk-extension.bbclass
+++ /dev/null
@@ -1,87 +0,0 @@ 
-# This software is a part of ISAR.
-# Copyright (C) Siemens AG, 2019
-#
-# SPDX-License-Identifier: MIT
-#
-# This class extends the image.bbclass to supply the creation of a sdk
-
-SDK_INCLUDE_ISAR_APT ?= "0"
-SDK_FORMATS ?= "tar-xz"
-
-sdk_tar_xz() {
-    # Copy mount_chroot.sh for convenience
-    sudo cp ${SCRIPTSDIR}/mount_chroot.sh ${SDKCHROOT_DIR}
-
-    # Create SDK archive
-    cd -P ${SDKCHROOT_DIR}/..
-    sudo tar --transform="s|^rootfs|sdk-${DISTRO}-${DISTRO_ARCH}|" \
-        -c rootfs | xz -T0 > ${DEPLOY_DIR_IMAGE}/sdk-${DISTRO}-${DISTRO_ARCH}.tar.xz
-    bbdebug 1 "SDK rootfs available in ${DEPLOY_DIR_IMAGE}/sdk-${DISTRO}-${DISTRO_ARCH}.tar.xz"
-}
-
-do_populate_sdk[stamp-extra-info] = "${DISTRO}-${MACHINE}"
-do_populate_sdk[depends] = "sdkchroot:do_build"
-do_populate_sdk[vardeps] += "SDK_INCLUDE_ISAR_APT SDK_FORMATS"
-do_populate_sdk() {
-    local sdk_container_formats=""
-
-    if [ "${SDK_INCLUDE_ISAR_APT}" = "1" ]; then
-        # Copy isar-apt with deployed Isar packages
-        sudo cp -Trpfx ${REPO_ISAR_DIR}/${DISTRO} ${SDKCHROOT_DIR}/isar-apt
-    else
-        # Remove isar-apt repo entry
-        sudo rm -f ${SDKCHROOT_DIR}/etc/apt/sources.list.d/isar-apt.list
-    fi
-
-    sudo umount -R ${SDKCHROOT_DIR}/dev || true
-    sudo umount ${SDKCHROOT_DIR}/proc || true
-    sudo umount -R ${SDKCHROOT_DIR}/sys || true
-
-    # Remove setup scripts
-    sudo rm -f ${SDKCHROOT_DIR}/chroot-setup.sh ${SDKCHROOT_DIR}/configscript.sh
-
-    # Make all links relative
-    for link in $(find ${SDKCHROOT_DIR}/ -type l); do
-        target=$(readlink $link)
-
-        if [ "${target#/}" != "${target}" ]; then
-            basedir=$(dirname $link)
-            new_target=$(realpath --no-symlinks -m --relative-to=$basedir ${SDKCHROOT_DIR}/${target})
-
-            # remove first to allow rewriting directory links
-            sudo rm $link
-            sudo ln -s $new_target $link
-        fi
-    done
-
-    # Set up sysroot wrapper
-    for tool_pattern in "gcc-[0-9]*" "g++-[0-9]*" "cpp-[0-9]*" "ld.bfd" "ld.gold"; do
-        for tool in $(find ${SDKCHROOT_DIR}/usr/bin -type f -name "*-linux-gnu*-${tool_pattern}"); do
-            sudo mv "${tool}" "${tool}.bin"
-            sudo ln -sf gcc-sysroot-wrapper.sh ${tool}
-        done
-    done
-
-    # separate SDK formats: TAR and container formats
-    for sdk_format in ${SDK_FORMATS} ; do
-        case ${sdk_format} in
-            "tar-xz")
-                sdk_tar_xz
-                ;;
-            "docker-archive" | "oci" | "oci-archive" | "docker-daemon" | "containers-storage")
-                sdk_container_formats="${sdk_container_formats} ${sdk_format}"
-                ;;
-            *)
-                die "unsupported SDK format specified: ${sdk_format}"
-                ;;
-        esac
-    done
-
-    # generate the SDK in all the desired container formats
-    if [ -n "${sdk_container_formats}" ] ; then
-        bbnote "Generating SDK container in ${sdk_container_formats} format"
-        containerize_rootfs "${SDKCHROOT_DIR}" "${sdk_container_formats}" "sdk-"
-    fi
-}
-
-addtask populate_sdk after do_rootfs
diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index 8899d1e9..f87b76e7 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -78,7 +78,7 @@  ROOTFS_PACKAGE_SUFFIX ?= "${PN}-${DISTRO}-${MACHINE}"
 ROOTFS_POSTPROCESS_COMMAND_prepend = "${@bb.utils.contains('BASE_REPO_FEATURES', 'cache-deb-src', 'cache_deb_src', '', d)} "
 
 inherit rootfs
-inherit image-sdk-extension
+inherit sdk
 inherit image-tools-extension
 inherit image-postproc-extension
 inherit image-locales-extension
diff --git a/meta/classes/sdk.bbclass b/meta/classes/sdk.bbclass
new file mode 100644
index 00000000..adf9a1fe
--- /dev/null
+++ b/meta/classes/sdk.bbclass
@@ -0,0 +1,137 @@ 
+# This software is a part of ISAR.
+# Copyright (C) Siemens AG, 2019
+#
+# SPDX-License-Identifier: MIT
+#
+# This class extends the image.bbclass to supply the creation of a sdk
+
+# hook up the -sdk image variant
+BBCLASSEXTEND = "sdk"
+BPN = "${PN}"
+
+python sdk_virtclass_handler() {
+    pn = e.data.getVar('PN')
+    if pn.endswith('-sdk'):
+        e.data.setVar('BPN', pn[:-len('-sdk')])
+        e.data.appendVar('OVERRIDES', ':class-sdk')
+        # sdkchroot deploy only for sdk image
+        bb.build.addtask('deploy_sdkchroot', 'do_build', 'do_rootfs', d)
+    else:
+        # add do_populate_sdk only to the non-sdk variant
+        # it only exists to preserve the interface...
+        bb.build.addtask('populate_sdk', '', '', e.data)
+        e.data.appendVarFlag('do_populate_sdk', 'depends', '${BPN}-sdk:do_build')
+        e.data.appendVarFlag('do_clean', 'depends', '${BPN}-sdk:do_clean')
+}
+addhandler sdk_virtclass_handler
+sdk_virtclass_handler[eventmask] = "bb.event.RecipePreFinalise"
+
+# SDK is image-specific:
+SDKCHROOT_DIR = "${DEPLOY_DIR_SDKCHROOT}/${BPN}-${MACHINE}"
+
+# SDK settings
+SDK_INCLUDE_ISAR_APT ?= "0"
+SDK_FORMATS ?= "targz-img"
+SDK_INSTALL ?= ""
+SDK_PREINSTALL += " \
+    debhelper \
+    autotools-dev \
+    dpkg \
+    locales \
+    docbook-to-man \
+    apt \
+    automake \
+    devscripts \
+    equivs"
+
+TOOLCHAIN = "crossbuild-essential-${DISTRO_ARCH}"
+TOOLCHAIN_${HOST_ARCH} = "build-essential"
+TOOLCHAIN_i386 = "build-essential"
+TOOLCHAIN_append_compat-arch = " crossbuild-essential-${COMPAT_DISTRO_ARCH}"
+
+# rootfs/image overrides for the SDK
+ROOTFS_ARCH_class-sdk = "${HOST_ARCH}"
+ROOTFS_DISTRO_class-sdk = "${HOST_DISTRO}"
+ROOTFS_PACKAGES_class-sdk = "sdk-files ${TOOLCHAIN} ${SDK_PREINSTALL} ${SDK_INSTALL}"
+ROOTFS_FEATURES_append_class-sdk = " clean-package-cache generate-manifest export-dpkg-status"
+ROOTFS_MANIFEST_DEPLOY_DIR_class-sdk = "${DEPLOY_DIR_SDKCHROOT}"
+ROOTFS_DPKGSTATUS_DEPLOY_DIR_class-sdk = "${DEPLOY_DIR_SDKCHROOT}"
+
+IMAGE_FSTYPES_class-sdk = "${SDK_FORMATS}"
+
+# bitbake dependencies
+SDKDEPENDS += "sdk-files ${SDK_INSTALL}"
+SDKDEPENDS_append_riscv64 = "${@' crossbuild-essential-riscv64' if d.getVar('ISAR_CROSS_COMPILE', True) == '1' and d.getVar('PN') != 'crossbuild-essential-riscv64' else ''}"
+DEPENDS_class-sdk = "${SDKDEPENDS}"
+
+SDKROOTFSDEPENDS = ""
+SDKROOTFSDEPENDS_class-sdk = "${BPN}:do_rootfs"
+do_rootfs_install[depends] += "${SDKROOTFSDEPENDS}"
+
+SDKROOTFSVARDEPS = ""
+SDKROOTFSVARDEPS_class-sdk = "SDK_INCLUDE_ISAR_APT"
+do_rootfs_install[vardeps] += "${SDKROOTFSVARDEPS}"
+
+# additional SDK steps
+ROOTFS_CONFIGURE_COMMAND_append_class-sdk = " ${@'rootfs_configure_isar_apt_dir' if d.getVar('SDK_INCLUDE_ISAR_APT') == '1' else ''}"
+rootfs_configure_isar_apt_dir() {
+    # Copy isar-apt instead of mounting:
+    sudo cp -Trpfx ${REPO_ISAR_DIR}/${DISTRO} ${ROOTFSDIR}/isar-apt
+}
+
+ROOTFS_POSTPROCESS_COMMAND_prepend_class-sdk = "sdkchroot_configscript "
+sdkchroot_configscript () {
+    sudo chroot ${ROOTFSDIR} /configscript.sh ${DISTRO_ARCH}
+}
+
+ROOTFS_POSTPROCESS_COMMAND_append_class-sdk = " sdkchroot_finalize"
+sdkchroot_finalize() {
+    if [ "${SDK_INCLUDE_ISAR_APT}" = "0" ]; then
+        # Remove isar-apt repo entry
+        sudo rm -f ${ROOTFSDIR}/etc/apt/sources.list.d/isar-apt.list
+    fi
+
+    sudo umount -R ${ROOTFSDIR}/dev || true
+    sudo umount ${ROOTFSDIR}/proc || true
+    sudo umount -R ${ROOTFSDIR}/sys || true
+
+    # Remove setup scripts
+    sudo rm -f ${ROOTFSDIR}/chroot-setup.sh ${ROOTFSDIR}/configscript.sh
+
+    # Make all links relative
+    for link in $(find ${ROOTFSDIR}/ -type l); do
+        target=$(readlink $link)
+
+        if [ "${target#/}" != "${target}" ]; then
+            basedir=$(dirname $link)
+            new_target=$(realpath --no-symlinks -m --relative-to=$basedir ${ROOTFSDIR}/${target})
+
+            # remove first to allow rewriting directory links
+            sudo rm $link
+            sudo ln -s $new_target $link
+        fi
+    done
+
+    # Set up sysroot wrapper
+    for tool_pattern in "gcc-[0-9]*" "g++-[0-9]*" "cpp-[0-9]*" "ld.bfd" "ld.gold"; do
+        for tool in $(find ${ROOTFSDIR}/usr/bin -type f -name "*-linux-gnu*-${tool_pattern}"); do
+            sudo mv "${tool}" "${tool}.bin"
+            sudo ln -sf gcc-sysroot-wrapper.sh ${tool}
+        done
+    done
+}
+
+do_deploy_sdkchroot[dirs] = "${DEPLOY_DIR_SDKCHROOT}"
+do_deploy_sdkchroot() {
+    ln -Tfsr "${ROOTFSDIR}" "${SDKCHROOT_DIR}"
+}
+
+CLEANFUNCS_class-sdk = "clean_deploy"
+clean_deploy() {
+    rm -f "${SDKCHROOT_DIR}"
+}
+
+do_populate_sdk[noexec] = "1"
+do_populate_sdk() {
+    :
+}
diff --git a/meta/recipes-devtools/sdkchroot/files/README.sdk b/meta/recipes-devtools/sdk-files/files/README.sdk
similarity index 100%
rename from meta/recipes-devtools/sdkchroot/files/README.sdk
rename to meta/recipes-devtools/sdk-files/files/README.sdk
diff --git a/meta/recipes-devtools/sdkchroot/files/configscript.sh b/meta/recipes-devtools/sdk-files/files/configscript.sh
similarity index 100%
rename from meta/recipes-devtools/sdkchroot/files/configscript.sh
rename to meta/recipes-devtools/sdk-files/files/configscript.sh
diff --git a/meta/recipes-devtools/sdkchroot/files/gcc-sysroot-wrapper.sh b/meta/recipes-devtools/sdk-files/files/gcc-sysroot-wrapper.sh
similarity index 100%
rename from meta/recipes-devtools/sdkchroot/files/gcc-sysroot-wrapper.sh
rename to meta/recipes-devtools/sdk-files/files/gcc-sysroot-wrapper.sh
diff --git a/meta/recipes-devtools/sdkchroot/files/relocate-sdk.sh b/meta/recipes-devtools/sdk-files/files/relocate-sdk.sh
similarity index 100%
rename from meta/recipes-devtools/sdkchroot/files/relocate-sdk.sh
rename to meta/recipes-devtools/sdk-files/files/relocate-sdk.sh
diff --git a/meta/recipes-devtools/sdk-files/sdk-files.bb b/meta/recipes-devtools/sdk-files/sdk-files.bb
new file mode 100644
index 00000000..36cdb319
--- /dev/null
+++ b/meta/recipes-devtools/sdk-files/sdk-files.bb
@@ -0,0 +1,26 @@ 
+# SDK Root filesystem
+#
+# This software is a part of ISAR.
+# Copyright (C) 2015-2018 ilbers GmbH
+
+DESCRIPTION = "Isar SDK Root filesystem"
+
+LICENSE = "gpl-2.0"
+LIC_FILES_CHKSUM = "file://${LAYERDIR_core}/licenses/COPYING.GPLv2;md5=751419260aa954499f7abaabaa882bbe"
+
+inherit dpkg-raw
+
+SRC_URI = " \
+    file://configscript.sh \
+    file://relocate-sdk.sh \
+    file://gcc-sysroot-wrapper.sh \
+    file://README.sdk"
+PV = "0.1"
+
+do_install() {
+    install -m 644 ${WORKDIR}/README.sdk ${D}
+    install -m 755 ${WORKDIR}/relocate-sdk.sh ${D}
+    install -m 755 -d ${D}/usr/bin
+    install -m 755 ${WORKDIR}/gcc-sysroot-wrapper.sh ${D}/usr/bin
+    install -m 755 ${WORKDIR}/configscript.sh ${D}
+}
diff --git a/meta/recipes-devtools/sdkchroot/sdkchroot.bb b/meta/recipes-devtools/sdkchroot/sdkchroot.bb
deleted file mode 100644
index e367eae2..00000000
--- a/meta/recipes-devtools/sdkchroot/sdkchroot.bb
+++ /dev/null
@@ -1,78 +0,0 @@ 
-# SDK Root filesystem
-#
-# This software is a part of ISAR.
-# Copyright (C) 2015-2018 ilbers GmbH
-
-DESCRIPTION = "Isar SDK Root filesystem"
-
-LICENSE = "gpl-2.0"
-LIC_FILES_CHKSUM = "file://${LAYERDIR_core}/licenses/COPYING.GPLv2;md5=751419260aa954499f7abaabaa882bbe"
-
-SRC_URI = " \
-    file://configscript.sh \
-    file://relocate-sdk.sh \
-    file://gcc-sysroot-wrapper.sh \
-    file://README.sdk"
-PV = "0.1"
-
-SDK_INSTALL ?= ""
-
-DEPENDS += "${SDK_INSTALL}"
-
-DEPENDS_append_riscv64 = "${@' crossbuild-essential-riscv64' if d.getVar('ISAR_CROSS_COMPILE', True) == '1' and d.getVar('PN') != 'crossbuild-essential-riscv64' else ''}"
-
-TOOLCHAIN = "crossbuild-essential-${DISTRO_ARCH}"
-TOOLCHAIN_${HOST_ARCH} = "build-essential"
-TOOLCHAIN_i386 = "build-essential"
-TOOLCHAIN_append_compat-arch = " crossbuild-essential-${COMPAT_DISTRO_ARCH}"
-
-inherit rootfs
-ROOTFS_ARCH = "${HOST_ARCH}"
-ROOTFS_DISTRO = "${HOST_DISTRO}"
-ROOTFSDIR = "${S}"
-ROOTFS_PACKAGES = "${SDK_PREINSTALL} ${SDK_INSTALL} ${TOOLCHAIN}"
-ROOTFS_FEATURES += "clean-package-cache generate-manifest export-dpkg-status"
-ROOTFS_MANIFEST_DEPLOY_DIR = "${DEPLOY_DIR_SDKCHROOT}"
-ROOTFS_DPKGSTATUS_DEPLOY_DIR = "${DEPLOY_DIR_SDKCHROOT}"
-
-SDK_PREINSTALL += " \
-    debhelper \
-    autotools-dev \
-    dpkg \
-    locales \
-    docbook-to-man \
-    apt \
-    automake \
-    devscripts \
-    equivs"
-
-SDK_INCLUDE_ISAR_APT ?= "0"
-
-S = "${WORKDIR}/rootfs"
-
-ROOTFS_CONFIGURE_COMMAND += "${@'rootfs_configure_isar_apt_dir' if d.getVar('SDK_INCLUDE_ISAR_APT') == '1' else ''}"
-rootfs_configure_isar_apt_dir() {
-    # Copy isar-apt instead of mounting:
-    sudo cp -Trpfx ${REPO_ISAR_DIR}/${DISTRO} ${ROOTFSDIR}/isar-apt
-}
-
-ROOTFS_POSTPROCESS_COMMAND =+ "sdkchroot_install_files"
-sdkchroot_install_files() {
-    # Configure root filesystem
-    sudo install -m 644 ${WORKDIR}/README.sdk ${S}
-    sudo install -m 755 ${WORKDIR}/relocate-sdk.sh ${S}
-    sudo install -m 755 ${WORKDIR}/gcc-sysroot-wrapper.sh ${S}/usr/bin
-    sudo install -m 755 ${WORKDIR}/configscript.sh ${S}
-    sudo chroot ${S} /configscript.sh  ${DISTRO_ARCH}
-}
-
-do_sdkchroot_deploy[dirs] = "${DEPLOY_DIR_SDKCHROOT}"
-do_sdkchroot_deploy() {
-    ln -Tfsr "${ROOTFSDIR}" "${SDKCHROOT_DIR}"
-}
-addtask sdkchroot_deploy before do_build after do_rootfs
-
-CLEANFUNCS = "clean_deploy"
-clean_deploy() {
-    rm -f "${SDKCHROOT_DIR}"
-}