public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: claudius.heine.ext@siemens.com
To: isar-users@googlegroups.com
Cc: Claudius Heine <ch@denx.de>
Subject: [PATCH v2 8/8] meta/classes/image: implement ROOTFS_POSTPROCESS_COMMAND
Date: Tue,  9 Apr 2019 14:29:15 +0200	[thread overview]
Message-ID: <20190409122915.14249-9-claudius.heine.ext@siemens.com> (raw)
In-Reply-To: <20190409122915.14249-1-claudius.heine.ext@siemens.com>

From: Claudius Heine <ch@denx.de>

Signed-off-by: Claudius Heine <ch@denx.de>
---
 meta/classes/image-postproc-extension.bbclass | 46 +++++++++++
 meta/classes/image.bbclass                    | 76 ++-----------------
 meta/classes/rootfs.bbclass                   | 58 ++++++++++++++
 3 files changed, 112 insertions(+), 68 deletions(-)
 create mode 100644 meta/classes/image-postproc-extension.bbclass
 create mode 100644 meta/classes/rootfs.bbclass

diff --git a/meta/classes/image-postproc-extension.bbclass b/meta/classes/image-postproc-extension.bbclass
new file mode 100644
index 0000000..625ba7d
--- /dev/null
+++ b/meta/classes/image-postproc-extension.bbclass
@@ -0,0 +1,46 @@
+# This software is a part of ISAR.
+# Copyright (C) Siemens AG, 2019
+
+update_etc_os_release() {
+    OS_RELEASE_BUILD_ID=""
+    OS_RELEASE_VARIANT=""
+    while true; do
+        case "$1" in
+        --build-id) OS_RELEASE_BUILD_ID=$2; shift ;;
+        --variant) OS_RELEASE_VARIANT=$2; shift ;;
+        -*) bbfatal "$0: invalid option specified: $1" ;;
+        *) break ;;
+        esac
+        shift
+    done
+
+    if [ -n "${OS_RELEASE_BUILD_ID}" ]; then
+        sudo sed -i '/^BUILD_ID=.*/d' '${IMAGE_ROOTFS}/etc/os-release'
+        echo "BUILD_ID=\"${OS_RELEASE_BUILD_ID}\"" | \
+            sudo tee -a '${IMAGE_ROOTFS}/etc/os-release'
+    fi
+    if [ -n "${OS_RELEASE_VARIANT}" ]; then
+        sudo sed -i '/^VARIANT=.*/d' '${IMAGE_ROOTFS}/etc/os-release'
+        echo "VARIANT=\"${OS_RELEASE_VARIANT}\"" | \
+            sudo tee -a '${IMAGE_ROOTFS}/etc/os-release'
+    fi
+}
+
+ROOTFS_POSTPROCESS_COMMAND =+ "image_postprocess_configure image_postprocess_mark"
+
+image_postprocess_configure() {
+    # Configure root filesystem
+    if [ -n "${DISTRO_CONFIG_SCRIPT}" ]; then
+        sudo install -m 755 "${WORKDIR}/${DISTRO_CONFIG_SCRIPT}" "${IMAGE_ROOTFS}"
+        TARGET_DISTRO_CONFIG_SCRIPT="$(basename ${DISTRO_CONFIG_SCRIPT})"
+        sudo chroot ${IMAGE_ROOTFS} "/$TARGET_DISTRO_CONFIG_SCRIPT" \
+                                    "${MACHINE_SERIAL}" "${BAUDRATE_TTY}"
+        sudo rm "${IMAGE_ROOTFS}/$TARGET_DISTRO_CONFIG_SCRIPT"
+   fi
+}
+
+image_postprocess_mark() {
+    BUILD_ID=$(get_build_id)
+    update_etc_os_release \
+        --build-id "${BUILD_ID}" --variant "${DESCRIPTION}"
+}
diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index bbfb80d..f9a3052 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -54,9 +54,12 @@ image_do_mounts() {
 }
 
 inherit isar-bootstrap-helper
+ROOTFS_FEATURES += "finalize-rootfs"
+inherit rootfs
 inherit image-sdk-extension
 inherit image-cache-extension
 inherit image-tools-extension
+inherit image-postproc-extension
 
 # Extra space for rootfs in MB
 ROOTFS_EXTRA ?= "64"
@@ -118,7 +121,7 @@ python set_image_size () {
     d.setVarFlag('ROOTFS_SIZE', 'export', '1')
 }
 
-isar_image_gen_fstab() {
+do_image_gen_fstab() {
     cat > ${WORKDIR}/fstab << EOF
 # Begin /etc/fstab
 /dev/root	/		auto		defaults		0	0
@@ -131,70 +134,19 @@ devtmpfs	/dev		devtmpfs	mode=0755,nosuid	0	0
 # End /etc/fstab
 EOF
 }
-
-isar_image_gen_rootfs() {
-    setup_root_file_system --clean --keep-apt-cache \
-        --fstab "${WORKDIR}/fstab" \
-        "${IMAGE_ROOTFS}" ${IMAGE_PREINSTALL} ${IMAGE_INSTALL}
-}
-
-isar_image_conf_rootfs() {
-    # Configure root filesystem
-    if [ -n "${DISTRO_CONFIG_SCRIPT}" ]; then
-        sudo install -m 755 "${WORKDIR}/${DISTRO_CONFIG_SCRIPT}" "${IMAGE_ROOTFS}"
-        TARGET_DISTRO_CONFIG_SCRIPT="$(basename ${DISTRO_CONFIG_SCRIPT})"
-        sudo chroot ${IMAGE_ROOTFS} "/$TARGET_DISTRO_CONFIG_SCRIPT" \
-                                    "${MACHINE_SERIAL}" "${BAUDRATE_TTY}"
-        sudo rm "${IMAGE_ROOTFS}/$TARGET_DISTRO_CONFIG_SCRIPT"
-   fi
-}
-
-isar_image_cleanup() {
-    # Cleanup
-    sudo sh -c ' \
-        rm "${IMAGE_ROOTFS}/etc/apt/sources.list.d/isar-apt.list"
-        test ! -e "${IMAGE_ROOTFS}/usr/share/doc/qemu-user-static" && \
-            find "${IMAGE_ROOTFS}/usr/bin" \
-                -maxdepth 1 -name 'qemu-*-static' -type f -delete
-             umount -l ${IMAGE_ROOTFS}/isar-apt
-        rmdir ${IMAGE_ROOTFS}/isar-apt
-        umount -l ${IMAGE_ROOTFS}/dev
-        umount -l ${IMAGE_ROOTFS}/proc
-        umount -l ${IMAGE_ROOTFS}/sys
-        rm -f "${IMAGE_ROOTFS}/etc/apt/apt.conf.d/55isar-fallback.conf"
-        if [ "${ISAR_USE_CACHED_BASE_REPO}" = "1" ]; then
-            umount -l ${IMAGE_ROOTFS}/base-apt
-            rmdir ${IMAGE_ROOTFS}/base-apt
-            # Replace the local apt we bootstrapped with the
-            # APT sources initially defined in DISTRO_APT_SOURCES
-            rm -f "${IMAGE_ROOTFS}/etc/apt/sources.list.d/base-apt.list"
-            mv "${IMAGE_ROOTFS}/etc/apt/sources-list" \
-                "${IMAGE_ROOTFS}/etc/apt/sources.list.d/bootstrap.list"
-        fi
-        rm -f "${IMAGE_ROOTFS}/etc/apt/sources-list"
-    '
-}
+addtask image_gen_fstab before do_rootfs_install
 
 do_rootfs_install[depends] = "isar-apt:do_cache_config isar-bootstrap-target:do_bootstrap"
 do_rootfs_install[deptask] = "do_deploy_deb"
 do_rootfs_install[root_cleandirs] = "${IMAGE_ROOTFS} \
                              ${IMAGE_ROOTFS}/isar-apt"
 do_rootfs_install() {
-    isar_image_gen_fstab
-    isar_image_gen_rootfs
-    isar_image_conf_rootfs
-    isar_image_cleanup
+    setup_root_file_system --clean --keep-apt-cache \
+        --fstab "${WORKDIR}/fstab" \
+        "${IMAGE_ROOTFS}" ${IMAGE_PREINSTALL} ${IMAGE_INSTALL}
 }
 addtask rootfs_install before do_build after do_unpack
 
-do_mark_rootfs() {
-    BUILD_ID=$(get_build_id)
-    update_etc_os_release \
-        --build-id "${BUILD_ID}" --variant "${DESCRIPTION}" \
-        "${IMAGE_ROOTFS}"
-}
-addtask mark_rootfs before do_rootfs_postprocess after do_rootfs_install
-
 do_copy_boot_files[dirs] = "${DEPLOY_DIR_IMAGE}"
 do_copy_boot_files() {
     if [ -n "${KERNEL_IMAGE}" ]; then
@@ -219,18 +171,6 @@ do_copy_boot_files() {
 }
 addtask copy_boot_files before do_rootfs_postprocess after do_rootfs_install
 
-python do_rootfs_postprocess() {
-    """Virtual task"""
-    pass
-}
-addtask rootfs_postprocess before do_build after do_rootfs_install
-
-python do_rootfs() {
-    """Virtual task"""
-    pass
-}
-addtask rootfs before do_build after do_rootfs_postprocess
-
 python do_image_tools() {
     """Virtual task"""
     pass
diff --git a/meta/classes/rootfs.bbclass b/meta/classes/rootfs.bbclass
new file mode 100644
index 0000000..45b0350
--- /dev/null
+++ b/meta/classes/rootfs.bbclass
@@ -0,0 +1,58 @@
+# This software is a part of ISAR.
+# Copyright (c) Siemens AG, 2019
+
+# Features of the rootfs creation:
+# available features are:
+# 'finalize-rootfs' - delete files needed to chroot into the rootfs
+ROOTFS_FEATURES ?= ""
+
+ROOTFS_POSTPROCESS_COMMAND += "${@bb.utils.contains('ROOTFS_FEATURES', 'finalize-rootfs', 'rootfs_postprocess_finalize', '', d)}"
+rootfs_postprocess_finalize() {
+    sudo -s <<'EOSUDO'
+        test ! -e "${ROOTFSDIR}/usr/share/doc/qemu-user-static" && \
+            find "${ROOTFSDIR}/usr/bin" \
+                -maxdepth 1 -name 'qemu-*-static' -type f -delete
+
+        mountpoint -q '${ROOTFSDIR}/isar-apt' && \
+            umount -l ${ROOTFSDIR}/isar-apt
+        rmdir --ignore-fail-on-non-empty ${ROOTFSDIR}/isar-apt
+
+        mountpoint -q '${ROOTFSDIR}/base-apt' && \
+            umount -l ${ROOTFSDIR}/base-apt
+        rmdir --ignore-fail-on-non-empty ${ROOTFSDIR}/base-apt
+
+        mountpoint -q '${ROOTFSDIR}/dev' && \
+            umount -l ${ROOTFSDIR}/dev
+        mountpoint -q '${ROOTFSDIR}/sys' && \
+            umount -l ${ROOTFSDIR}/proc
+        mountpoint -q '${ROOTFSDIR}/sys' && \
+            umount -l ${ROOTFSDIR}/sys
+
+        rm -f "${ROOTFSDIR}/etc/apt/apt.conf.d/55isar-fallback.conf"
+
+        rm -f "${ROOTFSDIR}/etc/apt/sources.list.d/isar-apt.list"
+        rm -f "${ROOTFSDIR}/etc/apt/sources.list.d/base-apt.list"
+
+        mv "${ROOTFSDIR}/etc/apt/sources-list" \
+            "${ROOTFSDIR}/etc/apt/sources.list.d/bootstrap.list"
+
+        rm -f "${ROOTFSDIR}/etc/apt/sources-list"
+EOSUDO
+}
+
+do_rootfs_postprocess[vardeps] = "${ROOTFS_POSTPROCESS_COMMAND}"
+python do_rootfs_postprocess() {
+    cmds = d.getVar("ROOTFS_POSTPROCESS_COMMAND")
+    if cmds is None or not cmds.strip():
+        return
+    cmds = cmds.split()
+    for cmd in cmds:
+        bb.build.exec_func(cmd, d)
+}
+addtask rootfs_postprocess before do_rootfs after do_rootfs_install
+
+python do_rootfs() {
+    """Virtual task"""
+    pass
+}
+addtask rootfs before do_build
-- 
2.20.1


  parent reply	other threads:[~2019-04-09 12:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-09 12:29 [PATCH v2 0/8] Implement ROOTFS postprocess commands claudius.heine.ext
2019-04-09 12:29 ` [PATCH v2 1/8] image.bbclass: make KERNEL_IMAGE & INITRD_IMAGE variable fixed claudius.heine.ext
2019-04-09 12:29 ` [PATCH v2 2/8] image.bbclass: limit `du` to only one file system claudius.heine.ext
2019-04-09 12:29 ` [PATCH v2 3/8] meta/classes/targz-img: limit tarball creation to " claudius.heine.ext
2019-04-09 12:29 ` [PATCH v2 4/8] meta/classes/buildchroot: add check before each mounting and quotes claudius.heine.ext
2019-04-09 12:29 ` [PATCH v2 5/8] meta/image classes: refactor task stamps claudius.heine.ext
2019-04-09 12:29 ` [PATCH v2 6/8] meta/classes/*-img: remove 'inherit image' statements claudius.heine.ext
2019-04-09 12:29 ` [PATCH v2 7/8] meta/classes/image*: refactor image pipeline and image.bbclass claudius.heine.ext
2019-04-09 12:29 ` claudius.heine.ext [this message]
2019-04-16  5:05 ` [PATCH v2 0/8] Implement ROOTFS postprocess commands Maxim Yu. Osipov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190409122915.14249-9-claudius.heine.ext@siemens.com \
    --to=claudius.heine.ext@siemens.com \
    --cc=ch@denx.de \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox