Skip to content

Commit

Permalink
Turn shellcheck into a normal make target. Fix new files it caught
Browse files Browse the repository at this point in the history
This checks every file it checked (and a few more),
but explicitly instead of "if it works it works" best-effort
(which wasn't that good anyway)

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes openzfs#10512
Closes openzfs#12101
  • Loading branch information
nabijaczleweli authored and behlendorf committed Jun 1, 2021
1 parent d3858ab commit c3ef9f7
Show file tree
Hide file tree
Showing 40 changed files with 214 additions and 108 deletions.
15 changes: 4 additions & 11 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include $(top_srcdir)/config/Shellcheck.am

ACLOCAL_AMFLAGS = -I config

SUBDIRS = include
Expand Down Expand Up @@ -123,17 +125,8 @@ cstyle:

filter_executable = -exec test -x '{}' \; -print

PHONY += shellcheck
shellcheck:
@if type shellcheck > /dev/null 2>&1; then \
shellcheck --exclude=SC1090,SC1117,SC1091 --format=gcc \
$$(find ${top_srcdir} -name "config*" -prune -name tests -prune \
-o -name "*.sh" -o -name "*.sh.in" -type f) \
$$(find ${top_srcdir}/cmd/zpool/zpool.d/* \
-type f ${filter_executable}); \
else \
echo "skipping shellcheck because shellcheck is not installed"; \
fi
SHELLCHECKDIRS = cmd contrib etc scripts tests
SHELLCHECKSCRIPTS = autogen.sh

PHONY += checkabi storeabi
checkabi: lib
Expand Down
6 changes: 6 additions & 0 deletions cmd/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
include $(top_srcdir)/config/Shellcheck.am

SUBDIRS = zfs zpool zdb zhack zinject zstream ztest
SUBDIRS += fsck_zfs vdev_id raidz_test zfs_ids_to_path
SUBDIRS += zpool_influxdb

CPPCHECKDIRS = zfs zpool zdb zhack zinject zstream ztest
CPPCHECKDIRS += raidz_test zfs_ids_to_path zpool_influxdb

# TODO: #12084: SHELLCHECKDIRS = fsck_zfs vdev_id zpool
SHELLCHECKDIRS = fsck_zfs zpool

if USING_PYTHON
SUBDIRS += arcstat arc_summary dbufstat
endif

if BUILD_LINUX
SUBDIRS += mount_zfs zed zgenhostid zvol_id zvol_wait
CPPCHECKDIRS += mount_zfs zed zgenhostid zvol_id
SHELLCHECKDIRS += zed
endif

PHONY = cppcheck
Expand Down
1 change: 1 addition & 0 deletions cmd/fsck_zfs/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include $(top_srcdir)/config/Substfiles.am
include $(top_srcdir)/config/Shellcheck.am

dist_sbin_SCRIPTS = fsck.zfs

Expand Down
2 changes: 2 additions & 0 deletions cmd/vdev_id/Makefile.am
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
include $(top_srcdir)/config/Shellcheck.am

dist_udev_SCRIPTS = vdev_id
2 changes: 2 additions & 0 deletions cmd/zed/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
include $(top_srcdir)/config/Rules.am
include $(top_srcdir)/config/Shellcheck.am

AM_CFLAGS += $(LIBUDEV_CFLAGS) $(LIBUUID_CFLAGS)

SUBDIRS = zed.d
SHELLCHECKDIRS = $(SUBDIRS)

sbin_PROGRAMS = zed

Expand Down
1 change: 1 addition & 0 deletions cmd/zed/zed.d/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include $(top_srcdir)/config/Rules.am
include $(top_srcdir)/config/Substfiles.am
include $(top_srcdir)/config/Shellcheck.am

EXTRA_DIST += README

Expand Down
1 change: 1 addition & 0 deletions cmd/zpool/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include $(top_srcdir)/config/Rules.am
include $(top_srcdir)/config/Shellcheck.am

AM_CFLAGS += $(LIBBLKID_CFLAGS) $(LIBUUID_CFLAGS)

Expand Down
6 changes: 3 additions & 3 deletions cmd/zpool/zpool.d/smart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ get_filename_from_dir()
num_files=$(find "$dir" -maxdepth 1 -type f | wc -l)
mod=$((pid % num_files))
i=0
find "$dir" -type f -printf "%f\n" | while read -r file ; do
find "$dir" -type f -printf '%f\n' | while read -r file ; do
if [ "$mod" = "$i" ] ; then
echo "$file"
break
Expand Down Expand Up @@ -231,11 +231,11 @@ esac
with_vals=$(echo "$out" | grep -E "$scripts")
if [ -n "$with_vals" ]; then
echo "$with_vals"
without_vals=$(echo "$scripts" | tr "|" "\n" |
without_vals=$(echo "$scripts" | tr '|' '\n' |
grep -v -E "$(echo "$with_vals" |
awk -F "=" '{print $1}')" | awk '{print $0"="}')
else
without_vals=$(echo "$scripts" | tr "|" "\n" | awk '{print $0"="}')
without_vals=$(echo "$scripts" | tr '|' '\n' | awk '{print $0"="}')
fi

if [ -n "$without_vals" ]; then
Expand Down
2 changes: 2 additions & 0 deletions cmd/zvol_wait/Makefile.am
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
include $(top_srcdir)/config/Shellcheck.am

dist_bin_SCRIPTS = zvol_wait
8 changes: 8 additions & 0 deletions config/Shellcheck.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.PHONY: shellcheck
shellcheck: $(SCRIPTS) $(SHELLCHECKSCRIPTS)
if HAVE_SHELLCHECK
[ -z "$(SCRIPTS)$(SHELLCHECKSCRIPTS)" ] && exit; shellcheck $$([ -n "$(SHELLCHECK_SHELL)" ] && echo "--shell=$(SHELLCHECK_SHELL)") --exclude=SC1090,SC1091$(SHELLCHECK_IGNORE) --format=gcc $(SCRIPTS) $(SHELLCHECKSCRIPTS)
else
@[ -z "$(SCRIPTS)$(SHELLCHECKSCRIPTS)" ] && exit; echo "skipping shellcheck of" $(SCRIPTS) $(SHELLCHECKSCRIPTS) "because shellcheck is not installed"
endif
@set -e; for dir in $(SHELLCHECKDIRS); do $(MAKE) -C $$dir shellcheck; done
7 changes: 7 additions & 0 deletions config/always-shellcheck.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dnl #
dnl # Check if shellcheck is available.
dnl #
AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_SHELLCHECK], [
AC_CHECK_PROG([SHELLCHECK], [shellcheck], [yes])
AM_CONDITIONAL([HAVE_SHELLCHECK], [test "x$SHELLCHECK" = "xyes"])
])
1 change: 1 addition & 0 deletions config/zfs-build.m4
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS], [
ZFS_AC_CONFIG_ALWAYS_PYZFS
ZFS_AC_CONFIG_ALWAYS_SED
ZFS_AC_CONFIG_ALWAYS_CPPCHECK
ZFS_AC_CONFIG_ALWAYS_SHELLCHECK
])

AC_DEFUN([ZFS_AC_CONFIG], [
Expand Down
4 changes: 4 additions & 0 deletions contrib/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include $(top_srcdir)/config/Shellcheck.am

SUBDIRS = bash_completion.d pyzfs zcp
if BUILD_LINUX
SUBDIRS += bpftrace dracut initramfs
Expand All @@ -6,3 +8,5 @@ if PAM_ZFS_ENABLED
SUBDIRS += pam_zfs_key
endif
DIST_SUBDIRS = bash_completion.d bpftrace dracut initramfs pam_zfs_key pyzfs zcp

SHELLCHECKDIRS = bash_completion.d bpftrace dracut initramfs
5 changes: 5 additions & 0 deletions contrib/bash_completion.d/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
include $(top_srcdir)/config/Substfiles.am
include $(top_srcdir)/config/Shellcheck.am

bashcompletiondir = $(sysconfdir)/bash_completion.d

noinst_DATA = zfs

EXTRA_DIST += $(noinst_DATA)
SUBSTFILES += $(noinst_DATA)

SHELLCHECKSCRIPTS = $(noinst_DATA)
SHELLCHECK_SHELL = bash
SHELLCHECK_IGNORE = ,SC2207
23 changes: 14 additions & 9 deletions contrib/bash_completion.d/zfs.in
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ __zfs_match_multiple_snapshots()
fi
local range_start
range_start="$(expr "$cur" : '\(.*%\)')"
# shellcheck disable=SC2016
$__ZFS_CMD list -H -o name -s name -t snapshot -d 1 "$base_dataset" | sed 's$.*@$'"$range_start"'$g'
fi
else
Expand All @@ -163,7 +164,7 @@ __zfs_argument_chosen()
then
return 0
fi
for property in $@
for property in "$@"
do
if [[ $prev == "$property"* ]]
then
Expand All @@ -181,6 +182,7 @@ __zfs_complete_ordered_arguments()
local list2=$2
local cur=$3
local extra=$4
# shellcheck disable=SC2086
if __zfs_argument_chosen $list1
then
COMPREPLY=($(compgen -W "$list2 $extra" -- "$cur"))
Expand All @@ -193,9 +195,10 @@ __zfs_complete_multiple_options()
{
local options=$1
local cur=$2
local existing_opts

COMPREPLY=($(compgen -W "$options" -- "${cur##*,}"))
local existing_opts=$(expr "$cur" : '\(.*,\)')
existing_opts=$(expr "$cur" : '\(.*,\)')
if [[ $existing_opts ]]
then
COMPREPLY=( "${COMPREPLY[@]/#/${existing_opts}}" )
Expand Down Expand Up @@ -290,6 +293,7 @@ __zfs_complete()
*)
if ! __zfs_complete_switch "H,r,p,d,o,t,s"
then
# shellcheck disable=SC2046
if __zfs_argument_chosen $(__zfs_get_properties)
then
COMPREPLY=($(compgen -W "$(__zfs_match_snapshot)" -- "$cur"))
Expand All @@ -303,7 +307,7 @@ __zfs_complete()
inherit)
if ! __zfs_complete_switch "r"
then
__zfs_complete_ordered_arguments "$(__zfs_get_inheritable_properties)" "$(__zfs_match_snapshot)" $cur
__zfs_complete_ordered_arguments "$(__zfs_get_inheritable_properties)" "$(__zfs_match_snapshot)" "$cur"
fi
;;
list)
Expand Down Expand Up @@ -369,7 +373,7 @@ __zfs_complete()
esac
;;
set)
__zfs_complete_ordered_arguments "$(__zfs_get_editable_properties)" "$(__zfs_match_snapshot)" $cur
__zfs_complete_ordered_arguments "$(__zfs_get_editable_properties)" "$(__zfs_match_snapshot)" "$cur"
__zfs_complete_nospace
;;
upgrade)
Expand All @@ -388,7 +392,7 @@ __zfs_complete()
destroy)
if ! __zfs_complete_switch "d,f,n,p,R,r,v"
then
__zfs_complete_multiple_options "$(__zfs_match_multiple_snapshots)" $cur
__zfs_complete_multiple_options "$(__zfs_match_multiple_snapshots)" "$cur"
__zfs_complete_nospace
fi
;;
Expand Down Expand Up @@ -425,7 +429,7 @@ __zpool_list_pools()

__zpool_complete()
{
local cur prev cmd cmds
local cur prev cmd cmds pools
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
Expand All @@ -440,7 +444,7 @@ __zpool_complete()

case "${cmd}" in
get)
__zfs_complete_ordered_arguments "$(__zpool_get_properties)" "$(__zpool_list_pools)" $cur
__zfs_complete_ordered_arguments "$(__zpool_get_properties)" "$(__zpool_list_pools)" "$cur"
return 0
;;
import)
Expand All @@ -453,12 +457,13 @@ __zpool_complete()
return 0
;;
set)
__zfs_complete_ordered_arguments "$(__zpool_get_editable_properties)" "$(__zpool_list_pools)" $cur
__zfs_complete_ordered_arguments "$(__zpool_get_editable_properties)" "$(__zpool_list_pools)" "$cur"
__zfs_complete_nospace
return 0
;;
add|attach|clear|create|detach|offline|online|remove|replace)
local pools="$(__zpool_list_pools)"
pools="$(__zpool_list_pools)"
# shellcheck disable=SC2086
if __zfs_argument_chosen $pools
then
_filedir
Expand Down
4 changes: 4 additions & 0 deletions contrib/bpftrace/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
include $(top_srcdir)/config/Shellcheck.am

EXTRA_DIST = \
taskqlatency.bt \
zfs-trace.sh

SHELLCHECKSCRIPTS = zfs-trace.sh
1 change: 1 addition & 0 deletions contrib/dracut/02zfsexpandknowledge/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include $(top_srcdir)/config/Substfiles.am
include $(top_srcdir)/config/Shellcheck.am

pkgdracutdir = $(dracutdir)/modules.d/02zfsexpandknowledge
pkgdracut_SCRIPTS = \
Expand Down
1 change: 1 addition & 0 deletions contrib/dracut/90zfs/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include $(top_srcdir)/config/Substfiles.am
include $(top_srcdir)/config/Shellcheck.am

pkgdracutdir = $(dracutdir)/modules.d/90zfs
pkgdracut_SCRIPTS = \
Expand Down
2 changes: 1 addition & 1 deletion contrib/dracut/90zfs/module-setup.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ install() {
# shellcheck disable=SC2050
if [ @LIBFETCH_DYNAMIC@ != 0 ]; then
for d in $libdirs; do
[ -e "$d"/@LIBFETCH_SONAME@ ] && dracut_install "$d"/@LIBFETCH_SONAME@
[ -e "$d/"@LIBFETCH_SONAME@ ] && dracut_install "$d/"@LIBFETCH_SONAME@
done
fi
dracut_install @mounthelperdir@/mount.zfs
Expand Down
3 changes: 3 additions & 0 deletions contrib/dracut/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
include $(top_srcdir)/config/Shellcheck.am

SUBDIRS = 02zfsexpandknowledge 90zfs
SHELLCHECKDIRS = $(SUBDIRS)

EXTRA_DIST = README.dracut.markdown
3 changes: 3 additions & 0 deletions contrib/initramfs/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
include $(top_srcdir)/config/Shellcheck.am

initrddir = /usr/share/initramfs-tools

dist_initrd_SCRIPTS = \
zfsunlock

SUBDIRS = conf.d conf-hooks.d hooks scripts
SHELLCHECKDIRS = hooks scripts

EXTRA_DIST = \
README.initramfs.markdown
1 change: 1 addition & 0 deletions contrib/initramfs/hooks/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include $(top_srcdir)/config/Substfiles.am
include $(top_srcdir)/config/Shellcheck.am

hooksdir = /usr/share/initramfs-tools/hooks

Expand Down
7 changes: 6 additions & 1 deletion contrib/initramfs/scripts/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
include $(top_srcdir)/config/Shellcheck.am

scriptsdir = /usr/share/initramfs-tools/scripts

dist_scripts_DATA = \
dist_scripts_SCRIPTS = \
zfs

SUBDIRS = local-top

SHELLCHECKDIRS = $(SUBDIRS)
SHELLCHECK_SHELL = sh
2 changes: 2 additions & 0 deletions contrib/initramfs/scripts/local-top/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include $(top_srcdir)/config/Shellcheck.am

localtopdir = /usr/share/initramfs-tools/scripts/local-top

dist_localtop_SCRIPTS = \
Expand Down
Loading

0 comments on commit c3ef9f7

Please sign in to comment.