2020# Standard color definitions
2121GREEN=" \033[32m"
2222RED=" \033[31m"
23- BLUE=" \033[94m"
24- BOLD=" \033[1m"
2523NORMAL=" \033[0m"
2624
2725info ()
@@ -109,7 +107,23 @@ gh_error_simple()
109107# Identify shell scripts that should be linted with shellcheck.
110108shellcheck-targets ()
111109{
112- git ls-files -z -- " *.sh" " scripts/*" " scripts/**/*"
110+ local file
111+
112+ # Emit every tracked file that explicitly ends with .sh.
113+ while IFS= read -r -d ' ' file; do
114+ printf ' %s\0' " $file "
115+ done < <( git ls-files -z -- ' *.sh' )
116+
117+ # Add extensionless shell scripts that live under scripts/.
118+ while IFS= read -r -d ' ' file; do
119+ if [[ -L $file || ! -f $file ]]; then
120+ continue
121+ fi
122+
123+ if head -n1 " $file " | grep -qE ' ^#!.*/(env )?(ba|da|k|mk|z|)sh' ; then
124+ printf ' %s\0' " $file "
125+ fi
126+ done < <( git ls-files -z -- ' scripts/*' ' scripts/**/*' )
113127}
114128
115129run-shellcheck ()
@@ -125,18 +139,7 @@ run-shellcheck()
125139 local file
126140 local -a files=()
127141 while IFS= read -r -d ' ' file; do
128- if [[ -L $file || ! -f $file ]]; then
129- continue
130- fi
131- case " $file " in
132- * .sh)
133- files+=(" $file " )
134- continue
135- ;;
136- esac
137- if head -n1 " $file " | grep -qE ' ^#!.*/(env )?(ba|da|k|mk|z|)sh' ; then
138- files+=(" $file " )
139- fi
142+ files+=(" $file " )
140143 done < <( shellcheck-targets)
141144
142145 if [[ ${# files[@]} == 0 ]]; then
@@ -146,7 +149,7 @@ run-shellcheck()
146149 fi
147150
148151 local shellcheck_out
149- if ! shellcheck_out=$( shellcheck --format=gcc " ${files[@]} " 2>&1 ) ; then
152+ if ! shellcheck_out=$( shellcheck --severity=warning " ${files[@]} " 2>&1 ) ; then
150153 gh_error_simple " Shellcheck error" " $shellcheck_out "
151154 error " Lint shellcheck"
152155 SUCCESS=false
@@ -165,7 +168,7 @@ checkerr "Lint nix" "$(nixpkgs-fmt --check "$ROOT")"
165168gh_group_end
166169
167170gh_group_start " Linting shell scripts with shfmt"
168- checkerr " Lint shell" " $( shfmt -s -l -i 2 -ci -fn $( shfmt -f $( git grep -l ' ' :/) ) ) "
171+ checkerr " Lint shell" " $( shfmt -s -l -i 2 -ci -fn " $( shfmt -f " $( git grep -l ' ' :/) " ) " ) "
169172gh_group_end
170173
171174gh_group_start " Linting shell scripts with shellcheck"
185188gh_group_end
186189
187190gh_group_start " Linting c files with clang-format"
188- checkerr " Lint C" " $( clang-format $( git ls-files " :/*.c" " :/*.h" ) --Werror --dry-run 2>&1 | grep " error:" | cut -d ' :' -f 1,2 | tr ' :' ' ' ) "
191+ checkerr " Lint C" " $( clang-format " $( git ls-files " :/*.c" " :/*.h" ) " --Werror --dry-run 2>&1 | grep " error:" | cut -d ' :' -f 1,2 | tr ' :' ' ' ) "
189192gh_group_end
190193
191194check-eol-dry-run ()
@@ -207,22 +210,22 @@ check-spdx()
207210 local success=true
208211 for file in $( git ls-files -- " :/" " :/!:*.json" " :/!:*.png" " :/!:*LICENSE*" " :/!:.git*" " :/!:flake.lock" ) ; do
209212 # Ignore symlinks
210- if [[ ! -L $file && $( grep " SPDX-License-Identifier:" $file | wc -l) == 0 ]]; then
213+ if [[ ! -L $file && $( grep " SPDX-License-Identifier:" " $file " | wc -l) == 0 ]]; then
211214 gh_error " $file " " ${line:- 1} " " Missing license header error" " $file is missing SPDX License header"
212215 success=false
213216 fi
214217 done
215218 for file in $( git ls-files -- " *.[chsS]" " *.py" " *.mk" " *.yml" " **/Makefile*" " :/!proofs/cbmc/*.py" " :/!examples/bring_your_own_fips202/custom_fips202/tiny_sha3/*" ) ; do
216219 # Ignore symlinks
217- if [[ ! -L $file && $( grep " Copyright (c) The mldsa-native project authors" $file | wc -l) == 0 ]]; then
220+ if [[ ! -L $file && $( grep " Copyright (c) The mldsa-native project authors" " $file " | wc -l) == 0 ]]; then
218221 gh_error " $file " " ${line:- 1} " " Missing copyright header error" " $file is missing copyright header"
219222 success=false
220223 fi
221224 done
222225 # For source files in dev/* and mldsa/*, we enforce `Apache-2.0 OR ISC OR MIT`
223226 for file in $( git ls-files -- " *.[chsSi]" | grep " ^dev/\|^mldsa/" ) ; do
224227 # Ignore symlinks
225- if [[ ! -L $file && $( grep " SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT" $file | wc -l) == 0 ]]; then
228+ if [[ ! -L $file && $( grep " SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT" " $file " | wc -l) == 0 ]]; then
226229 gh_error " $file " " ${line:- 1} " " Missing license header error" " $file is not licensed under 'Apache-2.0 OR ISC OR MIT'"
227230 success=false
228231 fi
@@ -243,7 +246,7 @@ gh_group_end
243246
244247check-autogenerated-files ()
245248{
246- if python3 $ROOT /scripts/autogen --dry-run; then
249+ if python3 " $ROOT " /scripts/autogen --dry-run; then
247250 info " Check native auto-generated files"
248251 gh_summary_success " Check native auto-generated files"
249252 else
@@ -259,7 +262,7 @@ gh_group_end
259262
260263check-magic ()
261264{
262- if python3 $ROOT /scripts/check-magic > /dev/null; then
265+ if python3 " $ROOT " /scripts/check-magic > /dev/null; then
263266 info " Check magic constants"
264267 gh_summary_success " Check magic constants"
265268 else
279282
280283check-contracts ()
281284{
282- if python3 $ROOT /scripts/check-contracts > /dev/null; then
285+ if python3 " $ROOT " /scripts/check-contracts > /dev/null; then
283286 info " Check contracts"
284287 gh_summary_success " Check contracts"
285288 else
0 commit comments