diff --git a/.clangd b/.clangd index 8cc437ab81..24886efe9e 100644 --- a/.clangd +++ b/.clangd @@ -1,4 +1,4 @@ # SPDX-License-Identifier: LGPL-2.1-or-later Diagnostics: - UnusedIncludes: None + UnusedIncludes: Strict diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 5aca56290d..252ae4eb6a 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -71,7 +71,7 @@ jobs: fi - name: Configure meson - run: mkosi sandbox -- env CC=clang CXX=clang++ meson setup build + run: mkosi sandbox -- env CC=clang CXX=clang++ meson setup -Dlocalegen-path=/usr/bin/locale-gen -Dcompat-mutable-uid-boundaries=true build - name: Run clang-tidy run: mkosi sandbox -- meson test -C build --suite=clang-tidy --print-errorlogs --no-stdsplit diff --git a/meson.build b/meson.build index 4618520bca..c1cdfb2c8e 100644 --- a/meson.build +++ b/meson.build @@ -2841,6 +2841,10 @@ alias_target('gensources', generated_sources) clang_tidy = find_program('clang-tidy', required : false) if meson.version().version_compare('>=1.4.0') foreach source : sources + if systemd_headers.contains(source) + continue + endif + if not source.full_path().endswith('.c') and not source.full_path().endswith('.h') continue endif @@ -2848,7 +2852,7 @@ if meson.version().version_compare('>=1.4.0') inputs = [source] header = source.full_path().replace('.c', '.h') - if fs.exists(header) and header != source.full_path() + if fs.exists(header) and header != source.full_path() and header != libudev_h_path inputs += header endif diff --git a/src/core/bpf/restrict_fs/restrict-fs-skel.h b/src/core/bpf/restrict_fs/restrict-fs-skel.h index 412cf62eda..825b8131f9 100644 --- a/src/core/bpf/restrict_fs/restrict-fs-skel.h +++ b/src/core/bpf/restrict_fs/restrict-fs-skel.h @@ -6,6 +6,8 @@ * fine given that LGPL-2.1-or-later downgrades to GPL if needed. */ +#include "bpf-dlopen.h" + /* libbpf is used via dlopen(), so rename symbols */ #define bpf_object__open_skeleton sym_bpf_object__open_skeleton #define bpf_object__load_skeleton sym_bpf_object__load_skeleton diff --git a/src/core/bpf/restrict_ifaces/restrict-ifaces-skel.h b/src/core/bpf/restrict_ifaces/restrict-ifaces-skel.h index f937490954..f0675f270b 100644 --- a/src/core/bpf/restrict_ifaces/restrict-ifaces-skel.h +++ b/src/core/bpf/restrict_ifaces/restrict-ifaces-skel.h @@ -6,6 +6,8 @@ * fine given that LGPL-2.1-or-later downgrades to GPL if needed. */ +#include "bpf-dlopen.h" + /* libbpf is used via dlopen(), so rename symbols */ #define bpf_object__open_skeleton sym_bpf_object__open_skeleton #define bpf_object__load_skeleton sym_bpf_object__load_skeleton diff --git a/src/core/bpf/socket_bind/socket-bind-skel.h b/src/core/bpf/socket_bind/socket-bind-skel.h index e0d16269cd..c92eae002d 100644 --- a/src/core/bpf/socket_bind/socket-bind-skel.h +++ b/src/core/bpf/socket_bind/socket-bind-skel.h @@ -6,6 +6,8 @@ * fine given that LGPL-2.1-or-later downgrades to GPL if needed. */ +#include "bpf-dlopen.h" + /* libbpf is used via dlopen(), so rename symbols */ #define bpf_object__open_skeleton sym_bpf_object__open_skeleton #define bpf_object__load_skeleton sym_bpf_object__load_skeleton diff --git a/src/fundamental/iovec-util-fundamental.h b/src/fundamental/iovec-util-fundamental.h index 4c86197e6f..024dd9bf78 100644 --- a/src/fundamental/iovec-util-fundamental.h +++ b/src/fundamental/iovec-util-fundamental.h @@ -2,7 +2,6 @@ #pragma once #if !SD_BOOT -#include #include #endif @@ -15,10 +14,6 @@ struct iovec { void *iov_base; size_t iov_len; }; - -DISABLE_WARNING_REDUNDANT_DECLS; -void free(void *p); -REENABLE_WARNING; #endif /* This accepts both const and non-const pointers */ diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h index 6a75d7864a..69bbeead48 100644 --- a/src/fundamental/macro-fundamental.h +++ b/src/fundamental/macro-fundamental.h @@ -396,6 +396,10 @@ assert_cc(sizeof(long long) == sizeof(intmax_t)); */ #define STRLEN(x) (sizeof(""x"") - sizeof(typeof(x[0]))) +DISABLE_WARNING_REDUNDANT_DECLS; +void free(void *p); +REENABLE_WARNING; + #define mfree(memory) \ ({ \ free(memory); \ diff --git a/src/test/generate-sym-test.py b/src/test/generate-sym-test.py index 7b5ded936c..5aaf372c1d 100755 --- a/src/test/generate-sym-test.py +++ b/src/test/generate-sym-test.py @@ -19,7 +19,9 @@ def process_sym_file(file: IO[str]) -> None: print(f' {{ "{m[1]}", {m[1]} }},') -def process_header_file(file: IO[str]) -> None: +def process_header_file(file: IO[str]) -> str: + text = '' + for line in file: if ( line.startswith('#') @@ -43,22 +45,24 @@ def process_header_file(file: IO[str]) -> None: # Functions m = re.search(r'^(\S+\s+)+\**(\w+)\s*\(', line) if m: - print(f' {{ "{m[2]}", {m[2]} }},') + text += f' {{ "{m[2]}", {m[2]} }},\n' continue # Variables m = re.search(r'^extern\s', line) if m: n = line.split()[-1].rstrip(';') - print(f' {{ "{n}", &{n} }},') + text += f' {{ "{n}", &{n} }},\n' continue # Functions defined by macro m = re.search(r'_SD_DEFINE_POINTER_CLEANUP_FUNC\(\w+,\s*(\w+)\)', line) if m: - print(f' {{ "{m[1]}", {m[1]} }},') + text += f' {{ "{m[1]}", {m[1]} }},\n' continue + return text + def process_source_file(file: IO[str]) -> None: for line in file: @@ -107,7 +111,9 @@ print("""/* SPDX-License-Identifier: LGPL-2.1-or-later */ """) for header in sys.argv[3:]: - print('#include "{}"'.format(header.split('/')[-1])) + with open(header, 'r') as f: + if process_header_file(f): + print('#include "{}"'.format(header.split('/')[-1])) print(""" /* We want to check deprecated symbols too, without complaining */ @@ -129,7 +135,7 @@ print(""" {} for header in sys.argv[3:]: with open(header, 'r') as f: - process_header_file(f) + print(process_header_file(f), end='') print(""" {} }, symbols_from_source[] = {""")