]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
run individual spatch form check-cocci.sh
authorColin Vidal <colin@isc.org>
Tue, 14 Oct 2025 12:01:42 +0000 (14:01 +0200)
committerColin Vidal <colin@isc.org>
Wed, 22 Oct 2025 06:41:26 +0000 (08:41 +0200)
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.

util/check-cocci.sh

index 1f749b137a3b6fe076b92870b8b9e4845187845b..5dd382c6ad58d33199485acc9a42fbeec22eb40f 100755 (executable)
 # 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