Skip to content

Commit

Permalink
shellcheck: use --source-path if supported
Browse files Browse the repository at this point in the history
... so that we get equivalent scan results as if we scanned all scripts
at once.
  • Loading branch information
kdudka committed Aug 13, 2024
1 parent f9d1a11 commit a42c5a5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions py/plugins/shellcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def handle_args(self, parser, args, props):
dirs_to_scan = csmock.common.util.dirs_to_scan_by_args(
parser, args, props, "shellcheck")

# append "/*" to each directory in dirs_to_scan (to scan pkg-specific dirs)
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}"
props.post_build_chroot_cmds += [cmd]
Expand Down
17 changes: 17 additions & 0 deletions scripts/run-shellcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ if shellcheck --help 2>/dev/null | grep external-sources > /dev/null; then
SC_OPTS="${SC_OPTS} --external-sources"
fi

# check whether shellcheck supports --source-path
if shellcheck --help 2>/dev/null | grep source-path > /dev/null; then
sp=
for dir in "$@"; do
# search path works only for directories
test -d "$dir" || continue

# spaces cannot be safely put to SC_OPTS because it is not an array
[[ "$dir" != *" "* ]] || continue

sp="${sp}:${dir}"
done
if test -n "$sp"; then
SC_OPTS="${SC_OPTS} --source-path=${sp#:}"
fi
fi

# implementation of the script that filters shell scripts
filter_shell_scripts() {
for i in "$@"; do
Expand Down

0 comments on commit a42c5a5

Please sign in to comment.