From ba5e4ef2d16d389383207430019f292457eb7f02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 2 Jul 2019 18:24:57 +0200 Subject: [PATCH] DynamicBuildrequires: Detect when no new packages were installed Prior to this change, the DynamicBuildrequires loop never ended. This commit fixes it in 2 ways: 1. It now actually stops when max_loops (10) happened. 2. It also stops when the package manager hasn't installed anything. Both is consistent with the comment present in the previously broken code. The detection of 2. is based on packages returned by `rpm -qa` before and after the installation. If they haven't changed, the package manager hasn't installed anything. --- mock/py/mockbuild/backend.py | 6 +++++- mock/py/mockbuild/buildroot.py | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/mock/py/mockbuild/backend.py b/mock/py/mockbuild/backend.py index 5f9a986ad..1c86504ed 100644 --- a/mock/py/mockbuild/backend.py +++ b/mock/py/mockbuild/backend.py @@ -721,11 +721,12 @@ def get_command(mode): max_loops = int(self.config.get('dynamic_buildrequires_max_loops')) success = False if dynamic_buildrequires and self.config.get('dynamic_buildrequires'): - while not success or max_loops > 0: + while not success and max_loops > 0: # run rpmbuild+installSrpmDeps until # * it fails # * installSrpmDeps does nothing # * or we run out of dynamic_buildrequires_max_loops tries + packages_before = self.buildroot.all_chroot_packages() try: self.buildroot.doChroot(get_command(['-br']), shell=False, logger=self.buildroot.build_log, timeout=timeout, @@ -743,6 +744,9 @@ def get_command(mode): self.buildroot.root_log.info("Going to install missing buildrequires") buildreqs = glob.glob(bd_out + '/SRPMS/*.buildreqs.nosrc.rpm') self.installSrpmDeps(*buildreqs) + packages_after = self.buildroot.all_chroot_packages() + if packages_after == packages_before: + success = True for f_buildreqs in buildreqs: os.remove(f_buildreqs) if not sc: diff --git a/mock/py/mockbuild/buildroot.py b/mock/py/mockbuild/buildroot.py index 0f4104db2..b55e54b07 100644 --- a/mock/py/mockbuild/buildroot.py +++ b/mock/py/mockbuild/buildroot.py @@ -207,6 +207,12 @@ def doChroot(self, command, nosync=False, *args, **kargs): self.uid_manager.restorePrivs() return result + def all_chroot_packages(self): + """package set, result of rpm -qa in the buildroot""" + out, _ = self.doChroot([self.config['rpm_command'], "-qa"], + returnOutput=True, printOutput=False, shell=False) + return set(out.splitlines()) + @traceLog() def _copy_config(self, filename): etcdir = self.make_chroot_path('etc')