]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
coccinelle: explicitly undefine SD_BOOT
authorFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 25 Dec 2023 23:41:40 +0000 (00:41 +0100)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Tue, 26 Dec 2023 10:23:19 +0000 (11:23 +0100)
So Coccinelle doesn't pull in includes guarded by #if SD_BOOT.

For example:

$ head -n5 main.c
 #if FOO
 #include "foo.h"
 #else
 #include "bar.h"
 #endif

$ spatch --verbose-includes --recursive-includes --sp-file zz-drop-braces.cocci main.c
init_defs_builtins: /usr/lib64/coccinelle/standard.h
HANDLING: main.c
including ./foo.h
including ./bar.h

$ spatch --verbose-includes --recursive-includes --sp-file zz-drop-braces.cocci main.c --undefined FOO
init_defs_builtins: /usr/lib64/coccinelle/standard.h
HANDLING: main.c
including ./bar.h

coccinelle/run-coccinelle.sh

index bb72a493f08f300d43355f17fc3b943298a7d326..360f9268e5a33149170a9bd7de2621d36db8fc38 100755 (executable)
@@ -7,7 +7,6 @@ set -e
 #     that TEST(xsetxattr) yields test_xsetxattr() and uses just xsetxattr() in this case, which then conflicts
 #     with the tested xsetxattr() function, leading up to the whole test case getting skipped due to
 #     conflicting typedefs
-#   - something keeps pulling in src/boot/efi/*.h stuff, even though it's excluded
 #   - Coccinelle has issues with some of our more complex macros
 
 # Exclude following paths from the Coccinelle transformations
@@ -73,7 +72,9 @@ for script in "${SCRIPTS[@]}"; do
     # definitions (--include-headers-for-types) - otherwise we'd start formating them as well, which might be
     # unwanted, especially for includes we fetch verbatim from third-parties
     #
-    # 4) Use cache, since generating the full AST is _very_ expensive, i.e. the uncached run takes 15 - 30
+    # 4) Explicitly undefine the SD_BOOT symbol, so Coccinelle ignores includes guarded by #if SD_BOOT
+    #
+    # 5) Use cache, since generating the full AST is _very_ expensive, i.e. the uncached run takes 15 - 30
     # minutes (for one rule(!)), vs 30 - 90 seconds when the cache is populated. One major downside of the
     # cache is that it's quite big - ATTOW the cache takes around 15 GiB, but the performance boost is
     # definitely worth it
@@ -82,6 +83,7 @@ for script in "${SCRIPTS[@]}"; do
                -I src \
                --recursive-includes \
                --include-headers-for-types \
+               --undefined SD_BOOT \
                --smpl-spacing \
                --sp-file "$script" \
                "${ARGS[@]}" ::: "${FILES[@]}" \