diff --git a/ament_cmake_lint_cmake/cmake/ament_cmake_lint_cmake_lint_hook.cmake b/ament_cmake_lint_cmake/cmake/ament_cmake_lint_cmake_lint_hook.cmake index dda7d439d..34cfebdb3 100644 --- a/ament_cmake_lint_cmake/cmake/ament_cmake_lint_cmake_lint_hook.cmake +++ b/ament_cmake_lint_cmake/cmake/ament_cmake_lint_cmake_lint_hook.cmake @@ -18,5 +18,9 @@ file(GLOB_RECURSE _cmake_files FOLLOW_SYMLINKS ) if(_cmake_files) message(STATUS "Added test 'lint_cmake' to check CMake code style") - ament_lint_cmake() + if(DEFINED AMENT_LINT_AUTO_FILE_EXCLUDE) + ament_lint_cmake(EXCLUDE ${AMENT_LINT_AUTO_FILE_EXCLUDE}) + else() + ament_lint_cmake() + endif() endif() diff --git a/ament_cmake_lint_cmake/cmake/ament_lint_cmake.cmake b/ament_cmake_lint_cmake/cmake/ament_lint_cmake.cmake index 3360e0a39..7e3d5f61a 100644 --- a/ament_cmake_lint_cmake/cmake/ament_lint_cmake.cmake +++ b/ament_cmake_lint_cmake/cmake/ament_lint_cmake.cmake @@ -20,13 +20,15 @@ # :param MAX_LINE_LENGTH: override the maximum line length, # the default is defined in ament_lint_cmake # :type MAX_LINE_LENGTH: integer +# :param EXCLUDE: an optional list of exclude files or directories for cmake lint check +# :type EXCLUDE: list # :param ARGN: the files or directories to check # :type ARGN: list of strings # # @public # function(ament_lint_cmake) - cmake_parse_arguments(ARG "" "MAX_LINE_LENGTH;TESTNAME" "" ${ARGN}) + cmake_parse_arguments(ARG "" "MAX_LINE_LENGTH;TESTNAME" "EXCLUDE" ${ARGN}) if(NOT ARG_TESTNAME) set(ARG_TESTNAME "lint_cmake") endif() @@ -41,6 +43,9 @@ function(ament_lint_cmake) if(DEFINED ARG_MAX_LINE_LENGTH) list(APPEND cmd "--linelength" "${ARG_MAX_LINE_LENGTH}") endif() + if(ARG_EXCLUDE) + list(APPEND cmd "--exclude" "${ARG_EXCLUDE}") + endif() list(APPEND cmd ${ARG_UNPARSED_ARGUMENTS}) file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/ament_lint_cmake") diff --git a/ament_cmake_pep257/cmake/ament_cmake_pep257_lint_hook.cmake b/ament_cmake_pep257/cmake/ament_cmake_pep257_lint_hook.cmake index 520e869e4..f43733dfa 100644 --- a/ament_cmake_pep257/cmake/ament_cmake_pep257_lint_hook.cmake +++ b/ament_cmake_pep257/cmake/ament_cmake_pep257_lint_hook.cmake @@ -15,5 +15,9 @@ file(GLOB_RECURSE _python_files FOLLOW_SYMLINKS "*.py") if(_python_files) message(STATUS "Added test 'pep257' to check Python code against some of the docstring style conventions in PEP 257") - ament_pep257() + if(DEFINED AMENT_LINT_AUTO_FILE_EXCLUDE) + ament_pep257(EXCLUDE ${AMENT_LINT_AUTO_FILE_EXCLUDE}) + else() + ament_pep257() + endif() endif() diff --git a/ament_cmake_pep257/cmake/ament_pep257.cmake b/ament_cmake_pep257/cmake/ament_pep257.cmake index ece07e4bb..35b68e745 100644 --- a/ament_cmake_pep257/cmake/ament_pep257.cmake +++ b/ament_cmake_pep257/cmake/ament_pep257.cmake @@ -17,13 +17,15 @@ # # :param TESTNAME: the name of the test, default: "pep257" # :type TESTNAME: string +# :param EXCLUDE: an optional list of exclude files or directories for cmake pep257 check +# :type EXCLUDE: list # :param ARGN: the files or directories to check # :type ARGN: list of strings # # @public # function(ament_pep257) - cmake_parse_arguments(ARG "" "TESTNAME" "" ${ARGN}) + cmake_parse_arguments(ARG "" "TESTNAME" "EXCLUDE" ${ARGN}) if(NOT ARG_TESTNAME) set(ARG_TESTNAME "pep257") endif() @@ -35,6 +37,9 @@ function(ament_pep257) set(result_file "${AMENT_TEST_RESULTS_DIR}/${PROJECT_NAME}/${ARG_TESTNAME}.xunit.xml") set(cmd "${ament_pep257_BIN}" "--xunit-file" "${result_file}") + if(ARG_EXCLUDE) + list(APPEND cmd "--exclude" "${ARG_EXCLUDE}") + endif() list(APPEND cmd ${ARG_UNPARSED_ARGUMENTS}) file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/ament_pep257") diff --git a/ament_cmake_xmllint/cmake/ament_cmake_xmllint_lint_hook.cmake b/ament_cmake_xmllint/cmake/ament_cmake_xmllint_lint_hook.cmake index 2c9456b27..dcf940fd7 100644 --- a/ament_cmake_xmllint/cmake/ament_cmake_xmllint_lint_hook.cmake +++ b/ament_cmake_xmllint/cmake/ament_cmake_xmllint_lint_hook.cmake @@ -15,5 +15,10 @@ file(GLOB_RECURSE _source_files FOLLOW_SYMLINKS "*.xml") if(_source_files) message(STATUS "Added test 'xmllint' to check XML markup files") - ament_xmllint() + + if(DEFINED AMENT_LINT_AUTO_FILE_EXCLUDE) + ament_xmllint(EXCLUDE ${AMENT_LINT_AUTO_FILE_EXCLUDE}) + else() + ament_xmllint() + endif() endif() diff --git a/ament_cmake_xmllint/cmake/ament_xmllint.cmake b/ament_cmake_xmllint/cmake/ament_xmllint.cmake index cf42857a1..fb3fa53e3 100644 --- a/ament_cmake_xmllint/cmake/ament_xmllint.cmake +++ b/ament_cmake_xmllint/cmake/ament_xmllint.cmake @@ -17,13 +17,15 @@ # # :param TESTNAME: the name of the test, default: "xmllint" # :type TESTNAME: string +# :param EXCLUDE: an optional list of exclude files or directories for xmllint check +# :type EXCLUDE: list # :param ARGN: the files or directories to check # :type ARGN: list of strings # # @public # function(ament_xmllint) - cmake_parse_arguments(ARG "" "MAX_LINE_LENGTH;TESTNAME" "" ${ARGN}) + cmake_parse_arguments(ARG "" "MAX_LINE_LENGTH;TESTNAME" "EXCLUDE" ${ARGN}) if(NOT ARG_TESTNAME) set(ARG_TESTNAME "xmllint") endif() @@ -35,6 +37,9 @@ function(ament_xmllint) set(result_file "${AMENT_TEST_RESULTS_DIR}/${PROJECT_NAME}/${ARG_TESTNAME}.xunit.xml") set(cmd "${ament_xmllint_BIN}" "--xunit-file" "${result_file}") + if(ARG_EXCLUDE) + list(APPEND cmd "--exclude" "${ARG_EXCLUDE}") + endif() list(APPEND cmd ${ARG_UNPARSED_ARGUMENTS}) find_program(xmllint_BIN NAMES "xmllint") diff --git a/ament_lint_cmake/ament_lint_cmake/main.py b/ament_lint_cmake/ament_lint_cmake/main.py index aa76fcbd0..f2acbced1 100755 --- a/ament_lint_cmake/ament_lint_cmake/main.py +++ b/ament_lint_cmake/ament_lint_cmake/main.py @@ -15,6 +15,7 @@ # limitations under the License. import argparse +import glob import os import sys import time @@ -51,6 +52,13 @@ def main(argv=sys.argv[1:]): parser.add_argument( '--linelength', metavar='N', type=int, default=140, help='The maximum line length') + parser.add_argument( + '--exclude', + metavar='filename', + nargs='*', + default=[], + dest='excludes', + help='The filenames to exclude.') # not using a file handle directly # in order to prevent leaving an empty file when something fails early parser.add_argument( @@ -61,7 +69,7 @@ def main(argv=sys.argv[1:]): if args.xunit_file: start_time = time.time() - files = get_files(args.paths) + files = get_files(args.paths, args.excludes) if not files: print('No files found', file=sys.stderr) return 1 @@ -125,7 +133,12 @@ def custom_error(filename, linenumber, category, message): return rc -def get_files(paths): +def get_files(paths, exclude_patterns): + excludes = [] + for exclude_pattern in exclude_patterns: + excludes.extend(glob.glob(exclude_pattern)) + excludes = {os.path.realpath(x) for x in excludes} + files = [] for path in paths: if os.path.isdir(path): @@ -145,9 +158,12 @@ def get_files(paths): fname_low.endswith('.cmake') or fname_low.endswith('.cmake.in') ): - files.append(os.path.join(dirpath, filename)) + fname = os.path.join(dirpath, filename) + if os.path.realpath(fname) not in excludes: + files.append(fname) if os.path.isfile(path): - files.append(path) + if os.path.realpath(path) not in excludes: + files.append(path) return [os.path.normpath(f) for f in files] diff --git a/ament_xmllint/ament_xmllint/main.py b/ament_xmllint/ament_xmllint/main.py index e1a27a7a0..8dd8fa97a 100755 --- a/ament_xmllint/ament_xmllint/main.py +++ b/ament_xmllint/ament_xmllint/main.py @@ -15,6 +15,7 @@ # limitations under the License. import argparse +import glob import os import shutil import subprocess @@ -46,6 +47,7 @@ def main(argv=sys.argv[1:]): '--exclude', nargs='*', default=[], + dest='excludes', help='Exclude specific file names and directory names from the check') # not using a file handle directly # in order to prevent leaving an empty file when something fails early @@ -62,7 +64,7 @@ def main(argv=sys.argv[1:]): if args.xunit_file: start_time = time.time() - files = get_files(args.paths, args.extensions, args.exclude) + files = get_files(args.paths, args.extensions, args.excludes) if not files: print('No files found', file=sys.stderr) return 1 @@ -158,7 +160,12 @@ def main(argv=sys.argv[1:]): return rc -def get_files(paths, extensions, excludes=[]): +def get_files(paths, extensions, exclude_patterns): + excludes = [] + for exclude_pattern in exclude_patterns: + excludes.extend(glob.glob(exclude_pattern)) + excludes = {os.path.realpath(x) for x in excludes} + files = [] for path in paths: if os.path.isdir(path): @@ -169,12 +176,12 @@ def get_files(paths, extensions, excludes=[]): # ignore folder starting with . or _ dirnames[:] = [d for d in dirnames if d[0] not in ['.', '_']] # ignore excluded folders - dirnames[:] = [d for d in dirnames if d not in excludes] + dirnames[:] = [d for d in dirnames if os.path.realpath(d) not in excludes] dirnames.sort() # select files by extension for filename in sorted(filenames): - if filename in excludes: + if os.path.realpath(os.path.join(dirpath, filename)) in excludes: continue _, ext = os.path.splitext(filename) if ext not in ['.%s' % e for e in extensions]: