diff --git a/py/plugins/shellcheck.py b/py/plugins/shellcheck.py index b5797cb..06e81f8 100644 --- a/py/plugins/shellcheck.py +++ b/py/plugins/shellcheck.py @@ -27,6 +27,9 @@ FILTER_CMD = "csgrep --mode=json --remove-duplicates --quiet " \ "--invert-match --event '^note|warning\\[SC1090\\]'" +# default maximum amount of wall-clock time taken by a single shellcheck process [s] +DEFAULT_SC_TIMEOUT = 30 + class PluginProps: def __init__(self): @@ -48,6 +51,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: @@ -61,7 +68,9 @@ def handle_args(self, parser, args, props): dirs_to_scan = " ".join([dir + "/*" for dir in dirs_to_scan.split()]) 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} " + cmd += f"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 ba79b70..0c4b604 100755 --- a/scripts/run-shellcheck.sh +++ b/scripts/run-shellcheck.sh @@ -9,7 +9,8 @@ SC_JOBS=$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1) export SC_JOBS # 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"