From 11392ae5d8fc6f87a0d9af93f00312afe0f0d2d1 Mon Sep 17 00:00:00 2001 From: Kamil Dudka Date: Mon, 12 Aug 2024 19:33:17 +0200 Subject: [PATCH] shellcheck: introduce the `--shellcheck-timeout` option ... to configure maximum amount of wall-clock time taken by a single shellcheck process Related: https://issues.redhat.com/browse/OSH-655 Closes: https://github.com/csutils/csmock/pull/182 --- py/plugins/shellcheck.py | 9 ++++++++- scripts/run-shellcheck.sh | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/py/plugins/shellcheck.py b/py/plugins/shellcheck.py index 8c1bce5..cec032c 100644 --- a/py/plugins/shellcheck.py +++ b/py/plugins/shellcheck.py @@ -27,6 +27,8 @@ FILTER_CMD = "csgrep --mode=json --remove-duplicates --quiet " \ "--invert-match --event '^note|warning\\[SC1090\\]'" +DEFAULT_SC_TIMEOUT = 30 + class PluginProps: def __init__(self): @@ -48,6 +50,10 @@ def enable(self): def init_parser(self, parser): csmock.common.util.install_script_scan_opts(parser, "shellcheck") + parser.add_argument( + "--shellcheck-timeout", type=int, default=DEFAULT_SC_TIMEOUT, + help="maximum amount of wall-clock time taken by a single shellcheck process [s]" \ + f" (defaults to {DEFAULT_SC_TIMEOUT})") def handle_args(self, parser, args, props): if not self.enabled: @@ -58,7 +64,8 @@ def handle_args(self, parser, args, props): parser, args, props, "shellcheck") props.install_pkgs += ["ShellCheck"] - cmd = f"SC_RESULTS_DIR={SHELLCHECK_CAP_DIR} {RUN_SHELLCHECK_SH} {dirs_to_scan}" + cmd = f"SC_RESULTS_DIR={SHELLCHECK_CAP_DIR} SC_TIMEOUT={args.shellcheck_timeout} " + cmd += f"{RUN_SHELLCHECK_SH} {dirs_to_scan}" props.post_build_chroot_cmds += [cmd] props.copy_out_files += [SHELLCHECK_CAP_DIR] diff --git a/scripts/run-shellcheck.sh b/scripts/run-shellcheck.sh index 97be4ad..5850a7d 100755 --- a/scripts/run-shellcheck.sh +++ b/scripts/run-shellcheck.sh @@ -8,7 +8,8 @@ export SC_BATCH=1 export SC_JOBS=$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1) # how long we wait (wall-clock time) for a single shellcheck process to finish -export SC_TIMEOUT=30 +test -n "$SC_TIMEOUT" || export SC_TIMEOUT=30 +test 0 -lt "$SC_TIMEOUT" || exit $? # directory for shellcheck results test -n "$SC_RESULTS_DIR" || export SC_RESULTS_DIR="./shellcheck-results"