Skip to content

Commit

Permalink
New mode --calculate-build-dependencies
Browse files Browse the repository at this point in the history
When specified, the ".buildreqs.nosrc.rpm" file is provided in the
results directory.

Fixes: #1358
  • Loading branch information
praiskup committed Jun 26, 2024
1 parent c6fc189 commit 611c60c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
8 changes: 8 additions & 0 deletions mock/py/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ def command_parse():
parser.add_option("--rebuild", action="store_const", const="rebuild",
dest="mode", default='__default__',
help="rebuild the specified SRPM(s)")
parser.add_option("--calculate-build-dependencies", action="store_const",
const="calculatedeps", dest="mode",
help="Resolve static and dynamic build dependencies")
parser.add_option("--chain", action="store_const", const="chain",
dest="mode",
help="build multiple RPMs in chain loop")
Expand Down Expand Up @@ -402,6 +405,11 @@ def command_parse():
else:
options.mode = 'rebuild'

options.calculatedeps = None
if options.mode == "calculatedeps":
options.mode = "rebuild"
options.calculatedeps = True

# Optparse.parse_args() eats '--' argument, while argparse doesn't. Do it manually.
if args and args[0] == '--':
args = args[1:]
Expand Down
24 changes: 15 additions & 9 deletions mock/py/mockbuild/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ def build(self, srpm, timeout, check=True, spec=None):
' See "dynamic_buildrequires" in config_opts.')

self.install_external(requires)
# install the (static) BuildRequires
self.installSrpmDeps(rebuilt_srpm)
self.state.finish(buildsetup)
buildsetup_finished = True
Expand Down Expand Up @@ -720,6 +721,7 @@ def rebuild_package(self, spec_path, timeout, check, dynamic_buildrequires):
# --nodeps because rpm in the root may not be able to read rpmdb
# created by rpm that created it (outside of chroot)
check_opt = []
depsonly = self.config["calculatedeps"]
if not check:
# this is because EL5/6 does not know --nocheck
# when EL5/6 targets are not supported, replace it with --nocheck
Expand Down Expand Up @@ -781,7 +783,9 @@ def get_command(mode, checkdeps=False):
if packages_after == packages_before:
success = True
for f_buildreqs in buildreqs:
os.remove(f_buildreqs)
if not (success and depsonly):
# we want to keep the nosrc.rpm file
os.remove(f_buildreqs)
# The first rpmbuild -br already did %prep, so we don't need waste time
if '--noprep' not in br_mode:
br_mode += ['--noprep']
Expand All @@ -803,14 +807,16 @@ def get_command(mode, checkdeps=False):
# Unfortunately, we can only do this when using a bootstrap chroot,
# because the rpm in the chroot might not understand the rpmdb otherwise.
# See https://github.com/rpm-software-management/mock/issues/1246
checkdeps = dynamic_buildrequires and self.bootstrap_buildroot is not None
self.buildroot.doChroot(get_command(mode, checkdeps=checkdeps),
shell=False, logger=self.buildroot.build_log, timeout=timeout,
uid=self.buildroot.chrootuid, gid=self.buildroot.chrootgid,
user=self.buildroot.chrootuser,
nspawn_args=self._get_nspawn_args(),
unshare_net=self.private_network,
printOutput=self.config['print_main_output'])

if not depsonly:
checkdeps = dynamic_buildrequires and self.bootstrap_buildroot is not None
self.buildroot.doChroot(get_command(mode, checkdeps=checkdeps),
shell=False, logger=self.buildroot.build_log, timeout=timeout,
uid=self.buildroot.chrootuid, gid=self.buildroot.chrootgid,
user=self.buildroot.chrootuser,
nspawn_args=self._get_nspawn_args(),
unshare_net=self.private_network,
printOutput=self.config['print_main_output'])
results = glob.glob(bd_out + '/RPMS/*.rpm')
results += glob.glob(bd_out + '/SRPMS/*.rpm')
self.buildroot.final_rpm_list = [os.path.basename(result) for result in results]
Expand Down
4 changes: 4 additions & 0 deletions mock/py/mockbuild/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ def setup_default_config_opts():

config_opts["recursion_limit"] = 5000

config_opts["calculatedeps"] = None

return config_opts


Expand Down Expand Up @@ -637,6 +639,8 @@ def set_config_opts_per_cmdline(config_opts, options, args):
# which though affects root_cache).
config_opts["additional_packages"] = options.additional_packages

config_opts["calculatedeps"] = options.calculatedeps


def check_config(config_opts):
if 'root' not in config_opts:
Expand Down

0 comments on commit 611c60c

Please sign in to comment.