From 521d8f69f9182a3d96e51b1df139c81302c026ef Mon Sep 17 00:00:00 2001 From: Patrick Williams Date: Wed, 27 Oct 2021 09:30:41 -0500 Subject: repotest: refactor shellcheck slightly Refactor the shellcheck implementation so that: 1. Files are checked by extension if their `file` type doesn't match a known list. Some shell scripts do not use the proper shebang and end up not being detected by `file`; attempt to revert to extension in that case. 2. Facilitate easier addition of multiple linting tools for other file types. A follow up commit will add 'json' linting with only a few changes. Signed-off-by: Patrick Williams Change-Id: I5ce60432c4bd123d9d9c14466505c2d4b2477959 --- meta-phosphor/scripts/run-repotest | 54 ++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 11 deletions(-) (limited to 'meta-phosphor/scripts/run-repotest') diff --git a/meta-phosphor/scripts/run-repotest b/meta-phosphor/scripts/run-repotest index dc4e87ca1..8c47e536c 100755 --- a/meta-phosphor/scripts/run-repotest +++ b/meta-phosphor/scripts/run-repotest @@ -87,6 +87,7 @@ meta-ampere/meta-jade/recipes-ampere/platform/ampere-platform-init/ampere_platfo meta-ampere/meta-jade/recipes-ampere/platform/mtjade-gpio-config/ampere_gpio_utils.sh meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/ampere_host_check.sh meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/ampere_power_util.sh +meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/gpio-defs.sh meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/gpio-lib.sh meta-ampere/meta-jade/recipes-phosphor/console/obmc-console/ampere_uartmux_ctrl.sh meta-ampere/meta-jade/recipes-phosphor/console/obmc-console/obmc-console-server-setup.sh @@ -119,6 +120,10 @@ meta-google/recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.sh.in meta-google/recipes-google/networking/files/gbmc-ip-monitor-test.sh meta-google/recipes-google/networking/files/gbmc-ip-monitor.sh meta-google/recipes-google/networking/files/gbmc-mac-config.sh.in +meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-from-ra.sh +meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-gw-src.sh +meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-nft.sh +meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-ula.sh meta-google/recipes-google/networking/google-usb-network/usb_network.sh meta-google/recipes-google/networking/google-usb-network/usb_network_test.sh meta-google/recipes-google/networking/network-sh/lib.sh @@ -144,6 +149,7 @@ meta-ibm/recipes-phosphor/mboxd/mboxd/check_pnor_format.sh meta-ingrasys/meta-zaius/recipes-phosphor/chassis/avsbus-control/zaius_avsbus.sh meta-ingrasys/meta-zaius/recipes-phosphor/chassis/vcs-control/zaius_vcs.sh meta-inventec/meta-transformers/recipes-phosphor/init/transformers-init/transformers-init.sh +meta-openpower/recipes-bsp/pdata/files/power-target.sh meta-openpower/recipes-phosphor/dump/phosphor-debug-collector/plugins.d/guard meta-openpower/recipes-phosphor/network/first-boot-set-hostname/first-boot-set-hostname.sh meta-openpower/recipes-phosphor/network/first-boot-set-mac/first-boot-set-mac.sh @@ -173,13 +179,27 @@ meta-quanta/meta-gsj/recipes-gsj/quanta-nvme-powerctrl/files/nvme_powerctrl_libr meta-quanta/meta-gsj/recipes-gsj/quanta-nvme-powerctrl/files/nvme_powermanager.sh meta-quanta/meta-gsj/recipes-gsj/usb-network/files/usb_network.sh meta-quanta/meta-gsj/recipes-phosphor/fans/phosphor-pid-control/fan-control.sh +meta-quanta/meta-gsj/recipes-phosphor/fans/phosphor-pid-control/fan-default-speed.sh meta-quanta/meta-olympus-nuvoton/recipes-olympus-nuvoton/power/first-boot-set-psu/first-boot-set-psu.sh +meta-quanta/meta-olympus-nuvoton/recipes-phosphor/fans/phosphor-pid-control/fan-full-speed.sh meta-quanta/meta-q71l/recipes-phosphor/quanta-powerctrl/files/init_once.sh meta-quanta/meta-q71l/recipes-phosphor/quanta-powerctrl/files/poweroff.sh meta-quanta/meta-q71l/recipes-phosphor/quanta-powerctrl/files/poweron.sh meta-yadro/meta-nicole/recipes-phosphor/chassis/avsbus-control/avsbus-control.sh " +types=(shell) +# shellcheck disable=SC2034 +check_shell="shellcheck -x" + +for t in "${types[@]}"; do + check_cmd="check_${t}" + if ! which "${!check_cmd%% *}" > /dev/null 2>&1; then + eval "${check_cmd}=\"echo WARNING: Skipping $t due to missing command:\"" + echo "${!check_cmd}" + fi +done + non_bbfiles=$(git ls-files -- \ ':!:poky/**' \ ':!:meta-security/**' \ @@ -188,22 +208,34 @@ non_bbfiles=$(git ls-files -- \ | grep -v -e "\.patch$" -e "\.bb$" -e "\.bbappend$") for f in $non_bbfiles; do - file_type=$(file "$f") - case $file_type in + unset file_type + file_info=$(file "$f") + case $file_info in *shell\ script*) - if ! shellcheck -x "$f"; then - if [[ $lint_exempt == *$f* ]]; then - echo "EXEMPT: $f" - else - echo "FAILED: $f" - false - fi - fi + file_type="shell" ;; *) - ;; + case $f in + *.sh) + file_type="shell" + ;; + + esac esac + + if [ -n "$file_type" ]; then + check_cmd="check_${file_type}" + if ! eval "${!check_cmd} $f"; then + if [[ $lint_exempt == *$f* ]]; then + echo "EXEMPT: $f" + else + echo "FAILED: $f" + false + fi + fi + fi + done echo "Repo test passed" -- cgit v1.2.3