Skip to content

Commit

Permalink
(cmake_xmllint) make extensions configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Matthijs van der Burgh <[email protected]>
  • Loading branch information
MatthijsBurgh committed Apr 9, 2024
1 parent 1f7e2b4 commit bc24af1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
22 changes: 20 additions & 2 deletions ament_cmake_xmllint/cmake/ament_cmake_xmllint_lint_hook.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
10 changes: 9 additions & 1 deletion ament_cmake_xmllint/cmake/ament_xmllint.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand Down

0 comments on commit bc24af1

Please sign in to comment.