Skip to content

Commit

Permalink
DynamicBuildrequires: Detect when no new packages were installed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hroncok authored and xsuchy committed Jul 3, 2019
1 parent 331dd75 commit ba5e4ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mock/py/mockbuild/backend.py
Expand Up @@ -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,
Expand All @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions mock/py/mockbuild/buildroot.py
Expand Up @@ -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')
Expand Down

0 comments on commit ba5e4ef

Please sign in to comment.