From 9b5895be12029846011a092a9059fe4b014e0a03 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 23 Apr 2025 15:21:11 +0200 Subject: [PATCH] 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 00000000000..f716a6650b3 --- /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 00000000000..6e0889f0807 --- /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 032c010b7d0..65a121306a5 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 -- 2.47.3