Skip to content

Commit 521d8f6

Browse files
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 <[email protected]> Change-Id: I5ce60432c4bd123d9d9c14466505c2d4b2477959
1 parent 9958f39 commit 521d8f6

File tree

1 file changed

+43
-11
lines changed

1 file changed

+43
-11
lines changed

meta-phosphor/scripts/run-repotest

+43-11
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ meta-ampere/meta-jade/recipes-ampere/platform/ampere-platform-init/ampere_platfo
8787
meta-ampere/meta-jade/recipes-ampere/platform/mtjade-gpio-config/ampere_gpio_utils.sh
8888
meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/ampere_host_check.sh
8989
meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/ampere_power_util.sh
90+
meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/gpio-defs.sh
9091
meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/gpio-lib.sh
9192
meta-ampere/meta-jade/recipes-phosphor/console/obmc-console/ampere_uartmux_ctrl.sh
9293
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
119120
meta-google/recipes-google/networking/files/gbmc-ip-monitor-test.sh
120121
meta-google/recipes-google/networking/files/gbmc-ip-monitor.sh
121122
meta-google/recipes-google/networking/files/gbmc-mac-config.sh.in
123+
meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-from-ra.sh
124+
meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-gw-src.sh
125+
meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-nft.sh
126+
meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-ula.sh
122127
meta-google/recipes-google/networking/google-usb-network/usb_network.sh
123128
meta-google/recipes-google/networking/google-usb-network/usb_network_test.sh
124129
meta-google/recipes-google/networking/network-sh/lib.sh
@@ -144,6 +149,7 @@ meta-ibm/recipes-phosphor/mboxd/mboxd/check_pnor_format.sh
144149
meta-ingrasys/meta-zaius/recipes-phosphor/chassis/avsbus-control/zaius_avsbus.sh
145150
meta-ingrasys/meta-zaius/recipes-phosphor/chassis/vcs-control/zaius_vcs.sh
146151
meta-inventec/meta-transformers/recipes-phosphor/init/transformers-init/transformers-init.sh
152+
meta-openpower/recipes-bsp/pdata/files/power-target.sh
147153
meta-openpower/recipes-phosphor/dump/phosphor-debug-collector/plugins.d/guard
148154
meta-openpower/recipes-phosphor/network/first-boot-set-hostname/first-boot-set-hostname.sh
149155
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
173179
meta-quanta/meta-gsj/recipes-gsj/quanta-nvme-powerctrl/files/nvme_powermanager.sh
174180
meta-quanta/meta-gsj/recipes-gsj/usb-network/files/usb_network.sh
175181
meta-quanta/meta-gsj/recipes-phosphor/fans/phosphor-pid-control/fan-control.sh
182+
meta-quanta/meta-gsj/recipes-phosphor/fans/phosphor-pid-control/fan-default-speed.sh
176183
meta-quanta/meta-olympus-nuvoton/recipes-olympus-nuvoton/power/first-boot-set-psu/first-boot-set-psu.sh
184+
meta-quanta/meta-olympus-nuvoton/recipes-phosphor/fans/phosphor-pid-control/fan-full-speed.sh
177185
meta-quanta/meta-q71l/recipes-phosphor/quanta-powerctrl/files/init_once.sh
178186
meta-quanta/meta-q71l/recipes-phosphor/quanta-powerctrl/files/poweroff.sh
179187
meta-quanta/meta-q71l/recipes-phosphor/quanta-powerctrl/files/poweron.sh
180188
meta-yadro/meta-nicole/recipes-phosphor/chassis/avsbus-control/avsbus-control.sh
181189
"
182190

191+
types=(shell)
192+
# shellcheck disable=SC2034
193+
check_shell="shellcheck -x"
194+
195+
for t in "${types[@]}"; do
196+
check_cmd="check_${t}"
197+
if ! which "${!check_cmd%% *}" > /dev/null 2>&1; then
198+
eval "${check_cmd}=\"echo WARNING: Skipping $t due to missing command:\""
199+
echo "${!check_cmd}"
200+
fi
201+
done
202+
183203
non_bbfiles=$(git ls-files -- \
184204
':!:poky/**' \
185205
':!:meta-security/**' \
@@ -188,22 +208,34 @@ non_bbfiles=$(git ls-files -- \
188208
| grep -v -e "\.patch$" -e "\.bb$" -e "\.bbappend$")
189209

190210
for f in $non_bbfiles; do
191-
file_type=$(file "$f")
192-
case $file_type in
211+
unset file_type
212+
file_info=$(file "$f")
213+
case $file_info in
193214
*shell\ script*)
194-
if ! shellcheck -x "$f"; then
195-
if [[ $lint_exempt == *$f* ]]; then
196-
echo "EXEMPT: $f"
197-
else
198-
echo "FAILED: $f"
199-
false
200-
fi
201-
fi
215+
file_type="shell"
202216
;;
203217

204218
*)
205-
;;
219+
case $f in
220+
*.sh)
221+
file_type="shell"
222+
;;
223+
224+
esac
206225
esac
226+
227+
if [ -n "$file_type" ]; then
228+
check_cmd="check_${file_type}"
229+
if ! eval "${!check_cmd} $f"; then
230+
if [[ $lint_exempt == *$f* ]]; then
231+
echo "EXEMPT: $f"
232+
else
233+
echo "FAILED: $f"
234+
false
235+
fi
236+
fi
237+
fi
238+
207239
done
208240

209241
echo "Repo test passed"

0 commit comments

Comments
 (0)