From cedaf1ada0629c36eff0bc898d9bac34b190c4d5 Mon Sep 17 00:00:00 2001
From: Pat Riehecky <riehecky@fnal.gov>
Date: May 11 2022 14:12:30 +0000
Subject: [PATCH 1/3] kojid: permit forcing releasever within mock per tag


---

diff --git a/builder/kojid b/builder/kojid
index a202425..951ddef 100755
--- a/builder/kojid
+++ b/builder/kojid
@@ -301,6 +301,8 @@ class BuildRoot(object):
             }
         if 'mock.module_setup_commands' in self.config['extra']:
             opts['module_setup_commands'] = self.config['extra']['mock.module_setup_commands']
+        if 'mock.releasever' in self.config['extra']:
+            opts['releasever'] = self.config['extra']['mock.releasever']
         if self.internal_dev_setup is not None:
             opts['internal_dev_setup'] = bool(self.internal_dev_setup)
         opts['tag_macros'] = {}
diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py
index 4c08506..9318f0b 100644
--- a/cli/koji_cli/commands.py
+++ b/cli/koji_cli/commands.py
@@ -1149,6 +1149,8 @@ def anon_handle_mock_config(goptions, session, args):
         opts['use_bootstrap'] = buildcfg['extra']['mock.use_bootstrap']
     if 'mock.module_setup_commands' in buildcfg['extra']:
         opts['module_setup_commands'] = buildcfg['extra']['mock.module_setup_commands']
+    if 'mock.releasever' in buildcfg['extra']:
+        opts['releasever'] = buildcfg['extra']['mock.releasever']
     opts['tag_macros'] = {}
     for key in buildcfg['extra']:
         if key.startswith('rpm.macro.'):
diff --git a/docs/source/using_the_koji_build_system.rst b/docs/source/using_the_koji_build_system.rst
index 7d8887b..73a3448 100644
--- a/docs/source/using_the_koji_build_system.rst
+++ b/docs/source/using_the_koji_build_system.rst
@@ -393,6 +393,8 @@ environment follows:
 * ``mock.new_chroot`` - 0/1 value. If it is set, ``--new-chroot`` or
   `--old-chroot` option is appended to any mock call. If it is not set,
   mock's default behavior is used.
+* ``mock.releasever`` - When doing cross-compiles it may be necessary
+  to explicitly set the ``releasever`` to be used.
 * ``mock.use_bootstrap`` - 0/1 value. If it is set, ``--bootstrap-chroot``
   is appended to the mock init call.  This tells mock to build in two stages,
   using chroot rpm for creating the build chroot. If it is not set, mock's
diff --git a/koji/__init__.py b/koji/__init__.py
index 348f060..f656564 100644
--- a/koji/__init__.py
+++ b/koji/__init__.py
@@ -1638,6 +1638,8 @@ def genMockConfig(name, arch, managed=False, repoid=None, tag_name=None, **opts)
         config_opts['use_bootstrap'] = bool(opts['use_bootstrap'])
     if 'module_setup_commands' in opts:
         config_opts['module_setup_commands'] = opts['module_setup_commands']
+    if 'releasever' in opts:
+        config_opts['releasever'] = opts['releasever']
 
     # bind_opts are used to mount parts (or all of) /dev if needed.
     # See kojid::LiveCDTask for a look at this option in action.

From 5fd10ab5174ad76b9a22a5a94b24559f66ad4f8e Mon Sep 17 00:00:00 2001
From: Pat Riehecky <riehecky@fnal.gov>
Date: May 11 2022 14:12:30 +0000
Subject: [PATCH 2/3] kojid: permit forcing the target arch within mock per tag


---

diff --git a/builder/kojid b/builder/kojid
index 951ddef..248f1fb 100755
--- a/builder/kojid
+++ b/builder/kojid
@@ -280,6 +280,9 @@ class BuildRoot(object):
         opts['maven_envs'] = self.maven_envs
         opts['bind_opts'] = self.bind_opts
         opts['target_arch'] = self.target_arch
+        if 'mock.forcearch' in self.config['extra']:
+            if bool(self.config['extra']['mock.forcearch']):
+                opts['forcearch'] = self.target_arch
         if 'mock.package_manager' in self.config['extra']:
             opts['package_manager'] = self.config['extra']['mock.package_manager']
         if 'mock.yum.module_hotfixes' in self.config['extra']:
diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py
index 9318f0b..00e515b 100644
--- a/cli/koji_cli/commands.py
+++ b/cli/koji_cli/commands.py
@@ -1136,6 +1136,9 @@ def anon_handle_mock_config(goptions, session, args):
             warn("Tag %s has an empty arch list" % opts['tag_name'])
         elif arch not in buildcfg['arches']:
             warn('%s is not in the list of tag arches' % arch)
+        if 'mock.forcearch' in buildcfg['extra']:
+            if bool(buildcfg['extra']['mock.forcearch']):
+                opts['forcearch'] = options.arch
     if 'mock.package_manager' in buildcfg['extra']:
         opts['package_manager'] = buildcfg['extra']['mock.package_manager']
     if 'mock.yum.module_hotfixes' in buildcfg['extra']:
diff --git a/docs/source/using_the_koji_build_system.rst b/docs/source/using_the_koji_build_system.rst
index 73a3448..b6b43d1 100644
--- a/docs/source/using_the_koji_build_system.rst
+++ b/docs/source/using_the_koji_build_system.rst
@@ -433,6 +433,8 @@ environment follows:
 * ``mock.module_setup_commands`` - commands for configuring the modules active
   in a buildroot. Available in `mock 2.4
   <https://github.com/rpm-software-management/mock/wiki/Release-Notes-2.4>`__.
+* ``mock.forcearch`` - 0/1 value. If true mock will set the ``forcearch``
+  config option to match the target arch of each buildroot.
 * ``mock.yum.best`` - 0/1 value. If set yum/dnf will use highest available rpm
   version (see man yum.conf)
 * ``mock.yum.module_hotfixes`` - 0/1 value. If set, yum/dnf will use packages
diff --git a/koji/__init__.py b/koji/__init__.py
index f656564..d12ecb5 100644
--- a/koji/__init__.py
+++ b/koji/__init__.py
@@ -1629,6 +1629,8 @@ def genMockConfig(name, arch, managed=False, repoid=None, tag_name=None, **opts)
         # turn off warning for yum being used in place of dnf
         'dnf_warning': False,
     }
+    if 'forcearch' in opts:
+        config_opts['forcearch'] = opts['forcearch']
     if opts.get('package_manager'):
         config_opts['package_manager'] = opts['package_manager']
     if opts.get('bootstrap_image'):

From 6bfe6c3f4bdb39eb5262d7381b6dfc2df4e5be23 Mon Sep 17 00:00:00 2001
From: Tomas Kopecek <tkopecek@redhat.com>
Date: May 11 2022 14:23:40 +0000
Subject: [PATCH 3/3] fix arch processing


Related: https://pagure.io/koji/issue/3304

---

diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py
index 00e515b..42213c3 100644
--- a/cli/koji_cli/commands.py
+++ b/cli/koji_cli/commands.py
@@ -1131,14 +1131,14 @@ def anon_handle_mock_config(goptions, session, args):
     if opts['repoid'] != 'latest':
         event = session.repoInfo(opts['repoid'])['create_event']
     buildcfg = session.getBuildConfig(opts['tag_name'], event=event)
-    if options.arch:
+    if arch:
         if not buildcfg['arches']:
             warn("Tag %s has an empty arch list" % opts['tag_name'])
         elif arch not in buildcfg['arches']:
             warn('%s is not in the list of tag arches' % arch)
         if 'mock.forcearch' in buildcfg['extra']:
             if bool(buildcfg['extra']['mock.forcearch']):
-                opts['forcearch'] = options.arch
+                opts['forcearch'] = arch
     if 'mock.package_manager' in buildcfg['extra']:
         opts['package_manager'] = buildcfg['extra']['mock.package_manager']
     if 'mock.yum.module_hotfixes' in buildcfg['extra']:

