fix: -Wtrailing-whitespace= in translation resources #808

Manually merged
uqlidi merged 1 commit from fix/warnings/trailing-whitspaces into qt6 2026-11-21 12:41:37 +00:00 AGit
uqlidi commented 2026-07-20 21:33:04 +00:00 (Migrated from github.com)

fix #777

fix #777
johnny9 (Migrated from github.com) reviewed 2026-07-21 12:05:28 +00:00
johnny9 (Migrated from github.com) commented 2026-07-21 12:05:19 +00:00

Is there a way to do this without referring to the hidden build artifacts Qt produces?

Is there a way to do this without referring to the hidden build artifacts Qt produces?
jarolrod (Migrated from github.com) reviewed 2026-07-23 03:01:27 +00:00
jarolrod (Migrated from github.com) commented 2026-07-23 03:01:27 +00:00

Maybe we can just use the same design pattern as the QML_QRC_CPP block, as in take the ${OUTVAR}?

Maybe we can just use the same design pattern as the QML_QRC_CPP block, as in take the ${OUTVAR}?
uqlidi (Migrated from github.com) reviewed 2026-07-31 17:23:45 +00:00
uqlidi (Migrated from github.com) commented 2026-07-31 17:23:45 +00:00

Is there a way to do this without referring to the hidden build artifacts Qt produces?

there's a way to generate them on build but I feel we should keep them simpe as possible

> Is there a way to do this without referring to the hidden build artifacts Qt produces? there's a way to generate them on build but I feel we should keep them simpe as possible
uqlidi (Migrated from github.com) reviewed 2026-07-31 17:50:02 +00:00
uqlidi (Migrated from github.com) commented 2026-07-31 17:50:02 +00:00

