From 7707c828b2825c38936bd227d9f3f3d7c5f0746e Mon Sep 17 00:00:00 2001 From: Michael Ripperger Date: Wed, 17 Jan 2024 16:13:10 -0600 Subject: [PATCH 1/4] Added linter files and scripts --- .clang-format | 65 +++++++++ .cmake-format | 346 ++++++++++++++++++++++++++++++++++++++++++++++ .run-clang-format | 2 + .run-cmake-format | 2 + 4 files changed, 415 insertions(+) create mode 100644 .clang-format create mode 100644 .cmake-format create mode 100755 .run-clang-format create mode 100755 .run-cmake-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..27285ab --- /dev/null +++ b/.clang-format @@ -0,0 +1,65 @@ +--- +BasedOnStyle: Google +AccessModifierOffset: -2 +ConstructorInitializerIndentWidth: 2 +AlignEscapedNewlinesLeft: false +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AlwaysBreakTemplateDeclarations: true +AlwaysBreakBeforeMultilineStrings: false +BreakBeforeBinaryOperators: false +BreakBeforeTernaryOperators: false +BreakConstructorInitializersBeforeComma: true +BinPackParameters: true +ColumnLimit: 120 +ConstructorInitializerAllOnOneLineOrOnePerLine: true +DerivePointerBinding: false +PointerBindsToType: true +ExperimentalAutoDetectBinPacking: false +IndentCaseLabels: true +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 60 +PenaltyBreakString: 1 +PenaltyBreakFirstLessLess: 1000 +PenaltyExcessCharacter: 1000 +PenaltyReturnTypeOnItsOwnLine: 90 +SpacesBeforeTrailingComments: 2 +Cpp11BracedListStyle: false +Standard: Auto +IndentWidth: 2 +TabWidth: 2 +UseTab: Never +IndentFunctionDeclarationAfterType: false +SpacesInParentheses: false +SpacesInAngles: false +SpaceInEmptyParentheses: false +SpacesInCStyleCastParentheses: false +SpaceAfterControlStatementKeyword: true +SpaceBeforeAssignmentOperators: true +ContinuationIndentWidth: 4 +SortIncludes: false +SpaceAfterCStyleCast: false + +# Configure each individual brace in BraceWrapping +BreakBeforeBraces: Custom + +# Control of individual brace wrapping cases +BraceWrapping: { + AfterClass: 'true' + AfterControlStatement: 'true' + AfterEnum : 'true' + AfterFunction : 'true' + AfterNamespace : 'true' + AfterStruct : 'true' + AfterUnion : 'true' + BeforeCatch : 'true' + BeforeElse : 'true' + IndentBraces : 'false' +} +... diff --git a/.cmake-format b/.cmake-format new file mode 100644 index 0000000..e787b25 --- /dev/null +++ b/.cmake-format @@ -0,0 +1,346 @@ +#!/bin/python +# ---------------------------------- +# Options affecting listfile parsing +# ---------------------------------- +with section("parse"): + + # Specify structure for custom cmake functions + additional_commands = { + 'target_clang_tidy': { + 'pargs': {'nargs': 1}, + 'kwargs': { + 'ARGUMENTS': '*', + 'ENABLE': 1, + } + }, + 'target_include_what_you_use': { + 'pargs': {'nargs': 1}, + 'kwargs': { + 'ARGUMENTS': '*', + 'ENABLE': 1, + } + }, + 'include_what_you_use': { + 'pargs': {'nargs': 0}, + 'kwargs': { + 'ARGUMENTS': '*', + 'ENABLE': 1, + } + }, + 'target_cppcheck': { + 'pargs': {'nargs': 1}, + 'kwargs': { + 'ARGUMENTS': '*', + 'ENABLE': 1, + } + }, + 'cppcheck': { + 'pargs': {'nargs': 0}, + 'kwargs': { + 'ARGUMENTS': '*', + 'ENABLE': 1, + } + }, + 'configure_package': { + 'pargs': {'nargs': 0}, + 'kwargs': { + 'NAMESPACE': '?', + 'TARGETS': '*', + } + }, + 'add_gtest_discover_tests': { + 'pargs': {'nargs': 1}, + }, + 'add_run_tests_target': { + 'pargs': {'nargs': 0}, + 'kwargs': { + 'ENABLE': 1, + } + }, + 'add_run_benchmark_target': { + 'pargs': {'nargs': 0}, + 'kwargs': { + 'ENABLE': 1, + } + }, + 'target_cxx_version': { + 'pargs': {'nargs': 1}, + 'kwargs': { + 'INTERFACE': '+', + 'PUBLIC': '+', + 'PRIVATE': '+', + 'VERSION': 1, + } + }, + 'target_code_coverage': { + 'pargs': {'nargs': 1}, + 'kwargs': { + 'AUTO': '+', + 'ALL': '+', + 'EXTERNAL': '+', + 'PRIVATE': '+', + 'PUBLIC': '+', + 'INTERFACE': '+', + 'ENABLE': 1, + 'EXCLUDE': '*', + } + }, + 'add_code_coverage': { + 'pargs': {'nargs': 0}, + 'kwargs': { + 'ENABLE': 1, + } + }, + 'add_code_coverage_all_targets': { + 'pargs': {'nargs': 0}, + 'kwargs': { + 'ENABLE': 1, + 'EXCLUDE': '*', + } + }, + 'tesseract_cpack': { + 'pargs': {'nargs': 0}, + 'kwargs': { + 'VERSION': 1, + 'MAINTAINER': 1, + 'DESCRIPTION': 1, + 'LICENSE_FILE': 1, + 'README_FILE': 1, + 'LINUX_DEPENDS': '*', + 'WINDOWS_DEPENDS': '*', + } + }, + } + + # Override configurations per-command where available + override_spec = {} + + # Specify variable tags. + vartags = [] + + # Specify property tags. + proptags = [] + +# ----------------------------- +# Options affecting formatting. +# ----------------------------- +with section("format"): + + # Disable formatting entirely, making cmake-format a no-op + disable = False + + # How wide to allow formatted cmake files + line_width = 120 + + # How many spaces to tab for indent + tab_size = 2 + + # If true, lines are indented using tab characters (utf-8 0x09) instead of + # space characters (utf-8 0x20). In cases where the layout would + # require a fractional tab character, the behavior of the fractional + # indentation is governed by + use_tabchars = False + + # If is True, then the value of this variable indicates how + # fractional indentions are handled during whitespace replacement. If set to + # 'use-space', fractional indentation is left as spaces (utf-8 0x20). If set + # to `round-up` fractional indentation is replaced with a single tab character + # (utf-8 0x09) effectively shifting the column to the next tabstop + fractional_tab_policy = 'use-space' + + # If an argument group contains more than this many sub-groups (parg or kwarg + # groups) then force it to a vertical layout. + max_subgroups_hwrap = 3 + + # If a positional argument group contains more than this many arguments, then + # force it to a vertical layout. + max_pargs_hwrap = 3 + + # If a cmdline positional group consumes more than this many lines without + # nesting, then invalidate the layout (and nest) + max_rows_cmdline = 2 + + # If true, separate flow control names from their parentheses with a space + separate_ctrl_name_with_space = False + + # If true, separate function names from parentheses with a space + separate_fn_name_with_space = False + + # If a statement is wrapped to more than one line, than dangle the closing + # parenthesis on its own line. + dangle_parens = False + + # If the trailing parenthesis must be 'dangled' on its on line, then align it + # to this reference: `prefix`: the start of the statement, `prefix-indent`: + # the start of the statement, plus one indentation level, `child`: align to + # the column of the arguments + dangle_align = 'prefix' + + # If the statement spelling length (including space and parenthesis) is + # smaller than this amount, then force reject nested layouts. + min_prefix_chars = 4 + + # If the statement spelling length (including space and parenthesis) is larger + # than the tab width by more than this amount, then force reject un-nested + # layouts. + max_prefix_chars = 10 + + # If a candidate layout is wrapped horizontally but it exceeds this many + # lines, then reject the layout. + max_lines_hwrap = 2 + + # What style line endings to use in the output. + line_ending = 'unix' + + # Format command names consistently as 'lower' or 'upper' case + command_case = 'canonical' + + # Format keywords consistently as 'lower' or 'upper' case + keyword_case = 'unchanged' + + # A list of command names which should always be wrapped + always_wrap = [] + + # If true, the argument lists which are known to be sortable will be sorted + # lexicographicall + enable_sort = True + + # If true, the parsers may infer whether or not an argument list is sortable + # (without annotation). + autosort = False + + # By default, if cmake-format cannot successfully fit everything into the + # desired linewidth it will apply the last, most agressive attempt that it + # made. If this flag is True, however, cmake-format will print error, exit + # with non-zero status code, and write-out nothing + require_valid_layout = False + + # A dictionary mapping layout nodes to a list of wrap decisions. See the + # documentation for more information. + layout_passes = {} + +# ------------------------------------------------ +# Options affecting comment reflow and formatting. +# ------------------------------------------------ +with section("markup"): + + # What character to use for bulleted lists + bullet_char = '*' + + # What character to use as punctuation after numerals in an enumerated list + enum_char = '.' + + # If comment markup is enabled, don't reflow the first comment block in each + # listfile. Use this to preserve formatting of your copyright/license + # statements. + first_comment_is_literal = False + + # If comment markup is enabled, don't reflow any comment block which matches + # this (regex) pattern. Default is `None` (disabled). + literal_comment_pattern = None + + # Regular expression to match preformat fences in comments default= + # ``r'^\s*([`~]{3}[`~]*)(.*)$'`` + fence_pattern = '^\\s*([`~]{3}[`~]*)(.*)$' + + # Regular expression to match rulers in comments default= + # ``r'^\s*[^\w\s]{3}.*[^\w\s]{3}$'`` + ruler_pattern = '^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$' + + # If a comment line matches starts with this pattern then it is explicitly a + # trailing comment for the preceeding argument. Default is '#<' + explicit_trailing_pattern = '#<' + + # If a comment line starts with at least this many consecutive hash + # characters, then don't lstrip() them off. This allows for lazy hash rulers + # where the first hash char is not separated by space + hashruler_min_length = 10 + + # If true, then insert a space between the first hash char and remaining hash + # chars in a hash ruler, and normalize its length to fill the column + canonicalize_hashrulers = True + + # enable comment markup parsing and reflow + enable_markup = True + +# ---------------------------- +# Options affecting the linter +# ---------------------------- +with section("lint"): + + # a list of lint codes to disable + disabled_codes = [] + + # regular expression pattern describing valid function names + function_pattern = '[0-9a-z_]+' + + # regular expression pattern describing valid macro names + macro_pattern = '[0-9A-Z_]+' + + # regular expression pattern describing valid names for variables with global + # (cache) scope + global_var_pattern = '[A-Z][0-9A-Z_]+' + + # regular expression pattern describing valid names for variables with global + # scope (but internal semantic) + internal_var_pattern = '_[A-Z][0-9A-Z_]+' + + # regular expression pattern describing valid names for variables with local + # scope + local_var_pattern = '[a-z][a-z0-9_]+' + + # regular expression pattern describing valid names for privatedirectory + # variables + private_var_pattern = '_[0-9a-z_]+' + + # regular expression pattern describing valid names for public directory + # variables + public_var_pattern = '[A-Z][0-9A-Z_]+' + + # regular expression pattern describing valid names for function/macro + # arguments and loop variables. + argument_var_pattern = '[a-z][a-z0-9_]+' + + # regular expression pattern describing valid names for keywords used in + # functions or macros + keyword_pattern = '[A-Z][0-9A-Z_]+' + + # In the heuristic for C0201, how many conditionals to match within a loop in + # before considering the loop a parser. + max_conditionals_custom_parser = 2 + + # Require at least this many newlines between statements + min_statement_spacing = 1 + + # Require no more than this many newlines between statements + max_statement_spacing = 2 + max_returns = 6 + max_branches = 12 + max_arguments = 5 + max_localvars = 15 + max_statements = 50 + +# ------------------------------- +# Options affecting file encoding +# ------------------------------- +with section("encode"): + + # If true, emit the unicode byte-order mark (BOM) at the start of the file + emit_byteorder_mark = False + + # Specify the encoding of the input file. Defaults to utf-8 + input_encoding = 'utf-8' + + # Specify the encoding of the output file. Defaults to utf-8. Note that cmake + # only claims to support utf-8 so be careful when using anything else + output_encoding = 'utf-8' + +# ------------------------------------- +# Miscellaneous configurations options. +# ------------------------------------- +with section("misc"): + + # A dictionary containing any per-command configuration overrides. Currently + # only `command_case` is supported. + per_command = {} + diff --git a/.run-clang-format b/.run-clang-format new file mode 100755 index 0000000..db12c95 --- /dev/null +++ b/.run-clang-format @@ -0,0 +1,2 @@ +#!/bin/bash +find . -type f -regex '.*\.\(cpp\|hpp\|cc\|cxx\|h\|hxx\)' -exec clang-format -style=file -i {} \; diff --git a/.run-cmake-format b/.run-cmake-format new file mode 100755 index 0000000..fe66f6d --- /dev/null +++ b/.run-cmake-format @@ -0,0 +1,2 @@ +#!/bin/bash +find . \( -name CMakeLists.txt -o -name \*.cmake \) -exec cmake-format -i {} \; From 06e9c9894d70d2f7daed76c1842f80c58ffbf77f Mon Sep 17 00:00:00 2001 From: Michael Ripperger Date: Wed, 17 Jan 2024 16:14:36 -0600 Subject: [PATCH 2/4] Ran CMake format --- CMakeLists.txt | 88 ++++++++++++++++---------------------------------- 1 file changed, 27 insertions(+), 61 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c32bbc..47367d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,89 +3,55 @@ project(trajectory_preview) add_compile_options(-std=c++11) -find_package(catkin REQUIRED COMPONENTS - rviz - sensor_msgs - trajectory_msgs -) +find_package(catkin REQUIRED COMPONENTS rviz sensor_msgs trajectory_msgs) find_package(Qt5 REQUIRED COMPONENTS Widgets) catkin_package( INCLUDE_DIRS - include + include LIBRARIES - ${PROJECT_NAME}_widget - ${PROJECT_NAME}_panel + ${PROJECT_NAME}_widget + ${PROJECT_NAME}_panel CATKIN_DEPENDS - rviz - sensor_msgs - trajectory_msgs -) + rviz + sensor_msgs + trajectory_msgs) -########### -## Build ## -########### +# ###################################################################################################################### +# Build ## +# ###################################################################################################################### -include_directories( - include - ${catkin_INCLUDE_DIRS} - ${CMAKE_CURRENT_BINARY_DIR} -) +include_directories(include ${catkin_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}) -qt5_wrap_ui(UI_MOC - ui/trajectory_preview_widget.ui -) +qt5_wrap_ui(UI_MOC ui/trajectory_preview_widget.ui) -qt5_wrap_cpp(WIDGET_MOC - include/${PROJECT_NAME}/trajectory_preview_widget.h - src/trajectory_preview_impl.h -) +qt5_wrap_cpp(WIDGET_MOC include/${PROJECT_NAME}/trajectory_preview_widget.h src/trajectory_preview_impl.h) -qt5_wrap_cpp(PANEL_MOC - include/${PROJECT_NAME}/trajectory_preview_panel.h -) +qt5_wrap_cpp(PANEL_MOC include/${PROJECT_NAME}/trajectory_preview_panel.h) # Widget Library -add_library(${PROJECT_NAME}_widget - src/trajectory_preview_widget.cpp - ${UI_MOC} - ${WIDGET_MOC} -) -target_link_libraries(${PROJECT_NAME}_widget - ${catkin_LIBRARIES} - Qt5::Widgets -) +add_library(${PROJECT_NAME}_widget src/trajectory_preview_widget.cpp ${UI_MOC} ${WIDGET_MOC}) +target_link_libraries(${PROJECT_NAME}_widget ${catkin_LIBRARIES} Qt5::Widgets) # Panel Library -add_library(${PROJECT_NAME}_panel - src/trajectory_preview_panel.cpp - ${PANEL_MOC} -) -target_link_libraries(${PROJECT_NAME}_panel +add_library(${PROJECT_NAME}_panel src/trajectory_preview_panel.cpp ${PANEL_MOC}) +target_link_libraries( + ${PROJECT_NAME}_panel ${catkin_LIBRARIES} Qt5::Widgets - ${PROJECT_NAME}_widget -) + ${PROJECT_NAME}_widget) -############# -## Install ## -############# +# ###################################################################################################################### +# Install ## +# ###################################################################################################################### install( - TARGETS - ${PROJECT_NAME}_widget - ${PROJECT_NAME}_panel + TARGETS ${PROJECT_NAME}_widget ${PROJECT_NAME}_panel ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION} -) + RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}) -install(DIRECTORY include/${PROJECT_NAME}/ - DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} -) +install(DIRECTORY include/${PROJECT_NAME}/ DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}) -install(FILES - plugin_description.xml - DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} -) +install(FILES plugin_description.xml DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}) From 6b3c41dace5998debf7f030f9e6512e337f3e5f0 Mon Sep 17 00:00:00 2001 From: Michael Ripperger Date: Wed, 17 Jan 2024 16:16:13 -0600 Subject: [PATCH 3/4] Added CI files --- .github/workflows/clang_format.yml | 29 +++++++++++++++++++++ .github/workflows/cmake_format.yml | 26 +++++++++++++++++++ .github/workflows/ubuntu.yml | 41 ++++++++++++++++++++++++++++++ ci | 1 + 4 files changed, 97 insertions(+) create mode 100644 .github/workflows/clang_format.yml create mode 100644 .github/workflows/cmake_format.yml create mode 100644 .github/workflows/ubuntu.yml create mode 120000 ci diff --git a/.github/workflows/clang_format.yml b/.github/workflows/clang_format.yml new file mode 100644 index 0000000..d288de1 --- /dev/null +++ b/.github/workflows/clang_format.yml @@ -0,0 +1,29 @@ +name: Clang-Format + +on: + push: + branches: + - master + pull_request: + paths: + - 'snp**' + - '.github/workflows/clang_format.yml' + - '**clang-format' + schedule: + - cron: '0 5 * * *' + +jobs: + clang_format: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + + - name: Run clang format + run: | + sudo apt update + sudo apt install -y git clang-format + if [ $? -ge 1 ]; then return 1; fi + ./.run-clang-format + if [ $? -ge 1 ]; then return 1; fi + output=$(git diff) + if [ -n "$output" ]; then exit 1; else exit 0; fi diff --git a/.github/workflows/cmake_format.yml b/.github/workflows/cmake_format.yml new file mode 100644 index 0000000..3269c97 --- /dev/null +++ b/.github/workflows/cmake_format.yml @@ -0,0 +1,26 @@ +name: CMake-Format + +on: + push: + branches: + - master + pull_request: + paths: + - 'snp**' + - '.github/workflows/cmake_format.yml' + - '**cmake-format' + schedule: + - cron: '0 5 * * *' + +jobs: + cmake_format: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v1 + + - name: Run CMake Lang Format Check + run: | + sudo pip3 install cmakelang + ./.run-cmake-format + output=$(git diff) + if [ -n "$output" ]; then exit 1; else exit 0; fi diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml new file mode 100644 index 0000000..13b2fed --- /dev/null +++ b/.github/workflows/ubuntu.yml @@ -0,0 +1,41 @@ +name: Ubuntu + +on: + push: + branches: + - master + pull_request: + schedule: + - cron: '0 5 * * *' + workflow_dispatch: + release: + types: + - released + +jobs: + ci: + name: ${{ matrix.distro }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + distro: [noetic] + container: + image: ros:${{ matrix.distro }} + env: + CCACHE_DIR: ${{ github.workspace }}/${{ matrix.distro }}/.ccache + DEBIAN_FRONTEND: noninteractive + TZ: Etc/UTC + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + path: target_ws/src + + - name: Build and Tests + uses: tesseract-robotics/colcon-action@v6 + with: + before-script: source /opt/ros/${{ matrix.distro }}/setup.bash + ccache-prefix: ${{ matrix.distro }} + target-path: target_ws/src + target-args: --cmake-args -DCMAKE_BUILD_TYPE=Debug diff --git a/ci b/ci new file mode 120000 index 0000000..ecd623e --- /dev/null +++ b/ci @@ -0,0 +1 @@ +.github/workflows/ \ No newline at end of file From 9d25b5c82f68acfa2e9141069a90f13508d0db86 Mon Sep 17 00:00:00 2001 From: Michael Ripperger Date: Wed, 17 Jan 2024 16:24:21 -0600 Subject: [PATCH 4/4] Add qtbase5-dev to package.xml --- package.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/package.xml b/package.xml index edc4f79..d9f340f 100644 --- a/package.xml +++ b/package.xml @@ -14,6 +14,7 @@ sensor_msgs trajectory_msgs libqt5-widgets + qtbase5-dev