Skip to content

Commit

Permalink
Fix multilib builds with --use-bootstrap-image
Browse files Browse the repository at this point in the history
When building an i?86 package (with i?86 chroot config) on an x86_64
host, we report to kernel that we work in 32 bit mode (using the
'/bin/setarch'-like condPersonality() call).  This is completely OK and
desired for the build (target) chroot, but not for the bootstrap chroot
which is generated from a container image.

The container image has always a host-native arch (unless there's a
configuration error).  So the pre-installed packages are x86_64.
When we want to install additional packages there (typically to provide
the 'dnf builddep' command in bootstrap), and we do that using the
package manager already installed in bootstrap image (no package manager
on host is required!), the package manager is confused by the 32-bit
mode and resolves '$basearch' into 'i386' instead of 'x86_64'.  So we
need to switch back to 64-bit mode (in a subprocess, preexec_fn).

Note that a late call to `os.uname()` would be confused by the
condPersonality() call.  So newly we rather remember the 'host_arch' at
the beginning in config_opts, before the initial call to
condPersonality().

Fixes: #1110
  • Loading branch information
praiskup committed Jul 28, 2023
1 parent 13d26bd commit bcb4841
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mock/py/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def check_arch_combination(target_arch, config_opts):
legal = config_opts['legal_host_arches']
except KeyError:
return
host_arch = os.uname()[-1]
host_arch = config_opts['host_arch']
if (host_arch not in legal) and not config_opts['forcearch']:
log.info("Unable to build arch %s natively on arch %s. Setting forcearch to use software emulation.",
target_arch, host_arch)
Expand Down
1 change: 1 addition & 0 deletions mock/py/mockbuild/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def setup_default_config_opts():
config_opts['chroothome'] = '/builddir'
config_opts['log_config_file'] = 'logging.ini'
config_opts['rpmbuild_timeout'] = 0
config_opts['host_arch'] = os.uname()[-1]
config_opts['chrootuid'] = os.getuid()
try:
config_opts['chrootgid'] = grp.getgrnam("mock")[2]
Expand Down
11 changes: 10 additions & 1 deletion mock/py/mockbuild/package_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,18 @@ def _execute_mounted(self, *args, **kwargs):
# either it does not support --installroot (microdnf) or
# it is bootstrap image made by container with incomaptible dnf/rpm
if not self.support_installroot or self.is_bootstrap_image:

personality = kwargs.pop("personality", None)
if self.is_bootstrap_image:
# Multilib fix - the in-bootstrap package manager needs
# to know what to resolve $buildarch, wither the 32 or
# 64-bit variant. But with bootstrap image, we always
# use the image of the hosts native architecture!
personality = self.config['host_arch']

out = util.do(invocation, env=env,
chrootPath=self.buildroot.make_chroot_path(),
**kwargs)
personality=personality, **kwargs)
elif self.bootstrap_buildroot is None:
out = util.do(invocation, env=env,
**kwargs)
Expand Down

0 comments on commit bcb4841

Please sign in to comment.