Skip to content

Commit 951ec75

Browse files
FrostyXpraiskup
authored andcommitted
Make sure to install BuildRequires defined by macros
Fix #1652
1 parent a06db88 commit 951ec75

File tree

4 files changed

+37
-12
lines changed

4 files changed

+37
-12
lines changed

mock/docs/site-defaults.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@
112112
# config_opts['dynamic_buildrequires'] = True
113113
# config_opts['dynamic_buildrequires_max_loops'] = 10
114114

115+
# BuildRequires are installed in a loop until there is nothing left to install.
116+
# This is useful for example when BuildRequires are generated by a macro,
117+
# which is provided by another dependency. This option limits the maximum number
118+
# of loops that are allowed to happen.
119+
# config_opts['static_buildrequires_max_loops'] = 10
120+
115121
# Allows use of external buildrequires. I.e. when dependencies are installed
116122
# from PyPI, Rubygems...
117123
# config_opts['external_buildrequires'] = False

mock/py/mockbuild/backend.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -281,21 +281,30 @@ def build(self, srpm, timeout, check=True, spec=None):
281281
spec = self.get_specfile_name(srpm)
282282
spec_path = os.path.join(self.buildroot.builddir, 'SPECS', spec)
283283

284-
rebuilt_srpm = self.rebuild_installed_srpm(spec_path, timeout)
284+
# We need to rebuild the SRPM and install dependencies multiple
285+
# times so that cases like #1652 are covered
286+
max_loops = int(self.config.get('static_buildrequires_max_loops'))
287+
for _ in range(max_loops):
288+
packages_before = self.buildroot.all_chroot_packages()
289+
rebuilt_srpm = self.rebuild_installed_srpm(spec_path, timeout)
285290

286-
# Check if we will have dynamic BuildRequires, but do not allow it
287-
hdr = next(util.yieldSrpmHeaders((rebuilt_srpm,)))
288-
# pylint: disable=no-member
289-
requires = {text._to_text(req) for req in hdr[rpm.RPMTAG_REQUIRES]}
290-
dynamic_buildreqs = 'rpmlib(DynamicBuildRequires)' in requires
291+
# Check if we will have dynamic BuildRequires, but do not allow it
292+
hdr = next(util.yieldSrpmHeaders((rebuilt_srpm,)))
293+
# pylint: disable=no-member
294+
requires = {text._to_text(req) for req in hdr[rpm.RPMTAG_REQUIRES]}
295+
dynamic_buildreqs = 'rpmlib(DynamicBuildRequires)' in requires
296+
297+
if dynamic_buildreqs and not self.config.get('dynamic_buildrequires'):
298+
raise Error('DynamicBuildRequires are found but support is disabled.'
299+
' See "dynamic_buildrequires" in config_opts.')
291300

292-
if dynamic_buildreqs and not self.config.get('dynamic_buildrequires'):
293-
raise Error('DynamicBuildRequires are found but support is disabled.'
294-
' See "dynamic_buildrequires" in config_opts.')
301+
self.install_external(requires)
302+
# Install the (static) BuildRequires
303+
self.installSrpmDeps(rebuilt_srpm)
304+
packages_after = self.buildroot.all_chroot_packages()
305+
if packages_after == packages_before:
306+
break
295307

296-
self.install_external(requires)
297-
# install the (static) BuildRequires
298-
self.installSrpmDeps(rebuilt_srpm)
299308
self.state.finish(buildsetup)
300309
buildsetup_finished = True
301310

mock/py/mockbuild/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ def setup_default_config_opts():
348348
config_opts['dynamic_buildrequires'] = True
349349
config_opts['dynamic_buildrequires_max_loops'] = 10
350350

351+
config_opts['static_buildrequires_max_loops'] = 10
352+
351353
config_opts['external_buildrequires'] = False
352354

353355
config_opts['dev_loop_count'] = 12
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Make sure to install `BuildRequires` defined by macros. For example:
2+
3+
```
4+
BuildRequires: selinux-policy
5+
%{?selinux_requires}
6+
```
7+
8+
This now properly installs the `selinux-policy-devel` package.

0 commit comments

Comments
 (0)