From 98a8117eb95b1d1a8819733062a0f1f78da9a018 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 23 Apr 2025 15:26:39 +0200 Subject: [PATCH 1/3] Add .clangd configuration file that disables the unused include check The clangd include checker is rather broken and is littered with false positives in our codebase, so let's disable the feature until it improves a bit. --- .clangd | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .clangd diff --git a/.clangd b/.clangd new file mode 100644 index 0000000000..8cc437ab81 --- /dev/null +++ b/.clangd @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +Diagnostics: + UnusedIncludes: None From 9e3d048bd0ce74b6285b47c8328de60d0ae63827 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 23 Apr 2025 15:17:33 +0200 Subject: [PATCH 2/3] ci: Use mkosi in linter workflow Let's reuse the mkosi tools tree to get all the tools we need instead of pulling them from pypi. --- .github/workflows/linter.yml | 27 +++++++++++++++++---------- tools/fetch-mkosi.py | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 0907e4358b..032c010b7d 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -36,29 +36,36 @@ jobs: VALIDATE_ALL_CODEBASE: false VALIDATE_GITHUB_ACTIONS: true + - uses: systemd/mkosi@dbb4020beee2cdf250f93a425794f1cf8b0fe693 + - name: Check that tabs are not used in Python code run: sh -c '! git grep -P "\\t" -- src/boot/generate-hwids-section.py src/ukify/ukify.py test/integration-tests/integration-test-wrapper.py' - - name: Install ruff and mypy + - name: Build tools tree run: | - python3 -m pip install --break-system-packages --upgrade setuptools wheel pip - python3 -m pip install --break-system-packages mypy types-Pillow ruff + tee mkosi/mkosi.local.conf < Date: Wed, 23 Apr 2025 15:21:11 +0200 Subject: [PATCH 3/3] ci: Add basic clang-tidy check to linter workflow Let's add a basic clang-tidy check to the linter workflow. This gives us the following: - A check so that we don't introduce any new cyclic header dependencies - A check to make sure all of our header files are standalone, as clang-tidy will fail to parse header files that don't include all their dependencies. --- .clang-tidy | 12 ++++++++++++ .clang-tidy-ignore | 12 ++++++++++++ .github/workflows/linter.yml | 10 ++++++++++ 3 files changed, 34 insertions(+) create mode 100644 .clang-tidy create mode 100644 .clang-tidy-ignore diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000000..f716a6650b --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +--- +Checks: ' + -*, + misc-header-include-cycle +' +WarningsAsErrors: '*' +HeaderFileExtensions: + - h +ImplementationFileExtensions: + - c +... diff --git a/.clang-tidy-ignore b/.clang-tidy-ignore new file mode 100644 index 0000000000..6e0889f080 --- /dev/null +++ b/.clang-tidy-ignore @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +man/* +# These contain external headers that we don't want to check. +src/basic/include/* +# clang-tidy can't parse BPF source files. +src/core/bpf/* +src/network/bpf/* +src/nsresourced/bpf/* +# The glib headers contain cyclic dependencies and clang-tidy +# can't distinguish between our code and glib headers so we +# exclude this test. +src/libsystemd/sd-bus/test-bus-marshal.c diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 032c010b7d..65a121306a 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -69,3 +69,13 @@ jobs: echo "Please run 'ruff format' on the above files or apply the diffs below manually" mkosi sandbox -- ruff format --check --quiet --diff src/boot/generate-hwids-section.py src/test/generate-sym-test.py src/ukify/ukify.py test/integration-tests/integration-test-wrapper.py fi + + - name: Configure meson + run: mkosi sandbox -- env CC=clang CXX=clang++ meson setup build + + # Make sure all generated source files are actually generated by doing a full build. + - name: Build systemd + run: mkosi sandbox -- ninja -C build + + - name: Run clang-tidy + run: mkosi sandbox -- ninja -C build clang-tidy