Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve handling of failed hooks #194

Merged
merged 3 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions py/csmock
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,15 @@ class ScanProps:
cmd_out += "sh -c %s" % shell_quote(cmd_in)
return cmd_out

def run_hooks(self, results, hook_name, *args):
"""run all hooks from the list specified by hook_name"""
item = hook_name.replace("-", "_") + "_hooks"
hook_list = getattr(self, item)
for hook in hook_list:
rv = hook(*args)
if rv != 0:
results.error(f"{hook_name} hook {hook.__module__}::{hook.__name__}() returned {rv}", ec=rv)


class PluginManager:
def __init__(self):
Expand Down Expand Up @@ -1074,10 +1083,7 @@ the package. Use --tools or --all-tools to enable them!\n", ec=0)
srpm_dup = None

# run pre-mock hooks
for hook in props.pre_mock_hooks:
rv = hook(results, props)
if rv != 0:
results.error("pre-mock hook failed", ec=rv)
props.run_hooks(results, "pre-mock", results, props)

with MockWrapper(results, props) as mock:
if srpm_dup is not None:
Expand Down Expand Up @@ -1143,10 +1149,7 @@ cd %%s*/ || cd *\n\
results.exec_cmd(cmd, shell=True)

# run post-depinst hooks
for hook in props.post_depinst_hooks:
rv = hook(results, mock)
if rv != 0:
results.error("post-depinst hook failed", ec=rv)
props.run_hooks(results, "post-depinst", results, mock)

if not props.no_scan:
if props.shell_cmd_to_build is None:
Expand Down Expand Up @@ -1228,10 +1231,7 @@ cd %%s*/ || cd *\n\

try:
# run post-install hooks
for hook in props.post_install_hooks:
rv = hook(results, mock, props)
if rv != 0:
results.error("post-install hook failed", ec=rv)
props.run_hooks(results, "post-install", results, mock, props)

# execute post-build commands in the chroot
for cmd in props.post_build_chroot_cmds:
Expand All @@ -1256,10 +1256,7 @@ cd %%s*/ || cd *\n\
results.error("failed to pick cswrap results")

# run post-process hooks
for hook in props.post_process_hooks:
rv = hook(results)
if rv != 0:
results.error("post-process hook failed", ec=rv)
props.run_hooks(results, "post-process", results)

# we are done with IniWriter
results.ini_writer.close()
Expand Down
4 changes: 3 additions & 1 deletion py/plugins/cppcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def enable(self):
def init_parser(self, parser):
parser.add_argument(
"--use-host-cppcheck", action="store_true",
help="use host's Cppcheck instead of the one in chroot \
help="use statically linked cppcheck installed on the host \
(automatically enables the Cppcheck plug-in)")

parser.add_argument(
Expand Down Expand Up @@ -103,6 +103,8 @@ def store_cppcheck_version_hook(results, mock):
cmd = mock.get_mock_cmd(["--chroot", "cppcheck --version"])
(ec, verstr) = results.get_cmd_output(cmd, shell=False)
if ec != 0:
if self.use_host_cppcheck:
results.error("--use-host-cppcheck expects statically linked cppcheck installed on the host", ec=0)
results.error("failed to query cppcheck version", ec=ec)
return ec

Expand Down