From 69b38641ec7a401add704afb2dc273ea2802c75f Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Aug 17 2017 06:56:52 +0000 Subject: [PATCH 1/2] Add --with and --without options to mockbuild These options are passed through to mock to configure the build. Test included, along with a general test for mockbuild. Signed-off-by: Petr Viktorin --- diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index ac6c841..070c274 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -685,6 +685,12 @@ defined, packages will be built sequentially.""" % {'name': self.name}) mockbuild_parser.add_argument( '--no-clean-all', '-N', help='Alias for both --no-clean and ' '--no-cleanup-after', action='store_true') + mockbuild_parser.add_argument( + '--with', help='Enable configure option (bcond) for the build', + dest='bcond_with', action='append') + mockbuild_parser.add_argument( + '--without', help='Disable configure option (bcond) for the build', + dest='bcond_without', action='append') mockbuild_parser.set_defaults(command=self.mockbuild) def register_mock_config(self): @@ -1298,6 +1304,14 @@ see API KEY section of copr-cli(1) man page. if self.args.no_cleanup_after or self.args.no_clean_all: mockargs.append('--no-cleanup-after') + if self.args.bcond_with: + for arg in self.args.bcond_with: + mockargs.extend(['--with', arg]) + + if self.args.bcond_without: + for arg in self.args.bcond_without: + mockargs.extend(['--without', arg]) + # Pick up any mockargs from the env try: mockargs += os.environ['MOCKARGS'].split() diff --git a/tests/test_cli.py b/tests/test_cli.py index ffa2c0c..923d2e3 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1022,3 +1022,41 @@ class TestImportSrpm(LookasideCacheMock, CliTestCase): def test_import(self): self.assert_import_srpm(self.chaos_repo) self.assert_import_srpm(self.cloned_repo_path) + + +class TestMockbuild(CliTestCase): + """Test mockbuild command""" + + @patch('pyrpkg.Commands._run_command') + def test_mockbuild(self, _run_command): + cli_cmd = ['rpkg', '--path', self.cloned_repo_path, + '--release', 'rhel-6', 'mockbuild', + '--root', '/etc/mock/some-root'] + + with patch('sys.argv', new=cli_cmd): + cli = self.new_cli() + cli.mockbuild() + + expected_cmd = ['mock', '-r', '/etc/mock/some-root', + '--resultdir', cli.cmd.mock_results_dir, '--rebuild', + cli.cmd.srpmname] + _run_command.assert_called_with(expected_cmd) + + @patch('pyrpkg.Commands._run_command') + def test_with_without(self, _run_command): + cli_cmd = ['rpkg', '--path', self.cloned_repo_path, + '--release', 'rhel-6', 'mockbuild', + '--root', '/etc/mock/some-root', + '--with', 'a', '--without', 'b', '--with', 'c', + '--without', 'd'] + + with patch('sys.argv', new=cli_cmd): + cli = self.new_cli() + cli.mockbuild() + + expected_cmd = ['mock', '--with', 'a', '--with', 'c', + '--without', 'b', '--without', 'd', + '-r', '/etc/mock/some-root', + '--resultdir', cli.cmd.mock_results_dir, '--rebuild', + cli.cmd.srpmname] + _run_command.assert_called_with(expected_cmd) From 8c8945e7bb017603cf6e32a7971e3253c8345ea5 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Aug 21 2017 09:07:26 +0000 Subject: [PATCH 2/2] Fix indentation Signed-off-by: Petr Viktorin --- diff --git a/tests/test_cli.py b/tests/test_cli.py index 923d2e3..a380d65 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1038,7 +1038,7 @@ class TestMockbuild(CliTestCase): cli.mockbuild() expected_cmd = ['mock', '-r', '/etc/mock/some-root', - '--resultdir', cli.cmd.mock_results_dir, '--rebuild', + '--resultdir', cli.cmd.mock_results_dir, '--rebuild', cli.cmd.srpmname] _run_command.assert_called_with(expected_cmd) @@ -1056,7 +1056,7 @@ class TestMockbuild(CliTestCase): expected_cmd = ['mock', '--with', 'a', '--with', 'c', '--without', 'b', '--without', 'd', - '-r', '/etc/mock/some-root', - '--resultdir', cli.cmd.mock_results_dir, '--rebuild', + '-r', '/etc/mock/some-root', + '--resultdir', cli.cmd.mock_results_dir, '--rebuild', cli.cmd.srpmname] _run_command.assert_called_with(expected_cmd)