From 3d457528d282697417130fb47e4d1161d1934e80 Mon Sep 17 00:00:00 2001 From: Ramon Roche Date: Mon, 9 Feb 2026 19:12:52 -0800 Subject: [PATCH] clang-tidy: gate NuttX-only driver libs by platform instead of exclude list The clang-tidy CI target builds against the SITL (px4_sitl_default-clang) compilation database. Three libraries in src/lib/drivers/ were unconditionally added via add_subdirectory(), causing them to appear in compile_commands.json despite requiring NuttX-only headers: - mcp_common: includes px4_platform/gpio/mcp.hpp (NuttX platform GPIO) - smbus: extends device::I2C which resolves to the NuttX I2C driver - smbus_sbs: includes smbus/SMBus.hpp, same I2C dependency chain When clang-tidy analyzed these files it failed on clang-diagnostic-error (fatal: header not found) since the platform headers don't exist in SITL. The previous commit worked around this by adding the paths to CLANG_TIDY_EXCLUDE_EXTRA in the Makefile, but the proper fix is to prevent these libraries from entering the compilation database at all. Gate mcp_common, smbus, and smbus_sbs behind if(PX4_PLATFORM STREQUAL "nuttx") in src/lib/drivers/CMakeLists.txt. This follows the established pattern already used by the device/ library in the same directory, which conditionally includes NuttX-specific sources (CDev.cpp, I2C.cpp, SPI.cpp) while compiling posix stubs for SITL. The other libraries in the directory (accelerometer, gyroscope, led, magnetometer, rangefinder) are pure abstractions over uORB topics and internal utilities with no platform-specific hardware dependencies, so they compile fine on all platforms without any gating. Remove the now-unnecessary mcp_common and smbus paths from CLANG_TIDY_EXCLUDE_EXTRA, keeping only the emscripten failsafe exclusion (requires the emscripten SDK, not a platform build issue). Signed-off-by: Ramon Roche --- Makefile | 5 ++--- src/lib/drivers/CMakeLists.txt | 9 ++++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 3fed0ae854..5c4bb6308a 100644 --- a/Makefile +++ b/Makefile @@ -497,14 +497,13 @@ px4_sitl_default-clang: # - Test code (allowed looser style) # - Example code (educational, not production) # - Vendored third-party code (e.g., CMSIS_5) -# - NuttX-only drivers that depend on platform headers unavailable in SITL builds -# (MCP GPIO, SMBus/I2C) +# - NuttX-only drivers excluded at CMake level (mcp_common, smbus); GPIO excluded here # - Emscripten failsafe web build (requires emscripten SDK not present in container) # # To add manual exclusions, append to CLANG_TIDY_EXCLUDE_EXTRA below. # Submodules are automatically excluded - no action needed when adding new ones. CLANG_TIDY_SUBMODULES := $(shell git config --file .gitmodules --get-regexp path | awk '{print $$2}' | tr '\n' '|' | sed 's/|$$//') -CLANG_TIDY_EXCLUDE_EXTRA := src/systemcmds/tests|src/examples|src/modules/gyro_fft/CMSIS_5|src/lib/drivers/mcp_common|src/drivers/gpio|src/lib/drivers/smbus|src/modules/commander/failsafe/emscripten +CLANG_TIDY_EXCLUDE_EXTRA := src/systemcmds/tests|src/examples|src/modules/gyro_fft/CMSIS_5|src/drivers/gpio|src/modules/commander/failsafe/emscripten CLANG_TIDY_EXCLUDE := $(CLANG_TIDY_SUBMODULES)|$(CLANG_TIDY_EXCLUDE_EXTRA) clang-tidy: px4_sitl_default-clang diff --git a/src/lib/drivers/CMakeLists.txt b/src/lib/drivers/CMakeLists.txt index 1511d19332..6ece18c65e 100644 --- a/src/lib/drivers/CMakeLists.txt +++ b/src/lib/drivers/CMakeLists.txt @@ -36,7 +36,10 @@ add_subdirectory(device) add_subdirectory(gyroscope) add_subdirectory(led) add_subdirectory(magnetometer) -add_subdirectory(mcp_common) add_subdirectory(rangefinder) -add_subdirectory(smbus) -add_subdirectory(smbus_sbs) + +if (${PX4_PLATFORM} STREQUAL "nuttx") + add_subdirectory(mcp_common) + add_subdirectory(smbus) + add_subdirectory(smbus_sbs) +endif()