Skip to content

Commit

Permalink
De-duplicate two opinionated doChroot() calls
Browse files Browse the repository at this point in the history
See #1456.
  • Loading branch information
praiskup committed Sep 24, 2024
1 parent d223072 commit 4ed9026
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
18 changes: 18 additions & 0 deletions mock/py/mockbuild/buildroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,24 @@ def doChroot(self, command, nosync=False, *args, **kargs):
self.uid_manager.restorePrivs()
return result

def doChrootPlugin(self, command, cwd=None):
"""
Execute command (specified as array, not a shell command string) in this
buildroot in `cwd`, as a non-privileged user. Used by plugins.
"""
private_network = not self.config.get('rpmbuild_networking', False)
self.doChroot(
command,
shell=False,
cwd=cwd,
logger=self.build_log,
uid=self.chrootuid,
gid=self.chrootgid,
user=self.chrootuser,
unshare_net=private_network,
printOutput=self.config.get('print_main_output', True)
)

def all_chroot_packages(self):
"""package set, result of rpm -qa in the buildroot"""
self.nuke_rpm_db()
Expand Down
16 changes: 1 addition & 15 deletions mock/py/mockbuild/plugins/rpkg_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,4 @@ def _preprocess(self, host_chroot_spec, host_chroot_sources):
command_str = self.opts.get('cmd') % {'source_spec': chroot_sources_spec,
'target_spec': chroot_spec}
command = shlex.split(command_str)

# determine whether to use private network or not based on rpmbuild_networking
private_network = (not self.config.get('rpmbuild_networking', False))

self.buildroot.doChroot(
command,
shell=False,
cwd=chroot_sources,
logger=self.buildroot.build_log,
uid=self.buildroot.chrootuid,
gid=self.buildroot.chrootgid,
user=self.buildroot.chrootuser,
unshare_net=private_network,
printOutput=self.config.get('print_main_output', True)
)
self.buildroot.doChrootPlugin(command, cwd=chroot_sources)
12 changes: 1 addition & 11 deletions mock/py/mockbuild/plugins/rpmautospec.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,4 @@ def attempt_process_distgit(
# bonus, spec files will be processed in the environment they will be
# built for, reducing the impact of the host system on the outcome,
# leading to more deterministic results and better repeatable builds.
self.buildroot.doChroot(
command,
shell=False,
cwd=chroot_sources,
logger=self.buildroot.build_log,
uid=self.buildroot.chrootuid,
gid=self.buildroot.chrootgid,
user=self.buildroot.chrootuser,
unshare_net=not self.config.get("rpmbuild_networking", False),
printOutput=self.config.get("print_main_output", True),
)
self.buildroot.doChrootPlugin(command, cwd=chroot_sources)

0 comments on commit 4ed9026

Please sign in to comment.