[v3,3/5] dpkg: Allow overriding build and host parameters for sbuild and schroot

Message ID 20230816121423.3956608-4-stefan-koch@siemens.com
State Superseded, archived
Headers show
Series linux-custom: Split up binaries from kernel headers to kbuild packages | expand

Commit Message

Koch, Stefan Aug. 16, 2023, 12:14 p.m. UTC
This functionality is initially used for custom linux builds using the
"-compat" and "-native" multiarch bitbake targets to run additional
target or host specific builds for kbuild scripts and tools.

Signed-off-by: Stefan Koch <stefan-koch@siemens.com>
---
 meta/classes/dpkg-base.bbclass | 19 ++++++++++++++++++-
 meta/classes/dpkg.bbclass      |  2 +-
 2 files changed, 19 insertions(+), 2 deletions(-)

Comments

Jan Kiszka Aug. 16, 2023, 1:55 p.m. UTC | #1
On 16.08.23 14:14, Koch, Stefan (DI PA DCP R&D 3) wrote:
> This functionality is initially used for custom linux builds using the
> "-compat" and "-native" multiarch bitbake targets to run additional
> target or host specific builds for kbuild scripts and tools.

But why does the kernel need these extra params? Why wouldn't it be
enough to add arch-specific profile settings for that package so that
linux-headers-mykernel-native will compile the kernel only for the
native headers and tools?

Same question for patch 2, in fact. I'm still missing the big picture.

Jan

