From eaddd45ee0f2f8ec7f9232dc0af3be3c5e5583ed Mon Sep 17 00:00:00 2001 From: qhdwight Date: Sun, 15 Sep 2024 11:55:08 -0700 Subject: [PATCH] Update bash scripts --- bootstrap.sh | 10 ++++----- build.sh | 2 +- build_ci.sh | 2 +- style.sh | 52 +++++++++++++++++++++++++++++++++++-------- units/units_eigen.hpp | 3 +++ 5 files changed, 53 insertions(+), 16 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index 1f93a51f..e4432299 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -50,16 +50,16 @@ echo -e "${GREY_BOLD}Using ${CATKIN_PATH} as ROS workspace${NC}" readonly MROVER_PATH=${CATKIN_PATH}/src/mrover FIRST_TIME_SETUP=false -if [ ! -d ${MROVER_PATH} ]; then +if [ ! -d "${MROVER_PATH}" ]; then echo -e "${GREY_BOLD}Creating ROS workspace ...${NC}" - mkdir -p ${CATKIN_PATH}/src - git clone git@github.com:umrover/mrover-ros2 ${CATKIN_PATH}/src/mrover - cd ${CATKIN_PATH}/src/mrover + mkdir -p "${CATKIN_PATH}"/src + git clone git@github.com:umrover/mrover-ros2 "${CATKIN_PATH}"/src/mrover + cd "${CATKIN_PATH}"/src/mrover FIRST_TIME_SETUP=true fi echo -e "${GREY_BOLD}Using Ansible to finish up ...${NC}" -${MROVER_PATH}/ansible.sh dev.yml +"${MROVER_PATH}"/ansible.sh dev.yml if [ "${FIRST_TIME_SETUP}" ]; then echo -e "${GREY_BOLD}All done! Welcome to MRover!${NC}" diff --git a/build.sh b/build.sh index 6fc32d8e..1f640485 100755 --- a/build.sh +++ b/build.sh @@ -14,4 +14,4 @@ colcon build \ --cmake-args -G Ninja -W no-dev -DCMAKE_BUILD_TYPE=RelWithDebInfo \ --symlink-install \ --event-handlers console_direct+ \ - $@ + "$@" diff --git a/build_ci.sh b/build_ci.sh index 0fbae0bf..07d01641 100755 --- a/build_ci.sh +++ b/build_ci.sh @@ -14,4 +14,4 @@ colcon build \ --cmake-args -G Ninja -W no-dev -D CMAKE_BUILD_TYPE=Release -D MROVER_CI=ON \ --symlink-install \ --event-handlers console_direct+ \ - $@ + "$@" diff --git a/style.sh b/style.sh index ae012938..ba3febf7 100755 --- a/style.sh +++ b/style.sh @@ -28,9 +28,9 @@ function print_update_error() { } function find_executable() { - local readonly executable="$1" - local readonly version="$2" - local readonly path=$(which "${executable}") + local -r executable="$1" + local -r version="$2" + local -r path=$(which "${executable}") if [ ! -x "${path}" ]; then echo -e "${RED}[Error] Could not find ${executable}${NC}" print_update_error @@ -44,24 +44,58 @@ function find_executable() { ## Check that all tools are installed -readonly CLANG_FORMAT_PATH=$(find_executable clang-format-18 18.1.8) +readonly CLANG_FORMAT_PATH=$(find_executable clang-format-18 18.1) readonly BLACK_PATH=$(find_executable black 24.8.0) 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 +) + echo "Style checking C++ ..." -find ./perception ./lie ./esw ./simulator -regex '.*\.\(cpp\|hpp\|h\)' -exec "${CLANG_FORMAT_PATH}" "${CLANG_FORMAT_ARGS[@]}" -i {} \; +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 echo "Done" +# Add new directories with Python code here: +readonly PYTHON_LINT_DIRS=( + ./navigation + ./localization + ./scripts + ./state_machine + ./lie + ./superstructure +) +readonly PYTHON_STYLE_DIRS=( + "${PYTHON_LINT_DIRS[@]}" + ./launch +) + echo echo "Style checking Python with black ..." -"$BLACK_PATH" "${BLACK_ARGS[@]}" . --exclude=venv +"${BLACK_PATH}" "${BLACK_ARGS[@]}" "${PYTHON_STYLE_DIRS[@]}" echo -echo "Style checking Python with mypy ..." -# TODO(quintin): Add other subteam folders and scripts folder -"$MYPY_PATH" --config-file=mypy.ini --check ./navigation ./scripts +echo "Linting Python with mypy ..." +"${MYPY_PATH}" --config-file=mypy.ini --check "${PYTHON_LINT_DIRS[@]}" + +if command -v shellcheck &> /dev/null; then + echo + echo "Linting bash scripts with shellcheck ..." + readonly SHELL_FILES=$(find . -depth 1 -name "*.sh") + for file in $SHELL_FILES; do + # SC2155 is separate declaration and command. + shellcheck "${file}" --exclude=SC2155 + done +fi if [ $# -eq 0 ] || [ "$1" != "--fix" ]; then echo diff --git a/units/units_eigen.hpp b/units/units_eigen.hpp index 5b1faad7..86a51994 100644 --- a/units/units_eigen.hpp +++ b/units/units_eigen.hpp @@ -1,5 +1,8 @@ #pragma once +// Including this file provides baseline compatibility with Eigen. +// Should be able to use unit types in Eigen matrices. + #include "units.hpp" #include