diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 00000000..1d2fb755 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,5 @@ +--- +Checks: "clang-analyzer-core-*" +WarningsAsErrors: '' +FormatStyle: none +HeaderFilterRegex: '^(?!/opt/ros/|/usr/).*' \ No newline at end of file diff --git a/.github/workflows/lint-and-format.yml b/.github/workflows/lint-and-format.yml index 7856e038..bd802d29 100644 --- a/.github/workflows/lint-and-format.yml +++ b/.github/workflows/lint-and-format.yml @@ -27,4 +27,4 @@ jobs: find ./src \ -path ./src/third-party -prune -o \ \( -name "*.h" -o -name "*.hpp" -o -name "*.cpp" \) -print \ - | xargs clang-format --dry-run --Werror + | xargs clang-format --dry-run --Werror \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 45746057..a4580612 100644 --- a/Dockerfile +++ b/Dockerfile @@ -158,7 +158,7 @@ FROM runtime AS dev RUN apt-get update && apt-get install -y --no-install-recommends \ git x11-apps ros-humble-desktop ros-dev-tools black pylint \ ros-humble-ament-cmake python3-colcon-common-extensions \ - python3-colcon-ros clang-format cuda-compiler-12-6 \ + python3-colcon-ros clang-format clang-tidy jq cuda-compiler-12-6 \ cuda-cudart-dev-12-6 cuda-driver-dev-12-6 libpng-dev ccache \ libc6-dev libssl-dev cuda-toolkit-12-6 libnvinfer10 \ libnvinfer-plugin10 libnvonnxparsers10 \ diff --git a/build.sh b/build.sh index 6a62a8bc..bf4368b6 100755 --- a/build.sh +++ b/build.sh @@ -10,4 +10,4 @@ find ./src -path ./src/third-party -prune -o \ rosdep install --from-paths src -i -r -y -colcon build --symlink-install --continue-on-error --cmake-args=-DCMAKE_BUILD_TYPE=Release --parallel-workers $(nproc) \ No newline at end of file +colcon build --symlink-install --continue-on-error --cmake-args -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON --parallel-workers $(nproc) diff --git a/linting-cpp.sh b/linting-cpp.sh new file mode 100755 index 00000000..d36e008d --- /dev/null +++ b/linting-cpp.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# To use this script: +# 1. Add the names of the projects you want to exclude to excludedProjects +# 2. Run the script: ./linting-cpp.sh +# Note: This script must be in the root directory because of build.sh + +# Additional checks can be added to the .clang-tidy file + +# List of excluded projects +excludedProjects=("third-party" "elevation_mapping" "interfaces" "kindr_msgs" + "kindr_ros" "ouster_ros" "ouster_sensor_msgs" "ublox" + "ublox_gps" "ublox_msgs" "ublox_serialization" + "zed_components" "zed_ros2" "zed_wrapper") + +rootPath=$(pwd) + +# Run build script to generate compile_commands.json for each CMake project +./build.sh + +excludedProjectsArgs=() + +# Format the excluded projects into an argument list that is read by find +for excludedProject in "${excludedProjects[@]}"; do + excludedProjectsArgs+=("-not" "-path" "*/$excludedProject/*") +done + +# Concatenate all compile_commands.json files into one file +find build -name compile_commands.json -exec jq '.[]' {} + \ + | jq -s '.' > build/compile_commands.json + +# Run clang-tidy +# The find command filters the excluded projects out +# All .cpp files in the included projects are linted (header files are also implicitly linted when included in a source file) +run-clang-tidy -p build $(find src -type f -name "*.cpp" "${excludedProjectsArgs[@]}") -extra-arg-before=-std=c++17 -j $(nproc) \ No newline at end of file