From d94c870fc9fd7942c3bad48d5e0bc926f9cc093d Mon Sep 17 00:00:00 2001 From: Todd Zullinger Date: May 08 2018 15:47:24 +0000 Subject: Add --with and --without options to 'local' The 'mockbuild' command learned these options in 69b3864 ("Add --with and --without options to mockbuild", 2017-08-17). Resolves: rhbz#1533416 Signed-off-by: Todd Zullinger --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 74cdbfc..9120fcf 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -2197,10 +2197,11 @@ class Commands(object): # Run the command self._run_command(cmd, shell=True) - def local(self, arch=None, hashtype=None, builddir=None): + def local(self, localargs, arch=None, hashtype=None, builddir=None): """rpmbuild locally for given arch. - Takes arch to build for, and hashtype to build with. + Takes localargs (passed to rpmbuild), arch to build for, and hashtype + to build with. Writes output to a log file and logs it to the logger @@ -2211,7 +2212,7 @@ class Commands(object): # Get the sources # build up the rpm command cmd = ['rpmbuild'] - cmd.extend(self.rpmdefines) + cmd.extend(self.rpmdefines + localargs) if builddir: # Tack on a new builddir to the end of the defines cmd.append("--define '_builddir %s'" % os.path.abspath(builddir)) diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index b165e64..c232920 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -649,6 +649,13 @@ defined, packages will be built sequentially.""" % {'name': self.name}) local_parser.add_argument( '--md5', action='store_const', const='md5', default=None, dest='hash', help='Use md5 checksums (for older rpm hosts)') + # Pass --with/without options to rpmbuild + local_parser.add_argument( + '--with', help='Enable configure option (bcond) for the build', + dest='bcond_with', action='append') + local_parser.add_argument( + '--without', help='Disable configure option (bcond) for the build', + dest='bcond_without', action='append') local_parser.set_defaults(command=self.local) def register_new(self): @@ -1385,7 +1392,18 @@ see API KEY section of copr-cli(1) man page. def local(self): self.sources() - self.cmd.local(arch=self.args.arch, hashtype=self.args.hash, + + localargs = [] + + if self.args.bcond_with: + for arg in self.args.bcond_with: + localargs.extend(['--with', arg]) + + if self.args.bcond_without: + for arg in self.args.bcond_without: + localargs.extend(['--without', arg]) + + self.cmd.local(localargs, arch=self.args.arch, hashtype=self.args.hash, builddir=self.args.builddir) def mockbuild(self): diff --git a/tests/test_cli.py b/tests/test_cli.py index fb95e5c..65a26e7 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -603,7 +603,7 @@ class TestLocal(CliTestCase): builddir = os.path.join(self.cloned_repo_path, 'this-builddir') cli_cmd = ['rpkg', '--path', self.cloned_repo_path, '--release', 'rhel-6', '-q', 'local', - '--builddir', builddir, '--arch', 'i686'] + '--builddir', builddir, '--arch', 'i686', '--with', 'a', '--without', 'b'] with patch('sys.argv', new=cli_cmd): cli = self.new_cli() @@ -611,7 +611,8 @@ class TestLocal(CliTestCase): spec = os.path.join(cli.cmd.path, cli.cmd.spec) rpmbuild = ['rpmbuild'] + cli.cmd.rpmdefines + \ - ["--define '_builddir %s'" % builddir, '--target', 'i686', '--quiet', '-ba', spec] + ['--with', 'a', '--without', 'b', "--define '_builddir %s'" % builddir, + '--target', 'i686', '--quiet', '-ba', spec] tee = ['tee', '.build-%s-%s.log' % (cli.cmd.ver, cli.cmd.rel)] cmd = '%s | %s; exit "${PIPESTATUS[0]} ${pipestatus[1]}"' % (