Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ament_lint_auto] General file exclusion with AMENT_LINT_AUTO_FILE_EXCLUDE #386

Merged
merged 5 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@
message(
STATUS
"Added test 'copyright' to check source files copyright and LICENSE")
ament_copyright()

if(DEFINED AMENT_LINT_AUTO_FILE_EXCLUDE)
ament_copyright(EXCLUDE ${AMENT_LINT_AUTO_FILE_EXCLUDE})
else()
ament_copyright()
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ if(_source_files)
list(APPEND _all_exclude ${ament_cmake_cppcheck_ADDITIONAL_EXCLUDE})
endif()

if(DEFINED AMENT_LINT_AUTO_FILE_EXCLUDE)
list(APPEND _all_exclude ${AMENT_LINT_AUTO_FILE_EXCLUDE})
endif()

# BUILDSYSTEM_TARGETS only supported in CMake >= 3.7
if(NOT CMAKE_VERSION VERSION_LESS "3.7.0")
get_directory_property(_build_targets DIRECTORY ${PROJECT_SOURCE_DIR} BUILDSYSTEM_TARGETS)
Expand Down
4 changes: 4 additions & 0 deletions ament_cmake_cpplint/cmake/ament_cmake_cpplint_lint_hook.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ if(_source_files)
list(APPEND _all_exclude ${ament_cmake_cpplint_ADDITIONAL_EXCLUDE})
endif()

if(DEFINED AMENT_LINT_AUTO_FILE_EXCLUDE)
list(APPEND _all_exclude ${AMENT_LINT_AUTO_FILE_EXCLUDE})
endif()

message(STATUS "Configured cpplint exclude dirs and/or files: ${_all_exclude}")
ament_cpplint(EXCLUDE ${_all_exclude})
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ if(_source_files)
list(APPEND _args ${ament_cmake_uncrustify_ADDITIONAL_ARGS})
endif()

set(_all_exclude "")
if(DEFINED ament_cmake_uncrustify_ADDITIONAL_EXCLUDE)
list(APPEND _all_exclude ${ament_cmake_uncrustify_ADDITIONAL_EXCLUDE})
endif()

if(DEFINED AMENT_LINT_AUTO_FILE_EXCLUDE)
list(APPEND _all_exclude ${AMENT_LINT_AUTO_FILE_EXCLUDE})
endif()

message(STATUS "Configured uncrustify additional arguments: ${_args}")
ament_uncrustify(${_args})
ament_uncrustify(${_args} EXCLUDE ${_all_exclude})
endif()
19 changes: 19 additions & 0 deletions ament_lint_auto/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,22 @@ sufficient to test with a set of common linters.
The documentation of the package `ament_cmake_test
<https://github.com/ament/ament_cmake>`_ provides more information on testing
in CMake ament packages.

How to exclude files with ament_lint_auto?
------------------------------------------

Linter hooks conform to the ament_lint_auto convention of excluding files
specified in the CMake list variable `AMENT_LINT_AUTO_FILE_EXCLUDE`.
As such, the CMake snippet from above can be modified to exclude files across
all linters with one addition.

``CMakeLists.txt``:

.. code:: cmake

# this must happen before the invocation of ament_package()
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
set(AMENT_LINT_AUTO_FILE_EXCLUDE /path/to/ignored_file ...)
ament_lint_auto_find_test_dependencies()
endif()