Blob Blame History Raw
From 89d3bb0d34250fe24eed5bc63edd992e932a622a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20Nosek?= <onosek@redhat.com>
Date: Wed, 15 Nov 2023 02:53:10 +0100
Subject: [PATCH 14/17] `mockbuild`: new argument --extra-pkgs
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Added the new argument `--extra-pkgs` to `mockbuild` command.
It installs additional packages to mock's chroot. In some cases is
possible to use the current mechanism of extra args placed
after `--` at the end of the command line instead of `--extra-pkgs`.

  Example: fedpkg mockbuild -- --additional-package <pkg>

Argument(s) `additional-package` is passed to `mock`.
`additional-package` can't be used together with `--shell`.

JIRA: RHELCMP-11017
Fixes: https://pagure.io/fedpkg/issue/498

Signed-off-by: Ondřej Nosek <onosek@redhat.com>
---
 pyrpkg/cli.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py
index 6fd6df0..06f4c1a 100644
--- a/pyrpkg/cli.py
+++ b/pyrpkg/cli.py
@@ -1152,6 +1152,9 @@ class cliClient(object):
             '--use-local-mock-config', default=None, dest="local_mock_config",
             action='store_true',
             help="Enforce use of local Mock configuration.")
+        mockbuild_parser.add_argument(
+            '--extra-pkgs', action='append', nargs='*',
+            help="Install additional packages into chroot")
 
         mockbuild_parser.set_defaults(command=self.mockbuild)
 
@@ -2514,6 +2517,24 @@ class cliClient(object):
                                                  "%s-%s-%s.src.rpm"
                                                  % (self.cmd.repo_name, self.cmd.ver, self.cmd.rel))
                 self.log.debug('Srpm generated: {0}'.format(self.cmd.srpmname))
+            if self.args.extra_pkgs:
+                mockargs_extra_pkgs = []
+                list_extra_pkgs = []
+                # process possible multiple argument's occurrences
+                for arg_arr in self.args.extra_pkgs:
+                    for additional_package in arg_arr:
+                        mockargs_extra_pkgs.extend(['--additional-package', additional_package])
+                        list_extra_pkgs.append(additional_package)
+                # installation will run in separated mock process, so do not clean prepared chroot
+                # before the main mock run
+                mockargs_extra_pkgs.extend(['--no-cleanup-after'])
+                self.log.info('Installing extra packages into the mock chroot: {}'.format(
+                    ', '.join(list_extra_pkgs)))
+                self.cmd.mockbuild(mockargs_extra_pkgs, self.args.root,
+                                   hashtype=self.args.hash,
+                                   shell=None,  # nosec
+                                   force_local_mock_config=self.args.local_mock_config)
+
             self.cmd.mockbuild(mockargs, self.args.root,
                                hashtype=self.args.hash,
                                shell=self.args.shell,  # nosec
-- 
2.43.0