From f14bc593dbf67086c4f6c189a1f262ecc3b08901 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Mon, 10 Jun 2024 09:24:11 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"use=20qt=20resource=20system's=20reco?= =?UTF-8?q?mmended=20approach=20for=20translation=20files=20(=E2=80=A6"=20?= =?UTF-8?q?(#451)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit e2934072d158cc26ee2b10c0065f82c8aceefdd1. --- RedPandaIDE/RedPandaIDE.pro | 35 ++++++++++++- RedPandaIDE/main.cpp | 2 - RedPandaIDE/utils.cpp | 10 ---- RedPandaIDE/utils.h | 5 -- RedPandaIDE/xmake.lua | 6 ++- libs/qsynedit/qsynedit.pro | 2 - libs/qsynedit/xmake.lua | 2 - libs/redpanda_qt_utils/redpanda_qt_utils.pro | 3 -- libs/redpanda_qt_utils/xmake.lua | 1 - xmake.lua | 53 ++++++++------------ 10 files changed, 58 insertions(+), 61 deletions(-) diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index d4630912..1ac6aedb 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -3,8 +3,6 @@ QT += core gui printsupport network svg xml widgets CONFIG += c++17 CONFIG += nokey -CONFIG += lrelease embed_translations - # uncomment the following line to enable vcs (git) support # CONFIG += ENABLE_VCS @@ -541,6 +539,13 @@ TRANSLATIONS += \ translations/RedPandaIDE_zh_TW.ts \ translations/RedPandaIDE_pt_BR.ts +EXTRA_TRANSLATIONS += \ + ../libs/redpanda_qt_utils/qt_utils_zh_CN.ts \ + ../libs/qsynedit/qsynedit_zh_CN.ts + + +#CONFIG += lrelease embed_translations + win32: { !isEmpty(PREFIX) { target.path = $${PREFIX} @@ -562,6 +567,31 @@ RESOURCES += \ RC_ICONS = images/devcpp.ico images/associations/c.ico images/associations/cpp.ico images/associations/dev.ico images/associations/c.ico images/associations/cpp.ico images/associations/h.ico images/associations/hpp.ico +# fixed lrelease.prf +qtPrepareTool(QMAKE_LRELEASE, lrelease) + +isEmpty(LRELEASE_DIR): LRELEASE_DIR = .qm +isEmpty(QM_FILES_RESOURCE_PREFIX): QM_FILES_RESOURCE_PREFIX = i18n + +lrelease.name = lrelease +lrelease.input = TRANSLATIONS EXTRA_TRANSLATIONS +lrelease.output = $$LRELEASE_DIR/${QMAKE_FILE_IN_BASE}.qm +lrelease.commands = $$QMAKE_LRELEASE ${QMAKE_FILE_IN} $$QMAKE_LRELEASE_FLAGS -qm ${QMAKE_FILE_OUT} +silent: lrelease.commands = @echo lrelease ${QMAKE_FILE_IN} && $$lrelease.commands +lrelease.CONFIG = no_link target_predeps +QMAKE_EXTRA_COMPILERS += lrelease + +all_translations = $$TRANSLATIONS $$EXTRA_TRANSLATIONS +for (translation, all_translations) { + # mirrors $$LRELEASE_DIR/${QMAKE_FILE_IN_BASE}.qm above + translation = $$basename(translation) + QM_FILES += $$OUT_PWD/$$LRELEASE_DIR/$$replace(translation, \\..*$, .qm) +} + +qmake_qm_files.files = $$QM_FILES +qmake_qm_files.base = $$OUT_PWD/$$LRELEASE_DIR +qmake_qm_files.prefix = $$QM_FILES_RESOURCE_PREFIX + iconsets_files.files += $$files(resources/iconsets/*.svg, true) iconsets_files.files += $$files(resources/iconsets/*.json, true) @@ -571,6 +601,7 @@ theme_files.files += $$files(resources/themes/*.png, false) colorscheme_files.files += $$files(resources/colorschemes/*.scheme, false) +RESOURCES += qmake_qm_files RESOURCES += iconsets_files RESOURCES += theme_files RESOURCES += colorscheme_files diff --git a/RedPandaIDE/main.cpp b/RedPandaIDE/main.cpp index 0789cf08..1e37d936 100644 --- a/RedPandaIDE/main.cpp +++ b/RedPandaIDE/main.cpp @@ -280,8 +280,6 @@ int main(int argc, char *argv[]) app.setAttribute(Qt::AA_UseHighDpiPixmaps); - ExternalResource resource; - QLockFile lockFile(QDir::tempPath()+QDir::separator()+"RedPandaDevCppStartUp.lock"); { bool firstRun; diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp index 2e3d8675..d7eb4726 100644 --- a/RedPandaIDE/utils.cpp +++ b/RedPandaIDE/utils.cpp @@ -784,13 +784,3 @@ QByteArray reformatContentUsingAstyle(const QByteArray &content, const QStringLi env); return newContent; } - -ExternalResource::ExternalResource() { - Q_INIT_RESOURCE(qsynedit_qmake_qmake_qm_files); - Q_INIT_RESOURCE(redpanda_qt_utils_qmake_qmake_qm_files); -} - -ExternalResource::~ExternalResource() { - Q_CLEANUP_RESOURCE(qsynedit_qmake_qmake_qm_files); - Q_CLEANUP_RESOURCE(redpanda_qt_utils_qmake_qmake_qm_files); -} diff --git a/RedPandaIDE/utils.h b/RedPandaIDE/utils.h index b4b5d039..cf4f8100 100644 --- a/RedPandaIDE/utils.h +++ b/RedPandaIDE/utils.h @@ -204,9 +204,4 @@ std::tuple wrapCommandFor std::tuple wrapCommandForTerminalEmulator(const QString &terminal, const QString &argsPattern, const QStringList &payloadArgsWithArgv0); -struct ExternalResource { - ExternalResource(); - ~ExternalResource(); -}; - #endif // UTILS_H diff --git a/RedPandaIDE/xmake.lua b/RedPandaIDE/xmake.lua index 3d0ba3d4..a3510fcc 100644 --- a/RedPandaIDE/xmake.lua +++ b/RedPandaIDE/xmake.lua @@ -228,7 +228,11 @@ target("RedPandaIDE") -- libs - add_links("redpanda_qt_utils", "qsynedit") + if is_plat("windows") then + add_links("redpanda_qt_utils", "qsynedit") -- xmake 2.8.6 workaround + else + add_linkgroups("redpanda_qt_utils", "qsynedit", {whole = true}) + end if is_os("windows") then add_links("psapi", "shlwapi") end diff --git a/libs/qsynedit/qsynedit.pro b/libs/qsynedit/qsynedit.pro index 3aa34ffb..60b03dd2 100644 --- a/libs/qsynedit/qsynedit.pro +++ b/libs/qsynedit/qsynedit.pro @@ -13,8 +13,6 @@ contains(QMAKE_HOST.arch, x86_64):{ } } -CONFIG += lrelease embed_translations -QMAKE_RESOURCE_FLAGS += -name $(QMAKE_TARGET)_${QMAKE_FILE_BASE} win32: { DEFINES += _WIN32_WINNT=0x0501 diff --git a/libs/qsynedit/xmake.lua b/libs/qsynedit/xmake.lua index 0449d190..844e3956 100644 --- a/libs/qsynedit/xmake.lua +++ b/libs/qsynedit/xmake.lua @@ -39,8 +39,6 @@ target("qsynedit") add_ui_classes() - add_files("*.ts") - add_includedirs(".", {interface = true}) -- do not install diff --git a/libs/redpanda_qt_utils/redpanda_qt_utils.pro b/libs/redpanda_qt_utils/redpanda_qt_utils.pro index b2f3419c..f63e244b 100644 --- a/libs/redpanda_qt_utils/redpanda_qt_utils.pro +++ b/libs/redpanda_qt_utils/redpanda_qt_utils.pro @@ -7,9 +7,6 @@ CONFIG += c++17 CONFIG += nokey CONFIG += staticlib -CONFIG += lrelease embed_translations -QMAKE_RESOURCE_FLAGS += -name $(QMAKE_TARGET)_${QMAKE_FILE_BASE} - win32: { DEFINES += _WIN32_WINNT=0x0501 } diff --git a/libs/redpanda_qt_utils/xmake.lua b/libs/redpanda_qt_utils/xmake.lua index 68aa25d7..3adcb2b2 100644 --- a/libs/redpanda_qt_utils/xmake.lua +++ b/libs/redpanda_qt_utils/xmake.lua @@ -5,7 +5,6 @@ target("redpanda_qt_utils") add_files("qt_utils/utils.cpp") add_moc_classes("qt_utils/charsetinfo") - add_files("*.ts") add_includedirs(".", {interface = true}) -- do not install diff --git a/xmake.lua b/xmake.lua index 79383d4a..47aa042c 100644 --- a/xmake.lua +++ b/xmake.lua @@ -75,48 +75,35 @@ rule("qt.ts") -- save lrelease target:data_set("qt.lrelease", lrelease) end) - on_buildcmd_files(function (target, batchcmds, sourcebatch, opt) + on_buildcmd_file(function (target, batchcmds, sourcefile_ts, opt) + -- get tools local lrelease = target:data("qt.lrelease") - local qrc_content = [[ - - - ]] - for _, sourcefile_ts in ipairs(sourcebatch.sourcefiles) do - if is_host("windows") then - sourcefile_ts = sourcefile_ts:gsub("\\", "/") - end - -- get qm file - local sourcefile_qm = path.join(target:autogendir(), "rules", "qt", "ts", path.basename(sourcefile_ts) .. ".qm") - local sourcefile_dir = path.directory(sourcefile_qm) - -- build ts to qm file - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.qt.ts %s", sourcefile_ts) - batchcmds:mkdir(sourcefile_dir) - batchcmds:vrunv(lrelease, {sourcefile_ts, "-qm", sourcefile_qm}) - - qrc_content = qrc_content .. [[ - ]] .. path.absolute(sourcefile_qm) .. [[ - ]] - end - qrc_content = qrc_content .. [[ - - - ]] - local rcc = target:data("qt.rcc") - local name = target:name() .. "_qmake_qmake_qm_files" -- same as qmake - local sourcefile_qrc = path.join(target:autogendir(), "rules", "qt", "ts", name .. ".qrc") - io.writefile(sourcefile_qrc, qrc_content) + -- get qm file + local sourcefile_qm = path.join(target:autogendir(), "rules", "qt", "ts", path.basename(sourcefile_ts) .. ".qm") + local sourcefile_dir = path.directory(sourcefile_qm) + -- prepare qrc file + local sourcefile_qrc = path.join(target:autogendir(), "rules", "qt", "ts", path.basename(sourcefile_ts) .. ".qrc") + io.writefile(sourcefile_qrc, [[ + + + ]] .. path.absolute(sourcefile_qm) .. [[ + + + ]]) -- get c++ source file for qrc - local sourcefile_cpp = path.join(target:autogendir(), "rules", "qt", "ts", name .. ".cpp") + local sourcefile_cpp = path.join(target:autogendir(), "rules", "qt", "ts", path.basename(sourcefile_ts) .. ".cpp") -- add objectfile local objectfile = target:objectfile(sourcefile_cpp) table.insert(target:objectfiles(), objectfile) -- add commands - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.qt.ts %s", sourcefile_cpp) - batchcmds:vrunv(rcc, {"-name", name, sourcefile_qrc, "-o", sourcefile_cpp}) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.qt.ts %s", sourcefile_ts) + batchcmds:mkdir(sourcefile_dir) + batchcmds:vrunv(lrelease, {sourcefile_ts, "-qm", sourcefile_qm}) + batchcmds:vrunv(rcc, {"-name", path.basename(sourcefile_qrc), sourcefile_qrc, "-o", sourcefile_cpp}) batchcmds:compile(sourcefile_cpp, objectfile) -- add deps - batchcmds:add_depfiles(sourcebatch.sourcefiles) + batchcmds:add_depfiles(sourcefile_ts) batchcmds:set_depmtime(os.mtime(objectfile)) batchcmds:set_depcache(target:dependfile(objectfile)) end)