From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 7306407937029701632 Date: Fri, 8 Dec 2023 06:13:32 -0800 (PST) From: Srinuvasan Arjunan To: isar-users Message-Id: <8f670376-f865-4169-8114-2dc4967603bfn@googlegroups.com> In-Reply-To: <20231128071401.1894962-1-srinuvasan_a@mentor.com> References: <20231128071401.1894962-1-srinuvasan_a@mentor.com> Subject: Re: [RFC][PATCH] Add sbuildchroot class MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_29715_1713941825.1702044812732" X-TUID: pFUEeyjSGXWK ------=_Part_29715_1713941825.1702044812732 Content-Type: multipart/alternative; boundary="----=_Part_29716_768545366.1702044812732" ------=_Part_29716_768545366.1702044812732 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi All, Any thoughts on this RFC, If you need additional use case also= =20 will provide. Many thanks, Srinu On Tuesday, November 28, 2023 at 12:44:22=E2=80=AFPM UTC+5:30 Srinuvasan Ar= junan=20 wrote: > From: Srinuvasan A > > 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. > > Hence install the required packages in persistence sbuildchroot, to > access isar-apt and other directories we introduces the sbuildchroot > class. > > Signed-off-by: Srinuvasan A > --- > meta/classes/sbuildchroot.bbclass | 101 ++++++++++++++++++++++++++++++ > 1 file changed, 101 insertions(+) > create mode 100644 meta/classes/sbuildchroot.bbclass > > diff --git a/meta/classes/sbuildchroot.bbclass=20 > 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 =3D "${SCHROOT_DIR}.lock" > + > +sbuildchroot_do_mounts() { > + if [ "${USE_CCACHE}" =3D "1" ]; then > + mkdir -p "${CCACHE_DIR}" > + if [ "${CCACHE_DEBUG}" =3D "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}" =3D "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 [=20 > "${@repr(bb.utils.to_boolean(d.getVar('ISAR_USE_CACHED_BASE_REPO')))}" = =3D=20 > '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')))}" =3D 'Tr= ue'=20 > ] > + 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=3Dyes] file:///isar-apt ${DEBDISTRONAME} main' > \ > + '${SCHROOT_DIR}/etc/apt/sources.list.d/isar-apt.list' > + echo 'deb-src [trusted=3Dyes] 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=3D${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 =3D "${SCHROOT_DIR}${PP}" > +BUILDROOT_DEPLOY =3D "${SCHROOT_DIR}${PP_DEPLOY}" > +BUILDROOT_ROOTFS =3D "${SCHROOT_DIR}${PP_ROOTFS}" > +BUILDROOT_WORK =3D "${SCHROOT_DIR}${PP_WORK}" > --=20 > 2.34.1 > > ------=_Part_29716_768545366.1702044812732 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi All,

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0Any thoughts on this RFC, If you need additional use case also will prov= ide.

Many thanks,
Srinu

On Tue= sday, November 28, 2023 at 12:44:22=E2=80=AFPM UTC+5:30 Srinuvasan Arjunan = wrote:
From: = Srinuvasan A <srinuv...@sieme= ns.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.

Hence install the required packages in persistence sbuildchroot, to
access isar-apt and other directories we introduces the sbuildchroot
class.

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/sbuildchr= oot.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 =3D "${SCHROOT_DIR}.lock"
+
+sbuildchroot_do_mounts() {
+ if [ "${USE_CCACHE}" =3D "1" ]; then
+ mkdir -p "${CCACHE_DIR}"
+ if [ "${CCACHE_DEBUG}" =3D "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}' '${S= CHROOT_DIR}/isar-apt'
+ if [ "${USE_CCACHE}" =3D "1" ]; then
+ mkdir -p '${SCHROOT_DIR}/ccache'
+ mountpoint -q '${SCHROOT_DIR}/ccache' ||
+ mount --bind '${CCACHE_DIR}' '${SCHROOT_DI= R}/ccache'
+ fi
+ mountpoint -q '${SCHROOT_DIR}/dev' ||
+ ( mount -o bind,private /dev '${SCHROOT_DIR}/dev' = &&
+ mount -t tmpfs none '${SCHROOT_DIR}/dev/shm' &am= p;&
+ 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')))}" =3D '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_NET= WORK')))}" =3D '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=3Dyes] file:///isar-apt ${DEBDISTRONAME} ma= in' > \
+ '${SCHROOT_DIR}/etc/apt/sources.list.d/isar-apt.list'
+ echo 'deb-src [trusted=3Dyes] 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/is= ar-apt'
+Package: *
+Pin: release n=3D${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.lis= t"
+ rm -f "${SCHROOT_DIR}/etc/apt/preferences.d/isar-apt"= ;
+ rm -f "${SCHROOT_DIR}/etc/apt/sources.list.d/base-apt.lis= t"
+ rm -f "${SCHROOT_DIR}/etc/apt/apt.conf.d/50isar"
+EOSUDO
+}
+
+image_do_mounts() {
+ sudo flock ${MOUNT_LOCKFILE} -c ' \
+ mkdir -p "${BUILDROOT_DEPLOY}" "${BUILDROOT_ROO= TFS}" "${BUILDROOT_WORK}"
+ mount --bind "${DEPLOY_DIR_IMAGE}" "${BUILDROOT= _DEPLOY}"
+ mount --bind "${IMAGE_ROOTFS}" "${BUILDROOT_ROO= TFS}"
+ mount --bind "${WORKDIR}" "${BUILDROOT_WORK}&qu= ot;
+ '
+ sbuildchroot_do_mounts
+}
+
+BUILDROOT =3D "${SCHROOT_DIR}${PP}"
+BUILDROOT_DEPLOY =3D "${SCHROOT_DIR}${PP_DEPLOY}"
+BUILDROOT_ROOTFS =3D "${SCHROOT_DIR}${PP_ROOTFS}"
+BUILDROOT_WORK =3D "${SCHROOT_DIR}${PP_WORK}"
--=20
2.34.1

------=_Part_29716_768545366.1702044812732-- ------=_Part_29715_1713941825.1702044812732--