Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(cmake_xmllint) make extensions configurable #479

Open
wants to merge 3 commits into
base: rolling
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a little weird. If the user doesn't specify anything for EXTENSIONS, then we won't pass --extensions to ament_xmllint at all, and then that script will choose the xml extension itself. If the user specifies some EXTENSIONS, then we will always pass --extensions xml, plus whatever they choose. There is no way for the user to ask for extensions that doesn't include xml.

I think we should do one of two things here:

  1. If the user specifies EXTENSIONS, then make that the complete set. Don't silently add .xml.
  2. Rename the variable from EXTENSIONS to EXTENSIONS_APPEND or something like that, to make it clear that we will always do at least xml.

Either way, we should document what we are doing in the documentation to ament_xmllint.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I checked the behaviour. When setting ament_cmake_xmllint_EXTENSIONS, it will completely overwrite the _extensions variable. As I use REGEX REPLACE.

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})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like either PATHS nor EXCLUDE are being used here, so let's just drop them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will check whether I want to add these as well or remove them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have update the macro to also use the PATHS and EXCLUDE args. (Though these are not use in the ament_lint_auto hook. As it looks for files, which eventually will be used by ament_xmllint. But then you are recreating the logic from ament_xmllint in CMake, which is undesired. But I don't think you want to call the python function from the ament_xmllint library here.

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