mirror of
https://github.com/rpm-software-management/tito.git
synced 2025-02-23 12:12:47 +00:00
Print mock output when building with MockBuilder
Currently when building RPMs or SRPMs with MockBuilder, tito will not print the output from mock. This makes diagnosis harder especially in CI environments. This PR will do the following changes: 1. If `--quiet` option is not specified, `run_command_print` will be used to run the `mock` or `rpmbuild` command. Otherwise we will continue to use `run_command`. 2. `run_command_print` will print error message when an error happens, like what `run_command` does.
This commit is contained in:
parent
9f901b1667
commit
a1ecfd3905
2 changed files with 32 additions and 17 deletions
|
@ -225,7 +225,8 @@ class BuilderBase(object):
|
|||
' "_binary_filedigest_algorithm md5" %s %s %s --nodeps -bs %s' % (
|
||||
rpmbuild_options, self._get_rpmbuild_dir_options(),
|
||||
define_dist, self.spec_file))
|
||||
output = run_command_print(cmd)
|
||||
run_command_func = run_command if self.quiet else run_command_print
|
||||
output = run_command_func(cmd)
|
||||
self.srpm_location = find_wrote_in_rpmbuild_output(output)[0]
|
||||
self.artifacts.append(self.srpm_location)
|
||||
|
||||
|
@ -1142,25 +1143,26 @@ class MockBuilder(Builder):
|
|||
self.normal_builder.cleanup()
|
||||
|
||||
def _build_in_mock(self):
|
||||
run_command_func = run_command if self.quiet else run_command_print
|
||||
if not self.speedup:
|
||||
print("Initializing mock...")
|
||||
run_command("mock %s -r %s --init" % (self.mock_cmd_args, self.mock_tag))
|
||||
run_command_func("mock %s -r %s --init" % (self.mock_cmd_args, self.mock_tag))
|
||||
else:
|
||||
print("Skipping mock --init due to speedup option.")
|
||||
|
||||
print("Installing deps in mock...")
|
||||
run_command("mock %s -r %s %s" % (
|
||||
run_command_func("mock %s -r %s %s" % (
|
||||
self.mock_cmd_args, self.mock_tag, self.srpm_location))
|
||||
print("Building RPMs in mock...")
|
||||
run_command('mock %s -r %s --rebuild %s' %
|
||||
run_command_func('mock %s -r %s --rebuild %s' %
|
||||
(self.mock_cmd_args, self.mock_tag, self.srpm_location))
|
||||
mock_output_dir = os.path.join(self.rpmbuild_dir, "mockoutput")
|
||||
run_command("mock %s -r %s --copyout /builddir/build/RPMS/ %s" %
|
||||
run_command_func("mock %s -r %s --copyout /builddir/build/RPMS/ %s" %
|
||||
(self.mock_cmd_args, self.mock_tag, mock_output_dir))
|
||||
|
||||
# Copy everything mock wrote out to /tmp/tito:
|
||||
files = os.listdir(mock_output_dir)
|
||||
run_command("cp -v %s/*.rpm %s" %
|
||||
run_command_func("cp -v %s/*.rpm %s" %
|
||||
(mock_output_dir, self.rpmbuild_basedir))
|
||||
print
|
||||
info_out("Wrote:")
|
||||
|
|
|
@ -443,16 +443,29 @@ def run_command_print(command):
|
|||
output = []
|
||||
env = os.environ.copy()
|
||||
env['LC_ALL'] = 'C'
|
||||
p = subprocess.Popen(shlex.split(command),
|
||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env,
|
||||
universal_newlines=True)
|
||||
for line in run_subprocess(p):
|
||||
line = line.rstrip('\n')
|
||||
print(line)
|
||||
output.append(line)
|
||||
print("\n"),
|
||||
if p.poll() > 0:
|
||||
raise RunCommandException(command, p.poll(), "\n".join(output))
|
||||
p = None
|
||||
try:
|
||||
p = subprocess.Popen(shlex.split(command),
|
||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env,
|
||||
universal_newlines=True)
|
||||
except OSError as e:
|
||||
status = e.errno
|
||||
output = e.strerror
|
||||
if p:
|
||||
for line in run_subprocess(p):
|
||||
line = line.rstrip('\n')
|
||||
print(line)
|
||||
output.append(line)
|
||||
print("\n"),
|
||||
status = p.poll()
|
||||
if status > 0:
|
||||
msgs = [
|
||||
"Error running command: %s\n" % command,
|
||||
"Status code: %s\n" % status,
|
||||
"Command output: %s\n" % output,
|
||||
]
|
||||
error_out(msgs, die=False)
|
||||
raise RunCommandException(command, status, "\n".join(output))
|
||||
return '\n'.join(output)
|
||||
|
||||
|
||||
|
@ -462,7 +475,7 @@ def run_subprocess(p):
|
|||
line = p.stdout.readline()
|
||||
if len(line) > 0:
|
||||
yield line
|
||||
if(retcode is not None):
|
||||
if retcode is not None:
|
||||
break
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue