diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2023-12-20 15:24:07 +0100 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2024-01-25 16:42:11 +0100 |
commit | 51a08cc79e0a6dffebef83b5ac8936826fca7db9 (patch) | |
tree | 40a3080e4304d5a8874125d391f821150a197e0a | |
parent | 5b2c12e1d45ec2fd46b24c4c870540f6965b6f87 (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.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>
(cherry picked from commit 22f3c6ac535afb217f6d3a26a5b74c4d5b29f287)
-rw-r--r-- | src/linguist/GenerateLUpdateProject.cmake | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/linguist/GenerateLUpdateProject.cmake b/src/linguist/GenerateLUpdateProject.cmake index 44647d86a..2c6b03d10 100644 --- a/src/linguist/GenerateLUpdateProject.cmake +++ b/src/linguist/GenerateLUpdateProject.cmake @@ -21,6 +21,27 @@ function(list_to_json_array srcList jsonList) set(${jsonList} "[ ${joinedList} ]" 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() + get_filename_component(project_root "${lupdate_project_file}" DIRECTORY) # Make relative paths absolute to the project root @@ -42,7 +63,9 @@ foreach(path IN LISTS absolute_sources) endif() endforeach() -list_to_json_array("${existing_sources}" json_sources) +filter_generated_ui_headers(sources ${existing_sources}) + +list_to_json_array("${sources}" json_sources) list_to_json_array("${absolute_include_paths}" json_include_paths) list_to_json_array("${absolute_translations}" json_translations) |