> 
> Signed-off-by: Stefan Koch <stefan-koch@siemens.com>
> ---
>  meta/classes/dpkg-base.bbclass | 19 ++++++++++++++++++-
>  meta/classes/dpkg.bbclass      |  2 +-
>  2 files changed, 19 insertions(+), 2 deletions(-)
> 
> diff --git a/meta/classes/dpkg-base.bbclass b/meta/classes/dpkg-base.bbclass
> index 7b02f378..eaeb0e8b 100644
> --- a/meta/classes/dpkg-base.bbclass
> +++ b/meta/classes/dpkg-base.bbclass
> @@ -208,7 +208,7 @@ dpkg_runbuild() {
>  
>  def isar_deb_build_profiles(d):
>      deb_build_profiles = d.getVar('DEB_BUILD_PROFILES')
> -    if d.getVar('ISAR_CROSS_COMPILE') == "1":
> +    if d.getVar('ISAR_CROSS_COMPILE') == "1" and d.getVar('ISAR_SKIP_CROSS_PROFILE') != "1":
>          deb_build_profiles += ' cross'
>      return deb_build_profiles.strip()
>  
> @@ -223,6 +223,23 @@ def isar_export_build_settings(d):
>      os.environ['DEB_BUILD_PROFILES'] = isar_deb_build_profiles(d)
>  
>  python do_dpkg_build() {
> +    schroot_dir_override = d.getVar('SCHROOT_DIR_OVERRIDE', True)
> +    sbuild_build_override = d.getVar('SBUILD_BUILD_OVERRIDE', True)
> +    sbuild_host_override = d.getVar('SBUILD_HOST_OVERRIDE', True)
> +
> +    if schroot_dir_override:
> +        d.setVar('SCHROOT_DIR', schroot_dir_override)
> +
> +    if sbuild_build_override:
> +        d.setVar('SBUILD_BUILD', sbuild_build_override)
> +    else:
> +        d.setVar('SBUILD_BUILD', d.getVar('BUILD_HOST_ARCH', True))
> +
> +    if sbuild_host_override:
> +        d.setVar('SBUILD_HOST', sbuild_host_override)
> +    else:
> +        d.setVar('SBUILD_HOST', d.getVar('PACKAGE_ARCH', True))
> +
>      bb.build.exec_func('schroot_create_configs', d)
>      try:
>          bb.build.exec_func("dpkg_runbuild", d)
> diff --git a/meta/classes/dpkg.bbclass b/meta/classes/dpkg.bbclass
> index c596adbf..7d659741 100644
> --- a/meta/classes/dpkg.bbclass
> +++ b/meta/classes/dpkg.bbclass
> @@ -102,7 +102,7 @@ dpkg_runbuild() {
>      DSC_FILE=$(find ${WORKDIR} -name "${DEB_SOURCE_NAME}*.dsc" -print)
>  
>      sbuild -A -n -c ${SBUILD_CHROOT} --extra-repository="${ISAR_APT_REPO}" \
> -        --host=${PACKAGE_ARCH} --build=${BUILD_HOST_ARCH} ${profiles} \
> +        --host=${SBUILD_HOST} --build=${SBUILD_BUILD} ${profiles} \
>          --no-run-lintian --no-run-piuparts --no-run-autopkgtest --resolve-alternatives \
>          --bd-uninstallable-explainer=apt \
>          --no-apt-update \
Koch, Stefan Aug. 16, 2023, 2:27 p.m. UTC | #2
On Wed, 2023-08-16 at 15:55 +0200, Jan Kiszka wrote:
> On 16.08.23 14:14, Koch, Stefan (DI PA DCP R&D 3) wrote:
> > This functionality is initially used for custom linux builds using
> > the
> > "-compat" and "-native" multiarch bitbake targets to run additional
> > target or host specific builds for kbuild scripts and tools.
> 
> But why does the kernel need these extra params? Why wouldn't it be
> enough to add arch-specific profile settings for that package so that
> linux-headers-mykernel-native will compile the kernel only for the
> native headers and tools?
> 

Given a image for a arm64 target cross-built on a amd64 host:



- "bitbake linux" generates with the kbuild-patches:
linux-headers_arm64.deb
linux-image_arm64.deb
linux-kbuild-cross_arm64.deb e. g. containing scripts/fixdep as amd64

=> move to -cross to indicate ARCH mismatch

*Without* the kbuild-patches there are only 
linux-headers_arm64.deb e. g. containing scripts/fixdep as amd64 (!!)
linux-image_arm64.deb

=> *Existing* limitation that ARCH does not match



- "bitbake linux-kbuild-compat" generates (forcing non-cross QEMU
build):
linux-kbuild_arm64.deb e. g. containing scripts/fixdep as arm64

=> scripts utilities can *not* compiled in a cross way
=> this enforces the SBUILD_DIR override to force non-cross QEMU

Maybe, unsetting ISAR_CROSS_COMPILE for the -compat target makes the
SBUILD_DIR override needless. It has to be ensured, that no cross-
compile is used.

What do you think?



- "bitbake linux-native" generates:
linux-kbuild_amd64.deb e. g. containing scripts/fixdep as amd64

=> Optional, only for completeness to have a package matching the
correct ARCH

> Same question for patch 2, in fact. I'm still missing the big
> picture.
> 
> Jan
> 
> > 
> > Signed-off-by: Stefan Koch <stefan-koch@siemens.com>
> > ---
> >  meta/classes/dpkg-base.bbclass | 19 ++++++++++++++++++-
> >  meta/classes/dpkg.bbclass      |  2 +-
> >  2 files changed, 19 insertions(+), 2 deletions(-)
> > 
> > diff --git a/meta/classes/dpkg-base.bbclass b/meta/classes/dpkg-
> > base.bbclass
> > index 7b02f378..eaeb0e8b 100644
> > --- a/meta/classes/dpkg-base.bbclass
> > +++ b/meta/classes/dpkg-base.bbclass
> > @@ -208,7 +208,7 @@ dpkg_runbuild() {
> >  
> >  def isar_deb_build_profiles(d):
> >      deb_build_profiles = d.getVar('DEB_BUILD_PROFILES')
> > -    if d.getVar('ISAR_CROSS_COMPILE') == "1":
> > +    if d.getVar('ISAR_CROSS_COMPILE') == "1" and
> > d.getVar('ISAR_SKIP_CROSS_PROFILE') != "1":
> >          deb_build_profiles += ' cross'
> >      return deb_build_profiles.strip()
> >  
> > @@ -223,6 +223,23 @@ def isar_export_build_settings(d):
> >      os.environ['DEB_BUILD_PROFILES'] = isar_deb_build_profiles(d)
> >  
> >  python do_dpkg_build() {
> > +    schroot_dir_override = d.getVar('SCHROOT_DIR_OVERRIDE', True)
> > +    sbuild_build_override = d.getVar('SBUILD_BUILD_OVERRIDE',
> > True)
> > +    sbuild_host_override = d.getVar('SBUILD_HOST_OVERRIDE', True)
> > +
> > +    if schroot_dir_override:
> > +        d.setVar('SCHROOT_DIR', schroot_dir_override)
> > +
> > +    if sbuild_build_override:
> > +        d.setVar('SBUILD_BUILD', sbuild_build_override)
> > +    else:
> > +        d.setVar('SBUILD_BUILD', d.getVar('BUILD_HOST_ARCH',
> > True))
> > +
> > +    if sbuild_host_override:
> > +        d.setVar('SBUILD_HOST', sbuild_host_override)
> > +    else:
> > +        d.setVar('SBUILD_HOST', d.getVar('PACKAGE_ARCH', True))
> > +
> >      bb.build.exec_func('schroot_create_configs', d)
> >      try:
> >          bb.build.exec_func("dpkg_runbuild", d)
> > diff --git a/meta/classes/dpkg.bbclass b/meta/classes/dpkg.bbclass
> > index c596adbf..7d659741 100644
> > --- a/meta/classes/dpkg.bbclass
> > +++ b/meta/classes/dpkg.bbclass
> > @@ -102,7 +102,7 @@ dpkg_runbuild() {
> >      DSC_FILE=$(find ${WORKDIR} -name "${DEB_SOURCE_NAME}*.dsc" -
> > print)
> >  
> >      sbuild -A -n -c ${SBUILD_CHROOT} --extra-
> > repository="${ISAR_APT_REPO}" \
> > -        --host=${PACKAGE_ARCH} --build=${BUILD_HOST_ARCH}
> > ${profiles} \
> > +        --host=${SBUILD_HOST} --build=${SBUILD_BUILD} ${profiles}
> > \
> >          --no-run-lintian --no-run-piuparts --no-run-autopkgtest --
> > resolve-alternatives \
> >          --bd-uninstallable-explainer=apt \
> >          --no-apt-update \
>
Jan Kiszka Aug. 16, 2023, 2:32 p.m. UTC | #3
On 16.08.23 16:27, Koch, Stefan (DI PA DCP R&D 3) wrote:
> On Wed, 2023-08-16 at 15:55 +0200, Jan Kiszka wrote:
>> On 16.08.23 14:14, Koch, Stefan (DI PA DCP R&D 3) wrote:
>>> This functionality is initially used for custom linux builds using
>>> the
>>> "-compat" and "-native" multiarch bitbake targets to run additional
>>> target or host specific builds for kbuild scripts and tools.
>>
>> But why does the kernel need these extra params? Why wouldn't it be
>> enough to add arch-specific profile settings for that package so that
>> linux-headers-mykernel-native will compile the kernel only for the
>> native headers and tools?
>>
> 
> Given a image for a arm64 target cross-built on a amd64 host:
> 
> 
> 
> - "bitbake linux" generates with the kbuild-patches:
> linux-headers_arm64.deb
> linux-image_arm64.deb
> linux-kbuild-cross_arm64.deb e. g. containing scripts/fixdep as amd64
> 
> => move to -cross to indicate ARCH mismatch
> 
> *Without* the kbuild-patches there are only 
> linux-headers_arm64.deb e. g. containing scripts/fixdep as amd64 (!!)
> linux-image_arm64.deb
> 
> => *Existing* limitation that ARCH does not match
> 
> 
> 
> - "bitbake linux-kbuild-compat" generates (forcing non-cross QEMU
> build):
> linux-kbuild_arm64.deb e. g. containing scripts/fixdep as arm64
> 
> => scripts utilities can *not* compiled in a cross way
> => this enforces the SBUILD_DIR override to force non-cross QEMU
> 
> Maybe, unsetting ISAR_CROSS_COMPILE for the -compat target makes the
> SBUILD_DIR override needless. It has to be ensured, that no cross-
> compile is used.
> 
> What do you think?
> 
> 
> 
> - "bitbake linux-native" generates:
> linux-kbuild_amd64.deb e. g. containing scripts/fixdep as amd64
> 
> => Optional, only for completeness to have a package matching the
> correct ARCH
> 

I still need to fully wrap around this, but I'm wondering if we are here
really addressing an issue of the sbuild machinery in Isar or rather an
issue of the kernel build recipe that should better be resolved there.

Maybe you can demonstrate the issue also with a simpler package than the
kernel?

Jan
Koch, Stefan Aug. 17, 2023, 12:25 p.m. UTC | #4
On Wed, 2023-08-16 at 16:32 +0200, Jan Kiszka wrote:
> On 16.08.23 16:27, Koch, Stefan (DI PA DCP R&D 3) wrote:
> > On Wed, 2023-08-16 at 15:55 +0200, Jan Kiszka wrote:
> > > On 16.08.23 14:14, Koch, Stefan (DI PA DCP R&D 3) wrote:
> > > > This functionality is initially used for custom linux builds
> > > > using
> > > > the
> > > > "-compat" and "-native" multiarch bitbake targets to run
> > > > additional
> > > > target or host specific builds for kbuild scripts and tools.
> > > 
> > > But why does the kernel need these extra params? Why wouldn't it
> > > be
> > > enough to add arch-specific profile settings for that package so
> > > that
> > > linux-headers-mykernel-native will compile the kernel only for
> > > the
> > > native headers and tools?
> > > 
> > 
> > Given a image for a arm64 target cross-built on a amd64 host:
> > 
> > 
> > 
> > - "bitbake linux" generates with the kbuild-patches:
> > linux-headers_arm64.deb
> > linux-image_arm64.deb
> > linux-kbuild-cross_arm64.deb e. g. containing scripts/fixdep as
> > amd64
> > 
> > => move to -cross to indicate ARCH mismatch
> > 
> > *Without* the kbuild-patches there are only 
> > linux-headers_arm64.deb e. g. containing scripts/fixdep as amd64
> > (!!)
> > linux-image_arm64.deb
> > 
> > => *Existing* limitation that ARCH does not match
> > 
> > 
> > 
> > - "bitbake linux-kbuild-compat" generates (forcing non-cross QEMU
> > build):
> > linux-kbuild_arm64.deb e. g. containing scripts/fixdep as arm64
> > 
> > => scripts utilities can *not* compiled in a cross way
> > => this enforces the SBUILD_DIR override to force non-cross QEMU
> > 
> > Maybe, unsetting ISAR_CROSS_COMPILE for the -compat target makes
> > the
> > SBUILD_DIR override needless. It has to be ensured, that no cross-
> > compile is used.
> > 
> > What do you think?
> > 
> > 
> > 
> > - "bitbake linux-native" generates:
> > linux-kbuild_amd64.deb e. g. containing scripts/fixdep as amd64
> > 
> > => Optional, only for completeness to have a package matching the
> > correct ARCH
> > 
> 
> I still need to fully wrap around this, but I'm wondering if we are
> here
> really addressing an issue of the sbuild machinery in Isar or rather
> an
> issue of the kernel build recipe that should better be resolved
> there.

I have found a solution by setting ISAR_CROSS_COMPILE = 0 in -compat
case. This eliminates patches 2 and 3.

I'll finish and test the patches again, and resubmit a new patchset.

> 
> Maybe you can demonstrate the issue also with a simpler package than
> the
> kernel?
> 
> Jan
>

Patch

diff --git a/meta/classes/dpkg-base.bbclass b/meta/classes/dpkg-base.bbclass
index 7b02f378..eaeb0e8b 100644
--- a/meta/classes/dpkg-base.bbclass
+++ b/meta/classes/dpkg-base.bbclass
@@ -208,7 +208,7 @@  dpkg_runbuild() {
 
 def isar_deb_build_profiles(d):
     deb_build_profiles = d.getVar('DEB_BUILD_PROFILES')
-    if d.getVar('ISAR_CROSS_COMPILE') == "1":
+    if d.getVar('ISAR_CROSS_COMPILE') == "1" and d.getVar('ISAR_SKIP_CROSS_PROFILE') != "1":
         deb_build_profiles += ' cross'
     return deb_build_profiles.strip()
 
@@ -223,6 +223,23 @@  def isar_export_build_settings(d):
     os.environ['DEB_BUILD_PROFILES'] = isar_deb_build_profiles(d)
 
 python do_dpkg_build() {
+    schroot_dir_override = d.getVar('SCHROOT_DIR_OVERRIDE', True)
+    sbuild_build_override = d.getVar('SBUILD_BUILD_OVERRIDE', True)
+    sbuild_host_override = d.getVar('SBUILD_HOST_OVERRIDE', True)
+
+    if schroot_dir_override:
+        d.setVar('SCHROOT_DIR', schroot_dir_override)
+
+    if sbuild_build_override:
+        d.setVar('SBUILD_BUILD', sbuild_build_override)
+    else:
+        d.setVar('SBUILD_BUILD', d.getVar('BUILD_HOST_ARCH', True))
+
+    if sbuild_host_override:
+        d.setVar('SBUILD_HOST', sbuild_host_override)
+    else:
+        d.setVar('SBUILD_HOST', d.getVar('PACKAGE_ARCH', True))
+
     bb.build.exec_func('schroot_create_configs', d)
     try:
         bb.build.exec_func("dpkg_runbuild", d)
diff --git a/meta/classes/dpkg.bbclass b/meta/classes/dpkg.bbclass
index c596adbf..7d659741 100644
--- a/meta/classes/dpkg.bbclass
+++ b/meta/classes/dpkg.bbclass
@@ -102,7 +102,7 @@  dpkg_runbuild() {
     DSC_FILE=$(find ${WORKDIR} -name "${DEB_SOURCE_NAME}*.dsc" -print)
 
     sbuild -A -n -c ${SBUILD_CHROOT} --extra-repository="${ISAR_APT_REPO}" \
-        --host=${PACKAGE_ARCH} --build=${BUILD_HOST_ARCH} ${profiles} \
+        --host=${SBUILD_HOST} --build=${SBUILD_BUILD} ${profiles} \
         --no-run-lintian --no-run-piuparts --no-run-autopkgtest --resolve-alternatives \
         --bd-uninstallable-explainer=apt \
         --no-apt-update \