Skip to content

Commit 942851d

Browse files
committed
(cmake_xmllint) make extensions configurable
Signed-off-by: Matthijs van der Burgh <[email protected]>
1 parent 2d4f46c commit 942851d

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

ament_cmake_xmllint/cmake/ament_cmake_xmllint_lint_hook.cmake

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,26 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
file(GLOB_RECURSE _source_files FOLLOW_SYMLINKS "*.xml")
15+
# Forces ament_xmllint to consider ament_cmake_xmllint_EXTENSIONS as the given extensions if defined
16+
set(_extensions "xml")
17+
if(DEFINED ament_cmake_xmllint_EXTENSIONS)
18+
string(REGEX REPLACE "[ \\*\\.,]+" ";" _extensions ${ament_cmake_xmllint_EXTENSIONS})
19+
message(STATUS "Configured xmllint extensions: ${_extensions}")
20+
endif()
21+
22+
# Make sure all extensions start with '*.' or add it if not
23+
foreach(_extension ${_extensions})
24+
string(REGEX MATCH "^\\*?\\.?(.+)$" _bare_extension ${_extension})
25+
list(APPEND _glob_extensions "*.${_bare_extension}")
26+
endforeach()
27+
28+
message(DEBUG "Globbing for xml files with extensions: ${_glob_extensions}")
29+
30+
file(GLOB_RECURSE _source_files FOLLOW_SYMLINKS ${_glob_extensions})
1631
if(_source_files)
32+
message(DEBUG "Found files with extensions: ${_source_files}")
1733
message(STATUS "Added test 'xmllint' to check XML markup files")
18-
ament_xmllint()
34+
ament_xmllint(EXTENSIONS ${_extensions})
35+
else()
36+
message(DEBUG "No files with extensions: ${_extensions} found, skipping test 'xmllint'")
1937
endif()

ament_cmake_xmllint/cmake/ament_xmllint.cmake

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# @public
2424
#
2525
function(ament_xmllint)
26-
cmake_parse_arguments(ARG "" "MAX_LINE_LENGTH;TESTNAME" "" ${ARGN})
26+
cmake_parse_arguments(ARG "" "TESTNAME" "PATHS;EXCLUDE;EXTENSIONS" ${ARGN})
2727
if(NOT ARG_TESTNAME)
2828
set(ARG_TESTNAME "xmllint")
2929
endif()
@@ -35,6 +35,14 @@ function(ament_xmllint)
3535

3636
set(result_file "${AMENT_TEST_RESULTS_DIR}/${PROJECT_NAME}/${ARG_TESTNAME}.xunit.xml")
3737
set(cmd "${ament_xmllint_BIN}" "--xunit-file" "${result_file}")
38+
39+
if(ARG_EXTENSIONS)
40+
list(APPEND cmd "--extensions")
41+
foreach(ext ${ARG_EXTENSIONS})
42+
list(APPEND cmd "${ext}")
43+
endforeach()
44+
endif()
45+
3846
list(APPEND cmd ${ARG_UNPARSED_ARGUMENTS})
3947

4048
find_program(xmllint_BIN NAMES "xmllint")

0 commit comments

Comments
 (0)