mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
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 <mrpollo@gmail.com>
This commit is contained in:
parent
d74007dc87
commit
3d457528d2
5
Makefile
5
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
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user