Skip to content

Commit

Permalink
A new 'repo_arch' option
Browse files Browse the repository at this point in the history
This option is used for the cases when $basearch DNF native variable
doesn't work as expected in URLs.

On top of this, Mock uses `repo_arch` for `man 2 personality` decisions
for the bootstrap chroot installation (supposed to be native).

Closes: rpm-software-management#1317
Fixes: rpm-software-management#1304
  • Loading branch information
praiskup committed Feb 9, 2024
1 parent f7f0ed6 commit 3d2c93f
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 38 deletions.
34 changes: 18 additions & 16 deletions mock-core-configs/etc/mock/templates/mageia-branched.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ config_opts['bootstrap_image'] = 'docker.io/library/mageia:{{ releasever }}'
config_opts['use_bootstrap_image'] = False
config_opts['description'] = 'Mageia {{ releasever }}'

config_opts["repo_arch_map"]["i386"] = "i386"

config_opts['dnf.conf'] = """
[main]
keepcache=1
Expand All @@ -29,43 +31,43 @@ user_agent={{ user_agent }}
# repos

[mageia]
name=Mageia $releasever - {{ target_arch }}
#baseurl=http://mirrors.kernel.org/mageia/distrib/$releasever/{{ target_arch }}/media/core/release/
#metalink=https://mirrors.mageia.org/metalink?distrib=mageia-$releasever&arch={{ target_arch }}@&section=core&repo=release
mirrorlist=https://www.mageia.org/mirrorlist/?release=$releasever&arch={{ target_arch }}&section=core&repo=release
name=Mageia $releasever - {{ repo_arch }}
#baseurl=http://mirrors.kernel.org/mageia/distrib/$releasever/{{ repo_arch }}/media/core/release/
#metalink=https://mirrors.mageia.org/metalink?distrib=mageia-$releasever&arch={{ repo_arch }}@&section=core&repo=release
mirrorlist=https://www.mageia.org/mirrorlist/?release=$releasever&arch={{ repo_arch }}&section=core&repo=release
fastestmirror=1
gpgcheck=1
gpgkey=file:///usr/share/distribution-gpg-keys/mageia/RPM-GPG-KEY-Mageia
enabled=1
skip_if_unavailable=False

[updates]
name=Mageia $releasever - {{ target_arch }} - Updates
#baseurl=http://mirrors.kernel.org/mageia/distrib/$releasever/{{ target_arch }}/media/core/updates/
#metalink=https://mirrors.mageia.org/metalink?distrib=mageia-$releasever&arch={{ target_arch }}@&section=core&repo=updates
mirrorlist=https://www.mageia.org/mirrorlist/?release=$releasever&arch={{ target_arch }}&section=core&repo=updates
name=Mageia $releasever - {{ repo_arch }} - Updates
#baseurl=http://mirrors.kernel.org/mageia/distrib/$releasever/{{ repo_arch }}/media/core/updates/
#metalink=https://mirrors.mageia.org/metalink?distrib=mageia-$releasever&arch={{ repo_arch }}@&section=core&repo=updates
mirrorlist=https://www.mageia.org/mirrorlist/?release=$releasever&arch={{ repo_arch }}&section=core&repo=updates
fastestmirror=1
gpgcheck=1
gpgkey=file:///usr/share/distribution-gpg-keys/mageia/RPM-GPG-KEY-Mageia
enabled=1
skip_if_unavailable=False

[mageia-debuginfo]
name=Mageia $releasever - {{ target_arch }} - Debug
#baseurl=http://mirrors.kernel.org/mageia/distrib/$releasever/{{ target_arch }}/media/debug/core/release/
#metalink=https://mirrors.mageia.org/metalink?distrib=mageia-$releasever&arch={{ target_arch }}@&section=core&repo=release&debug=true
mirrorlist=https://www.mageia.org/mirrorlist/?release=$releasever&arch={{ target_arch }}&section=core&repo=release&debug=1
name=Mageia $releasever - {{ repo_arch }} - Debug
#baseurl=http://mirrors.kernel.org/mageia/distrib/$releasever/{{ repo_arch }}/media/debug/core/release/
#metalink=https://mirrors.mageia.org/metalink?distrib=mageia-$releasever&arch={{ repo_arch }}@&section=core&repo=release&debug=true
mirrorlist=https://www.mageia.org/mirrorlist/?release=$releasever&arch={{ repo_arch }}&section=core&repo=release&debug=1
fastestmirror=1
gpgcheck=1
gpgkey=file:///usr/share/distribution-gpg-keys/mageia/RPM-GPG-KEY-Mageia
enabled=0
skip_if_unavailable=False

[updates-debuginfo]
name=Mageia $releasever - {{ target_arch }} - Updates - Debug
#baseurl=http://mirrors.kernel.org/mageia/distrib/$releasever/{{ target_arch }}/media/debug/core/updates/
#metalink=https://mirrors.mageia.org/metalink?distrib=mageia-$releasever&arch={{ target_arch }}@&section=core&repo=updates&debug=true
mirrorlist=https://www.mageia.org/mirrorlist/?release=$releasever&arch={{ target_arch }}&section=core&repo=updates&debug=1
name=Mageia $releasever - {{ repo_arch }} - Updates - Debug
#baseurl=http://mirrors.kernel.org/mageia/distrib/$releasever/{{ repo_arch }}/media/debug/core/updates/
#metalink=https://mirrors.mageia.org/metalink?distrib=mageia-$releasever&arch={{ repo_arch }}@&section=core&repo=updates&debug=true
mirrorlist=https://www.mageia.org/mirrorlist/?release=$releasever&arch={{ repo_arch }}&section=core&repo=updates&debug=1
fastestmirror=1
gpgcheck=1
gpgkey=file:///usr/share/distribution-gpg-keys/mageia/RPM-GPG-KEY-Mageia
Expand Down
18 changes: 10 additions & 8 deletions mock-core-configs/etc/mock/templates/mageia-cauldron.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ config_opts['bootstrap_image'] = 'docker.io/library/mageia:cauldron'
config_opts['use_bootstrap_image'] = False
config_opts['description'] = 'Mageia Cauldron'

config_opts["repo_arch_map"]["i386"] = "i386"

config_opts['dnf.conf'] = """
[main]
keepcache=1
Expand All @@ -30,21 +32,21 @@ user_agent={{ user_agent }}
# repos

[mageia-cauldron]
name=Mageia Cauldron - {{ target_arch }}
#baseurl=http://mirrors.kernel.org/mageia/distrib/cauldron/{{ target_arch }}/media/core/release/
#metalink=https://mirrors.mageia.org/metalink?distrib=cauldron&arch={{ target_arch }}@&section=core&repo=release
mirrorlist=https://www.mageia.org/mirrorlist/?release=cauldron&arch={{ target_arch }}&section=core&repo=release
name=Mageia Cauldron - {{ repo_arch }}
#baseurl=http://mirrors.kernel.org/mageia/distrib/cauldron/{{ repo_arch }}/media/core/release/
#metalink=https://mirrors.mageia.org/metalink?distrib=cauldron&arch={{ repo_arch }}@&section=core&repo=release
mirrorlist=https://www.mageia.org/mirrorlist/?release=cauldron&arch={{ repo_arch }}&section=core&repo=release
fastestmirror=1
gpgcheck=1
gpgkey=file:///usr/share/distribution-gpg-keys/mageia/RPM-GPG-KEY-Mageia
enabled=1
skip_if_unavailable=False

[mageia-cauldron-debuginfo]
name=Mageia Cauldron - {{ target_arch }} - Debug
#baseurl=http://mirrors.kernel.org/mageia/distrib/cauldron/{{ target_arch }}/media/debug/core/release/
#metalink=https://mirrors.mageia.org/metalink?distrib=cauldron&arch={{ target_arch }}@&section=core&repo=release&debug=true
mirrorlist=https://www.mageia.org/mirrorlist/?release=cauldron&arch={{ target_arch }}&section=core&repo=release&debug=1
name=Mageia Cauldron - {{ repo_arch }} - Debug
#baseurl=http://mirrors.kernel.org/mageia/distrib/cauldron/{{ repo_arch }}/media/debug/core/release/
#metalink=https://mirrors.mageia.org/metalink?distrib=cauldron&arch={{ repo_arch }}@&section=core&repo=release&debug=true
mirrorlist=https://www.mageia.org/mirrorlist/?release=cauldron&arch={{ repo_arch }}&section=core&repo=release&debug=1
fastestmirror=1
gpgcheck=1
gpgkey=file:///usr/share/distribution-gpg-keys/mageia/RPM-GPG-KEY-Mageia
Expand Down
4 changes: 4 additions & 0 deletions mock/py/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,10 @@ def main():
# disable updating bootstrap chroot
bootstrap_buildroot_config['update_before_build'] = False

