CMake: Clean up _qt_internal_finalize_batch
The _qt_internal_finalize_batch function had a bunch of problems, style-wise and function-wise: - it called find_package(Qt6) in its body, which broke when configuring qtbase with in-tree tests - it constantly rewrote the merged blacklist file on each reconfiguration - it used file(WRITE) to concatenate content - it was in the public API file The changes are: - Move the function to the internal test helpers file. - Change it to use qt_configure_file instead of file(WRITE). - Call it at the end of the qt_build_tests for a repo, or at the end of configuring a super build, instead of relying on a finalizer. - Remove the find_package call. The reason this was added in the first place, was to populate the __qt_core_macros_module_base_dir variable so that qt_internal_add_resource configure_file call doesn't fail in standalone tests build. The variable was unset because the finalized function was called in the top level directory scope, whereas the very first find_package call was in the tests/ scope, meaning the variable was empty. This is still a problem in the top-level build where the tests scope and the top-level scope are different. Work around it by relying on a global property to reset the value if it's empty. Amends 6a9e89121d7766a34c4281d298057bfbe8af36b3 Pick-to: 6.8 Change-Id: Id6fe41ee86d09b8118bea52cac8a59965d7ecb9e Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
parent
0ac8ab0d20
commit
c997e3bb8b
@ -69,6 +69,10 @@ macro(qt_internal_top_level_setup_no_create_targets)
|
||||
endmacro()
|
||||
|
||||
macro(qt_internal_top_level_end)
|
||||
if(QT_BUILD_TESTS)
|
||||
qt_internal_finalize_test_batch_blacklist()
|
||||
endif()
|
||||
|
||||
qt_internal_print_top_level_info()
|
||||
|
||||
# Depends on QtBuildInternalsConfig being included, which is the case whenver any repo is
|
||||
|
@ -783,6 +783,12 @@ macro(qt_build_tests)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT QT_SUPERBUILD)
|
||||
# In a super build, we don't want to finalize the batch blacklist at the end of each repo,
|
||||
# but rather once at the end of the top-level configuration.
|
||||
qt_internal_finalize_test_batch_blacklist()
|
||||
endif()
|
||||
|
||||
set(CMAKE_UNITY_BUILD ${QT_UNITY_BUILD})
|
||||
unset(QT_INTERNAL_CONFIGURING_TESTS)
|
||||
endmacro()
|
||||
|
@ -825,10 +825,10 @@ function(qt_internal_add_test name)
|
||||
if(NOT blacklist_files)
|
||||
set_target_properties(${name} PROPERTIES _qt_blacklist_files "")
|
||||
set(blacklist_files "")
|
||||
cmake_language(EVAL CODE "cmake_language(DEFER DIRECTORY \"${CMAKE_SOURCE_DIR}\" CALL \"_qt_internal_finalize_batch\" \"${name}\") ")
|
||||
endif()
|
||||
list(PREPEND blacklist_files "${CMAKE_CURRENT_SOURCE_DIR}/${blacklist_path}")
|
||||
set_target_properties(${name} PROPERTIES _qt_blacklist_files "${blacklist_files}")
|
||||
set_target_properties(${name} PROPERTIES
|
||||
_qt_blacklist_files "${blacklist_files}")
|
||||
endif()
|
||||
else()
|
||||
set(blacklist_path "BLACKLIST")
|
||||
@ -891,6 +891,35 @@ function(qt_internal_add_test name)
|
||||
qt_internal_add_test_finalizers("${name}")
|
||||
endfunction()
|
||||
|
||||
# Generates a blacklist file for the global batched test target.
|
||||
function(qt_internal_finalize_test_batch_blacklist)
|
||||
_qt_internal_test_batch_target_name(batch_target_name)
|
||||
if(NOT TARGET "${batch_target_name}")
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(generated_blacklist_file "${CMAKE_CURRENT_BINARY_DIR}/BLACKLIST")
|
||||
|
||||
set(final_contents "")
|
||||
|
||||
get_target_property(blacklist_files "${batch_target_name}" _qt_blacklist_files)
|
||||
if(blacklist_files)
|
||||
foreach(blacklist_file ${blacklist_files})
|
||||
file(READ "${blacklist_file}" file_contents)
|
||||
if(file_contents)
|
||||
string(APPEND final_contents "${file_contents}\n")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
qt_configure_file(OUTPUT "${generated_blacklist_file}" CONTENT "${final_contents}")
|
||||
|
||||
qt_internal_add_resource(${batch_target_name} "batch_blacklist"
|
||||
PREFIX "/"
|
||||
FILES "${generated_blacklist_file}"
|
||||
BASE ${CMAKE_CURRENT_BINARY_DIR})
|
||||
endfunction()
|
||||
|
||||
# Given an optional test timeout value (specified via qt_internal_add_test's TIMEOUT option)
|
||||
# returns a percentage of the final timeout to be passed to the androidtestrunner executable.
|
||||
#
|
||||
|
@ -1715,6 +1715,7 @@ function(_qt_internal_android_create_runner_wrapper target)
|
||||
set(wrapper_path "${target_binary_dir}/${target}")
|
||||
endif()
|
||||
|
||||
get_property(__qt_core_macros_module_base_dir GLOBAL PROPERTY __qt_core_macros_module_base_dir)
|
||||
set(template_file "${__qt_core_macros_module_base_dir}/Qt6CoreConfigureFileTemplate.in")
|
||||
set(qt_core_configure_file_contents "${script_content}")
|
||||
configure_file("${template_file}" "${wrapper_path}")
|
||||
|
@ -8,7 +8,9 @@
|
||||
#
|
||||
######################################
|
||||
|
||||
set(__qt_core_macros_module_base_dir "${CMAKE_CURRENT_LIST_DIR}")
|
||||
# Save the 'macros base dir' in a global property instead of a variable, to allow access in a
|
||||
# deferred function where the variable might not be accessible by the function scope.
|
||||
set_property(GLOBAL PROPERTY __qt_core_macros_module_base_dir "${CMAKE_CURRENT_LIST_DIR}")
|
||||
|
||||
# macro used to create the names of output files preserving relative dirs
|
||||
macro(_qt_internal_make_output_file infile prefix ext outfile )
|
||||
@ -780,26 +782,6 @@ function(_qt_internal_finalize_executable target)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(_cat IN_FILE OUT_FILE)
|
||||
file(READ ${IN_FILE} CONTENTS)
|
||||
file(APPEND ${OUT_FILE} "${CONTENTS}\n")
|
||||
endfunction()
|
||||
|
||||
function(_qt_internal_finalize_batch name)
|
||||
find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS Core)
|
||||
|
||||
set(generated_blacklist_file "${CMAKE_CURRENT_BINARY_DIR}/BLACKLIST")
|
||||
get_target_property(blacklist_files "${name}" _qt_blacklist_files)
|
||||
file(WRITE "${generated_blacklist_file}" "")
|
||||
foreach(blacklist_file ${blacklist_files})
|
||||
_cat("${blacklist_file}" "${generated_blacklist_file}")
|
||||
endforeach()
|
||||
qt_internal_add_resource(${name} "batch_blacklist"
|
||||
PREFIX "/"
|
||||
FILES "${CMAKE_CURRENT_BINARY_DIR}/BLACKLIST"
|
||||
BASE ${CMAKE_CURRENT_BINARY_DIR})
|
||||
endfunction()
|
||||
|
||||
# If a task needs to run before any targets are finalized in the current directory
|
||||
# scope, call this function and pass the ID of that task as the argument.
|
||||
function(_qt_internal_delay_finalization_until_after defer_id)
|
||||
@ -2110,6 +2092,7 @@ function(__qt_internal_sanitize_resource_name out_var name)
|
||||
endfunction()
|
||||
|
||||
function(__qt_internal_generate_init_resource_source_file out_var target resource_name)
|
||||
get_property(__qt_core_macros_module_base_dir GLOBAL PROPERTY __qt_core_macros_module_base_dir)
|
||||
set(template_file "${__qt_core_macros_module_base_dir}/Qt6CoreResourceInit.in.cpp")
|
||||
|
||||
# Gets replaced in the template
|
||||
@ -2378,6 +2361,7 @@ function(_qt_internal_process_resource target resourceName)
|
||||
# </qresource></RCC>
|
||||
string(APPEND qrcContents " </qresource>\n</RCC>\n")
|
||||
|
||||
get_property(__qt_core_macros_module_base_dir GLOBAL PROPERTY __qt_core_macros_module_base_dir)
|
||||
set(template_file "${__qt_core_macros_module_base_dir}/Qt6CoreConfigureFileTemplate.in")
|
||||
set(qt_core_configure_file_contents "${qrcContents}")
|
||||
configure_file("${template_file}" "${generatedResourceFile}")
|
||||
|
Loading…
x
Reference in New Issue
Block a user