From c0ebfb81de8fbd352b5a63973f5dde978599c08c Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Mon, 7 Dec 2020 17:57:03 +0100 Subject: [PATCH] CMake: Improve tests wrapper arguments handling Use 'separate_arguments' to explicitly split arguments from environment that form 'COMMAND' for execute_process. Enclose using bracket syntax arguments, that propagated to wrapper script as pure strings. Amends f19266bd02a01d4b7b277ea769c4c17727b1e661 Pick-to: 6.0 Change-Id: I858ddff7efa281f9cecfda656a02e1fd12361758 Reviewed-by: Alexandru Croitor --- cmake/QtTestHelpers.cmake | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cmake/QtTestHelpers.cmake b/cmake/QtTestHelpers.cmake index f849ba6037..c43a9aa7a9 100644 --- a/cmake/QtTestHelpers.cmake +++ b/cmake/QtTestHelpers.cmake @@ -468,6 +468,8 @@ function(_qt_internal_wrap_test name test_executable extra_test_args test_workin get_test_property(${name} CROSSCOMPILING_EMULATOR crosscompiling_emulator) if(NOT crosscompiling_emulator) set(crosscompiling_emulator "") + else() + qt_internal_wrap_command_arguments(crosscompiling_emulator) endif() endif() @@ -478,13 +480,18 @@ function(_qt_internal_wrap_test name test_executable extra_test_args test_workin set(extra_test_runner "cmd /c") endif() + qt_internal_wrap_command_arguments(extra_test_args) + file(GENERATE OUTPUT "${test_wrapper_name}" CONTENT "#!${CMAKE_COMMAND} -P # Qt generated test wrapper for ${name} ${environment_extras} -execute_process(COMMAND ${crosscompiling_emulator} ${extra_test_runner} \$ENV{TESTRUNNER} \"${test_executable_file}\" \ -\$ENV{TESTARGS} ${extra_test_args} WORKING_DIRECTORY \"${test_working_dir}\" \ +separate_arguments(test_args NATIVE_COMMAND \"\$ENV{TESTARGS}\") +separate_arguments(test_runner NATIVE_COMMAND \"\$ENV{TESTRUNNER}\") +execute_process(COMMAND ${crosscompiling_emulator} ${extra_test_runner} \${test_runner} \ +\"${test_executable_file}\" \${test_args} ${extra_test_args} \ +WORKING_DIRECTORY \"${test_working_dir}\" \ RESULT_VARIABLE result) if(NOT result EQUAL 0) message(FATAL_ERROR) @@ -528,3 +535,9 @@ function(qt_internal_add_test_helper name) qt_internal_add_executable("${name}" NO_INSTALL ${extra_args_to_pass} ${forward_args}) endfunction() + +function(qt_internal_wrap_command_arguments argument_list) + list(TRANSFORM ${argument_list} REPLACE "^(.+)$" "[=[\\1]=]") + list(JOIN ${argument_list} " " ${argument_list}) + set(${argument_list} "${${argument_list}}" PARENT_SCOPE) +endfunction()