summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2023-12-20 15:24:07 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-01-24 14:04:25 +0000
commit22f3c6ac535afb217f6d3a26a5b74c4d5b29f287 (patch)
tree1da56b6e65c38c6524cdba8405c435e76a0d4571
parent667537524cd72704ca3efee9276f6afad41bb5fc (diff)
CMake: Don't pass generated ui_foo.h headers to lupdate
If the user has added foo.ui to the target sources we passed foo.ui and ui_foo.h to lupdate. If foo.ui is id-based, ui_foo.h is generated without context and source text information, and the created .ts file will contain a name-less context. We're now filtering out ui_foo.h if foo.ui is in the sources of a target. This ensures that we'll have the correct id-based translation generated from the information in foo.ui. Note: If the user relies on AUTOUIC's feature that autodetects ui_foo.h without having foo.ui in the sources, we still have the described problem due to the lacking information in ui_foo.h. That will need to be fixed in uic (to generate the context and source info) and lupdate (to pick up context information, which isn't currently possible). Fixes: QTBUG-118808 Pick-to: 6.6 6.5 Change-Id: I05a6eec3ed601908429672ee6edaf38209ebcd71 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> (cherry picked from commit d52c7a8864f2f5d2806728f1a04a033abce5b6dd) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/linguist/GenerateLUpdateProject.cmake37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/linguist/GenerateLUpdateProject.cmake b/src/linguist/GenerateLUpdateProject.cmake
index 9138e0d78..8fe087fdb 100644
--- a/src/linguist/GenerateLUpdateProject.cmake
+++ b/src/linguist/GenerateLUpdateProject.cmake
@@ -35,6 +35,37 @@ function(filter_nonexistent_files out_var)
set("${out_var}" "${existing_sources}" PARENT_SCOPE)
endfunction()
+# Remove ui_foo.h for each foo.ui file found in the sources.
+# filter_generated_ui_headers(existing_files .../src/foo.ui .../target_autogen/include/ui_foo.h)
+# -> .../src/foo.ui
+function(filter_generated_ui_headers out_var)
+ set(ui_file_paths ${ARGN})
+ list(FILTER ui_file_paths INCLUDE REGEX "/[^/]+\\.ui$")
+
+ set(filter_regex "")
+ foreach(file_path IN LISTS ui_file_paths)
+ get_filename_component(file_name "${file_path}" NAME_WLE)
+ if(NOT "${filter_regex}" STREQUAL "")
+ string(APPEND filter_regex "|")
+ endif()
+ string(APPEND filter_regex "(/ui_${file_name}\\.h$)")
+ endforeach()
+
+ set(result ${ARGN})
+ if(NOT "${filter_regex}" STREQUAL "")
+ list(FILTER result EXCLUDE REGEX ${filter_regex})
+ endif()
+
+ set("${out_var}" "${result}" PARENT_SCOPE)
+endfunction()
+
+function(prepare_json_sources out_var)
+ filter_nonexistent_files(sources ${ARGN})
+ filter_generated_ui_headers(sources ${sources})
+ list_to_json_array("${sources}" result)
+ set("${out_var}" "${result}" PARENT_SCOPE)
+endfunction()
+
get_filename_component(project_root "${lupdate_project_file}" DIRECTORY)
# Make relative paths absolute to the project root
@@ -61,8 +92,7 @@ foreach(path_var IN LISTS path_variables)
endforeach()
endforeach()
-filter_nonexistent_files(existing_sources ${absolute_sources})
-list_to_json_array("${existing_sources}" json_sources)
+prepare_json_sources(json_sources ${absolute_sources})
list_to_json_array("${absolute_include_paths}" json_include_paths)
list_to_json_array("${absolute_translations}" json_translations)
@@ -74,8 +104,7 @@ set(content "{
\"subProjects\": [
")
foreach(i RANGE 1 ${lupdate_subproject_count})
- filter_nonexistent_files(existing_sources ${absolute_subproject${i}_sources})
- list_to_json_array("${existing_sources}" json_sources)
+ prepare_json_sources(json_sources ${absolute_subproject${i}_sources})
list_to_json_array("${absolute_subproject${i}_include_paths}" json_include_paths)
list_to_json_array("${absolute_subproject${i}_excluded}" json_sources_exclusions)
string(APPEND content " {