run individual spatch form check-cocci.sh

Add util/check-cocci.sh support for a command-line argument which is a
path to a spatch file. Running `util/check-cocci.sh` runs all the spatch
in `cocci` folder. Running `util/check-cocci.sh cocci/foo.spatch` only
run the spatch `cocci/foo.spatch`.

Any command line parameters after `--` are forwarded to `spatch`
command, for instance:

`util/check-cocci.sh -- --debug`
`util/check-cocci.sh cocci/foo.spatch -- --debug`

Will (1) run all spatch files in cocci/ with --debug spatch option and
(2) run only `cocci/foo.spatch` with --debug options.
This commit is contained in:
Colin Vidal 2025-10-14 14:01:42 +02:00
parent 9e8fd9f4d7
commit 085bf46a09

View file

@ -12,11 +12,16 @@
# information regarding copyright ownership.
ret=0
for spatch in cocci/*.spatch; do
patch="$(dirname "$spatch")/$(basename "$spatch" .spatch).patch"
run_spatch() {
local spatch=$1
shift
local spatchargs="$@"
local patch="$(dirname "$spatch")/$(basename "$spatch" .spatch).patch"
: >"$patch"
echo "Applying semantic patch $spatch..."
spatch --jobs "${TEST_PARALLEL_JOBS:-1}" --sp-file "$spatch" --use-gitgrep --dir "." --very-quiet --include-headers "$@" >>"$patch" 2>cocci.stderr
spatch --jobs "${TEST_PARALLEL_JOBS:-1}" --sp-file "$spatch" --use-gitgrep --dir "." --include-headers $spatchargs >>"$patch" 2>cocci.stderr
cat cocci.stderr
if grep -q -e "parse error" cocci.stderr; then
ret=1
@ -27,8 +32,35 @@ for spatch in cocci/*.spatch; do
else
rm "$patch"
fi
}
spatchargs=""
spatchfile=""
for arg in "$@"; do
if [ "$arg" = "--" ]; then
shift
spatchargs="$@"
break
fi
if [ -z "$spatchfile" ]; then
spatchfile="$arg"
shift
else
echo "USAGE: $0 [spatch-file] [-- spatch arguments]"
exit 1
fi
done
if [ -n "$spatchfile" ]; then
run_spatch $spatchfile $spatchargs
else
for spatch in cocci/*.spatch; do
run_spatch $spatch --very-quiet $spatchargs
done
fi
rm -f cocci.stderr
exit $ret