meson: Rework clang-tidy integration to be done via unit tests
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.
This commit is contained in:
@@ -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
|
||||
|
||||
+32
-18
@@ -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')
|
||||
|
||||
@@ -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')
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <sys/resource.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "macro.h"
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "errno-list.h"
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
@@ -13,3 +13,5 @@ fundamental_sources = files(
|
||||
'string-util-fundamental.c',
|
||||
'uki.c',
|
||||
)
|
||||
|
||||
sources += fundamental_sources
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -11,6 +11,8 @@ libudev_sources = files(
|
||||
'libudev.c',
|
||||
)
|
||||
|
||||
sources += libudev_sources
|
||||
|
||||
############################################################
|
||||
|
||||
libudev_includes = [includes, include_directories('.')]
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "list.h"
|
||||
#include "memory-util.h"
|
||||
#include "set.h"
|
||||
#include "string-util.h"
|
||||
#include "time-util.h"
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "sd-event.h"
|
||||
#include "sd-varlink.h"
|
||||
|
||||
#include "assert-util.h"
|
||||
#include "list.h"
|
||||
|
||||
typedef struct Machine Machine;
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
Author: Auke Kok <auke-jan.h.kok@intel.com>
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "assert-util.h"
|
||||
#include "time-util.h"
|
||||
|
||||
#if ENABLE_UTMP
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user