From e7834e90f38891382f830da7700f00ebd81f21a8 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Thu, 20 Mar 2025 15:39:02 +0100 Subject: [PATCH] CMake: Fix dbus and vk headers to be excluded from doc generation Before this change, if someone called ninja Gui_generate_docs, it would implicitly depend on sync_all_public_headers -> Gui_sync_headers which would generate dbus headers. This caused trouble with the new 'build doc tools from qttools/dev/HEAD' approach, because an older pre-built dbus tool might be passed a newer option when integrating a qtbase change that passes the new option. To avoid that, we now filter out the dbus headers from the list of headers that should be processed by syncqt when building a documentation target. We do the same for the qvkgen generated headers. This also removes the dependency on the ${target}_sync_headers target, which means there is a potential issue when someone manually calls `ninja sync_all_public_headers Gui_sync_headers` or something like it, which would spawn two syncqt processes that access the same files concurrently. This is an edge case that should not happen, but if it ends up happening, we will have to implement some kind of lock file mechanism. Pick-to: 6.8 6.9 Fixes: QTBUG-134672 Task-number: QTBUG-128730 Change-Id: I9061f9495e2faa77744f5f5c0de8fedd362ba228 Reviewed-by: Alexey Edelev --- cmake/QtDbusHelpers.cmake | 5 +++++ cmake/QtModuleHelpers.cmake | 15 +++++++++++++-- cmake/QtSyncQtHelpers.cmake | 21 ++++++++++++++++++--- src/gui/CMakeLists.txt | 1 + 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/cmake/QtDbusHelpers.cmake b/cmake/QtDbusHelpers.cmake index db113b0d982..ad796ca69d7 100644 --- a/cmake/QtDbusHelpers.cmake +++ b/cmake/QtDbusHelpers.cmake @@ -79,4 +79,9 @@ function(qt_create_qdbusxml2cpp_command target infile) "${header_file_full}" "${source_file_full}" ) + set_source_files_properties( + "${header_file_full}" + "${source_file_full}" + PROPERTIES + _qt_syncqt_exclude_from_docs TRUE) endfunction() diff --git a/cmake/QtModuleHelpers.cmake b/cmake/QtModuleHelpers.cmake index bdf00c68b64..fdcbb700899 100644 --- a/cmake/QtModuleHelpers.cmake +++ b/cmake/QtModuleHelpers.cmake @@ -1196,8 +1196,11 @@ function(qt_finalize_module target) # property which supposed to be updated inside every qt_internal_install_module_headers # call. qt_internal_add_headersclean_target(${target} "${module_headers_public}") - qt_internal_target_sync_headers(${target} "${module_headers_all}" - "${module_headers_generated}") + qt_internal_target_sync_headers(${target} + "${module_headers_all}" + "${module_headers_generated}" + "${module_headers_exclude_from_docs}" + ) get_target_property(module_depends_header ${target} _qt_module_depends_header) qt_internal_install_module_headers(${target} PUBLIC ${module_headers_public} "${module_depends_header}" @@ -1627,6 +1630,7 @@ endfunction() function(qt_internal_collect_module_headers out_var target) set(${out_var}_public "") set(${out_var}_private "") + set(${out_var}_exclude_from_docs "") set(${out_var}_qpa "") set(${out_var}_rhi "") set(${out_var}_ssg "") @@ -1698,6 +1702,12 @@ function(qt_internal_collect_module_headers out_var target) set(is_3rdparty_header FALSE) endif() list(APPEND ${out_var}_all "${file_path}") + + get_source_file_property(exclude_from_docs "${file_path}" _qt_syncqt_exclude_from_docs) + if(exclude_from_docs) + list(APPEND ${out_var}_exclude_from_docs "${file_path}") + endif() + if(qpa_filter AND file_name MATCHES "${qpa_filter}") list(APPEND ${out_var}_qpa "${file_path}") elseif(rhi_filter AND file_name MATCHES "${rhi_filter}") @@ -1740,6 +1750,7 @@ function(qt_internal_collect_module_headers out_var target) endforeach() set(${out_var}_all "${${out_var}_all}" PARENT_SCOPE) set(${out_var}_generated "${${out_var}_generated}" PARENT_SCOPE) + set(${out_var}_exclude_from_docs "${${out_var}_exclude_from_docs}" PARENT_SCOPE) if(has_header_types_properties) set_target_properties(${target} PROPERTIES ${has_header_types_properties}) diff --git a/cmake/QtSyncQtHelpers.cmake b/cmake/QtSyncQtHelpers.cmake index 0188b87c6ab..96669a03c32 100644 --- a/cmake/QtSyncQtHelpers.cmake +++ b/cmake/QtSyncQtHelpers.cmake @@ -6,7 +6,11 @@ # QT_REPO_PUBLIC_NAMESPACE_REGEX cache variable, that can be set by repository in .cmake.conf file. # The variable tells the syncqt program, what namespaces are treated as public. Symbols in public # namespaces are considered when generating CaMeL case header files. -function(qt_internal_target_sync_headers target module_headers module_headers_generated) +function(qt_internal_target_sync_headers target + module_headers + module_headers_generated + module_headers_exclude_from_docs + ) if(NOT TARGET ${QT_CMAKE_EXPORT_NAMESPACE}::syncqt) message(FATAL_ERROR "${QT_CMAKE_EXPORT_NAMESPACE}::syncqt is not a target.") endif() @@ -146,6 +150,11 @@ function(qt_internal_target_sync_headers target module_headers module_headers_ge list(FILTER module_headers EXCLUDE REGEX "(.+/(ui_)[^/]+\\.h|${CMAKE_CURRENT_SOURCE_DIR}(/.+)?/doc/+\\.h)") + # Filter out all headers that should be excluded from documentation generation. + # Documentation generation shouldn't depend on headers like the dbus-generated ones. + set(module_headers_for_docs "${module_headers}") + list(REMOVE_ITEM module_headers_for_docs ${module_headers_exclude_from_docs}) + set(syncqt_staging_dir "${module_build_interface_include_dir}/.syncqt_staging") set(syncqt_args "${common_syncqt_arguments}") @@ -225,10 +234,16 @@ function(qt_internal_target_sync_headers target module_headers module_headers_ge "@${syncqt_all_args_rsp}" ${external_headers_dir_copy_cmd} DEPENDS - ${module_headers} + # Note, we don't depend anymore on ${target}_sync_headers so that we don't bring + # in the headers that are usually excluded from docs. + # This means if someone manually calls + # `ninja sync_all_public_headers Gui_sync_headers` it will cause havoc due to two + # syncqt calls accessing the same files concurrently. This is an edge case that should + # not happen, but it ends up happening, we will have to implement some kind of lock + # file mechanism. + ${module_headers_for_docs} ${syncqt_all_args_rsp} ${QT_CMAKE_EXPORT_NAMESPACE}::syncqt - ${target}_sync_headers VERBATIM ) diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 0002c33ae5d..cd4f6c8d2df 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -1001,6 +1001,7 @@ add_custom_command( WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" VERBATIM ) +set_source_files_properties(${vulkan_fun_outputs} PROPERTIES _qt_syncqt_exclude_from_docs TRUE) qt_internal_extend_target(Gui CONDITION WASM SOURCES