Revert "use qt resource system's recommended approach for translation files (…" (#451)

This reverts commit e2934072d1.
This commit is contained in:
Roy Qu 2024-06-10 09:24:11 +08:00 committed by GitHub
parent e2934072d1
commit f14bc593db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 58 additions and 61 deletions

View File

@ -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

View File

@ -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;

View File

@ -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);
}

View File

@ -204,9 +204,4 @@ std::tuple<QString, QStringList, PNonExclusiveTemporaryFileOwner> wrapCommandFor
std::tuple<QString, QStringList, PNonExclusiveTemporaryFileOwner> wrapCommandForTerminalEmulator(const QString &terminal, const QString &argsPattern, const QStringList &payloadArgsWithArgv0);
struct ExternalResource {
ExternalResource();
~ExternalResource();
};
#endif // UTILS_H

View File

@ -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

View File

@ -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

View File

@ -39,8 +39,6 @@ target("qsynedit")
add_ui_classes()
add_files("*.ts")
add_includedirs(".", {interface = true})
-- do not install

View File

@ -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
}

View File

@ -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

View File

@ -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 = [[
<RCC>
<qresource prefix="/i18n">
]]
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 .. [[
<file alias="]] .. path.filename(sourcefile_qm) .. [[">]] .. path.absolute(sourcefile_qm) .. [[</file>
]]
end
qrc_content = qrc_content .. [[
</qresource>
</RCC>
]]
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, [[
<RCC>
<qresource prefix="/i18n">
<file alias="]] .. path.filename(sourcefile_qm) .. [[">]] .. path.absolute(sourcefile_qm) .. [[</file>
</qresource>
</RCC>
]])
-- 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)