From 2505049c2f6abe76b313a56822cb43203005bf56 Mon Sep 17 00:00:00 2001 From: Ponnuvel Palaniyappan Date: Thu, 14 May 2026 12:46:34 +0200 Subject: [PATCH] Add clang-tidy support for static analysis Signed-off-by: Ponnuvel Palaniyappan --- .github/workflows/pr-build.yaml | 17 +++++++++++++++++ Makefile | 17 ++++++++++++++++- tox.ini | 9 ++++++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-build.yaml b/.github/workflows/pr-build.yaml index 78b40da..df5d543 100644 --- a/.github/workflows/pr-build.yaml +++ b/.github/workflows/pr-build.yaml @@ -106,3 +106,20 @@ jobs: - name: Run Makefile build run: make -j radostrace osdtrace + + clang-tidy: + runs-on: ubuntu-24.04 + steps: + - name: Checkout code and submodules + uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y g++ clang clang-tidy libelf-dev libc6-dev-i386 libdw-dev + + - name: Run clang-tidy + run: make -j clang-tidy diff --git a/Makefile b/Makefile index 379464a..de3fdfd 100755 --- a/Makefile +++ b/Makefile @@ -78,7 +78,7 @@ else endif # Main targets -.PHONY: all clean +.PHONY: all clean clang-tidy all: $(OSDTRACE_SRC)/ceph_btf_local.h $(EMBEDDED_DWARF_HDR) $(PROG_OBJS) install: @@ -116,6 +116,21 @@ clean: $(call msg,CLEAN) $(Q)rm -rf $(OUTPUT) $(PROG_OBJS) $(DOCDIR)/*.8.gz $(DOCDIR)/*.in $(OSDTRACE_SRC)/ceph_btf_local.h $(EMBEDDED_DWARF_HDR) +# clang-tidy static analysis (requires skeleton headers in .output/) +CLANG_TIDY ?= clang-tidy +TIDY_SRCS := $(OSDTRACE_SRC)/osdtrace.cc \ + $(OSDTRACE_SRC)/radostrace.cc \ + $(OSDTRACE_SRC)/kfstrace.cc \ + $(OSDTRACE_SRC)/dwarf_parser.cc \ + $(OSDTRACE_SRC)/version_utils.cc + +clang-tidy: $(OUTPUT)/osdtrace.skel.h $(OUTPUT)/radostrace.skel.h $(OUTPUT)/kfstrace.skel.h $(EMBEDDED_DWARF_HDR) + $(call msg,TIDY) + $(Q)for src in $(TIDY_SRCS); do \ + printf ' %-8s %s\n' "TIDY" "$$src"; \ + $(CLANG_TIDY) $$src -- $(CXXFLAGS) $(VERSION_DEFINES) || exit 1; \ + done + $(OUTPUT) $(OUTPUT)/libbpf $(BPFTOOL_OUTPUT): $(call msg,MKDIR,$@) $(Q)mkdir -p $@ diff --git a/tox.ini b/tox.ini index 11c8fd7..20bbc75 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = lint, pylint, pep8, test +envlist = lint, pylint, pep8, test, clang-tidy [vars] @@ -31,3 +31,10 @@ deps = commands = pytest --fixtures tests/ pytest tests/ -v + +[testenv:clang-tidy] +description = run clang-tidy static analysis on C++ sources +skip_install = true +allowlist_externals = make +commands = + make clang-tidy