Skip to content
Open
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 @@ -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()
7 changes: 6 additions & 1 deletion ament_cmake_lint_cmake/cmake/ament_lint_cmake.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand Down
6 changes: 5 additions & 1 deletion ament_cmake_pep257/cmake/ament_cmake_pep257_lint_hook.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
7 changes: 6 additions & 1 deletion ament_cmake_pep257/cmake/ament_pep257.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
7 changes: 6 additions & 1 deletion ament_cmake_xmllint/cmake/ament_xmllint.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand Down
24 changes: 20 additions & 4 deletions ament_lint_cmake/ament_lint_cmake/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.

import argparse
import glob
import os
import sys
import time
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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]


Expand Down
15 changes: 11 additions & 4 deletions ament_xmllint/ament_xmllint/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.

import argparse
import glob
import os
import shutil
import subprocess
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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]:
Expand Down