On Friday, December 8, 2023 at 7:45:06 PM UTC+5:30 Jan Kiszka wrote:
On 28.11.23 08:14, Srinuvasan Arjunan wrote:
> From: Srinuvasan A <srinuv...@siemens.com>
>
> In present implementation we are using sbuild/schroot to build the
> packages, this schroot created via sessions during package build, and
> immediatley vanish once build the packages.
>
> Some of the downstream projects uses this chroot at many
> places for doing some postprocessing the meta data based on the chroot
> path, but unfortunately we cannot refer this path due to creating the
> chroot via session.
Can you be more specific in the use cases?
In our case we need to install the custom packages in buildchroot,
once we installed the isar-apt packages, later we refer those and do some
postprocessing before image creation.
ISAR provides the provision to pre-install the upstream packages
not custom packages and this chroot will be used as a base chroot to
build the packages or imager_run, hence SBUILD_FLAVOR would not be
helpful atleast for my scenario.
SBUILD_CHROOT_PREINSTALL_EXTRA variable directly install the upstream
packages in rootfs not custom packages.
>
> Hence install the required packages in persistence sbuildchroot, to
> access isar-apt and other directories we introduces the sbuildchroot
> class.
Did no one commented yet that we already have SBUILD_FLAVOR to
pre-install common packages into reusable sbuild schroots?
Jan
>
> Signed-off-by: Srinuvasan A <srinuv...@siemens.com>
> ---
> meta/classes/sbuildchroot.bbclass | 101 ++++++++++++++++++++++++++++++
> 1 file changed, 101 insertions(+)
> create mode 100644 meta/classes/sbuildchroot.bbclass
>
> diff --git a/meta/classes/sbuildchroot.bbclass b/meta/classes/sbuildchroot.bbclass
> new file mode 100644
> index 00000000..edddd566
> --- /dev/null
> +++ b/meta/classes/sbuildchroot.bbclass
> @@ -0,0 +1,101 @@
> +# This software is a part of ISAR.
> +# Copyright (C) 2018 Siemens AG
> +#
> +# SPDX-License-Identifier: MIT
> +
> +inherit crossvars
> +
> +MOUNT_LOCKFILE = "${SCHROOT_DIR}.lock"
> +
> +sbuildchroot_do_mounts() {
> + if [ "${USE_CCACHE}" = "1" ]; then
> + mkdir -p "${CCACHE_DIR}"
> + if [ "${CCACHE_DEBUG}" = "1" ]; then
> + mkdir -p "${CCACHE_DIR}/debug"
> + fi
> + fi
> +
> + sudo -s <<'EOSUDO'
> + ( flock 9
> + set -e
> +
> + mountpoint -q '${SCHROOT_DIR}/isar-apt' ||
> + mount --bind '${REPO_ISAR_DIR}/${DISTRO}' '${SCHROOT_DIR}/isar-apt'
> + if [ "${USE_CCACHE}" = "1" ]; then
> + mkdir -p '${SCHROOT_DIR}/ccache'
> + mountpoint -q '${SCHROOT_DIR}/ccache' ||
> + mount --bind '${CCACHE_DIR}' '${SCHROOT_DIR}/ccache'
> + fi
> + mountpoint -q '${SCHROOT_DIR}/dev' ||
> + ( mount -o bind,private /dev '${SCHROOT_DIR}/dev' &&
> + mount -t tmpfs none '${SCHROOT_DIR}/dev/shm' &&
> + mount --bind /dev/pts '${SCHROOT_DIR}/dev/pts' )
> + mountpoint -q '${SCHROOT_DIR}/proc' ||
> + mount -t proc none '${SCHROOT_DIR}/proc'
> + mountpoint -q '${SCHROOT_DIR}/sys' ||
> + mount --rbind /sys '${SCHROOT_DIR}/sys'
> + mount --make-rslave '${SCHROOT_DIR}/sys'
> +
> + # Mount base-apt if 'ISAR_USE_CACHED_BASE_REPO' is set
> + if [ "${@repr(bb.utils.to_boolean(d.getVar('ISAR_USE_CACHED_BASE_REPO')))}" = 'True' ]
> + then
> + mkdir -p '${SCHROOT_DIR}/base-apt'
> + mountpoint -q '${SCHROOT_DIR}/base-apt' || \
> + mount --bind '${REPO_BASE_DIR}' '${SCHROOT_DIR}/base-apt'
> + fi
> +
> + # Refresh or remove /etc/resolv.conf at this chance
> + if [ "${@repr(bb.utils.to_boolean(d.getVar('BB_NO_NETWORK')))}" = 'True' ]
> + then
> + rm -rf '${SCHROOT_DIR}/etc/resolv.conf'
> + else
> + cp -L /etc/resolv.conf '${SCHROOT_DIR}/etc'
> + fi
> +
> + ) 9>'${MOUNT_LOCKFILE}'
> +EOSUDO
> +}
> +
> +add_isar_apt() {
> + sudo -s <<'EOSUDO'
> + set -e
> +
> + mkdir -p '${SCHROOT_DIR}/etc/apt/sources.list.d'
> + echo 'deb [trusted=yes] file:///isar-apt ${DEBDISTRONAME} main' > \
> + '${SCHROOT_DIR}/etc/apt/sources.list.d/isar-apt.list'
> + echo 'deb-src [trusted=yes] file:///isar-apt ${DEBDISTRONAME} main' >> \
> + '${SCHROOT_DIR}/etc/apt/sources.list.d/isar-apt.list'
> +
> + mkdir -p '${SCHROOT_DIR}/etc/apt/preferences.d'
> + cat << EOF > '${SCHROOT_DIR}/etc/apt/preferences.d/isar-apt'
> +Package: *
> +Pin: release n=${DEBDISTRONAME}
> +Pin-Priority: 1000
> +EOF
> +EOSUDO
> +}
> +
> +cleanup_isar_apt() {
> + sudo -s <<'EOSUDO'
> + set -e
> + rm -f "${SCHROOT_DIR}/etc/apt/sources.list.d/isar-apt.list"
> + rm -f "${SCHROOT_DIR}/etc/apt/preferences.d/isar-apt"
> + rm -f "${SCHROOT_DIR}/etc/apt/sources.list.d/base-apt.list"
> + rm -f "${SCHROOT_DIR}/etc/apt/apt.conf.d/50isar"
> +EOSUDO
> +}
> +
> +image_do_mounts() {
> + sudo flock ${MOUNT_LOCKFILE} -c ' \
> + mkdir -p "${BUILDROOT_DEPLOY}" "${BUILDROOT_ROOTFS}" "${BUILDROOT_WORK}"
> + mount --bind "${DEPLOY_DIR_IMAGE}" "${BUILDROOT_DEPLOY}"
> + mount --bind "${IMAGE_ROOTFS}" "${BUILDROOT_ROOTFS}"
> + mount --bind "${WORKDIR}" "${BUILDROOT_WORK}"
> + '
> + sbuildchroot_do_mounts
> +}
> +
> +BUILDROOT = "${SCHROOT_DIR}${PP}"
> +BUILDROOT_DEPLOY = "${SCHROOT_DIR}${PP_DEPLOY}"
> +BUILDROOT_ROOTFS = "${SCHROOT_DIR}${PP_ROOTFS}"
> +BUILDROOT_WORK = "${SCHROOT_DIR}${PP_WORK}"
--
Siemens AG, Technology
Linux Expert Center