From 26957a90e9165f0eb22684e66e6805072e118682 Mon Sep 17 00:00:00 2001
From: Ben Morrice <ben.morrice@cern.ch>
Date: Jan 13 2025 08:28:22 +0000
Subject: Fix (?) do_multilib


---

diff --git a/builder/kojid b/builder/kojid
index 672391b..4821c73 100755
--- a/builder/kojid
+++ b/builder/kojid
@@ -6429,6 +6429,7 @@ class createDistRepoTask(BaseTaskHandler):
         dnfbase = dnf.Base()
         mlm = multilib.DevelMultilibMethod(ml_conf)
         fs_missing = set()
+        ml_packages = {}
         for bnp in self.kojipkgs:
             rpminfo = self.kojipkgs[bnp]
             ppath = rpminfo['_pkgpath']
@@ -6437,7 +6438,7 @@ class createDistRepoTask(BaseTaskHandler):
             if mlm.select(po):
                 # we need a multilib package to be included
                 ml_bnp = bnp.replace(arch, self.archmap[arch])
-                ml_path = os.path.join(mldir, ml_bnp[0].lower(), ml_bnp)
+                ml_path = os.path.join(mldir, 'Packages', ml_bnp[0].lower(), ml_bnp)
                 # ^ XXX - should actually generate this
                 if ml_bnp not in ml_pkgs:
                     # not in our multilib repo
@@ -6445,101 +6446,13 @@ class createDistRepoTask(BaseTaskHandler):
                     fs_missing.add(ml_path)
                     # we defer failure so can report all the missing deps
                     continue
-                ml_true.add(ml_path)
-
-        # step 2: set up architectures for dnf configuration
-        self.logger.info("Resolving multilib for %s using method devel" % arch)
-        dnfdir = os.path.join(self.workdir, 'dnf')
-        # TODO: unwind this arch mess
-        archlist = (arch, 'noarch')
-        transaction_arch = arch
-        archlist = archlist + self.compat[self.biarch[arch]]
-        best_compat = self.compat[self.biarch[arch]][0]
-        if koji.arch.archDifference(best_compat, arch) > 0:
-            transaction_arch = best_compat
-        dnfconfig = """
-[main]
-debuglevel=2
-#pkgpolicy=newest
-#exactarch=1
-gpgcheck=0
-#reposdir=/dev/null
-#cachedir=/dnfcache
-installroot=%s
-#logfile=/dnf.log
-
-[koji-%s]
-name=koji multilib task
-baseurl=file://%s
-enabled=1
-
-""" % (dnfdir, self.id, mldir)
-        os.makedirs(os.path.join(dnfdir, "dnfcache"))
-        os.makedirs(os.path.join(dnfdir, 'var/lib/rpm'))
-
-        # step 3: proceed with dnf config and set up
-        yconfig_path = os.path.join(dnfdir, 'dnf.conf-koji-%s' % arch)
-        with koji._open_text_file(yconfig_path, 'wt') as f:
-            f.write(dnfconfig)
-        self.session.uploadWrapper(yconfig_path, self.uploadpath,
-                                   os.path.basename(yconfig_path))
-        conf = dnf.conf.Conf()
-        conf.reposdir = []  # don't use system repos at all
-        conf.read(yconfig_path)
-        dnfbase = dnf.Base(conf)
-        if hasattr(koji.arch, 'ArchStorage'):
-            dnfbase.conf.arch = transaction_arch
-        else:
-            koji.arch.canonArch = transaction_arch
-        dnfbase.read_all_repos()
-        dnfbase.fill_sack(load_system_repo=False, load_available_repos=True)
-        for pkg in ml_true:
-            dnfbase.install(pkg)
-
-        # step 4: execute dnf transaction to get dependencies
-        self.logger.info("Resolving dependencies for arch %s" % arch)
-
-        ml_needed = {}
-        try:
-            dnfbase.resolve()
-            self.logger.info('dnf depsolve successfully finished')
-            for po in dnfbase.transaction.install_set:
-                bnp = os.path.basename(po.localPkg())
-                dep_path = os.path.join(mldir, bnp[0].lower(), bnp)
-                ml_needed[dep_path] = po
-                if not os.path.exists(dep_path):
-                    self.logger.error('%s (multilib dep) not on filesystem' % dep_path)
-                    fs_missing.add(dep_path)
-        except dnf.exceptions.DepsolveError:
-            self.logger.error('dnf depsolve was unsuccessful')
-            raise
-
-        if len(fs_missing) > 0:
-            missing_log = os.path.join(self.workdir, 'missing_multilib.log')
-            with koji._open_text_file(missing_log, 'wt') as outfile:
-                outfile.write('The following multilib files were missing:\n')
-                for ml_path in fs_missing:
-                    outfile.write(ml_path + '\n')
-            self.session.uploadWrapper(missing_log, self.uploadpath)
-            raise koji.GenericError('multilib packages missing. '
-                                    'See missing_multilib.log')
-
-        # step 5: update kojipkgs
-        for dep_path in ml_needed:
-            tspkg = ml_needed[dep_path]
-            bnp = os.path.basename(dep_path)
-            if bnp in self.kojipkgs:
-                # we expect duplication with noarch, but not other arches
-                if tspkg.arch != 'noarch':
-                    self.logger.warning("Multilib duplicate: %s", bnp)
-                continue
-            rpminfo = ml_pkgs[bnp].copy()
-            # fix _pkgpath, which comes from another task and could be wrong
-            # for us
-            # TODO: would be better if we could use the proper path here
-            rpminfo['_pkgpath'] = dep_path
-            rpminfo['_multilib'] = True
-            self.kojipkgs[bnp] = rpminfo
+                self.logger.info(f'{ml_path} should be added as a multilib rpm')
+                ml_rpm = ml_pkgs[bnp.replace("x86_64", "i686")].copy()
+                ml_bnp = os.path.basename(ml_path)
+                ml_rpm['_pkgpath'] = ml_path
+                ml_rpm['_multilib'] = True
+                ml_packages[ml_bnp] = ml_rpm
+        self.kojipkgs.update(ml_packages)
 
     def pick_key(self, keys, avail_keys):
         best = None

