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 2c9456b2..c202417e 100644 --- a/ament_cmake_xmllint/cmake/ament_cmake_xmllint_lint_hook.cmake +++ b/ament_cmake_xmllint/cmake/ament_cmake_xmllint_lint_hook.cmake @@ -12,8 +12,26 @@ # See the License for the specific language governing permissions and # limitations under the License. -file(GLOB_RECURSE _source_files FOLLOW_SYMLINKS "*.xml") +# Forces ament_xmllint to consider ament_cmake_xmllint_EXTENSIONS as the given extensions if defined +set(_extensions "xml") +if(DEFINED ament_cmake_xmllint_EXTENSIONS) + string(REGEX REPLACE "[ \\*\\.,]+" ";" _extensions ${ament_cmake_xmllint_EXTENSIONS}) + message(STATUS "Configured xmllint extensions: ${_extensions}") +endif() + +# Make sure all extensions start with '*.' or add it if not +foreach(_extension ${_extensions}) + string(REGEX MATCH "^\\*?\\.?(.+)$" _bare_extension ${_extension}) + list(APPEND _glob_extensions "*.${_bare_extension}") +endforeach() + +message(DEBUG "Globbing for xml files with extensions: ${_glob_extensions}") + +file(GLOB_RECURSE _source_files FOLLOW_SYMLINKS ${_glob_extensions}) if(_source_files) + message(DEBUG "Found files with extensions: ${_source_files}") message(STATUS "Added test 'xmllint' to check XML markup files") - ament_xmllint() + ament_xmllint(EXTENSIONS ${_extensions}) +else() + message(DEBUG "No files with extensions: ${_extensions} found, skipping test 'xmllint'") endif() diff --git a/ament_cmake_xmllint/cmake/ament_xmllint.cmake b/ament_cmake_xmllint/cmake/ament_xmllint.cmake index cf42857a..4fe562bc 100644 --- a/ament_cmake_xmllint/cmake/ament_xmllint.cmake +++ b/ament_cmake_xmllint/cmake/ament_xmllint.cmake @@ -23,7 +23,7 @@ # @public # function(ament_xmllint) - cmake_parse_arguments(ARG "" "MAX_LINE_LENGTH;TESTNAME" "" ${ARGN}) + cmake_parse_arguments(ARG "" "TESTNAME" "PATHS;EXCLUDE;EXTENSIONS" ${ARGN}) if(NOT ARG_TESTNAME) set(ARG_TESTNAME "xmllint") endif() @@ -35,6 +35,14 @@ 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_EXTENSIONS) + list(APPEND cmd "--extensions") + foreach(ext ${ARG_EXTENSIONS}) + list(APPEND cmd "${ext}") + endforeach() + endif() + list(APPEND cmd ${ARG_UNPARSED_ARGUMENTS}) find_program(xmllint_BIN NAMES "xmllint")