Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support of the control custom translation files. #529

Merged
merged 3 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Deploy/configparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ bool ConfigParser::loadFromFile(const QString& confFile) {
}

auto obj = doc.object();

for (const auto &key: obj.keys()) {
const auto keys = obj.keys();
for (const auto &key: keys) {
readKey(key, obj, confFilePath);
}

Expand Down Expand Up @@ -387,6 +387,8 @@ bool ConfigParser::initDistroStruct() {
auto extraData = QuasarAppUtils::Params::getStrArg("extraData").
split(DeployCore::getSeparator(0), splitbehavior);

auto trData = QuasarAppUtils::Params::getStrArg("tr").
split(DeployCore::getSeparator(0), splitbehavior);

// init distro stucts for all targets
if (binOut.size() && !parsePackagesPrivate(mainDistro, binOut, &DistroModule::setBinOutDir)) {
Expand Down Expand Up @@ -469,6 +471,11 @@ bool ConfigParser::initDistroStruct() {
return false;
}

if (trData.size() && !parsePackagesPrivate(mainDistro, trData, &DistroModule::addTr)) {
packagesErrorLog("tr");
return false;
}

return true;
}

Expand Down
12 changes: 12 additions & 0 deletions Deploy/deployconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ QString DeployConfig::getTargetDir(const QString &target) const {
return targetDir;
}

QString DeployConfig::getPackageTargetDir(const QString &package) const {
if (!_packages.contains(package)) {
#ifdef QT_DEBUG
abort();
#endif
return "";
}

return targetDir + "/" + package;

}

void DeployConfig::setTargetDir(const QString &target) {
targetDir = target;

Expand Down
7 changes: 7 additions & 0 deletions Deploy/deployconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ class DEPLOYSHARED_EXPORT DeployConfig {
*/
QString getTargetDir(const QString& target = "") const;

/**
* @brief getPackageTargetDir This method return the target dif of the package.
* @param package This is id of the package
* @return target diractory path
*/
QString getPackageTargetDir(const QString& package) const;

/**
* @brief setTargetDir
* @param target
Expand Down
6 changes: 4 additions & 2 deletions Deploy/deploycore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ void DeployCore::help() {
{"-runScript [list,parems]", "forces cqtdeployer swap default run script to new from the arguments of option."
" This option copy all content from input file and insert all code into runScript.sh or .bat"
" Example of use: cqtdeployer -runScript \"myTargetMame;path/to/my/myCustomLaunchScript.sh,myTargetSecondMame;path/to/my/mySecondCustomLaunchScript.sh\""},

{"-verbose [0-3]", "Shows debug log"},

}
Expand All @@ -270,6 +269,8 @@ void DeployCore::help() {
{"-homePage [package;val,val]", "Sets the home page url for a package"},
{"-prefix [package;val,val]", "Sets the prefix for the package relatively a target directory "},
{"-extraData [package;val,val]", "Adds the extra files or directories like a target. The selected directory will be copy to the extraDataOut location with save own structure."},
{"-tr [package;val,val]", "Adds qm files into the translations folder."},


}
},
Expand Down Expand Up @@ -364,7 +365,8 @@ QStringList DeployCore::helpKeys() {
"deb",
"allowEmptyPackages",
"runScript",
"getDefaultTemplate"
"getDefaultTemplate",
"tr"
};
}

Expand Down
12 changes: 12 additions & 0 deletions Deploy/distromodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ void DistroModule::setKey(const QString &key) {
_key = key;
}

QSet<QString> DistroModule::tr() const {
return _tr;
}

void DistroModule::setTr(const QSet<QString> &tr) {
_tr = tr;
}

void DistroModule::addTr(const QString &tr) {
_tr += tr;
}

QSet<QString> DistroModule::extraData() const {
return _extraData;
}
Expand Down
10 changes: 10 additions & 0 deletions Deploy/distromodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ class DEPLOYSHARED_EXPORT DistroModule: public DistroStruct
void setExtraData(const QSet<QString> &extraFiles);
void addExtraData(const QString &extraFile);

QSet<QString> tr() const;
void setTr(const QSet<QString> &tr);
void addTr(const QString &tr);

protected:
void setKey(const QString &key);

Expand All @@ -94,8 +98,14 @@ class DEPLOYSHARED_EXPORT DistroModule: public DistroStruct
QSet<QString> _enabled;
QSet<QString> _disabled;
QSet<QString> _extraPlugins;

// extra data
QSet<QString> _extraData;

// extra translations
QSet<QString> _tr;


};

#endif // DISTROMODULE_H
19 changes: 15 additions & 4 deletions Deploy/extracter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,21 +250,28 @@ void Extracter::copyFiles() {
}
}

void Extracter::copyTr() {
bool Extracter::copyTr() {

if (!QuasarAppUtils::Params::isEndable("noTranslations")) {

auto cnf = DeployCore::_config;

for (auto i = cnf->packages().cbegin(); i != cnf->packages().cend(); ++i) {
if (!copyTranslations(DeployCore::extractTranslation(_packageDependencyes[i.key()].neadedLibs()),
i.key())) {
QuasarAppUtils::Params::log("Failed to copy standard Qt translations",
QuasarAppUtils::Warning);
}
}

const auto trFiles = i->tr();
for (const auto &tr: trFiles) {
if (!_fileManager->copyFile(tr, cnf->getPackageTargetDir(i.key()) + i->getTrOutDir())) {
return false;
}
}
}
}

return true;
}

bool Extracter::deploy() {
Expand All @@ -287,7 +294,11 @@ bool Extracter::deploy() {

copyFiles();

copyTr();
if (!copyTr()) {
QuasarAppUtils::Params::log("Fail to copy translations", QuasarAppUtils::Error);

return false;
};

if (!extractWebEngine()) {
QuasarAppUtils::Params::log("deploy webEngine failed", QuasarAppUtils::Error);
Expand Down
2 changes: 1 addition & 1 deletion Deploy/extracter.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class DEPLOYSHARED_EXPORT Extracter {
void extractPlugins();

void copyFiles();
void copyTr();
bool copyTr();

/**
* @brief copyLibs This method copy input libraryes into libOut dir.
Expand Down
1 change: 1 addition & 0 deletions UnitTests/res.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
<file>testRes/TestQMLWidgets.sh</file>
<file>testRes/testMultiPackageConfig.json</file>
<file>testRes/customRunScript.sh</file>
<file>testRes/TestTr.qm</file>
</qresource>
</RCC>
1 change: 1 addition & 0 deletions UnitTests/testRes/TestTr.qm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TEST TR
21 changes: 21 additions & 0 deletions UnitTests/tst_deploytest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ private slots:
void testRunScripts();
void testGetDefaultTemplate();
void testDeployGeneralFiles();
void testTr();

void customTest();
};
Expand Down Expand Up @@ -1167,6 +1168,26 @@ void deploytest::testDeployGeneralFiles() {
}, &comapareTree);
}

void deploytest::testTr() {
TestUtils utils;
#ifdef Q_OS_UNIX
QString bin = TestBinDir + "QtWidgetsProject";
QString qmake = TestQtDir + "bin/qmake";

#else
QString bin = TestBinDir + "QtWidgetsProject.exe";
QString qmake = TestQtDir + "bin/qmake.exe";

#endif
auto comapareTree = TestModule.qtLibs();

comapareTree += utils.createTree({"./" + DISTRO_DIR + "/translations/TestTr.qm"});

runTestParams({"-bin", bin, "clear" ,
"-tr", ":/testResurces/testRes/TestTr.qm",
"-qmake", qmake}, &comapareTree);
}

void deploytest::customTest() {
// runTestParams({"-confFile", "path",
// "qifFromSystem"});
Expand Down
4 changes: 3 additions & 1 deletion docs/en/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ cqtdeployer -option1 value1 -option2 list, of, values ​​flag1 flag2 flag3

| Option | Descriptiion |
|-----------------------------|-----------------------------------------------------------|
| -targetPackage [package;tar1,package;tar2]| Creates a new package and adds 'tar1 and tar2' to it |
| -targetPackage [package;tar1,package;tar2]| Creates a new package and adds 'tar1 and tar2' to it |
| -qmlOut [package;path,path] | Sets path to qml out directory |
| -libOut [package;path,path] | Sets path to libraries out directory |
| -trOut [package;path,path] | Sets path to translations out directory |
Expand All @@ -104,6 +104,8 @@ cqtdeployer -option1 value1 -option2 list, of, values ​​flag1 flag2 flag3
| -homePage [package;val,val] | Sets the homepage url for a package |
| -prefix [package;val,val] | Sets the prefix for the package relatively a target directory |
| -extraData [package;val,val]| Adds the extra files or directories like a target. The selected directory will be copy to the extraDataOut location with save own structure.|
| -tr [package;val,val] | Adds qm files into the translations folder. |


### Plugins Controll Options

Expand Down
1 change: 1 addition & 0 deletions docs/ru/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ cqtdeployer -option1 value1 -option2 list,of,values flag1 flag2 flag3
| -homePage [package;val,val] | Установит URL-адрес домашней страницы для пакета |
| -prefix [package;val,val] | Устанавливает префикс для пакета относительно целевого каталога |
| -extraData [package;val,val]| Добавляет дополнительные файлы или каталоги как цель. Выбранный каталог будет скопирован в расположение extraDataOut с сохранением собственной структуры.|
| -tr [package;val,val] | Добавляет qm файлы в папку переводов. |

### Параметры управления плагинами:

Expand Down