From fdd738b1eb19a0f23df032669905995e94153169 Mon Sep 17 00:00:00 2001 From: qhdwight Date: Thu, 19 Sep 2024 16:49:45 -0700 Subject: [PATCH] Format, make CI actually fail if not formatted --- .github/workflows/ci.yml | 1 + perception/object_detector/object_detector.cpp | 5 ++--- perception/object_detector/pch.hpp | 2 +- perception/zed_wrapper/zed_wrapper.cpp | 3 +-- style.sh | 18 +++++++----------- 5 files changed, 12 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5e699b0b..883d6d03 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,7 @@ jobs: - name: Style Check run: . /home/mrover/ros2_ws/src/mrover/venv/bin/activate && cd $GITHUB_WORKSPACE/src/mrover/ && ./style.sh - name: Compiler Cache + if: github.event.pull_request.draft == false uses: hendrikmuhs/ccache-action@v1.2 - name: Build if: github.event.pull_request.draft == false diff --git a/perception/object_detector/object_detector.cpp b/perception/object_detector/object_detector.cpp index f6511b79..dc7f91e6 100644 --- a/perception/object_detector/object_detector.cpp +++ b/perception/object_detector/object_detector.cpp @@ -13,12 +13,11 @@ namespace mrover { {"hitcount_max", mObjMaxHitcount, 10}, {"model_name", mModelName, "Large-Dataset"}, {"model_score_threshold", mModelScoreThreshold, 0.75}, - {"model_nms_threshold", mModelNmsThreshold, 0.5} - }; + {"model_nms_threshold", mModelNmsThreshold, 0.5}}; ParameterWrapper::declareParameters(this, params); - std::filesystem::path packagePath = std::filesystem::path{ament_index_cpp::get_package_prefix("mrover")} / ".." / ".." / "src" / "mrover"; + std::filesystem::path packagePath = std::filesystem::path{ament_index_cpp::get_package_prefix("mrover")} / ".." / ".." / "src" / "mrover"; RCLCPP_INFO_STREAM(get_logger(), "Opening Model " << mModelName); diff --git a/perception/object_detector/pch.hpp b/perception/object_detector/pch.hpp index 81eda570..7ab5af34 100644 --- a/perception/object_detector/pch.hpp +++ b/perception/object_detector/pch.hpp @@ -28,10 +28,10 @@ #include // Ros Client Library +#include #include #include #include -#include // Messages #include "sensor_msgs/image_encodings.hpp" diff --git a/perception/zed_wrapper/zed_wrapper.cpp b/perception/zed_wrapper/zed_wrapper.cpp index 806efecb..cf35ca6b 100644 --- a/perception/zed_wrapper/zed_wrapper.cpp +++ b/perception/zed_wrapper/zed_wrapper.cpp @@ -48,8 +48,7 @@ namespace mrover { {"depth_maximum_distance", mDepthMaximumDistance, 12.0}, {"use_builtin_visual_odom", mUseBuiltinPosTracking, false}, {"use_pose_smoothing", mUsePoseSmoothing, true}, - {"use_area_memory", mUseAreaMemory, true} - }; + {"use_area_memory", mUseAreaMemory, true}}; ParameterWrapper::declareParameters(this, params); diff --git a/style.sh b/style.sh index ba3febf7..f4097ddf 100755 --- a/style.sh +++ b/style.sh @@ -3,6 +3,9 @@ # See: https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ set -Eeuo pipefail +# Prevent globbing from failing if no files match +shopt -s nullglob + readonly RED='\033[0;31m' readonly NC='\033[0m' readonly YELLOW_BOLD='\033[1;33m' @@ -19,7 +22,7 @@ CLANG_FORMAT_ARGS=( if [ $# -eq 0 ] || [ "$1" != "--fix" ]; then BLACK_ARGS+=("--diff") # Show difference BLACK_ARGS+=("--check") # Exit with non-zero code if changes are required (for CI) - CLANG_FORMAT_ARGS+=("--dry-run") + CLANG_FORMAT_ARGS+=("--dry-run" "--Werror") # Don't modify, exit with non-zero code if changes are required fi function print_update_error() { @@ -51,18 +54,11 @@ readonly MYPY_PATH=$(find_executable mypy 1.11.2) ## Run checks # Add new directories with C++ code here: -readonly CPP_DIRS=( - ./perception - ./lie - ./esw - ./simulator +readonly CPP_FILES=( + ./{perception,lie,esw,simulator}/**/*.{cpp,hpp,h,cu,cuh} ) - echo "Style checking C++ ..." -readonly CPP_FILES=$(find "${CPP_DIRS[@]}" -name "*.cpp" -o -name "*.hpp" -o -name "*.h" -o -name "*.cu") -for file in $CPP_FILES; do - "${CLANG_FORMAT_PATH}" "${CLANG_FORMAT_ARGS[@]}" -i "${file}" -done +"${CLANG_FORMAT_PATH}" "${CLANG_FORMAT_ARGS[@]}" -i "${CPP_FILES[@]}" echo "Done" # Add new directories with Python code here: