Skip to content

Commit

Permalink
shellcheck: introduce the --shellcheck-batch option
Browse files Browse the repository at this point in the history
... to configure maximum number of scripts scanned by a single
shellcheck process

Related: https://issues.redhat.com/browse/OSH-655
  • Loading branch information
kdudka committed Aug 26, 2024
1 parent b6bc001 commit ec1fd5e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions py/plugins/shellcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
FILTER_CMD = "csgrep --mode=json --remove-duplicates --quiet " \
"--invert-match --event '^note|warning\\[SC1090\\]'"

# default maximum number of scripts scanned by a single shellcheck process
DEFAULT_SC_BATCH = 1

# default maximum amount of wall-clock time taken by a single shellcheck process [s]
DEFAULT_SC_TIMEOUT = 30

Expand All @@ -51,6 +54,10 @@ def enable(self):

def init_parser(self, parser):
csmock.common.util.install_script_scan_opts(parser, "shellcheck")
parser.add_argument(
"--shellcheck-batch", type=int, default=DEFAULT_SC_BATCH,
help="maximum number of scripts scanned by a single shellcheck process" \
f" (defaults to {DEFAULT_SC_BATCH})")
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]" \
Expand All @@ -69,6 +76,7 @@ def handle_args(self, parser, args, props):

props.install_pkgs += ["ShellCheck"]
cmd = f"SC_RESULTS_DIR={SHELLCHECK_CAP_DIR} "
cmd += f"SC_BATCH={args.shellcheck_batch} "
cmd += f"SC_TIMEOUT={args.shellcheck_timeout} "
cmd += f"{RUN_SHELLCHECK_SH} {dirs_to_scan}"
props.post_build_chroot_cmds += [cmd]
Expand Down
3 changes: 2 additions & 1 deletion scripts/run-shellcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
export LC_ALL="C"

# how many shell scripts we pass to shellcheck at a time
export SC_BATCH=1
test -n "$SC_BATCH" || export SC_BATCH=1
test 0 -lt "$SC_BATCH" || exit $?

# how many shellcheck processes we run in parallel
SC_JOBS=$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)
Expand Down

0 comments on commit ec1fd5e

Please sign in to comment.