CQtDeployer/Deploy/configparser.cpp

1599 lines
52 KiB
C++
Raw Normal View History

2019-09-23 16:46:57 +03:00
//#
//# Copyright (C) 2018-2021 QuasarApp.
2019-09-23 16:46:57 +03:00
//# Distributed under the lgplv3 software license, see the accompanying
//# Everyone is permitted to copy and distribute verbatim copies
//# of this license document, but changing it is not allowed.
//#
2019-09-14 13:59:11 +03:00
#include "configparser.h"
2019-09-07 12:01:20 +03:00
#include <QDebug>
#include <QDir>
#include <QFileInfo>
2019-09-07 12:36:20 +03:00
#include <QProcess>
2019-11-13 18:18:44 +03:00
#include "dependenciesscanner.h"
2019-09-07 12:01:20 +03:00
#include "deploycore.h"
2019-09-08 13:37:33 +03:00
#include "filemanager.h"
#include "packing.h"
#include "pathutils.h"
#include "pluginsparser.h"
2019-09-07 12:01:20 +03:00
#include "quasarapp.h"
2019-09-04 21:27:29 +03:00
2020-01-12 16:43:03 +03:00
#include <cassert>
2020-11-09 16:33:50 +03:00
#include <Distributions/deb.h>
#include <Distributions/defaultdistro.h>
#include <Distributions/qif.h>
2020-08-14 17:47:34 +03:00
#include <Distributions/ziparhive.h>
2020-09-07 10:14:15 +03:00
/**
2020-01-27 20:02:25 +03:00
* this function init packages of project
* inputParamsList - list of parameters
2020-01-27 20:02:25 +03:00
* patern : value;package
* mainContainer - container for insert data, usually it is packages map.
* seterFunc - this is method of item of mainConteiner for set value from inputParamsList
2020-01-27 20:02:25 +03:00
* important : package in inputParamsList must be second.
*/
2020-01-15 18:31:09 +03:00
2020-01-27 20:02:25 +03:00
static QString defaultPackage = "";
2020-01-15 18:31:09 +03:00
2020-07-04 23:08:41 +03:00
template<typename Container, typename Adder>
2020-01-27 20:02:25 +03:00
bool parsePackagesPrivate(Container& mainContainer,
const QStringList &inputParamsList,
2020-07-04 23:08:41 +03:00
Adder adder) {
2020-01-12 16:43:03 +03:00
for (const auto& str: inputParamsList) {
2020-07-04 23:08:41 +03:00
auto paramsList = str.split(DeployCore::getSeparator(1));
auto first = paramsList.value(0, "");
if (paramsList.size() == 1)
2020-12-03 20:00:14 +03:00
(valueLink(mainContainer, defaultPackage, DistroModule{defaultPackage}).*adder)(first);
2019-12-29 14:19:07 +03:00
else {
bool skipError = QuasarAppUtils::Params::isEndable("allowEmptyPackages");
2020-02-27 20:37:05 +03:00
first = PathUtils::fullStripPath(first);
if (!skipError && !mainContainer.contains(first)) {
2019-12-29 14:19:07 +03:00
return false;
}
2020-07-04 23:08:41 +03:00
for (int i = 1; i < paramsList.size(); ++i) {
2020-12-03 20:00:14 +03:00
(valueLink(mainContainer, first, DistroModule{first}).*adder)(paramsList[i]);
2020-07-04 23:08:41 +03:00
}
2019-12-29 14:19:07 +03:00
}
2019-12-28 15:06:43 +03:00
}
2019-12-29 14:19:07 +03:00
return true;
}
2019-12-28 15:06:43 +03:00
2021-02-26 20:24:06 +03:00
template <typename Adder>
void parseTargetPrivate(DeployConfig& conf,
const QStringList &inputParams,
Adder adder) {
auto &cointainer = conf.targetsEdit();
for (const auto &iconPair: inputParams) {
auto pair = iconPair.split(DeployCore::getSeparator(1), splitbehavior);
if (pair.size() == 1) {
QuasarAppUtils::Params::log(QString("Set new default property for all tagets: " + pair.value(0)),
2021-05-12 16:21:59 +03:00
QuasarAppUtils::Debug);
2021-02-26 20:24:06 +03:00
for (auto& editableTarget: cointainer) {
(editableTarget.*adder)(pair.value(0));
}
2021-05-12 16:21:59 +03:00
2021-02-26 20:24:06 +03:00
continue;
}
2021-05-12 16:21:59 +03:00
const auto targetsMap = conf.getTargetsListByFilter(pair.value(0));
2021-02-26 20:24:06 +03:00
if (pair.value(0).isEmpty() || targetsMap.isEmpty()) {
QuasarAppUtils::Params::log(QString("You try sets property for the not exits target."
" target: %0").arg(pair.value(0)),
QuasarAppUtils::Warning);
continue;
}
2021-05-12 16:21:59 +03:00
for (const auto &target: targetsMap) {
QuasarAppUtils::Params::log(QString("Set new property for %0 taget.").
2021-05-12 16:21:59 +03:00
arg(pair.value(0), pair.value(1)),
QuasarAppUtils::Debug);
(target->*adder)(pair.value(1));
}
2021-02-26 20:24:06 +03:00
}
}
template <typename Enabler>
bool enableOptionFotTargetPrivate(DeployConfig& conf,
const QStringList &inputParams,
Enabler enabler) {
for (const auto &iconPair: inputParams) {
auto pair = iconPair.split(DeployCore::getSeparator(1), splitbehavior);
if (pair.size() != 1) {
QuasarAppUtils::Params::log(QString("Failed parese list of option values, This option support only single leve list. "
" Example: use -Option val1,val2,val3 "),
QuasarAppUtils::Error);
return false;
}
const auto targetsMap = conf.getTargetsListByFilter(pair.value(0));
if (!targetsMap.size()) {
QuasarAppUtils::Params::log(QString("Not found any targets for the %0 selector").
arg(pair.value(0)),
QuasarAppUtils::Warning);
}
for (const auto &target: targetsMap) {
QuasarAppUtils::Params::log(QString("Set new property for %0 taget.").
arg(pair.value(0)),
QuasarAppUtils::Debug);
(target->*enabler)();
}
}
return true;
}
2019-09-14 13:59:11 +03:00
bool ConfigParser::parseParams() {
2019-09-10 18:22:49 +03:00
2021-04-07 19:36:08 +03:00
auto path = QuasarAppUtils::Params::getArg("confFile");
bool createFile = !QFile::exists(path) &&
QuasarAppUtils::Params::isEndable("confFile");
if (path.isEmpty() &&
2021-04-30 12:40:33 +03:00
QuasarAppUtils::Params::size() <= 0) {
2020-03-09 14:37:12 +03:00
path = DEFAULT_COFIGURATION_FILE;
}
2020-03-09 11:53:39 +03:00
2020-03-08 19:58:23 +03:00
if (QFile::exists(path)) {
if (!loadFromFile(path)) {
QuasarAppUtils::Params::log("Failed to parse json file : " + path,
2020-08-15 19:29:17 +03:00
QuasarAppUtils::Error);
return false;
}
2019-09-10 18:22:49 +03:00
}
2020-03-15 14:22:19 +03:00
auto distro = getDistribution();
_packing->setDistribution(distro);
2019-09-07 12:01:20 +03:00
switch (DeployCore::getMode()) {
case RunMode::Info: {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("Print info ...",
2020-08-15 19:29:17 +03:00
QuasarAppUtils::Info);
2019-09-07 12:01:20 +03:00
2020-01-24 13:57:55 +03:00
if (!parseInfoMode()) {
2021-05-01 00:31:15 +03:00
QuasarAppUtils::Params::log("Show info is failed!",
2020-08-15 19:29:17 +03:00
QuasarAppUtils::Error);
2019-09-07 12:01:20 +03:00
return false;
}
2019-09-10 18:22:49 +03:00
break;
2019-09-07 12:01:20 +03:00
}
case RunMode::Clear: {
2021-05-01 00:31:15 +03:00
QuasarAppUtils::Params::log("Clear ...",
2020-08-15 19:29:17 +03:00
QuasarAppUtils::Info);
2019-09-07 12:01:20 +03:00
2020-01-24 13:57:55 +03:00
if (!parseClearMode()) {
QuasarAppUtils::Params::log("Clear failed!",
2020-08-15 19:29:17 +03:00
QuasarAppUtils::Error);
2019-09-07 12:01:20 +03:00
return false;
}
2020-01-24 13:57:55 +03:00
break;
}
2019-09-07 12:01:20 +03:00
2020-01-24 13:57:55 +03:00
case RunMode::Init: {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("Init ...",
2020-08-15 19:29:17 +03:00
QuasarAppUtils::Info);
2020-01-24 13:57:55 +03:00
if (!parseInitMode()) {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("init is failed!",
2020-08-15 19:29:17 +03:00
QuasarAppUtils::Error);
2020-01-24 13:57:55 +03:00
return false;
}
2019-09-10 18:22:49 +03:00
break;
2019-09-07 12:01:20 +03:00
}
case RunMode::Deploy: {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("Deploy ...",
2020-08-15 19:29:17 +03:00
QuasarAppUtils::Info);
2019-09-07 12:01:20 +03:00
2021-07-12 11:58:41 +03:00
if (!parseDeployMode(true)) {
QuasarAppUtils::Params::log("Deploy failed!",
2020-08-15 19:29:17 +03:00
QuasarAppUtils::Error);
2019-09-07 12:01:20 +03:00
return false;
}
2019-09-10 18:22:49 +03:00
break;
}
case RunMode::Template: {
QuasarAppUtils::Params::log("Extract defaults Templates ...",
QuasarAppUtils::Info);
2021-07-12 11:58:41 +03:00
if (!parseDeployMode(false)) {
QuasarAppUtils::Params::log("Extract defaults Templates is failed!",
QuasarAppUtils::Error);
return false;
}
break;
}
2019-09-07 12:01:20 +03:00
}
2020-01-24 13:57:55 +03:00
DeployCore::_config = &_config;
2019-10-16 14:25:44 +03:00
if (createFile && !createFromDeploy(path)) {
QuasarAppUtils::Params::log("Failed to create a deploy config file in " + path,
2020-08-15 19:29:17 +03:00
QuasarAppUtils::Error);
2019-09-07 12:01:20 +03:00
}
2019-09-10 18:22:49 +03:00
return true;
2019-09-07 12:01:20 +03:00
}
2019-09-14 13:59:11 +03:00
const DeployConfig *ConfigParser::config() const {
2019-09-08 13:37:33 +03:00
return &_config;
2019-09-07 12:01:20 +03:00
}
2020-01-27 20:02:25 +03:00
// FIX ME. if package contains the path separators then package rewrite to RelativeLink of configFile location
QJsonValue ConfigParser::writeKeyArray(int separatorLvl, const QString &parameter,
2020-08-15 19:29:17 +03:00
const QString &confFileDir) const {
auto list = parameter.split(DeployCore::getSeparator(separatorLvl));
2020-01-02 19:27:40 +03:00
if (DeployCore::isContainsArraySeparators(parameter)) {
QJsonArray array;
2020-01-12 16:43:03 +03:00
for (const auto &i: list) {
array.push_back(writeKeyArray(separatorLvl + 1, i, confFileDir));
}
return array;
}
if (list.size() && list.first().isEmpty()) {
return QJsonValue(true);
}
auto val = list.first();
if (PathUtils::isPath(val)) {
2020-01-02 19:27:40 +03:00
val = PathUtils::getRelativeLink(
QFileInfo(confFileDir).absoluteFilePath(),
QFileInfo(val).absoluteFilePath());
}
return val;
}
void ConfigParser::writeKey(const QString& key, QJsonObject& obj,
const QString& confFileDir) const {
2019-09-10 15:40:12 +03:00
if (QuasarAppUtils::Params::isEndable(key)) {
2021-04-07 19:36:08 +03:00
obj[key] = writeKeyArray(0, QuasarAppUtils::Params::getArg(key), confFileDir);
}
}
2019-09-12 17:00:50 +03:00
QString ConfigParser::readKeyArray(int separatorLvl, const QJsonArray &array,
2020-08-15 19:29:17 +03:00
const QString& confFileDir) const {
2019-09-12 17:00:50 +03:00
QStringList list;
2020-01-12 16:43:03 +03:00
for (const QJsonValue &i : array) {
2019-09-12 17:00:50 +03:00
if (i.isArray()) {
list.push_back(readKeyArray(separatorLvl + 1, i.toArray(), confFileDir));
2019-09-12 17:00:50 +03:00
} else {
QString val = i.toString();
2020-03-15 12:48:38 +03:00
if (i.type() == QJsonValue::Double) {
val = QString::number(i.toDouble(0), 'f');
}
if (!val.isEmpty()) {
2020-01-18 17:32:10 +03:00
if (PathUtils::isReleativePath(val)) {
list.push_back(QFileInfo(confFileDir + '/' + val).absoluteFilePath());
} else {
list.push_back(val);
}
2019-09-12 17:00:50 +03:00
}
}
2019-09-10 15:40:12 +03:00
}
return list.join(DeployCore::getSeparator(separatorLvl));
2019-09-10 15:40:12 +03:00
}
void ConfigParser::readKey(const QString& key, const QJsonObject& obj,
const QString& confFileDir) const {
2019-09-10 15:40:12 +03:00
if (!QuasarAppUtils::Params::isEndable(key)) {
2020-03-15 12:48:38 +03:00
auto type = obj[key].type();
switch (type) {
case QJsonValue::Array: {
auto array = obj[key].toArray();
QuasarAppUtils::Params::setArg(key, readKeyArray(0, array, confFileDir));
break;
}
case QJsonValue::Double: {
readString(key,
QString::number(obj[key].toDouble(0), 'f'),
confFileDir);
2019-09-12 17:00:50 +03:00
2020-03-15 12:48:38 +03:00
break;
}
case QJsonValue::String: {
readString(key,
obj[key].toString(),
confFileDir);
break;
}
default: {
auto value = obj[key].toBool(true);
QuasarAppUtils::Params::setEnable(key, value);
break;
}
}
}
}
2019-09-12 17:00:50 +03:00
2020-03-15 12:48:38 +03:00
void ConfigParser::readString(const QString &key, const QString &val,
const QString& confFileDir) const
{
if (PathUtils::isReleativePath(val)) {
QuasarAppUtils::Params::setArg(key, QFileInfo(confFileDir + '/' + val).absoluteFilePath());
} else {
QuasarAppUtils::Params::setArg(key, val);
2019-09-10 15:40:12 +03:00
}
}
2019-09-14 13:59:11 +03:00
bool ConfigParser::createFromDeploy(const QString& confFile) const {
2019-09-10 15:40:12 +03:00
QJsonObject obj;
2019-10-16 14:25:44 +03:00
auto info = QFileInfo(confFile);
2021-02-26 20:24:06 +03:00
const auto keys = DeployCore::helpKeys();
for (const auto &key :keys) {
2019-10-16 14:25:44 +03:00
writeKey(key, obj, info.absolutePath());
}
if (!QFile::exists(info.absolutePath()) &&
!QDir("/").mkpath(info.absolutePath())) {
return false;
2019-09-10 15:40:12 +03:00
}
QJsonDocument doc(obj);
QFile file(confFile);
if (file.open(QIODevice::WriteOnly| QIODevice::Truncate)) {
file.write(doc.toJson());
file.close();
return true;
}
return false;
2019-09-07 12:01:20 +03:00
}
2019-09-14 13:59:11 +03:00
bool ConfigParser::loadFromFile(const QString& confFile) {
2019-09-10 15:40:12 +03:00
QFile file(confFile);
QString confFilePath = QFileInfo(confFile).absolutePath();
2019-09-10 15:40:12 +03:00
if (file.open(QIODevice::ReadOnly)) {
auto doc = QJsonDocument::fromJson(file.readAll());
if (!doc.isObject()) {
return false;
}
auto obj = doc.object();
const auto keys = obj.keys();
for (const auto &key: keys) {
readKey(key, obj, confFilePath);
2019-09-10 15:40:12 +03:00
}
file.close();
return true;
}
return false;
2019-09-07 12:01:20 +03:00
}
2019-12-27 20:23:55 +03:00
bool ConfigParser::initDistroStruct() {
2019-12-09 17:28:56 +03:00
2020-01-27 20:02:25 +03:00
if (!initPackages()) {
2019-12-29 14:19:07 +03:00
return false;
}
2020-01-27 20:02:25 +03:00
auto &mainDistro = _config.packagesEdit();
2019-12-09 17:28:56 +03:00
#ifdef Q_OS_LINUX
2021-04-07 19:36:08 +03:00
auto binOut = QuasarAppUtils::Params::getArg("binOut").
2020-09-07 10:14:15 +03:00
split(DeployCore::getSeparator(0), splitbehavior);
2021-04-07 19:36:08 +03:00
auto libOut = QuasarAppUtils::Params::getArg("libOut").
2020-09-07 10:14:15 +03:00
split(DeployCore::getSeparator(0), splitbehavior);
2019-12-09 17:28:56 +03:00
#else
2021-04-07 19:36:08 +03:00
auto binOut = QuasarAppUtils::Params::getArg("binOut").
2020-09-07 10:14:15 +03:00
split(DeployCore::getSeparator(0), splitbehavior);
2021-04-07 19:36:08 +03:00
auto libOut = QuasarAppUtils::Params::getArg("libOut").
2020-09-07 10:14:15 +03:00
split(DeployCore::getSeparator(0), splitbehavior);
2019-12-09 17:28:56 +03:00
#endif
2021-04-07 19:36:08 +03:00
auto qmlOut = QuasarAppUtils::Params::getArg("qmlOut").
2020-09-07 10:14:15 +03:00
split(DeployCore::getSeparator(0), splitbehavior);
2021-04-07 19:36:08 +03:00
auto trOut = QuasarAppUtils::Params::getArg("trOut").
2020-09-07 10:14:15 +03:00
split(DeployCore::getSeparator(0), splitbehavior);
2021-04-07 19:36:08 +03:00
auto pluginOut = QuasarAppUtils::Params::getArg("pluginOut").
2020-09-07 10:14:15 +03:00
split(DeployCore::getSeparator(0), splitbehavior);
2021-04-07 19:36:08 +03:00
auto recOut = QuasarAppUtils::Params::getArg("recOut").
2020-09-07 10:14:15 +03:00
split(DeployCore::getSeparator(0), splitbehavior);
2021-04-07 19:36:08 +03:00
auto extraDataOut = QuasarAppUtils::Params::getArg("extraDataOut").
split(DeployCore::getSeparator(0), splitbehavior);
2019-12-09 17:28:56 +03:00
2021-04-07 19:36:08 +03:00
auto name = QuasarAppUtils::Params::getArg("name").
2020-09-07 10:14:15 +03:00
split(DeployCore::getSeparator(0), splitbehavior);
2021-04-07 19:36:08 +03:00
auto description = QuasarAppUtils::Params::getArg("description").
2020-09-07 10:14:15 +03:00
split(DeployCore::getSeparator(0), splitbehavior);
2021-04-07 19:36:08 +03:00
auto deployVersion = QuasarAppUtils::Params::getArg("deployVersion").
2020-09-07 10:14:15 +03:00
split(DeployCore::getSeparator(0), splitbehavior);
2021-04-07 19:36:08 +03:00
auto releaseDate = QuasarAppUtils::Params::getArg("releaseDate").
2020-09-07 10:14:15 +03:00
split(DeployCore::getSeparator(0), splitbehavior);
2021-04-07 19:36:08 +03:00
auto publisher = QuasarAppUtils::Params::getArg("publisher").
2020-09-07 10:14:15 +03:00
split(DeployCore::getSeparator(0), splitbehavior);
2020-01-14 15:48:35 +03:00
2021-04-07 19:36:08 +03:00
auto homepage = QuasarAppUtils::Params::getArg("homePage").
2020-12-03 20:00:14 +03:00
split(DeployCore::getSeparator(0), splitbehavior);
2021-04-07 19:36:08 +03:00
auto prefix = QuasarAppUtils::Params::getArg("prefix").
split(DeployCore::getSeparator(0), splitbehavior);
2021-04-07 19:36:08 +03:00
auto extraData = QuasarAppUtils::Params::getArg("extraData").
split(DeployCore::getSeparator(0), splitbehavior);
2021-04-07 19:36:08 +03:00
auto trData = QuasarAppUtils::Params::getArg("tr").
split(DeployCore::getSeparator(0), splitbehavior);
2019-12-29 14:19:07 +03:00
2019-12-10 18:43:01 +03:00
// init distro stucts for all targets
2020-01-27 20:02:25 +03:00
if (binOut.size() && !parsePackagesPrivate(mainDistro, binOut, &DistroModule::setBinOutDir)) {
packagesErrorLog("binOut");
2019-12-29 14:19:07 +03:00
return false;
}
2020-01-27 20:02:25 +03:00
if (libOut.size() && !parsePackagesPrivate(mainDistro, libOut, &DistroModule::setLibOutDir)) {
packagesErrorLog("libOut");
2019-12-29 14:19:07 +03:00
return false;
}
2020-01-27 20:02:25 +03:00
if (qmlOut.size() && !parsePackagesPrivate(mainDistro, qmlOut, &DistroModule::setQmlOutDir)) {
packagesErrorLog("qmlOut");
2019-12-29 14:19:07 +03:00
return false;
}
2020-01-27 20:02:25 +03:00
if (trOut.size() && !parsePackagesPrivate(mainDistro, trOut, &DistroModule::setTrOutDir)) {
packagesErrorLog("trOut");
2019-12-29 14:19:07 +03:00
return false;
}
2020-01-27 20:02:25 +03:00
if (pluginOut.size() && !parsePackagesPrivate(mainDistro, pluginOut, &DistroModule::setPluginsOutDir)) {
packagesErrorLog("pluginOut");
2019-12-29 14:19:07 +03:00
return false;
}
2020-01-27 20:02:25 +03:00
if (recOut.size() && !parsePackagesPrivate(mainDistro, recOut, &DistroModule::setResOutDir)) {
packagesErrorLog("recOut");
2019-12-29 14:19:07 +03:00
return false;
}
2019-12-28 15:06:43 +03:00
if (extraDataOut.size() && !parsePackagesPrivate(mainDistro, extraDataOut, &DistroModule::setExtraDataOutDir)) {
packagesErrorLog("extraDataOut");
return false;
}
2020-01-27 20:02:25 +03:00
if (name.size() && !parsePackagesPrivate(mainDistro, name, &DistroModule::setName)) {
packagesErrorLog("name");
2020-01-14 15:48:35 +03:00
return false;
}
2020-01-27 20:02:25 +03:00
if (description.size() && !parsePackagesPrivate(mainDistro, description, &DistroModule::setDescription)) {
packagesErrorLog("description");
2020-01-14 15:48:35 +03:00
return false;
}
2020-01-27 20:02:25 +03:00
if (deployVersion.size() && !parsePackagesPrivate(mainDistro, deployVersion, &DistroModule::setVersion)) {
packagesErrorLog("deployVersion");
2020-01-14 15:48:35 +03:00
return false;
}
2020-01-27 20:02:25 +03:00
if (releaseDate.size() && !parsePackagesPrivate(mainDistro, releaseDate, &DistroModule::setReleaseData)) {
packagesErrorLog("releaseDate");
2020-01-14 15:48:35 +03:00
return false;
}
2020-01-27 20:02:25 +03:00
if (publisher.size() && !parsePackagesPrivate(mainDistro, publisher, &DistroModule::setPublisher)) {
packagesErrorLog("Publisher");
2020-01-15 11:50:30 +03:00
return false;
}
2020-12-03 20:00:14 +03:00
if (homepage.size() && !parsePackagesPrivate(mainDistro, homepage, &DistroModule::setHomePage)) {
packagesErrorLog("homePage");
2020-12-03 20:00:14 +03:00
return false;
}
if (prefix.size() && !parsePackagesPrivate(mainDistro, prefix, &DistroModule::setPrefix)) {
packagesErrorLog("prefix");
return false;
}
if (extraData.size() && !parsePackagesPrivate(mainDistro, extraData, &DistroModule::addExtraData)) {
packagesErrorLog("extraData");
return false;
}
if (trData.size() && !parsePackagesPrivate(mainDistro, trData, &DistroModule::addTr)) {
packagesErrorLog("tr");
return false;
}
2019-12-28 15:06:43 +03:00
return true;
}
2020-01-27 20:02:25 +03:00
bool ConfigParser::initPackages() {
2020-08-15 19:29:17 +03:00
defaultPackage = "Application";
2019-12-28 15:06:43 +03:00
2020-08-15 19:29:17 +03:00
QSet<QString> configuredTargets;
2020-01-18 23:32:41 +03:00
2020-01-27 20:02:25 +03:00
if (QuasarAppUtils::Params::isEndable("targetPackage")) {
2021-04-07 19:36:08 +03:00
auto tar_packages_array = QuasarAppUtils::Params::getArg("targetPackage", "").
2019-12-29 14:19:07 +03:00
split(DeployCore::getSeparator(0));
2020-01-27 20:02:25 +03:00
for (auto& str: tar_packages_array) {
2021-01-19 14:26:11 +03:00
auto paramsList = str.split(DeployCore::getSeparator(1));
auto package = PathUtils::fullStripPath(paramsList.value(0, ""));
2019-12-29 14:19:07 +03:00
2021-01-19 14:26:11 +03:00
for (int i = 1; i < paramsList.size(); ++i) {
auto targetPattern = paramsList.value(i);
auto list = _config.getTargetsListByFilter(targetPattern);
if (!list.size()) {
auto warning = QString("You create the %0 package with the %1 pattern, "
"but no matches were found for this pattern. ").
arg(package, targetPattern);
QuasarAppUtils::Params::log(warning, QuasarAppUtils::Warning);
continue;
}
2020-11-12 14:42:51 +03:00
2021-01-19 14:26:11 +03:00
for (auto it = list.begin(); it != list.end(); ++it) {
if (!configuredTargets.contains(it.key())) {
configuredTargets.insert(it.key());
it.value()->setPackage(package);
}
2020-01-18 15:39:02 +03:00
}
2019-12-28 15:06:43 +03:00
2021-01-19 14:26:11 +03:00
_config.packagesEdit().insert(package, DistroModule{package});
}
2019-12-29 14:19:07 +03:00
2021-01-19 14:26:11 +03:00
if (paramsList.size() < 2) {
2020-01-27 20:02:25 +03:00
defaultPackage = package;
2019-12-29 14:19:07 +03:00
}
}
2020-01-15 18:31:09 +03:00
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log(
2021-05-01 00:31:15 +03:00
"The default package is " + defaultPackage,
2020-01-15 18:31:09 +03:00
QuasarAppUtils::Info);
2020-08-15 19:29:17 +03:00
}
// init default packages
2020-12-02 17:53:14 +03:00
bool fDefaultPackage = false;
2020-08-15 19:29:17 +03:00
for (auto it = _config.targetsEdit().begin(); it != _config.targetsEdit().end(); ++it) {
if (!configuredTargets.contains(it.key())) {
configuredTargets.insert(it.key());
it.value().setPackage(defaultPackage);
2020-12-02 17:53:14 +03:00
fDefaultPackage = true;
2020-08-15 19:29:17 +03:00
}
2019-12-29 14:19:07 +03:00
}
2020-11-12 14:42:51 +03:00
2020-12-02 17:53:14 +03:00
if (fDefaultPackage) {
2020-12-03 20:00:14 +03:00
_config.packagesEdit().insert(defaultPackage, DistroModule{defaultPackage});
2020-11-12 14:42:51 +03:00
}
2019-12-09 17:28:56 +03:00
2020-12-02 17:53:14 +03:00
_config.setDefaultPackage(defaultPackage);
2019-12-09 17:28:56 +03:00
return true;
}
2019-12-15 18:30:24 +03:00
bool ConfigParser::initQmlInput() {
2021-04-07 19:36:08 +03:00
auto qmlDir = QuasarAppUtils::Params::getArg("qmlDir").
2020-09-07 10:14:15 +03:00
split(DeployCore::getSeparator(0), splitbehavior);
2019-12-15 18:30:24 +03:00
2020-01-02 19:27:40 +03:00
// init distro stucts for all targets
_config.deployQml = qmlDir.size();
2019-12-15 18:30:24 +03:00
2020-01-27 20:02:25 +03:00
if (qmlDir.size() && !parsePackagesPrivate(_config.packagesEdit(), qmlDir, &DistroModule::addQmlInput)) {
packagesErrorLog("qmlDir");
2020-01-02 19:27:40 +03:00
return false;
2019-12-15 18:30:24 +03:00
}
return true;
}
2021-05-01 00:31:15 +03:00
void ConfigParser::packagesErrorLog(const QString &option) {
QuasarAppUtils::Params::log(QString("Failed to set the %0 option, because you are trying to set it for an uninitialized package."
" Use the 'targetPackage' flag to init this package. "
"Or, if you want to configure an empty package, "
"use the allowEmptyPackages option to disable this error message.").
2021-05-01 00:31:15 +03:00
arg(option),
2021-02-26 20:24:06 +03:00
QuasarAppUtils::Error);
}
2021-07-12 11:58:41 +03:00
bool ConfigParser::parseDeployMode(bool checkBin) {
2019-09-07 12:01:20 +03:00
2019-09-24 16:30:52 +03:00
if (QuasarAppUtils::Params::isEndable("deploySystem-with-libc")) {
QuasarAppUtils::Params::log("You are using a deprecated option \"deploySystem-with-libc\"."
2021-03-30 11:27:51 +03:00
" In this version this option is no different from \"deploySystem\"."
2021-05-01 00:31:15 +03:00
" Please use the deploySystem option.", QuasarAppUtils::Warning);
2019-09-24 16:30:52 +03:00
QuasarAppUtils::Params::setEnable("deploySystem", true );
}
if (!checkSnapPermisions()) {
return false;
}
setTargetDir();
2021-04-07 19:36:08 +03:00
auto bin = QuasarAppUtils::Params::getArg("bin").
split(DeployCore::getSeparator(0), splitbehavior);
2019-09-08 13:37:33 +03:00
if (bin.size() && !setTargets(bin)) {
2019-09-08 13:37:33 +03:00
QuasarAppUtils::Params::log("Failed to set targets",
QuasarAppUtils::Warning);
}
2021-04-07 19:36:08 +03:00
auto xData = QuasarAppUtils::Params::getArg("extraData").
split(DeployCore::getSeparator(0), splitbehavior);
2021-07-12 11:58:41 +03:00
if (checkBin && !(_config.targets().count() || xData.count())) {
QuasarAppUtils::Params::log("Failed to initialize targets or extra data!",
QuasarAppUtils::Error);
QuasarAppUtils::Params::log("Use bin or extraData optins. And check input pathes.",
QuasarAppUtils::Info);
return false;
2019-09-08 13:37:33 +03:00
}
_config.depchLimit = 0;
if (QuasarAppUtils::Params::isEndable("recursiveDepth")) {
bool ok;
_config.depchLimit = QuasarAppUtils::Params::getArg("recursiveDepth").toInt(&ok);
if (!ok) {
_config.depchLimit = 0;
QuasarAppUtils::Params::log("Failed to set the recursive depth. The argument of the recursiveDepth option is invalid!"
" Using the default value 0",
2020-08-15 19:29:17 +03:00
QuasarAppUtils::Warning);
2019-09-08 13:37:33 +03:00
}
}
2020-05-06 13:35:13 +03:00
initIgnoreEnvList();
initEnvirement();
initIgnoreList();
if (!initDistroStruct()) {
return false;
}
initExtraPath();
initExtraNames();
initPlugins();
2019-09-08 13:37:33 +03:00
2019-11-14 17:35:21 +03:00
if (!initQmake()) {
2020-10-16 17:08:38 +03:00
if (DeployCore::isSnap()) {
QuasarAppUtils::Params::log("If you are using qmake from the system repository,"
" then you must use the classic version of CQtDeployer instead of the snap version."
2021-05-01 00:31:15 +03:00
" This is due to the fact that the snap version"
" runs in an isolated container and has limited access"
" to system utilities and the environment."
" For get the classic version of cqtdeployer use the cqtdeployer installer"
" https://github.com/QuasarApp/CQtDeployer/releases", QuasarAppUtils::Info);
2020-10-16 17:08:38 +03:00
}
2019-11-14 17:35:21 +03:00
return false;
2019-11-01 15:12:03 +03:00
}
2019-09-08 13:37:33 +03:00
2020-02-27 10:50:11 +03:00
if (!initQmlInput()) {
return false;
}
2019-09-08 13:37:33 +03:00
return true;
2019-09-07 12:01:20 +03:00
}
2020-01-24 13:57:55 +03:00
bool ConfigParser::parseInfoMode() {
2019-09-08 13:37:33 +03:00
if ((QuasarAppUtils::Params::isEndable("v") ||
2020-08-15 19:29:17 +03:00
QuasarAppUtils::Params::isEndable("version"))) {
2019-09-08 13:37:33 +03:00
DeployCore::printVersion();
return true;
}
DeployCore::help();
2019-09-07 12:01:20 +03:00
2019-09-08 13:37:33 +03:00
return true;
2019-09-07 12:01:20 +03:00
}
2020-01-24 13:57:55 +03:00
bool ConfigParser::parseInitMode() {
2021-04-07 19:36:08 +03:00
auto initLvl = QuasarAppUtils::Params::getArg("init");
2020-03-08 14:46:17 +03:00
QString sourceUrl(":/Distro/Distributions/configures/Init.json");
2020-01-27 19:35:02 +03:00
2020-03-08 14:46:17 +03:00
if (initLvl == "multi") {
2020-01-27 19:35:02 +03:00
sourceUrl = ":/Distro/Distributions/configures/Init multiPackage configuration.json";
2020-03-08 14:46:17 +03:00
} else if (initLvl == "single") {
sourceUrl = ":/Distro/Distributions/configures/Init single configuration.json";
2020-01-27 19:35:02 +03:00
}
2020-01-24 13:57:55 +03:00
QFile configFile(DEFAULT_COFIGURATION_FILE);
2020-01-27 19:35:02 +03:00
QFile source(sourceUrl);
2020-01-24 13:57:55 +03:00
if (configFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
if (source.open(QIODevice::ReadOnly)) {
configFile.write(source.readAll());
source.close();
}
configFile.close();
}
return true;
}
bool ConfigParser::configureTargets() {
2021-04-07 19:36:08 +03:00
const auto icons = QuasarAppUtils::Params::getArg("icon").
2021-02-26 20:24:06 +03:00
split(DeployCore::getSeparator(0), splitbehavior);
const auto runScripts = QuasarAppUtils::Params::getArg("runScript").
split(DeployCore::getSeparator(0), splitbehavior);
const auto disableRunScripts = QuasarAppUtils::Params::getArg("disableRunScript").
split(DeployCore::getSeparator(0), splitbehavior);
const auto disableShortcuts = QuasarAppUtils::Params::getArg("disableShortCut").
split(DeployCore::getSeparator(0), splitbehavior);
2021-02-26 20:24:06 +03:00
if (icons.size()) {
parseTargetPrivate(_config, icons, &TargetInfo::setIcon);
}
if (runScripts.size()) {
parseTargetPrivate(_config, runScripts, &TargetInfo::setRunScript);
}
if (disableShortcuts.size() && !enableOptionFotTargetPrivate(_config, disableShortcuts, &TargetInfo::disableShortCut)) {
packagesErrorLog("disableShortCut");
return false;
}
if (disableRunScripts.size() && !enableOptionFotTargetPrivate(_config, disableRunScripts, &TargetInfo::disableRunScript)) {
packagesErrorLog("disableRunScript");
return false;
}
return true;
2021-02-26 20:24:06 +03:00
}
2020-01-24 13:57:55 +03:00
bool ConfigParser::parseClearMode() {
2019-09-16 12:38:48 +03:00
setTargetDir("./" + DISTRO_DIR);
2019-09-08 13:37:33 +03:00
return true;
2019-09-07 12:01:20 +03:00
}
2019-11-14 17:35:21 +03:00
QSet<QString> ConfigParser::getQtPathesFromTargets() {
QSet<QString> res;
2020-01-12 16:43:03 +03:00
for (const auto &i: _config.targets()) {
2019-11-14 17:35:21 +03:00
if (i.isValid() && !i.getQtPath().isEmpty()) {
res.insert(i.getQtPath());
}
}
return res;
}
2019-09-14 13:59:11 +03:00
void ConfigParser::setTargetDir(const QString &target) {
2019-09-07 12:01:20 +03:00
if (QuasarAppUtils::Params::isEndable("targetDir")) {
2021-04-07 19:36:08 +03:00
_config.setTargetDir(QFileInfo(QuasarAppUtils::Params::getArg("targetDir")).absoluteFilePath());
2019-09-07 12:01:20 +03:00
} else if (target.size()) {
2019-12-14 17:38:43 +03:00
_config.setTargetDir(QFileInfo(target).absoluteFilePath());
2019-09-07 12:01:20 +03:00
} else {
2019-12-14 17:38:43 +03:00
_config.setTargetDir(QFileInfo("./" + DISTRO_DIR).absoluteFilePath());
2021-05-01 00:31:15 +03:00
QuasarAppUtils::Params::log("The targetDir option is not used."
" CQtDeployer will use default target dir :" + _config.getTargetDir(),
2020-08-15 19:29:17 +03:00
QuasarAppUtils::Info);
2019-09-07 12:01:20 +03:00
}
}
2019-09-14 13:59:11 +03:00
bool ConfigParser::setTargets(const QStringList &value) {
2019-09-07 12:01:20 +03:00
bool isfillList = false;
2020-01-12 16:43:03 +03:00
for (const auto &i : value) {
2021-07-02 16:59:45 +03:00
QFileInfo targetInfo = DeployCore::findItem(i);
2019-09-07 12:01:20 +03:00
if (i.isEmpty())
continue;
if (targetInfo.isFile()) {
2021-04-20 14:19:05 +03:00
auto target = createTarget(targetInfo.absoluteFilePath());
2021-01-19 14:26:11 +03:00
if (!_config.targetsEdit().contains(target.target)) {
_config.targetsEdit().insert(target.target, target.targetInfo);
}
2019-11-13 18:18:44 +03:00
2019-09-07 12:01:20 +03:00
isfillList = true;
}
else if (targetInfo.isDir()) {
2021-04-20 14:19:05 +03:00
if (!setTargetsInDir(targetInfo.absoluteFilePath())) {
QuasarAppUtils::Params::log(i + " does not contain executable binaries!",
2020-08-15 19:29:17 +03:00
QuasarAppUtils::Debug);
2019-09-07 12:01:20 +03:00
continue;
}
isfillList = true;
} else {
QuasarAppUtils::Params::log(targetInfo.absoluteFilePath() + " does not exist!",
2020-08-15 19:29:17 +03:00
QuasarAppUtils::Debug);
2019-09-07 12:01:20 +03:00
}
}
if (!isfillList)
return false;
return true;
}
2019-09-14 13:59:11 +03:00
bool ConfigParser::setTargetsRecursive(const QString &dir) {
if (!setTargetsInDir(dir, true)) {
QuasarAppUtils::Params::log("setTargetsInDir failed!",
2021-05-01 00:31:15 +03:00
QuasarAppUtils::Debug);
2019-09-07 12:01:20 +03:00
return false;
}
return true;
}
bool ConfigParser::setTargetsInDir(const QString &dir, bool recursive) {
2019-09-07 12:01:20 +03:00
QDir d(dir);
if (dir.isEmpty() || !d.exists()) {
2020-04-04 16:21:44 +03:00
QuasarAppUtils::Params::log(dir + " dir not exits!",
2020-08-15 19:29:17 +03:00
QuasarAppUtils::Debug);
2019-09-07 12:01:20 +03:00
return false;
}
QuasarAppUtils::Params::log("setTargetsInDir check path: " + dir,
2020-08-15 19:29:17 +03:00
QuasarAppUtils::Debug);
2019-09-07 12:01:20 +03:00
QFileInfoList list;
if (recursive) {
list = d.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
} else {
list = d.entryInfoList(QDir::Files | QDir::NoDotAndDotDot);
}
bool result = false;
2021-01-19 14:26:11 +03:00
for (const auto &file : qAsConst(list)) {
2019-09-07 12:01:20 +03:00
if (file.isDir()) {
result |= setTargetsInDir(file.absoluteFilePath(), recursive);
2019-09-07 12:01:20 +03:00
continue;
}
2019-09-12 21:42:10 +03:00
auto name = file.fileName();
2019-09-07 12:01:20 +03:00
auto sufix = file.completeSuffix();
2019-09-12 21:42:10 +03:00
if (sufix.isEmpty() || name.contains(".dll", Qt::CaseInsensitive) ||
2020-08-15 19:29:17 +03:00
name.contains(".so", Qt::CaseInsensitive) || name.contains(".exe", Qt::CaseInsensitive)) {
2019-09-12 21:42:10 +03:00
2019-11-13 18:18:44 +03:00
2021-01-19 14:26:11 +03:00
auto target = createTarget(QDir::fromNativeSeparators(file.absoluteFilePath()));
if (!_config.targetsEdit().contains(target.target)) {
_config.targetsEdit().insert(target.target, target.targetInfo);
}
result = true;
2019-09-12 21:42:10 +03:00
2019-09-07 12:01:20 +03:00
}
2020-08-15 19:29:17 +03:00
}
2019-09-07 12:01:20 +03:00
return result;
}
2021-01-19 14:26:11 +03:00
TargetData ConfigParser::createTarget(const QString &target) {
2019-12-08 13:57:20 +03:00
TargetInfo libinfo;
2019-11-13 18:18:44 +03:00
auto key = target;
if (_scaner->fillLibInfo(libinfo, key)) {
2021-01-19 14:26:11 +03:00
return {libinfo.fullPath(), libinfo};
2019-11-13 18:18:44 +03:00
}
2021-01-19 14:26:11 +03:00
return {key, {}};
2019-11-13 18:18:44 +03:00
}
2020-01-01 23:44:16 +03:00
QHash<QString, TargetInfo>
ConfigParser::moveTarget(TargetInfo target, const QString& newLocation) {
target.setPath(QFileInfo(newLocation).absolutePath());
return {{newLocation, target}};
}
2019-09-14 13:59:11 +03:00
void ConfigParser::initIgnoreList()
2019-09-04 21:27:29 +03:00
{
2019-09-07 12:01:20 +03:00
if (QuasarAppUtils::Params::isEndable("ignore")) {
2021-04-07 19:36:08 +03:00
auto list = QuasarAppUtils::Params::getArg("ignore").
split(DeployCore::getSeparator(0));
2019-09-23 10:06:22 +03:00
2020-01-12 16:43:03 +03:00
for (const auto &i : list) {
2019-09-23 10:06:22 +03:00
_config.ignoreList.addRule(IgnoreData(i));
}
2019-09-07 12:01:20 +03:00
}
2019-09-24 15:11:30 +03:00
IgnoreData ruleUnix, ruleWin;
Envirement envUnix, envWin;
2019-09-23 10:06:22 +03:00
2021-03-30 11:27:51 +03:00
envUnix.addEnv(Envirement::recursiveInvairement("/lib", 3));
envUnix.addEnv(Envirement::recursiveInvairement("/usr/lib", 3));
if (DeployCore::isSnap()) {
envUnix.addEnv(Envirement::recursiveInvairement(DeployCore::transportPathToSnapRoot("/lib"), 3));
envUnix.addEnv(Envirement::recursiveInvairement(DeployCore::transportPathToSnapRoot("/usr/lib"), 3));
}
ruleUnix.prority = SystemLib;
ruleUnix.platform = Unix;
ruleUnix.enfirement = envUnix;
auto addRuleUnix = [&ruleUnix](const QString & lib) {
ruleUnix.label = lib;
return ruleUnix;
};
_config.ignoreList.addRule(addRuleUnix("libc"));
_config.ignoreList.addRule(addRuleUnix("libstdc++"));
_config.ignoreList.addRule(addRuleUnix("ld-"));
_config.ignoreList.addRule(addRuleUnix("libpthread"));
_config.ignoreList.addRule(addRuleUnix("libm"));
_config.ignoreList.addRule(addRuleUnix("libz"));
_config.ignoreList.addRule(addRuleUnix("librt"));
_config.ignoreList.addRule(addRuleUnix("libnsl"));
_config.ignoreList.addRule(addRuleUnix("libdl"));
_config.ignoreList.addRule(addRuleUnix("libutil"));
_config.ignoreList.addRule(addRuleUnix("libresolv"));
_config.ignoreList.addRule(addRuleUnix("libBrokenLocale"));
_config.ignoreList.addRule(addRuleUnix("libBrokenLocale"));
_config.ignoreList.addRule(addRuleUnix("libSegFault"));
_config.ignoreList.addRule(addRuleUnix("libanl"));
_config.ignoreList.addRule(addRuleUnix("libcrypt.so"));
_config.ignoreList.addRule(addRuleUnix("/gconv/"));
_config.ignoreList.addRule(addRuleUnix("libnss"));
2019-09-24 15:11:30 +03:00
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
auto path = env.value("PATH");
auto winPath = findWindowsPath(path);
2020-02-26 14:29:04 +03:00
envWin.addEnv(Envirement::recursiveInvairement(winPath + "/System32", 2));
envWin.addEnv(Envirement::recursiveInvairement(winPath + "/SysWOW64", 2));
ruleWin.prority = SystemLib;
2019-12-18 13:49:07 +03:00
ruleWin.platform = Win;
ruleWin.enfirement = envWin;
auto addRuleWin = [&ruleWin](const QString & lib) {
ruleWin.label = lib;
return ruleWin;
};
// win and core libs : see https://en.wikipedia.org/wiki/Microsoft_Windows_library_files
_config.ignoreList.addRule(addRuleWin("Hal.DLL"));
_config.ignoreList.addRule(addRuleWin("NTDLL.DLL"));
_config.ignoreList.addRule(addRuleWin("KERNEL32.DLL"));
_config.ignoreList.addRule(addRuleWin("GDI32.DLL"));
_config.ignoreList.addRule(addRuleWin("USER32.DLL"));
_config.ignoreList.addRule(addRuleWin("COMCTL32.DLL"));
_config.ignoreList.addRule(addRuleWin("COMDLG32.DLL"));
_config.ignoreList.addRule(addRuleWin("WS2_32.DLL"));
_config.ignoreList.addRule(addRuleWin("ADVAPI32.DLL"));
_config.ignoreList.addRule(addRuleWin("NETAPI32.DLL"));
_config.ignoreList.addRule(addRuleWin("OLE32.DLL"));
_config.ignoreList.addRule(addRuleWin("SHSCRAP.DLL"));
_config.ignoreList.addRule(addRuleWin("WINMM.DLL"));
_config.ignoreList.addRule(addRuleWin("IMM32.DLL"));
2019-12-20 17:25:20 +03:00
_config.ignoreList.addRule(addRuleWin("KernelBase.DLL"));
_config.ignoreList.addRule(addRuleWin("dwmapi.DLL"));
2019-09-24 15:11:30 +03:00
2019-09-07 12:01:20 +03:00
}
2019-09-14 13:59:11 +03:00
void ConfigParser::initIgnoreEnvList() {
2019-09-24 15:11:30 +03:00
QStringList ignoreEnvList;
2019-09-07 12:01:20 +03:00
if (QuasarAppUtils::Params::isEndable("ignoreEnv")) {
2021-04-07 19:36:08 +03:00
auto ignoreList = QuasarAppUtils::Params::getArg("ignoreEnv").
split(DeployCore::getSeparator(0));
2019-09-07 12:01:20 +03:00
2019-09-07 12:36:20 +03:00
2020-01-12 16:43:03 +03:00
for (const auto &i : ignoreList) {
2019-09-07 12:01:20 +03:00
auto path = QFileInfo(i).absoluteFilePath();
if (path.right(1) == "/" || path.right(1) == "\\") {
path.remove(path.size() - 1, 1);
}
ignoreEnvList.append(path);
}
}
2019-09-24 15:11:30 +03:00
2020-10-14 17:43:59 +03:00
// forbid pathes of the snap container
if (DeployCore::isSnap()) {
ignoreEnvList.push_back("/lib");
ignoreEnvList.push_back("/usr/lib");
}
2020-02-24 10:34:08 +03:00
ignoreEnvList.push_back(_config.appDir);
2020-02-26 14:29:04 +03:00
ignoreEnvList.push_back(_config.getTargetDir());
2020-05-06 13:35:13 +03:00
if (QuasarAppUtils::Params::isEndable("noRecursiveiIgnoreEnv")) {
_config.envirement.setIgnoreEnvList(ignoreEnvList);
} else {
_config.envirement.setIgnoreEnvListRecursive(ignoreEnvList, _config.depchLimit);
}
2020-02-24 10:34:08 +03:00
2019-09-24 15:11:30 +03:00
2019-09-07 12:01:20 +03:00
}
2019-11-02 01:00:05 +03:00
QString ConfigParser::getPathFrmoQmakeLine(const QString &in) const {
auto list = in.split(':');
if (list.size() > 1) {
list.removeAt(0);
return DeployCore::transportPathToSnapRoot(
QFileInfo(list.join(':')).absoluteFilePath().remove('\r'));
2019-11-02 01:00:05 +03:00
}
return "";
}
2019-11-14 17:35:21 +03:00
bool ConfigParser::initQmakePrivate(const QString &qmake) {
QFileInfo info(qmake);
QString basePath = info.absolutePath();
if (!setQmake(qmake)) {
QDir dir(basePath);
if (!dir.cdUp()) {
QuasarAppUtils::Params::log("Failed to initialize qt directories by qmake.",
2020-08-15 19:29:17 +03:00
QuasarAppUtils::Error);
2019-11-14 17:35:21 +03:00
return false;
}
QuasarAppUtils::Params::log("Failed to execute the qmake process!"
" Trying to initialize Qt directories from path: " + dir.absolutePath(),
2020-08-15 19:29:17 +03:00
QuasarAppUtils::Warning);
2019-11-14 17:35:21 +03:00
if (!setQtDir(dir.absolutePath())){
QuasarAppUtils::Params::log("Failed to initialize Qt directories",
2020-08-15 19:29:17 +03:00
QuasarAppUtils::Error);
2019-11-14 17:35:21 +03:00
return false;
}
}
return true;
}
bool ConfigParser::initQmake() {
2020-10-13 22:38:16 +03:00
if (!_config.isNeededQt()) {
QuasarAppUtils::Params::log("Deploy only C/C++ libraries because"
" all target applications do not depend on the Qt libraries",
2020-10-13 14:07:51 +03:00
QuasarAppUtils::Info);
return true;
}
2021-04-07 19:36:08 +03:00
auto qmake = QuasarAppUtils::Params::getArg("qmake");
2019-11-14 17:35:21 +03:00
QFileInfo info(qmake);
if (!info.isFile() || (info.baseName() != "qmake")) {
auto qtList = getQtPathesFromTargets();
if (qtList.isEmpty()) {
2020-01-28 13:51:00 +03:00
2020-10-13 14:07:51 +03:00
if (!QuasarAppUtils::Params::isEndable("noCheckPATH")) {
2020-01-28 15:25:35 +03:00
auto env = QProcessEnvironment::systemEnvironment();
auto proc = DeployCore::findProcess(env.value("PATH"), "qmake");
2020-04-04 15:43:46 +03:00
if (proc.isEmpty()) {
2021-05-01 00:31:15 +03:00
QuasarAppUtils::Params::log("The deployment target requires Qt libraries,"
" but initialize of Qt directories is failed."
" Please use the qmake option to set a path to the qmake executable.",
2020-08-15 19:29:17 +03:00
QuasarAppUtils::Error);
2020-01-28 13:51:00 +03:00
return false;
2020-04-04 15:43:46 +03:00
}
2020-01-28 13:51:00 +03:00
return initQmakePrivate(proc);
}
2020-10-13 14:07:51 +03:00
2021-05-01 00:31:15 +03:00
QuasarAppUtils::Params::log("Your distribution required Qt libraries "
"but qmake executable cannot be found in the 'qmake' option or RPATH. "
"You are using the option noCheckPATH, "
"please remove this option from your deploy command to search qmake in PATH",
2020-10-13 14:07:51 +03:00
QuasarAppUtils::Error);
return false;
2019-11-14 17:35:21 +03:00
2020-01-12 16:43:03 +03:00
}
if (qtList.size() > 1) {
QuasarAppUtils::Params::log("Your deployment targets were compiled by different qmakes, "
2021-05-01 00:31:15 +03:00
"auto-capture of the Qt libraries is not possible. "
"Please use the -qmake flag to solve this problem.",
2020-10-13 14:07:51 +03:00
QuasarAppUtils::Error);
2019-11-14 17:35:21 +03:00
return false;
}
auto qt = *qtList.begin();
if (qt.rightRef(3).compare(QString("lib"), Qt::CaseInsensitive)) {
2019-11-14 17:35:21 +03:00
return initQmakePrivate(QFileInfo(qt + "/../bin/qmake").absoluteFilePath());
}
return initQmakePrivate(QFileInfo(qt + "/qmake").absoluteFilePath());
}
2020-10-13 14:07:51 +03:00
2019-11-14 17:35:21 +03:00
return initQmakePrivate(qmake);
}
2019-10-31 18:09:54 +03:00
bool ConfigParser::setQmake(const QString &value) {
2019-11-01 15:12:03 +03:00
auto qmakeInfo = QFileInfo(QDir::fromNativeSeparators(value));
2019-10-31 18:09:54 +03:00
if (!(qmakeInfo.fileName().compare("qmake", Qt::CaseInsensitive) ||
2020-08-15 19:29:17 +03:00
qmakeInfo.fileName().compare("qmake.exe", Qt::CaseInsensitive))) {
2020-01-28 13:51:00 +03:00
2019-10-31 18:09:54 +03:00
return false;
}
QProcess proc;
proc.setProgram(qmakeInfo.absoluteFilePath());
proc.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
2019-11-01 17:43:43 +03:00
proc.setArguments({"-query"});
2019-10-31 18:09:54 +03:00
proc.start();
if (!proc.waitForFinished(1000)) {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("run qmake fail!");
2019-10-31 18:09:54 +03:00
return false;
}
QString qmakeData = proc.readAll();
auto list = qmakeData.split('\n');
2020-01-12 16:43:03 +03:00
for (const auto &value : list) {
2019-10-31 18:09:54 +03:00
if (value.contains("QT_INSTALL_LIBS")) {
2019-12-20 17:25:20 +03:00
_config.qtDir.setLibs(getPathFrmoQmakeLine(value));
2019-10-31 18:09:54 +03:00
} else if (value.contains("QT_INSTALL_LIBEXECS")) {
2019-12-20 17:25:20 +03:00
_config.qtDir.setLibexecs(getPathFrmoQmakeLine(value));
2019-10-31 18:09:54 +03:00
} else if (value.contains("QT_INSTALL_BINS")) {
2019-12-20 17:25:20 +03:00
_config.qtDir.setBins(getPathFrmoQmakeLine(value));
2019-10-31 18:09:54 +03:00
} else if (value.contains("QT_INSTALL_PLUGINS")) {
2019-12-20 17:25:20 +03:00
_config.qtDir.setPlugins(getPathFrmoQmakeLine(value));
2019-10-31 18:09:54 +03:00
} else if (value.contains("QT_INSTALL_QML")) {
2019-12-20 17:25:20 +03:00
_config.qtDir.setQmls(getPathFrmoQmakeLine(value));
2019-10-31 18:09:54 +03:00
} else if (value.contains("QT_INSTALL_TRANSLATIONS")) {
2019-12-20 17:25:20 +03:00
_config.qtDir.setTranslations(getPathFrmoQmakeLine(value));
2019-11-01 15:12:03 +03:00
} else if (value.contains("QT_INSTALL_DATA")) {
2019-12-20 17:25:20 +03:00
_config.qtDir.setResources(getPathFrmoQmakeLine(value) + "/resources");
2019-11-01 15:12:03 +03:00
} else if (value.contains("QMAKE_XSPEC")) {
auto val = value.split(':').value(1);
if (val.contains("win32")) {
2019-12-20 17:25:20 +03:00
_config.qtDir.setQtPlatform(Platform::Win);
2019-11-01 15:12:03 +03:00
} else {
2019-12-20 17:25:20 +03:00
_config.qtDir.setQtPlatform(Platform::Unix);
2019-11-01 15:12:03 +03:00
}
2019-10-31 18:09:54 +03:00
}
}
2020-11-05 12:57:41 +03:00
_config.qtDir.setQtVersion(_config.isNeededQt());
2020-11-05 12:57:41 +03:00
2020-02-26 14:29:04 +03:00
_config.envirement.addEnv(_config.qtDir.getLibs());
_config.envirement.addEnv(_config.qtDir.getBins());
2019-11-01 15:12:03 +03:00
return true;
}
bool ConfigParser::setQtDir(const QString &value) {
2019-09-07 12:01:20 +03:00
2019-11-01 15:12:03 +03:00
QFileInfo info(value);
2019-09-07 12:01:20 +03:00
2019-11-01 15:12:03 +03:00
if (!QFile::exists(info.absoluteFilePath() + ("/bin"))) {
QuasarAppUtils::Params::log("get qt bin failed!", QuasarAppUtils::Debug);
2019-11-01 15:12:03 +03:00
return false;
2019-09-07 12:01:20 +03:00
}
2019-12-20 17:25:20 +03:00
_config.qtDir.setBins(info.absoluteFilePath() + ("/bin"));
2019-09-07 12:01:20 +03:00
2019-11-01 15:12:03 +03:00
if (!QFile::exists(info.absoluteFilePath() + ("/lib"))) {
QuasarAppUtils::Params::log("get qt lib failed!", QuasarAppUtils::Debug);
2019-11-01 15:12:03 +03:00
return false;
}
2019-12-20 17:25:20 +03:00
_config.qtDir.setLibs(info.absoluteFilePath() + ("/lib"));
2019-09-07 12:01:20 +03:00
2019-11-01 15:12:03 +03:00
if (!QFile::exists(info.absoluteFilePath() + ("/qml"))) {
QuasarAppUtils::Params::log("get qt qml failed!", QuasarAppUtils::Debug);
2019-11-01 15:12:03 +03:00
} else {
2019-12-20 17:25:20 +03:00
_config.qtDir.setQmls(info.absoluteFilePath() + ("/qml"));
2019-09-07 12:01:20 +03:00
}
2019-11-01 15:12:03 +03:00
if (!QFile::exists(info.absoluteFilePath() + ("/plugins"))) {
QuasarAppUtils::Params::log("get qt plugins failed!", QuasarAppUtils::Debug);
2019-11-01 15:12:03 +03:00
} else {
2019-12-20 17:25:20 +03:00
_config.qtDir.setPlugins(info.absoluteFilePath() + ("/plugins"));
2019-11-01 15:12:03 +03:00
}
#ifdef Q_OS_UNIX
if (!QFile::exists(info.absoluteFilePath() + ("/libexec"))) {
QuasarAppUtils::Params::log("get qt libexec failed!", QuasarAppUtils::Debug);
2019-11-01 15:12:03 +03:00
} else {
2019-12-20 17:25:20 +03:00
_config.qtDir.setLibexecs(info.absoluteFilePath() + ("/libexec"));
2019-11-01 15:12:03 +03:00
}
#endif
#ifdef Q_OS_WIN
2019-12-20 17:25:20 +03:00
_config.qtDir.setLibexecs(info.absoluteFilePath() + ("/bin"));
2019-11-01 15:12:03 +03:00
#endif
if (!QFile::exists(info.absoluteFilePath() + ("/translations"))) {
QuasarAppUtils::Params::log("get qt translations failed!", QuasarAppUtils::Debug);
2019-11-01 15:12:03 +03:00
} else {
2019-12-20 17:25:20 +03:00
_config.qtDir.setTranslations(info.absoluteFilePath() + ("/translations"));
2019-11-01 15:12:03 +03:00
}
if (!QFile::exists(info.absoluteFilePath() + ("/resources"))) {
QuasarAppUtils::Params::log("get qt resources failed!", QuasarAppUtils::Debug);
2019-11-01 15:12:03 +03:00
} else {
2019-12-20 17:25:20 +03:00
_config.qtDir.setResources(info.absoluteFilePath() + ("/resources"));
2019-11-01 15:12:03 +03:00
}
#ifdef Q_OS_UNIX
2019-12-20 17:25:20 +03:00
_config.qtDir.setQtPlatform(Platform::Unix);
2019-11-01 15:12:03 +03:00
#endif
#ifdef Q_OS_WIN
2019-12-20 17:25:20 +03:00
_config.qtDir.setQtPlatform(Platform::Win);
2019-11-01 15:12:03 +03:00
#endif
2019-09-07 12:01:20 +03:00
_config.qtDir.setQtVersion(_config.isNeededQt());
2020-11-05 12:57:41 +03:00
2020-02-26 14:29:04 +03:00
_config.envirement.addEnv(_config.qtDir.getLibs());
_config.envirement.addEnv(_config.qtDir.getBins());
2019-09-07 12:01:20 +03:00
2019-11-01 15:12:03 +03:00
return true;
2019-09-07 12:01:20 +03:00
}
void ConfigParser::initExtraPath() {
2021-04-07 19:36:08 +03:00
auto listLibDir = QuasarAppUtils::Params::getArg("libDir").
split(DeployCore::getSeparator(0));
2019-09-07 12:01:20 +03:00
QDir dir;
for (const auto &i : listLibDir) {
2020-07-28 23:56:34 +03:00
QFileInfo info(DeployCore::transportPathToSnapRoot(i));
2019-09-07 12:01:20 +03:00
if (info.isDir()) {
2020-01-02 19:27:40 +03:00
if (_config.targets().contains(info.absoluteFilePath())) {
2021-05-01 00:31:15 +03:00
QuasarAppUtils::Params::log("Skip the extra library path because it is target!",
2021-05-01 12:19:31 +03:00
QuasarAppUtils::Debug);
2019-09-07 12:01:20 +03:00
continue;
}
dir.setPath(info.absoluteFilePath());
2019-11-05 13:17:52 +03:00
auto extraDirs = getSetDirsRecursive(QDir::fromNativeSeparators(info.absoluteFilePath()), _config.depchLimit);
2019-12-20 17:25:20 +03:00
_config.extraPaths.addExtraPaths(extraDirs);
2019-09-26 13:18:10 +03:00
2020-02-26 14:29:04 +03:00
_config.envirement.addEnv(Envirement::recursiveInvairement(dir, 0, _config.depchLimit));
2019-11-05 13:17:52 +03:00
} else if (i.size() > 1) {
2019-12-20 17:25:20 +03:00
_config.extraPaths.addExtraPathsMasks({i});
2019-11-05 13:17:52 +03:00
QuasarAppUtils::Params::log(i + " is added as a path mask",
2021-05-01 12:19:31 +03:00
QuasarAppUtils::Debug);
2019-09-07 12:01:20 +03:00
} else {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log(i + " not added in path mask because"
2020-08-15 19:29:17 +03:00
" the path mask must be large 2 characters",
2021-05-01 12:19:31 +03:00
QuasarAppUtils::Debug);
2019-09-07 12:01:20 +03:00
}
}
}
void ConfigParser::initExtraNames() {
2019-11-05 13:17:52 +03:00
const auto deployExtraNames = [this](const QStringList& listNamesMasks){
for (const auto &i : listNamesMasks) {
if (i.size() > 1) {
_config.allowedPaths.addtExtraNamesMasks({i});
QuasarAppUtils::Params::log(i + " is added as a filename mask",
QuasarAppUtils::Debug);
} else {
QuasarAppUtils::Params::log(i + " not added in file mask because"
" the file mask must be large 2 characters",
2021-05-01 12:19:31 +03:00
QuasarAppUtils::Debug);
}
2019-11-05 13:17:52 +03:00
}
};
2019-11-05 13:17:52 +03:00
2021-04-07 19:36:08 +03:00
auto listNamesMasks = QuasarAppUtils::Params::getArg("extraLibs").
split(DeployCore::getSeparator(0));
deployExtraNames(listNamesMasks);
2019-11-05 13:17:52 +03:00
/*
* Task https://github.com/QuasarApp/CQtDeployer/issues/422
* We need to add to extra names libraries without which qt will not work,
*
*/
if (_config.isNeededQt()) {
2020-10-14 13:17:26 +03:00
auto libs = DeployCore::Qt3rdpartyLibs( _config.getPlatformOfAll());
deployExtraNames(libs);
2019-11-05 13:17:52 +03:00
}
}
bool ConfigParser::initPlugins() {
2021-04-07 19:36:08 +03:00
auto listExtraPlugin = QuasarAppUtils::Params::getArg("extraPlugin").
2020-09-07 10:14:15 +03:00
split(DeployCore::getSeparator(0), splitbehavior);
2021-04-07 19:36:08 +03:00
auto listEnablePlugins = QuasarAppUtils::Params::getArg("enablePlugins").
2020-09-07 10:14:15 +03:00
split(DeployCore::getSeparator(0), splitbehavior);
2021-04-07 19:36:08 +03:00
auto listDisablePlugins = QuasarAppUtils::Params::getArg("disablePlugins").
2020-09-07 10:14:15 +03:00
split(DeployCore::getSeparator(0), splitbehavior);
2020-07-04 23:08:41 +03:00
if (listExtraPlugin.size() && !parsePackagesPrivate(_config.packagesEdit(),
listExtraPlugin,
&DistroModule::addExtraPlugins)) {
packagesErrorLog("extra plugins");
return false;
2019-09-07 12:01:20 +03:00
}
2020-07-04 23:08:41 +03:00
if (listEnablePlugins.size() && !parsePackagesPrivate(_config.packagesEdit(),
listEnablePlugins,
&DistroModule::addEnabledPlugins)) {
packagesErrorLog("enable plugins");
return false;
}
2020-07-04 23:08:41 +03:00
if (listDisablePlugins.size() && !parsePackagesPrivate(_config.packagesEdit(),
listDisablePlugins,
&DistroModule::addDisabledPlugins)) {
packagesErrorLog("disable plugins");
return false;
}
return true;
2019-09-07 12:01:20 +03:00
}
2019-12-18 13:49:07 +03:00
QString ConfigParser::findWindowsPath(const QString& path) const {
auto list = path.split(';');
QString win_magic = "windows";
2019-12-18 13:49:07 +03:00
2020-01-12 16:43:03 +03:00
for (const auto &i: list ) {
int index = i.indexOf(win_magic, 0, Qt::CaseInsensitive);
2019-12-18 13:49:07 +03:00
if (index > 0 && i.size() == index + win_magic.size()) {
return QDir::fromNativeSeparators(i);
}
}
return "C:/" + win_magic;
2019-12-18 13:49:07 +03:00
}
2020-08-15 14:38:03 +03:00
QList<iDistribution *> ConfigParser::getDistribution() {
QList<iDistribution *> distros;
2020-11-09 16:33:50 +03:00
if (QuasarAppUtils::Params::isEndable("deb")) {
2020-11-30 13:07:38 +03:00
#ifdef Q_OS_LINUX
2020-11-09 16:33:50 +03:00
distros.push_back(new Deb(_fileManager));
2020-11-30 13:07:38 +03:00
#else
QuasarAppUtils::Params::log("The deb option availabel only on Linux host palatforms,"
" please remove this options from your deploy command",
QuasarAppUtils::Warning);
#endif
2020-11-09 16:33:50 +03:00
}
2020-08-14 17:47:34 +03:00
if (QuasarAppUtils::Params::isEndable("zip")) {
2020-08-15 14:38:03 +03:00
distros.push_back(new ZipArhive(_fileManager));
2020-08-14 17:47:34 +03:00
}
if (QuasarAppUtils::Params::isEndable("qif")) {
2020-08-15 14:38:03 +03:00
distros.push_back(new QIF(_fileManager));
}
2020-01-04 16:39:25 +03:00
2020-08-15 19:29:17 +03:00
if (distros.isEmpty()) {
distros.push_back(new DefaultDistro(_fileManager));
}
2020-08-15 14:38:03 +03:00
2020-08-15 19:29:17 +03:00
return distros;
2020-01-04 16:39:25 +03:00
}
2019-09-14 13:59:11 +03:00
void ConfigParser::initEnvirement() {
2019-09-07 12:01:20 +03:00
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
2020-07-29 18:12:55 +03:00
auto path = env.value("PATH");
2019-12-18 13:49:07 +03:00
2020-07-28 23:56:34 +03:00
if (!DeployCore::isSnap()) {
2019-12-18 13:49:07 +03:00
2020-07-28 23:56:34 +03:00
_config.envirement.addEnv(env.value("LD_LIBRARY_PATH"));
_config.envirement.addEnv(path);
}
2019-09-07 12:01:20 +03:00
2019-11-05 13:17:52 +03:00
QStringList dirs;
2019-12-18 13:49:07 +03:00
#ifdef Q_OS_LINUX
2020-07-28 23:56:34 +03:00
dirs.append(getDirsRecursive(DeployCore::transportPathToSnapRoot("/lib"), 5));
dirs.append(getDirsRecursive(DeployCore::transportPathToSnapRoot("/usr/lib"), 5));
#else
2019-12-18 13:49:07 +03:00
auto winPath = findWindowsPath(path);
dirs.append(getDirsRecursive(winPath + "/System32", 2));
dirs.append(getDirsRecursive(winPath + "/SysWOW64", 2));
#endif
2020-02-26 14:29:04 +03:00
_config.envirement.addEnv(dirs);
2019-09-07 12:01:20 +03:00
2019-09-07 12:36:20 +03:00
if (_config.envirement.size() < 2) {
QuasarAppUtils::Params::log("System environment is empty",
2020-08-15 19:29:17 +03:00
QuasarAppUtils::Warning);
2019-09-07 12:01:20 +03:00
}
}
bool ConfigParser::checkSnapPermisions() {
if (!DeployCore::isSnap())
return true;
2020-07-29 18:12:55 +03:00
bool system = QuasarAppUtils::Params::isEndable("deploySystem") ||
QuasarAppUtils::Params::isEndable("extraLibs");
2020-07-30 10:55:15 +03:00
if (system && !DeployCore::checkSystemBakupSnapInterface()) {
2020-07-29 18:12:55 +03:00
QuasarAppUtils::Params::log("You use a deploySystem or extraLibs options,"
" but not added permision system-backup for cqtdeployer."
" Please add permissions system-backup before using cqtdeployer."
2020-07-29 18:12:55 +03:00
" Add system-backup permision from console: ",
QuasarAppUtils::Error);
QuasarAppUtils::Params::log(
2020-08-15 19:29:17 +03:00
"'snap connect cqtdeployer:system-backup :system-backup'",
QuasarAppUtils::Info);
2020-07-29 18:12:55 +03:00
QuasarAppUtils::Params::log(
2020-08-15 19:29:17 +03:00
"GUI: Open the gnome system setting >> Applications >> CQtDeployer. "
"in menu rights and permisions enable system-backup.",
QuasarAppUtils::Info);
return false;
}
return true;
}
2019-09-14 13:59:11 +03:00
QStringList ConfigParser::getDirsRecursive(const QString &path, int maxDepch, int depch) {
2020-02-20 10:35:00 +03:00
return getSetDirsRecursive(path, maxDepch, depch).values();
2019-11-05 13:17:52 +03:00
}
QSet<QString> ConfigParser::getSetDirsRecursive(const QString &path, int maxDepch, int depch) {
2019-09-07 12:01:20 +03:00
QDir dir(path);
2020-02-26 14:29:04 +03:00
QSet<QString> res = {dir.path()};
2019-09-07 12:01:20 +03:00
2019-09-26 13:18:10 +03:00
if (maxDepch >= 0 && maxDepch <= depch) {
2019-09-14 15:51:23 +03:00
return res;
}
2019-09-07 12:01:20 +03:00
auto list = dir.entryInfoList(QDir::Dirs| QDir::NoDotAndDotDot);
2020-01-12 16:43:03 +03:00
for (const auto &subDir: list) {
2019-11-05 13:17:52 +03:00
res.insert(subDir.absoluteFilePath());
res.unite(getSetDirsRecursive(subDir.absoluteFilePath(), maxDepch, depch + 1));
2019-09-07 12:01:20 +03:00
}
return res;
}
2019-09-14 13:59:11 +03:00
bool ConfigParser::smartMoveTargets() {
2019-09-08 13:37:33 +03:00
2020-08-14 10:29:56 +03:00
QMultiHash<QString, TargetInfo> temp;
2019-09-08 13:37:33 +03:00
bool result = true;
2021-05-12 16:21:59 +03:00
QuasarAppUtils::Params::log(QString("Available Targets: "),
QuasarAppUtils::Debug);
2020-01-02 19:27:40 +03:00
for (auto i = _config.targets().cbegin(); i != _config.targets().cend(); ++i) {
2019-09-08 13:37:33 +03:00
2021-01-19 14:26:11 +03:00
if (!i.value().isValid()) {
2021-03-01 09:44:59 +03:00
internalError();
2021-01-19 14:26:11 +03:00
return false;
}
2019-11-13 18:18:44 +03:00
QFileInfo target(i.key());
2019-09-08 13:37:33 +03:00
2020-02-26 16:51:28 +03:00
QString targetPath = _config.getTargetDir() + "/" + i.value().getPackage();
2019-09-08 13:37:33 +03:00
targetPath += _config.getDistro(i.key()).getBinOutDir();
2019-09-08 13:37:33 +03:00
if (!_fileManager->cp(target.absoluteFilePath(), targetPath)) {
2019-09-08 13:37:33 +03:00
result = false;
}
2019-12-29 14:19:07 +03:00
auto newTargetKey = targetPath + "/" + target.fileName();
2021-05-12 16:21:59 +03:00
const auto newTarget = moveTarget(i.value(), newTargetKey);
temp.unite(newTarget);
QuasarAppUtils::Params::log(QString("Target: " + newTarget.begin().key()),
QuasarAppUtils::Debug);
2019-09-08 13:37:33 +03:00
2020-12-03 20:00:14 +03:00
auto pkgKey = i.value().getPackage();
2021-05-14 15:36:25 +03:00
if (!_config.packagesEdit().contains(pkgKey)) {
QuasarAppUtils::Params::log(QString("The target %0 belongs to package %1"
" but this package is not initialized!").
2021-05-14 15:36:25 +03:00
arg(i.key(), pkgKey));
internalError();
return false;
}
valueLink(_config.packagesEdit(), pkgKey,
DistroModule{pkgKey}).addTarget(newTargetKey);
2021-05-12 16:21:59 +03:00
2019-09-08 13:37:33 +03:00
}
2020-01-02 19:27:40 +03:00
_config.targetsEdit() = temp;
2019-09-08 13:37:33 +03:00
return result && configureTargets();
2019-09-08 13:37:33 +03:00
}
ConfigParser::ConfigParser(FileManager *filemanager, PluginsParser *pluginsParser, DependenciesScanner* scaner, Packing *pac):
2019-11-13 18:18:44 +03:00
_fileManager(filemanager),
_pluginsParser(pluginsParser),
2020-01-04 16:39:25 +03:00
_scaner(scaner),
_packing(pac) {
2019-09-08 13:37:33 +03:00
assert(_fileManager);
assert(_pluginsParser);
2019-11-13 18:18:44 +03:00
assert(_scaner);
2020-01-04 16:39:25 +03:00
assert(_packing);
2019-09-07 12:01:20 +03:00
2021-05-21 22:35:16 +03:00
_config.appDir = QuasarAppUtils::Params::getCurrentExecutableDir();
2019-09-08 13:37:33 +03:00
if (_config.appDir.right(4) == "/bin") {
_config.appDir = _config.appDir.left(_config.appDir.size() - 4);
}
2019-09-04 21:27:29 +03:00
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("appDir = " + _config.appDir);
2019-09-04 21:27:29 +03:00
}