]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
meson: Rework clang-tidy integration to be done via unit tests
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 15 May 2025 13:09:27 +0000 (15:09 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 20 May 2025 08:29:59 +0000 (10:29 +0200)
Instead of using run-clang-tidy.py with its own scheduling, let's
just gather a list of source files ourselves and then use that to
add a unit test for each source file that runs clang-tidy on the
source file.

We also add a bit of logic to run clang-tidy on most header files
as well for extra coverage. This uncovered various header files that
were not standalone so this commit also includes fixes to make sure
the clang-tidy tests are all green.

We can also use this in a later commit to run clang-include-cleaner
on each source file in the same way.

21 files changed:
.github/workflows/linter.yml
meson.build
src/basic/meson.build
src/basic/rlimit-util.h
src/basic/uid-range.h
src/basic/virt.h
src/boot/meson.build
src/core/meson.build
src/core/show-status.h
src/fundamental/meson.build
src/journal/journald-stream.h
src/journal/journald-sync.h
src/libsystemd-network/meson.build
src/libsystemd/meson.build
src/libudev/meson.build
src/login/logind-seat.h
src/machine/operation.h
src/shared/meson.build
src/shared/smack-util.h
src/shared/utmp-wtmp.h
src/sysupdate/sysupdate-partition.h

index b4ab5769ae590358a38810a317aedc5c48da8f66..5aca56290d2d8aa56ad6c626e91c09925f364a41 100644 (file)
@@ -74,4 +74,4 @@ jobs:
         run: mkosi sandbox -- env CC=clang CXX=clang++ meson setup build
 
       - name: Run clang-tidy
-        run: mkosi sandbox -- ninja -C build clang-tidy
+        run: mkosi sandbox -- meson test -C build --suite=clang-tidy --print-errorlogs --no-stdsplit
index aeff1b3629c2665c8fbcfbb681030f9e33cf1a47..5dd5f348aa79fc91e64d8f85d241aab0da231221 100644 (file)
@@ -15,7 +15,7 @@ project('systemd', 'c',
 
 add_test_setup(
         'default',
-        exclude_suites : ['integration-tests'],
+        exclude_suites : ['clang-tidy', 'integration-tests'],
         is_default : true,
 )
 
@@ -2002,6 +2002,7 @@ executables_by_name = {}
 objects_by_name = {}
 fuzzer_exes = []
 generated_sources = [version_h, vmlinux_h_dependency]
+sources = []
 
 # binaries that have --help and are intended for use by humans,
 # usually, but not always, installed in /bin.
@@ -2470,6 +2471,10 @@ foreach dict : executables
 
         executables_by_name += { name : exe }
 
+        if not name.endswith('.standalone')
+                sources += dict.get('sources', [])
+        endif
+
         if dict.has_key('extract')
                 objects_by_name += {
                         name : {
@@ -2829,23 +2834,32 @@ endif
 
 alias_target('gensources', generated_sources)
 
-run_clang_tidy = find_program('run-clang-tidy', required : false)
-if run_clang_tidy.found()
-        run_target(
-                'clang-tidy',
-                command : [
-                        run_clang_tidy,
-                        '-use-color',
-                        '-quiet',
-                        '-p', meson.project_build_root(),
-                        # There seems to be a bug in clang-tidy where by even with --quiet some
-                        # messages from clang's own diagnostics engine leak through:
-                        #     X warnings generated.
-                        # Until this is fixed upstream, we use -fno-caret-diagnostics to suppress these.
-                        '-extra-arg=-fno-caret-diagnostics',
-                ],
-                depends : generated_sources
-        )
+clang_tidy = find_program('clang-tidy', required : false)
+if meson.version().version_compare('>=1.4.0')
+        foreach source : sources
+                if fs.name(source).endswith('.h')
+                        continue
+                endif
+
+                inputs = [source]
+
+                header = source.full_path().replace('.c', '.h')
+                if fs.exists(header)
+                        inputs += header
+                endif
+
+                foreach input : inputs
+                        if clang_tidy.found()
+                                test(
+                                        'clang-tidy-@0@'.format(fs.name(input)),
+                                        clang_tidy,
+                                        args : ['-p', meson.project_build_root(), input],
+                                        suite : 'clang-tidy',
+                                        depends : generated_sources,
+                                )
+                        endif
+                endforeach
+        endforeach
 endif
 
 check_api_docs_sh = find_program('tools/check-api-docs.sh')
index 44b90c2e768050b43330c945835b7961a1cd65fe..df363f6048e2867b1fe9d9d452a2e59a3f2d21a1 100644 (file)
@@ -118,6 +118,8 @@ basic_sources = files(
         'xattr-util.c',
 )
 
+sources += basic_sources
+
 missing_audit_h = files('missing_audit.h')
 missing_socket_h = files('missing_socket.h')
 
index ad48e315501d09ab6f6bc9564305cafde7467310..dd1fef439689db8d349bf1b5c15eeeecbe0c92b5 100644 (file)
@@ -2,6 +2,7 @@
 #pragma once
 
 #include <sys/resource.h>
+#include <sys/types.h>
 
 #include "macro.h"
 
index 197085a60b124cd905e77501dae00cb1a5628cb1..e1965cf9b7d51500b729d8a96f7d1492e50f7602 100644 (file)
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include <errno.h>
 #include <stdbool.h>
 #include <sys/types.h>
 
index 8193d4a760807a994821967e1d828c86b55de750..e4fdaca9769d2dae8447650f8223b2a6c8fdbe1f 100644 (file)
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include <errno.h>
 #include <stdbool.h>
 
 #include "errno-list.h"
index 48d03b5b807ef8ec18bf33c69fbb9bd7b32c1528..dffd5db88eafd93362e8504cab5c1a9eac5b5425 100644 (file)
@@ -348,6 +348,11 @@ if host_machine.cpu_family() in ['aarch64', 'arm', 'x86_64', 'x86']
         systemd_boot_sources += files('bcd.c')
 endif
 
+sources += libefi_sources
+sources += systemd_boot_sources
+sources += stub_sources
+sources += addon_sources
+
 boot_targets = []
 efi_elf_binaries = []
 efi_archspecs = [
index 659dc9b7ea50117d179971a96bf9c92930ee0fe1..24843ec789da89296fdd7d0bb0516ebacc4f019e 100644 (file)
@@ -78,6 +78,8 @@ if conf.get('BPF_FRAMEWORK') == 1
                 restrict_ifaces_skel_h]
 endif
 
+sources += libcore_sources
+
 load_fragment_gperf_gperf = custom_target(
         'load-fragment-gperf.gperf',
         input : 'load-fragment-gperf.gperf.in',
index a51616f75aa0f675d0503babf01e6fb2592c1660..1986985c210775df03bba118f5481e1923719f63 100644 (file)
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include <errno.h>
 #include <stdarg.h>
 #include <stdbool.h>
 
index 5536be6e4c4ad6dfdfc270eecfd81253404c5b3f..6bc26caad2b1d2fae7ed830aed2cc52721534473 100644 (file)
@@ -13,3 +13,5 @@ fundamental_sources = files(
         'string-util-fundamental.c',
         'uki.c',
 )
+
+sources += fundamental_sources
index a22b1360494042bd0048508e1944aded5ad15224..cb55970059d6b4a76784cbde81f6341ae760f558 100644 (file)
@@ -1,13 +1,19 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-typedef struct Manager Manager;
-typedef struct StdoutStream StdoutStream;
-typedef struct StreamSyncReq StreamSyncReq;
+#include <sys/socket.h>
+
+#include "sd-event.h"
+#include "sd-id128.h"
 
 #include "fdset.h"
 #include "list.h"
 
+typedef struct ClientContext ClientContext;
+typedef struct Manager Manager;
+typedef struct StdoutStream StdoutStream;
+typedef struct StreamSyncReq StreamSyncReq;
+
 typedef enum StdoutStreamState {
         STDOUT_STREAM_IDENTIFIER,
         STDOUT_STREAM_UNIT_ID,
index 5f042ece96abcde9be4d7f626f18e916b8d5e071..4ef4aa4952ef8d1cc2b9c320286c61e3a673ca85 100644 (file)
@@ -1,14 +1,16 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-typedef struct Manager Manager;
-typedef struct StreamSyncReq StreamSyncReq;
-typedef struct SyncReq SyncReq;
+#include "sd-varlink.h"
 
 #include "journald-stream.h"
 #include "list.h"
 #include "macro.h"
 
+typedef struct Manager Manager;
+typedef struct StreamSyncReq StreamSyncReq;
+typedef struct SyncReq SyncReq;
+
 /* Encapsulates the synchronization request data we need to keep per STDOUT stream. Primarily a byte counter
  * to count down. */
 struct StreamSyncReq {
index a6de329627b7e624b5a79c56a323b0ec82d2d694..6b36c2eb649ba58d97848fd27a078769cebe6e6e 100644 (file)
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 
-sources = files(
+libsystemd_network_sources = files(
         'arp-util.c',
         'dhcp-network.c',
         'dhcp-option.c',
@@ -36,9 +36,11 @@ sources = files(
         'sd-radv.c',
 )
 
+sources += libsystemd_network_sources
+
 libsystemd_network = static_library(
         'systemd-network',
-        sources,
+        libsystemd_network_sources,
         include_directories : includes,
         implicit_include_directories : false,
         dependencies : userspace,
index 60b73f4da1a19ea605d327829af5887a8a316ed1..57fc116929a9999e6455def3b374136cf0ac67e9 100644 (file)
@@ -137,6 +137,8 @@ libsystemd_sources = files(
   + sd_login_sources + sd_json_sources + sd_varlink_sources \
   + sd_path_sources + sd_netlink_sources + sd_network_sources
 
+sources += libsystemd_sources
+
 libsystemd_c_args = ['-fvisibility=default']
 
 libsystemd_static = static_library(
index e5c0c8361be1b32bf7d030dac8bb04a70abbcd9b..43959640b9f346b1e2179629bb57965e06d5adde 100644 (file)
@@ -11,6 +11,8 @@ libudev_sources = files(
         'libudev.c',
 )
 
+sources += libudev_sources
+
 ############################################################
 
 libudev_includes = [includes, include_directories('.')]
index 2dc57686e9ecb7236b18ac6f7e4a144c5ebb6372..c39136330325b7c24235c2760268bef1ea3a2eb7 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "list.h"
 #include "memory-util.h"
+#include "set.h"
 #include "string-util.h"
 #include "time-util.h"
 
index 1fd8d42a2ef943b2f3b88339a11e62e2929f9852..330ef0bf98b8f143e2944fe9e5299d97cef87938 100644 (file)
@@ -7,6 +7,7 @@
 #include "sd-event.h"
 #include "sd-varlink.h"
 
+#include "assert-util.h"
 #include "list.h"
 
 typedef struct Machine Machine;
index d57bd93da1fc6ebe7c60b3277958298977f950b1..3f70ddbfd52334277e06aba01e3db68d9acfa445 100644 (file)
@@ -317,6 +317,7 @@ ethtool_link_mode_h = custom_target(
 
 generated_sources += ethtool_link_mode_h
 shared_sources += ethtool_link_mode_h
+sources += shared_sources
 
 fname = 'ethtool-link-mode.xml'
 ethtool_link_mode_xml = custom_target(
index e380de3dd74818d4c77116a521678256cf61da45..5bd2cea38bc52ebec6e4e6cac508eb9ae5f3ebca 100644 (file)
@@ -7,6 +7,7 @@
   Author: Auke Kok <auke-jan.h.kok@intel.com>
 ***/
 
+#include <errno.h>
 #include <stdbool.h>
 #include <sys/types.h>
 
index 2e04fac404726ef6e048d2da144f74aafea954a4..8577d9b013d3e06642d365737e2824388bd715b5 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdbool.h>
 #include <sys/types.h>
 
+#include "assert-util.h"
 #include "time-util.h"
 
 #if ENABLE_UTMP
index 094d8e0ca49be03b3bf0aea60a3ab7f0f8e412cf..15324013f3be158e4329f6e1ad9426094755124f 100644 (file)
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include <errno.h>
 #include <inttypes.h>
 #include <sys/types.h>