Skip to content

Commit

Permalink
rpmbuild: build RPM in one mock call
Browse files Browse the repository at this point in the history
  • Loading branch information
FrostyX committed Aug 10, 2023
1 parent 727b40b commit 7de0fe8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
10 changes: 4 additions & 6 deletions rpmbuild/copr_rpmbuild/builders/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ def run(self):
spec = locate_spec(self.sourcedir)
shutil.copy(spec, self.resultdir)
try:
self.produce_srpm(spec, self.sourcedir, self.resultdir)

srpm = locate_srpm(self.resultdir)
self.produce_rpm(srpm, self.resultdir)
self.produce_rpm(spec, self.sourcedir, self.resultdir)
finally:
self.mock_clean()

Expand Down Expand Up @@ -165,9 +162,10 @@ def module_setup_commands(self):

return tuples

def produce_rpm(self, srpm, resultdir):
def produce_rpm(self, spec, sources, resultdir):
cmd = MOCK_CALL + [
"--rebuild", srpm,
"--spec", spec,
"--sources", sources,
"--resultdir", resultdir,
"--uniqueext", self.uniqueext,
"-r", self.mock_config_file]
Expand Down
20 changes: 6 additions & 14 deletions rpmbuild/tests/test_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def setup_method(self, method):
self.child_config = os.path.join(self.configdir, 'child.cfg')

self.mock_rpm_call = [
'unbuffer', 'mock', '--rebuild', 'srpm',
'unbuffer', 'mock', '--spec', 'spec', '--sources', self.sourcedir,
'--resultdir', self.resultdir, '--uniqueext', '0',
'-r', self.child_config,
]
Expand Down Expand Up @@ -172,12 +172,8 @@ def test_mock_options(self, archive_configs, prep_configs, f_mock_calls):
""" test that mock options are correctly constructed """
MockBuilder(self.task, self.sourcedir, self.resultdir,
self.config).run()
assert len(f_mock_calls) == 2 # srpm + rpm

assert len(f_mock_calls) == 1
call = f_mock_calls[0]
assert call[0][0] == self.mock_srpm_call

call = f_mock_calls[1]
assert call[0][0] == self.mock_rpm_call

@mock.patch("copr_rpmbuild.builders.mock.subprocess.call")
Expand All @@ -190,9 +186,10 @@ def test_produce_rpm(self, popen_mock, get_mock_uniqueext_mock,
builder = MockBuilder(self.task, self.sourcedir, self.resultdir, self.config)
process = mock.MagicMock(returncode=0)
popen_mock.return_value = process
builder.produce_rpm("/path/to/pkg.src.rpm", "/path/to/results")
builder.produce_rpm("foo.spec", "/path/to/foo", "/path/to/results")
assert_cmd = ['unbuffer', 'mock',
'--rebuild', '/path/to/pkg.src.rpm',
'--spec', 'foo.spec',
'--sources', '/path/to/foo',
'--resultdir', '/path/to/results',
'--uniqueext', '2',
'-r', builder.mock_config_file]
Expand Down Expand Up @@ -228,13 +225,8 @@ def test_module_mock_options(self, f_mock_calls, modules):
MockBuilder(self.task, self.sourcedir, self.resultdir,
self.config).run()

assert len(f_mock_calls) == 2 # srpm + rpm

# srpm call isn't affected by modules
assert len(f_mock_calls) == 1
call = f_mock_calls[0]
assert call[0][0] == self.mock_srpm_call

call = f_mock_calls[1]
assert call[0][0] == self.mock_rpm_call

expected1 = "config_opts['macros']['%buildtag'] = '.copr10'\n"
Expand Down

0 comments on commit 7de0fe8

Please sign in to comment.