1:255.13-alt1
[systemd_ALT.git] / coccinelle / run-coccinelle.sh
blobcd951790b9ddc649b861e24b612714f06150efd9
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 set -e
5 # Exclude following paths from the Coccinelle transformations
6 EXCLUDED_PATHS=(
7 "src/boot/efi/*"
8 "src/shared/linux/*"
9 "src/basic/linux/*"
10 # Symlinked to test-bus-vtable-cc.cc, which causes issues with the IN_SET macro
11 "src/libsystemd/sd-bus/test-bus-vtable.c"
12 "src/libsystemd/sd-journal/lookup3.c"
15 TOP_DIR="$(git rev-parse --show-toplevel)"
16 ARGS=()
18 # Create an array from files tracked by git...
19 mapfile -t FILES < <(git ls-files ':/*.[ch]')
20 # ...and filter everything that matches patterns from EXCLUDED_PATHS
21 for excl in "${EXCLUDED_PATHS[@]}"; do
22 # shellcheck disable=SC2206
23 FILES=(${FILES[@]//$excl})
24 done
26 case "$1" in
27 -i)
28 ARGS+=(--in-place)
29 shift
31 esac
33 if ! parallel -h >/dev/null; then
34 echo 'Please install GNU parallel (package "parallel")'
35 exit 1
38 [[ ${#@} -ne 0 ]] && SCRIPTS=("$@") || SCRIPTS=("$TOP_DIR"/coccinelle/*.cocci)
40 for script in "${SCRIPTS[@]}"; do
41 echo "--x-- Processing $script --x--"
42 TMPFILE="$(mktemp)"
43 echo "+ spatch --sp-file $script ${ARGS[*]} ..."
44 parallel --halt now,fail=1 --keep-order --noswap --max-args=20 \
45 spatch --macro-file="$TOP_DIR/coccinelle/macros.h" --smpl-spacing --sp-file "$script" "${ARGS[@]}" ::: "${FILES[@]}" \
46 2>"$TMPFILE" || cat "$TMPFILE"
47 echo -e "--x-- Processed $script --x--\n"
48 done