]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
coccinelle: simplify file exclusions main
authorFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 13 Mar 2026 16:09:40 +0000 (17:09 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sat, 14 Mar 2026 23:56:53 +0000 (23:56 +0000)
Use Coccinelle's "depends on" directive to exclude files from certain
transformations. This should make them a bit simpler and possibly
faster, since we don't have to shell out to Python.

Unfortunately, this works only for file/directory exclusions. For
function and other more complex exclusions we still need to use Python,
at least for now.

Also, completely drop the file exclusion for man/ in the xsprintf
transformation, since we filter out everything under man/ before we even
run Coccinelle (in run-coccinelle.sh).

coccinelle/dup-fcntl.cocci
coccinelle/isempty.cocci
coccinelle/sd_build_pair.cocci
coccinelle/timestamp-is-set.cocci
coccinelle/xsprintf.cocci
coccinelle/zz-drop-braces.cocci

index 2c87f70dc3d4fa1082dcd6404f4faed8390179df..434e48d51415a682abde9387932d8a660fc87a8b 100644 (file)
@@ -1,8 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
-@@
 /* We want to stick with dup() in test-fd-util.c */
-position p : script:python() { p[0].file != "src/test/test-fd-util.c" };
+@ depends on !(file in "src/test/test-fd-util.c") @
 expression fd;
 @@
-- dup@p(fd)
+- dup(fd)
 + fcntl(fd, F_DUPFD, 3)
index 20899708864997393998e26ee2f354c2a7cda95f..4a266c4195329a70658361a084ed81ccc3443f66 100644 (file)
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
-@@
 /* Disable this transformation for the test-string-util.c */
-position p : script:python() { p[0].file != "src/test/test-string-util.c" };
+@ depends on !(file in "src/test/test-string-util.c") @
 expression s;
 @@
 (
-- strv_length@p(s) == 0
+- strv_length(s) == 0
 + strv_isempty(s)
 |
-- strv_length@p(s) <= 0
+- strv_length(s) <= 0
 + strv_isempty(s)
 |
-- strv_length@p(s) > 0
+- strv_length(s) > 0
 + !strv_isempty(s)
 |
-- strv_length@p(s) != 0
+- strv_length(s) != 0
 + !strv_isempty(s)
 |
-- strlen@p(s) == 0
+- strlen(s) == 0
 + isempty(s)
 |
-- strlen@p(s) <= 0
+- strlen(s) <= 0
 + isempty(s)
 |
-- strlen@p(s) > 0
+- strlen(s) > 0
 + !isempty(s)
 |
-- strlen@p(s) != 0
+- strlen(s) != 0
 + !isempty(s)
 |
-- strlen_ptr@p(s) == 0
+- strlen_ptr(s) == 0
 + isempty(s)
 |
-- strlen_ptr@p(s) <= 0
+- strlen_ptr(s) <= 0
 + isempty(s)
 |
-- strlen_ptr@p(s) > 0
+- strlen_ptr(s) > 0
 + !isempty(s)
 |
-- strlen_ptr@p(s) != 0
+- strlen_ptr(s) != 0
 + !isempty(s)
 )
-@@
 /* Disable this transformation for the hashmap.h, set.h, test-hashmap.c, test-hashmap-plain.c */
-position p : script:python() {
-                p[0].file != "src/basic/hashmap.h" and
-                p[0].file != "src/basic/set.h" and
-                p[0].file != "src/test/test-hashmap.c" and
-                p[0].file != "src/test/test-hashmap-plain.c"
-        };
+@ depends on !(file in "src/basic/hashmap.h")
+           && !(file in "src/basic/set.h")
+           && !(file in "src/test/test-hashmap.c")
+           && !(file in "src/test/test-hashmap-plain.c") @
 expression s;
 @@
 (
-- hashmap_size@p(s) == 0
+- hashmap_size(s) == 0
 + hashmap_isempty(s)
 |
-- hashmap_size@p(s) <= 0
+- hashmap_size(s) <= 0
 + hashmap_isempty(s)
 |
-- hashmap_size@p(s) > 0
+- hashmap_size(s) > 0
 + !hashmap_isempty(s)
 |
-- hashmap_size@p(s) != 0
+- hashmap_size(s) != 0
 + !hashmap_isempty(s)
 |
-- ordered_hashmap_size@p(s) == 0
+- ordered_hashmap_size(s) == 0
 + ordered_hashmap_isempty(s)
 |
-- ordered_hashmap_size@p(s) <= 0
+- ordered_hashmap_size(s) <= 0
 + ordered_hashmap_isempty(s)
 |
-- ordered_hashmap_size@p(s) > 0
+- ordered_hashmap_size(s) > 0
 + !ordered_hashmap_isempty(s)
 |
-- ordered_hashmap_size@p(s) != 0
+- ordered_hashmap_size(s) != 0
 + !ordered_hashmap_isempty(s)
 |
-- set_size@p(s) == 0
+- set_size(s) == 0
 + set_isempty(s)
 |
-- set_size@p(s) <= 0
+- set_size(s) <= 0
 + set_isempty(s)
 |
-- set_size@p(s) > 0
+- set_size(s) > 0
 + !set_isempty(s)
 |
-- set_size@p(s) != 0
+- set_size(s) != 0
 + !set_isempty(s)
 |
-- ordered_set_size@p(s) == 0
+- ordered_set_size(s) == 0
 + ordered_set_isempty(s)
 |
-- ordered_set_size@p(s) <= 0
+- ordered_set_size(s) <= 0
 + ordered_set_isempty(s)
 |
-- ordered_set_size@p(s) > 0
+- ordered_set_size(s) > 0
 + !ordered_set_isempty(s)
 |
-- ordered_set_size@p(s) != 0
+- ordered_set_size(s) != 0
 + !ordered_set_isempty(s)
 )
 @@
index 8c9af38cb2d1345dc5aa486db57cbceb9753b43f..e97c273e71f34d36952dcc55c65596479e136c71 100644 (file)
@@ -1,22 +1,21 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
-@@
 /* Disable this transformation on test-json.c */
-position p : script:python() { p[0].file != "src/test/test-json.c" };
+@ depends on !(file in "src/test/test-json.c") @
 expression key, val;
 @@
 (
-- SD_JSON_BUILD_PAIR@p(key, SD_JSON_BUILD_BOOLEAN(val))
+- SD_JSON_BUILD_PAIR(key, SD_JSON_BUILD_BOOLEAN(val))
 + SD_JSON_BUILD_PAIR_BOOLEAN(key, val)
 |
-- SD_JSON_BUILD_PAIR@p(key, SD_JSON_BUILD_INTEGER(val))
+- SD_JSON_BUILD_PAIR(key, SD_JSON_BUILD_INTEGER(val))
 + SD_JSON_BUILD_PAIR_INTEGER(key, val)
 |
-- SD_JSON_BUILD_PAIR@p(key, SD_JSON_BUILD_STRING(val))
+- SD_JSON_BUILD_PAIR(key, SD_JSON_BUILD_STRING(val))
 + SD_JSON_BUILD_PAIR_STRING(key, val)
 |
-- SD_JSON_BUILD_PAIR@p(key, SD_JSON_BUILD_UNSIGNED(val))
+- SD_JSON_BUILD_PAIR(key, SD_JSON_BUILD_UNSIGNED(val))
 + SD_JSON_BUILD_PAIR_UNSIGNED(key, val)
 |
-- SD_JSON_BUILD_PAIR@p(key, SD_JSON_BUILD_VARIANT(val))
+- SD_JSON_BUILD_PAIR(key, SD_JSON_BUILD_VARIANT(val))
 + SD_JSON_BUILD_PAIR_VARIANT(key, val)
 )
index 2d251fa2057e9d5996c2a29b329f83b6e5ca1734..34f37458f74f3368eea53f91cf57bc771bd24d45 100644 (file)
@@ -1,9 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
-@@
+/* We want to stick with the literal expression in the implementation of timestamp_is_set(), i.e. in time-util.h */
+@ depends on !(file in "src/basic/time-util.h") @
 expression x;
 constant USEC_INFINITY = USEC_INFINITY;
-/* We want to stick with the literal expression in the implementation of timestamp_is_set(), i.e. in time-util.c */
-position p : script:python() { p[0].file != "src/basic/time-util.h" };
 @@
 (
 - x > 0 && x < USEC_INFINITY
@@ -12,7 +11,7 @@ position p : script:python() { p[0].file != "src/basic/time-util.h" };
 - x < USEC_INFINITY && x > 0
 + timestamp_is_set(x)
 |
-- x@p > 0 && x != USEC_INFINITY
+- x > 0 && x != USEC_INFINITY
 + timestamp_is_set(x)
 |
 - x != USEC_INFINITY && x > 0
index 3b38090652e798edbf9f51c9e73d1676ec2548f8..669734946caa425e0ab0af96f4a21fec7e019374 100644 (file)
@@ -1,8 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 @@
-position p : script:python() { not p[0].file.startswith("man/") };
 expression e, fmt;
 expression list vaargs;
 @@
-- snprintf@p(e, sizeof(e), fmt, vaargs);
+- snprintf(e, sizeof(e), fmt, vaargs);
 + xsprintf(e, fmt, vaargs);
index 7a3382c9a7b9e2f13f54d64b7bbad7bb9b95cdf1..a1d9f8d4a34d5bcd0032a676a0d99f3f5241e1fb 100644 (file)
@@ -1,13 +1,12 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
-@@
-position p : script:python() { p[0].file != "src/journal/lookup3.c" };
-expression e,e1;
+@ depends on !(file in "src/journal/lookup3.c") @
+expression e, e1;
 @@
 - if (e) {
 + if (e)
 (
-  e1@p;
+  e1;
 |
-  return e1@p;
+  return e1;
 )
 - }