something like that:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 90478632d..c64039340 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -134,13 +134,15 @@ target_link_libraries(bitcoinqml
 qt6_add_translation(QML_GUI_QM_FILES
     ${CMAKE_CURRENT_SOURCE_DIR}/qml/locale/bitcoin_qml_es.ts
 )
-set_source_files_properties(${QML_GUI_QM_FILES} PROPERTIES
-    QT_RESOURCE_ALIAS "bitcoin_qml_es.qm"
-)
-qt6_add_resources(bitcoinqml "qml_gui_translations"
-    PREFIX "/translations"
-    FILES ${QML_GUI_QM_FILES}
-)
+set(qml_gui_qrc_entries "")
+foreach(qm_file IN LISTS QML_GUI_QM_FILES)
+    get_filename_component(qm_name "${qm_file}" NAME)
+    string(APPEND qml_gui_qrc_entries "    <file alias=\"${qm_name}\">${qm_file}</file>\n")
+endforeach()
+set(QML_GUI_TRANSLATIONS_QRC "${CMAKE_CURRENT_BINARY_DIR}/qml_gui_translations.qrc")
+file(WRITE "${QML_GUI_TRANSLATIONS_QRC}"
+    "<!DOCTYPE RCC><RCC version=\"1.0\">\n  <qresource prefix=\"/translations\">\n${qml_gui_qrc_entries}  </qresource>\n</RCC>\n")
+qt6_add_resources(QML_GUI_TRANSLATIONS_CPP ${QML_GUI_TRANSLATIONS_QRC})
 
 # Embed bitcoin-qt translations built by the bitcoin submodule.
 # The submodule (BUILD_GUI=ON) compiles .ts -> .qm files into
@@ -148,21 +150,17 @@ qt6_add_resources(bitcoinqml "qml_gui_translations"
 # embedded list from the submodule's current source list so Core translation
 # additions/removals do not leave stale resource inputs behind.
 include("${CMAKE_CURRENT_SOURCE_DIR}/bitcoin/src/qt/locale/ts_files.cmake")
-set(BITCOIN_QT_QM_FILES)
+set(bitcoin_qt_qrc_entries "")
 foreach(ts_file IN LISTS ts_files)
     string(REGEX REPLACE "^bitcoin_(.+)\\.ts$" "\\1" tag "${ts_file}")
     set(qm_file "${CMAKE_BINARY_DIR}/bitcoin/src/qt/locale/bitcoin_${tag}.qm")
-    set_source_files_properties(${qm_file} PROPERTIES
-        GENERATED TRUE
-        QT_RESOURCE_ALIAS "bitcoin_${tag}.qm"
-    )
-    list(APPEND BITCOIN_QT_QM_FILES ${qm_file})
+    string(APPEND bitcoin_qt_qrc_entries "    <file alias=\"bitcoin_${tag}.qm\">${qm_file}</file>\n")
 endforeach()
 unset(ts_files)
-qt6_add_resources(bitcoinqml "bitcoin_qt_translations"
-    PREFIX "/translations"
-    FILES ${BITCOIN_QT_QM_FILES}
-)
+set(BITCOIN_QT_TRANSLATIONS_QRC "${CMAKE_CURRENT_BINARY_DIR}/bitcoin_qt_translations.qrc")
+file(WRITE "${BITCOIN_QT_TRANSLATIONS_QRC}"
+    "<!DOCTYPE RCC><RCC version=\"1.0\">\n  <qresource prefix=\"/translations\">\n${bitcoin_qt_qrc_entries}  </qresource>\n</RCC>\n")
+qt6_add_resources(BITCOIN_QT_TRANSLATIONS_CPP ${BITCOIN_QT_TRANSLATIONS_QRC})
 
 # RCC-generated translation sources contain trailing whitespace that trips
 # -Wtrailing-whitespace=any (GCC >= 15). Suppress it only for those generated
@@ -170,14 +168,13 @@ qt6_add_resources(bitcoinqml "bitcoin_qt_translations"
 # See: https://bugreports.qt.io/browse/QTBUG-141858.
 get_target_property(warn_flags warn_interface INTERFACE_COMPILE_OPTIONS)
 if("-Wtrailing-whitespace=any" IN_LIST warn_flags)
-    set_source_files_properties(
-        ${CMAKE_CURRENT_BINARY_DIR}/.qt/rcc/qrc_qml_gui_translations.cpp
-        ${CMAKE_CURRENT_BINARY_DIR}/.qt/rcc/qrc_bitcoin_qt_translations.cpp
+    set_source_files_properties(${QML_GUI_TRANSLATIONS_CPP} ${BITCOIN_QT_TRANSLATIONS_CPP}
         PROPERTIES COMPILE_OPTIONS -Wno-trailing-whitespace
     )
 endif()
 unset(warn_flags)
 
+target_sources(bitcoinqml PRIVATE ${QML_GUI_TRANSLATIONS_CPP} ${BITCOIN_QT_TRANSLATIONS_CPP})
 add_dependencies(bitcoinqml bitcoin-qt)
 
 # Put it all together


something like that: ```diff diff --git a/CMakeLists.txt b/CMakeLists.txt index 90478632d..c64039340 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -134,13 +134,15 @@ target_link_libraries(bitcoinqml qt6_add_translation(QML_GUI_QM_FILES ${CMAKE_CURRENT_SOURCE_DIR}/qml/locale/bitcoin_qml_es.ts ) -set_source_files_properties(${QML_GUI_QM_FILES} PROPERTIES - QT_RESOURCE_ALIAS "bitcoin_qml_es.qm" -) -qt6_add_resources(bitcoinqml "qml_gui_translations" - PREFIX "/translations" - FILES ${QML_GUI_QM_FILES} -) +set(qml_gui_qrc_entries "") +foreach(qm_file IN LISTS QML_GUI_QM_FILES) + get_filename_component(qm_name "${qm_file}" NAME) + string(APPEND qml_gui_qrc_entries " <file alias=\"${qm_name}\">${qm_file}</file>\n") +endforeach() +set(QML_GUI_TRANSLATIONS_QRC "${CMAKE_CURRENT_BINARY_DIR}/qml_gui_translations.qrc") +file(WRITE "${QML_GUI_TRANSLATIONS_QRC}" + "<!DOCTYPE RCC><RCC version=\"1.0\">\n <qresource prefix=\"/translations\">\n${qml_gui_qrc_entries} </qresource>\n</RCC>\n") +qt6_add_resources(QML_GUI_TRANSLATIONS_CPP ${QML_GUI_TRANSLATIONS_QRC}) # Embed bitcoin-qt translations built by the bitcoin submodule. # The submodule (BUILD_GUI=ON) compiles .ts -> .qm files into @@ -148,21 +150,17 @@ qt6_add_resources(bitcoinqml "qml_gui_translations" # embedded list from the submodule's current source list so Core translation # additions/removals do not leave stale resource inputs behind. include("${CMAKE_CURRENT_SOURCE_DIR}/bitcoin/src/qt/locale/ts_files.cmake") -set(BITCOIN_QT_QM_FILES) +set(bitcoin_qt_qrc_entries "") foreach(ts_file IN LISTS ts_files) string(REGEX REPLACE "^bitcoin_(.+)\\.ts$" "\\1" tag "${ts_file}") set(qm_file "${CMAKE_BINARY_DIR}/bitcoin/src/qt/locale/bitcoin_${tag}.qm") - set_source_files_properties(${qm_file} PROPERTIES - GENERATED TRUE - QT_RESOURCE_ALIAS "bitcoin_${tag}.qm" - ) - list(APPEND BITCOIN_QT_QM_FILES ${qm_file}) + string(APPEND bitcoin_qt_qrc_entries " <file alias=\"bitcoin_${tag}.qm\">${qm_file}</file>\n") endforeach() unset(ts_files) -qt6_add_resources(bitcoinqml "bitcoin_qt_translations" - PREFIX "/translations" - FILES ${BITCOIN_QT_QM_FILES} -) +set(BITCOIN_QT_TRANSLATIONS_QRC "${CMAKE_CURRENT_BINARY_DIR}/bitcoin_qt_translations.qrc") +file(WRITE "${BITCOIN_QT_TRANSLATIONS_QRC}" + "<!DOCTYPE RCC><RCC version=\"1.0\">\n <qresource prefix=\"/translations\">\n${bitcoin_qt_qrc_entries} </qresource>\n</RCC>\n") +qt6_add_resources(BITCOIN_QT_TRANSLATIONS_CPP ${BITCOIN_QT_TRANSLATIONS_QRC}) # RCC-generated translation sources contain trailing whitespace that trips # -Wtrailing-whitespace=any (GCC >= 15). Suppress it only for those generated @@ -170,14 +168,13 @@ qt6_add_resources(bitcoinqml "bitcoin_qt_translations" # See: https://bugreports.qt.io/browse/QTBUG-141858. get_target_property(warn_flags warn_interface INTERFACE_COMPILE_OPTIONS) if("-Wtrailing-whitespace=any" IN_LIST warn_flags) - set_source_files_properties( - ${CMAKE_CURRENT_BINARY_DIR}/.qt/rcc/qrc_qml_gui_translations.cpp - ${CMAKE_CURRENT_BINARY_DIR}/.qt/rcc/qrc_bitcoin_qt_translations.cpp + set_source_files_properties(${QML_GUI_TRANSLATIONS_CPP} ${BITCOIN_QT_TRANSLATIONS_CPP} PROPERTIES COMPILE_OPTIONS -Wno-trailing-whitespace ) endif() unset(warn_flags) +target_sources(bitcoinqml PRIVATE ${QML_GUI_TRANSLATIONS_CPP} ${BITCOIN_QT_TRANSLATIONS_CPP}) add_dependencies(bitcoinqml bitcoin-qt) # Put it all together ```
uqlidi (Migrated from github.com) reviewed 2026-08-21 09:06:07 +00:00
uqlidi (Migrated from github.com) commented 2026-08-21 09:06:07 +00:00

@johnny9 @jarolrod I would like to know your opinion about that

@johnny9 @jarolrod I would like to know your opinion about that
johnny9 (Migrated from github.com) reviewed 2026-08-22 05:29:32 +00:00
johnny9 (Migrated from github.com) commented 2026-08-22 05:29:32 +00:00

Here is potentiality a simpler solution that doesnt require generating XML

qt6_add_resources(bitcoinqml "qml_gui_translations"
    OUTPUT_TARGETS QML_GUI_TRANSLATION_RESOURCE_TARGETS
    PREFIX "/translations"
    FILES ${QML_GUI_QM_FILES}
)

qt6_add_resources(bitcoinqml "bitcoin_qt_translations"
    OUTPUT_TARGETS BITCOIN_QT_TRANSLATION_RESOURCE_TARGETS
    PREFIX "/translations"
    FILES ${BITCOIN_QT_QM_FILES}
)

get_target_property(warn_flags warn_interface INTERFACE_COMPILE_OPTIONS)
if("-Wtrailing-whitespace=any" IN_LIST warn_flags)
    foreach(resource_target IN LISTS
        QML_GUI_TRANSLATION_RESOURCE_TARGETS
        BITCOIN_QT_TRANSLATION_RESOURCE_TARGETS
    )
        target_compile_options(${resource_target} PRIVATE -Wno-trailing-whitespace)
    endforeach()
endif()
unset(warn_flags)
Here is potentiality a simpler solution that doesnt require generating XML ```cmake qt6_add_resources(bitcoinqml "qml_gui_translations" OUTPUT_TARGETS QML_GUI_TRANSLATION_RESOURCE_TARGETS PREFIX "/translations" FILES ${QML_GUI_QM_FILES} ) qt6_add_resources(bitcoinqml "bitcoin_qt_translations" OUTPUT_TARGETS BITCOIN_QT_TRANSLATION_RESOURCE_TARGETS PREFIX "/translations" FILES ${BITCOIN_QT_QM_FILES} ) get_target_property(warn_flags warn_interface INTERFACE_COMPILE_OPTIONS) if("-Wtrailing-whitespace=any" IN_LIST warn_flags) foreach(resource_target IN LISTS QML_GUI_TRANSLATION_RESOURCE_TARGETS BITCOIN_QT_TRANSLATION_RESOURCE_TARGETS ) target_compile_options(${resource_target} PRIVATE -Wno-trailing-whitespace) endforeach() endif() unset(warn_flags) ```
uqlidi (Migrated from github.com) reviewed 2026-08-23 07:21:17 +00:00
uqlidi (Migrated from github.com) commented 2026-08-23 07:21:17 +00:00

still it emits the warnings and doesn't solve the issue. i think the simplest solution would be something like that

get_target_property(qml_translation_srcs bitcoinqml SOURCES)
list(FILTER qml_translation_srcs INCLUDE REGEX "qrc_(qml_gui|bitcoin_qt)_translations\\.cpp$")
set_source_files_properties(${qml_translation_srcs}
    PROPERTIES COMPILE_OPTIONS -Wno-trailing-whitespace
)

What do you think?

still it emits the warnings and doesn't solve the issue. i think the simplest solution would be something like that ```cmake get_target_property(qml_translation_srcs bitcoinqml SOURCES) list(FILTER qml_translation_srcs INCLUDE REGEX "qrc_(qml_gui|bitcoin_qt)_translations\\.cpp$") set_source_files_properties(${qml_translation_srcs} PROPERTIES COMPILE_OPTIONS -Wno-trailing-whitespace ) ``` What do you think?
johnny9 (Migrated from github.com) reviewed 2026-10-07 20:06:30 +00:00
johnny9 (Migrated from github.com) commented 2026-10-07 20:06:30 +00:00

yeah we can try that

yeah we can try that
johnny9 (Migrated from github.com) approved these changes 2026-10-10 16:39:40 +00:00
johnny9 (Migrated from github.com) left a comment
ACK 0eb79e61966e33c0ff4ecb5d219bc68c75554b79
rreview commented 2026-11-04 23:30:01 +00:00 (Migrated from github.com)

No verified findings are available from this review.

Review coverage was incomplete.


Reviewed: 5f90d1332b36 · Full review report

<!-- ralph-major:bitcoin-core/gui-qml --> No verified findings are available from this review. Review coverage was incomplete. <!-- Review tier: standard --> --- Reviewed: [`5f90d1332b36`](<https://github.com/bitcoin-core/gui-qml/commit/5f90d1332b36369fe2b00bb0c1404a684341e0d2>) · [Full review report](<https://review.fish.foo/traces/gui/808-5f90d1332b36369fe2b00bb0c1404a684341e0d2-2166-1.html>)
johnny9 (Migrated from github.com) approved these changes 2026-11-10 18:22:58 +00:00
johnny9 (Migrated from github.com) left a comment

ACK 5f90d1332b

Compared with my previous ACK at 0eb79e6. The patch is unchanged after the rebase, and CI passed.

ACK 5f90d1332b36369fe2b00bb0c1404a684341e0d2 Compared with my previous ACK at 0eb79e6. The patch is unchanged after the rebase, and CI passed.
uqlidi commented 2026-11-21 02:11:15 +00:00 (Migrated from github.com)

@hebasto this one is ready to be merged

@hebasto this one is ready to be merged
Sign in to join this conversation.
No description provided.