if config_opts["host_arch"] not in config_opts.get("legal_host_arches", []):
exp_arch = config_opts["host_arch"]
bootstrap_buildroot_config['repo_arch'] = config_opts['repo_arch_map'].get(exp_arch, exp_arch)

# disable forcearch in bootstrap, per https://github.com/rpm-software-management/mock/issues/1110
bootstrap_buildroot_config['forcearch'] = None

Expand Down
6 changes: 6 additions & 0 deletions mock/py/mockbuild/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ def setup_default_config_opts():
# dependent on guest OS
config_opts['use_host_resolv'] = False
config_opts['chroot_setup_cmd'] = ('groupinstall', 'buildsys-build')
config_opts['repo_arch'] = None
config_opts['repo_arch_map'] = {}
config_opts['target_arch'] = 'i386'
config_opts['releasever'] = None
config_opts['rpmbuild_arch'] = None # <-- None means set automatically from target_arch
Expand Down Expand Up @@ -432,6 +434,10 @@ def set_config_opts_per_cmdline(config_opts, options, args):
if options.forcearch:
config_opts['forcearch'] = options.forcearch

if not config_opts['repo_arch']:
target = config_opts['target_arch']
config_opts['repo_arch'] = config_opts['repo_arch_map'].get(target, target)

if not options.clean:
config_opts['clean'] = options.clean

Expand Down
22 changes: 8 additions & 14 deletions mock/py/mockbuild/package_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,30 +307,24 @@ def _execute_mounted(self, *args, **kwargs):
try:
# 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, see on an example: The host-native
# 64-bit package manager installed in the bootstrap
# chroot (from image) needs to know how to resolve the
# $basearch variable. It would be confused our previous
# 'condPersonality("i386")' call (switched to 32-bit).
# Switch back to 64-bit mode (only the particular DNF
# sub-process).
personality = self.config['host_arch']
personality = kwargs.pop("personality", None)
if self.buildroot.is_bootstrap and not self.buildroot.config["forcearch"]:
personality = self.buildroot.config["repo_arch"]

if not self.support_installroot or self.is_bootstrap_image:
out = util.do(invocation, env=env,
chrootPath=self.buildroot.make_chroot_path(),
personality=personality, **kwargs)
elif self.bootstrap_buildroot is None:


out = util.do(invocation, env=env,
**kwargs)
personality=personality, **kwargs)
else:
out = util.do(invocation, env=env,
chrootPath=self.bootstrap_buildroot.make_chroot_path(),
nspawn_args=self.bootstrap_buildroot.config['nspawn_args'],
**kwargs)
personality=personality, **kwargs)
error = None
break
except Error as e:
Expand Down
20 changes: 20 additions & 0 deletions mock/tests/test_config_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@ def test_transitive_expand():
config['__jinja_expand'] = True
assert config['c'] == 'test test test test'

@pytest.mark.parametrize('setup', [
# host target bootstrap expected_repo
('x86_64', 'arm7hl', True, 'x86_64'),
('x86_64', 'arm7hl', False, 'armhfp'),
('ppc64le', 'arm7hl', True, 'ppc64le'),
('ppc64le', 'arm7hl', False, 'armhfp'),
])
def test_nested_access(setup):
host, target, bootstrap, result = setup
config = TemplatedDictionary()
config["archmap"] = {"i386": "i686", "arm7hl": "armhfp", "x86_64": "x86_64"}
config["host_arch"] = host
config["target_arch"] = target
config["root"] = "foo-bootstrap" if bootstrap else "foo"
config["repo_arch"] = (
"{% set desired = host_arch if root.endswith('bootstrap') else target_arch %}"
"{{ archmap[desired] if desired in archmap else desired }}"
)
config['__jinja_expand'] = True
assert config['repo_arch'] == result

def test_aliases():
config = TemplatedDictionary(
Expand Down

0 comments on commit 3d2c93f

Please sign in to comment.