CQtDeployer/Deploy/configparser.cpp

1283 lines
40 KiB
C++
Raw Normal View History

2019-09-23 16:46:57 +03:00
//#
2019-12-08 13:57:20 +03:00
//# Copyright (C) 2018-2020 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>
#include <Distributions/defaultdistro.h>
#include <Distributions/qif.h>
/**
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, "");
auto second = paramsList.value(1, "");
if (paramsList.size() == 1)
(mainContainer[defaultPackage].*adder)(first);
2019-12-29 14:19:07 +03:00
else {
2020-02-27 20:37:05 +03:00
first = PathUtils::fullStripPath(first);
2019-12-29 14:19:07 +03:00
if (!mainContainer.contains(first)) {
return false;
}
2020-07-04 23:08:41 +03:00
for (int i = 1; i < paramsList.size(); ++i) {
(mainContainer[first].*adder)(paramsList[i]);
}
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
2019-09-14 13:59:11 +03:00
bool ConfigParser::parseParams() {
2019-09-10 18:22:49 +03:00
auto path = QuasarAppUtils::Params::getStrArg("confFile");
bool createFile = !QFile::exists(path) &&
QuasarAppUtils::Params::isEndable("confFile");
if (path.isEmpty() &&
QuasarAppUtils::Params::customParamasSize() <= 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)) {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("failed to parse " + path,
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 ...",
QuasarAppUtils::Info);
2019-09-07 12:01:20 +03:00
2020-01-24 13:57:55 +03:00
if (!parseInfoMode()) {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("show info is failed!",
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: {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("clear ...",
QuasarAppUtils::Info);
2019-09-07 12:01:20 +03:00
2020-01-24 13:57:55 +03:00
if (!parseClearMode()) {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("clear is failed!",
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 ...",
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!",
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 ...",
QuasarAppUtils::Info);
2019-09-07 12:01:20 +03:00
2020-01-24 13:57:55 +03:00
if (!parseDeployMode()) {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("deploy is failed!",
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
}
2020-01-24 13:57:55 +03:00
DeployCore::_config = &_config;
2019-10-16 14:25:44 +03:00
if (createFile && !createFromDeploy(path)) {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("Do not create a deploy config file in " + path,
2019-10-16 14:25:44 +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,
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)) {
obj[key] = writeKeyArray(0, QuasarAppUtils::Params::getStrArg(key), confFileDir);
}
}
2019-09-12 17:00:50 +03:00
QString ConfigParser::readKeyArray(int separatorLvl, const QJsonArray &array,
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);
2020-01-12 16:43:03 +03:00
for (const auto &key :DeployCore::helpKeys()) {
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();
2019-09-07 12:01:20 +03:00
2020-01-12 16:43:03 +03:00
for (const auto &key: obj.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
2020-01-02 19:27:40 +03:00
auto binOut = QuasarAppUtils::Params::getStrArg("binOut").
split(DeployCore::getSeparator(0), QString::SkipEmptyParts);
auto libOut = QuasarAppUtils::Params::getStrArg("libOut").
split(DeployCore::getSeparator(0), QString::SkipEmptyParts);
2019-12-09 17:28:56 +03:00
#else
2020-01-02 19:27:40 +03:00
auto binOut = QuasarAppUtils::Params::getStrArg("binOut").
split(DeployCore::getSeparator(0), QString::SkipEmptyParts);
auto libOut = QuasarAppUtils::Params::getStrArg("libOut").
split(DeployCore::getSeparator(0), QString::SkipEmptyParts);
2019-12-09 17:28:56 +03:00
#endif
2020-01-02 19:27:40 +03:00
auto qmlOut = QuasarAppUtils::Params::getStrArg("qmlOut").
split(DeployCore::getSeparator(0), QString::SkipEmptyParts);
auto trOut = QuasarAppUtils::Params::getStrArg("trOut").
split(DeployCore::getSeparator(0), QString::SkipEmptyParts);
auto pluginOut = QuasarAppUtils::Params::getStrArg("pluginOut").
split(DeployCore::getSeparator(0), QString::SkipEmptyParts);
auto recOut = QuasarAppUtils::Params::getStrArg("recOut").
split(DeployCore::getSeparator(0), QString::SkipEmptyParts);
2019-12-09 17:28:56 +03:00
2020-01-14 15:48:35 +03:00
auto name = QuasarAppUtils::Params::getStrArg("name").
split(DeployCore::getSeparator(0), QString::SkipEmptyParts);
auto description = QuasarAppUtils::Params::getStrArg("description").
split(DeployCore::getSeparator(0), QString::SkipEmptyParts);
auto deployVersion = QuasarAppUtils::Params::getStrArg("deployVersion").
split(DeployCore::getSeparator(0), QString::SkipEmptyParts);
auto releaseDate = QuasarAppUtils::Params::getStrArg("releaseDate").
split(DeployCore::getSeparator(0), QString::SkipEmptyParts);
auto icon = QuasarAppUtils::Params::getStrArg("icon").
split(DeployCore::getSeparator(0), QString::SkipEmptyParts);
2020-01-15 11:50:30 +03:00
auto publisher = QuasarAppUtils::Params::getStrArg("publisher").
split(DeployCore::getSeparator(0), QString::SkipEmptyParts);
2020-01-14 15:48:35 +03:00
2019-12-29 14:19:07 +03:00
auto erroLog = [](const QString &flag){
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log(QString("Set %0 fail, because you try set %0 for not inited package."
2020-01-27 20:02:25 +03:00
" Use 'targetPackage' flag for init the packages").arg(flag),
2019-12-29 14:19:07 +03:00
QuasarAppUtils::Error);
};
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)) {
2019-12-29 14:19:07 +03:00
erroLog("binOut");
return false;
}
2020-01-27 20:02:25 +03:00
if (libOut.size() && !parsePackagesPrivate(mainDistro, libOut, &DistroModule::setLibOutDir)) {
2019-12-29 14:19:07 +03:00
erroLog("libOut");
return false;
}
2020-01-27 20:02:25 +03:00
if (qmlOut.size() && !parsePackagesPrivate(mainDistro, qmlOut, &DistroModule::setQmlOutDir)) {
2019-12-29 14:19:07 +03:00
erroLog("qmlOut");
return false;
}
2020-01-27 20:02:25 +03:00
if (trOut.size() && !parsePackagesPrivate(mainDistro, trOut, &DistroModule::setTrOutDir)) {
2019-12-29 14:19:07 +03:00
erroLog("trOut");
return false;
}
2020-01-27 20:02:25 +03:00
if (pluginOut.size() && !parsePackagesPrivate(mainDistro, pluginOut, &DistroModule::setPluginsOutDir)) {
2019-12-29 14:19:07 +03:00
erroLog("pluginOut");
return false;
}
2020-01-27 20:02:25 +03:00
if (recOut.size() && !parsePackagesPrivate(mainDistro, recOut, &DistroModule::setResOutDir)) {
2019-12-29 14:19:07 +03:00
erroLog("recOut");
return false;
}
2019-12-28 15:06:43 +03:00
2020-01-27 20:02:25 +03:00
if (name.size() && !parsePackagesPrivate(mainDistro, name, &DistroModule::setName)) {
2020-01-14 15:48:35 +03:00
erroLog("name");
return false;
}
2020-01-27 20:02:25 +03:00
if (description.size() && !parsePackagesPrivate(mainDistro, description, &DistroModule::setDescription)) {
2020-01-14 15:48:35 +03:00
erroLog("description");
return false;
}
2020-01-27 20:02:25 +03:00
if (deployVersion.size() && !parsePackagesPrivate(mainDistro, deployVersion, &DistroModule::setVersion)) {
2020-01-14 15:48:35 +03:00
erroLog("deployVersion");
return false;
}
2020-01-27 20:02:25 +03:00
if (releaseDate.size() && !parsePackagesPrivate(mainDistro, releaseDate, &DistroModule::setReleaseData)) {
2020-01-14 15:48:35 +03:00
erroLog("releaseDate");
return false;
}
2020-01-27 20:02:25 +03:00
if (icon.size() && !parsePackagesPrivate(mainDistro, icon, &DistroModule::setIcon)) {
2020-01-14 15:48:35 +03:00
erroLog("icon");
return false;
}
2020-01-27 20:02:25 +03:00
if (publisher.size() && !parsePackagesPrivate(mainDistro, publisher, &DistroModule::setPublisher)) {
2020-01-15 11:50:30 +03:00
erroLog("Publisher");
return false;
}
2019-12-28 15:06:43 +03:00
return true;
}
2020-01-27 20:02:25 +03:00
bool ConfigParser::initPackages() {
2019-12-28 15:06:43 +03:00
2020-01-27 20:02:25 +03:00
defaultPackage = "";
2020-01-18 23:32:41 +03:00
2020-01-27 20:02:25 +03:00
if (QuasarAppUtils::Params::isEndable("targetPackage")) {
auto tar_packages_array = QuasarAppUtils::Params::getStrArg("targetPackage", "").
2019-12-29 14:19:07 +03:00
split(DeployCore::getSeparator(0));
2020-01-18 15:39:02 +03:00
QSet<QString> configuredTargets;
2020-01-27 20:02:25 +03:00
for (auto& str: tar_packages_array) {
2019-12-29 14:19:07 +03:00
auto pair = str.split(DeployCore::getSeparator(1));
2020-02-27 20:37:05 +03:00
auto package = PathUtils::fullStripPath(pair.value(0, ""));
2019-12-29 14:19:07 +03:00
auto list = _config.getTargetsListByFilter(pair.value(1, ""));
2020-01-18 15:39:02 +03:00
for (auto it = list.begin(); it != list.end(); ++it) {
if (!configuredTargets.contains(it.key())) {
configuredTargets.insert(it.key());
2020-02-26 16:51:28 +03:00
it.value()->setPackage(package);
2020-01-18 15:39:02 +03:00
}
2019-12-29 14:19:07 +03:00
}
2019-12-28 15:06:43 +03:00
2020-01-27 20:02:25 +03:00
_config.packagesEdit().insert(package, {});
2019-12-29 14:19:07 +03:00
if (pair.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(
2020-01-27 20:02:25 +03:00
"Set Default Package to " + defaultPackage,
2020-01-15 18:31:09 +03:00
QuasarAppUtils::Info);
2019-12-29 14:19:07 +03:00
}
2019-12-09 17:28:56 +03:00
return true;
}
2019-12-15 18:30:24 +03:00
bool ConfigParser::initQmlInput() {
auto qmlDir = QuasarAppUtils::Params::getStrArg("qmlDir").
2020-01-02 19:27:40 +03:00
split(DeployCore::getSeparator(0), QString::SkipEmptyParts);
2019-12-15 18:30:24 +03:00
if (QuasarAppUtils::Params::isEndable("allQmlDependes")) {
_config.deployQml = true;
2020-01-02 19:27:40 +03:00
return true;
2019-12-15 18:30:24 +03:00
}
2020-01-02 19:27:40 +03:00
auto erroLog = [](const QString &flag){
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log(QString("Set %0 fail, because you try set %0 for not inited package."
2020-01-27 20:02:25 +03:00
" Use 'targetPackage' flag for init the packages").arg(flag),
2020-01-02 19:27:40 +03:00
QuasarAppUtils::Error);
};
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)) {
2020-01-02 19:27:40 +03:00
erroLog("qmlDir");
return false;
2019-12-15 18:30:24 +03:00
}
return true;
}
2020-01-24 13:57:55 +03:00
bool ConfigParser::parseDeployMode() {
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::setEnable("deploySystem", true );
}
auto bin = QuasarAppUtils::Params::getStrArg("bin").
split(DeployCore::getSeparator(0));
2019-09-08 13:37:33 +03:00
if (!setTargets(bin)) {
auto binDir = QuasarAppUtils::Params::getStrArg("binDir");
2020-03-09 15:48:09 +03:00
if (!setTargetsRecursive(binDir)) {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("setTargetDir fail!",
QuasarAppUtils::Error);
2019-09-08 13:37:33 +03:00
return false;
}
}
_config.depchLimit = 0;
if (QuasarAppUtils::Params::isEndable("recursiveDepth")) {
bool ok;
_config.depchLimit = QuasarAppUtils::Params::getArg("recursiveDepth").toInt(&ok);
if (!ok) {
_config.depchLimit = 0;
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("recursiveDepth is invalid! use default value 0",
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;
}
auto listLibDir = QuasarAppUtils::Params::getStrArg("libDir").
split(DeployCore::getSeparator(0));
auto listNamesMasks = QuasarAppUtils::Params::getStrArg("extraLibs").
split(DeployCore::getSeparator(0));
2019-11-05 13:17:52 +03:00
2019-09-08 13:37:33 +03:00
setExtraPath(listLibDir);
2019-11-05 13:17:52 +03:00
setExtraNames(listNamesMasks);
initPlugins();
2019-09-08 13:37:33 +03:00
2019-11-14 17:35:21 +03:00
if (!initQmake()) {
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") ||
QuasarAppUtils::Params::isEndable("version"))) {
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() {
2020-01-27 19:35:02 +03:00
auto initLvl = QuasarAppUtils::Params::getStrArg("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::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;
}
2020-01-28 13:51:00 +03:00
bool ConfigParser::isNeededQt() const {
for (const auto &i: _config.targets()) {
if (i.isValid() && i.isDependetOfQt()) {
return true;
}
}
return false;
}
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")) {
2019-12-14 17:38:43 +03:00
_config.setTargetDir(QFileInfo(QuasarAppUtils::Params::getStrArg("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());
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("flag targetDir not used. use default target dir :" + _config.getTargetDir(),
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) {
2019-09-07 12:01:20 +03:00
QFileInfo targetInfo(i);
if (i.isEmpty())
continue;
if (targetInfo.isFile()) {
2020-01-02 19:27:40 +03:00
_config.targetsEdit().unite(createTarget(QDir::fromNativeSeparators(i)));
2019-11-13 18:18:44 +03:00
2019-09-07 12:01:20 +03:00
isfillList = true;
}
else if (targetInfo.isDir()) {
if (!setBinDir(i)) {
2020-04-04 16:21:44 +03:00
QuasarAppUtils::Params::log(i + " du not contains executable binaries!",
QuasarAppUtils::Debug);
2019-09-07 12:01:20 +03:00
continue;
}
isfillList = true;
} else {
2020-04-04 16:21:44 +03:00
QuasarAppUtils::Params::log(targetInfo.absoluteFilePath() + " not exits!",
QuasarAppUtils::Debug);
2019-09-07 12:01:20 +03:00
}
}
if (!isfillList)
return false;
setTargetDir();
return true;
}
2019-09-14 13:59:11 +03:00
bool ConfigParser::setTargetsRecursive(const QString &dir) {
2019-09-07 12:01:20 +03:00
if (!setBinDir(dir, true)) {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("setBinDir failed!",
2020-04-04 16:21:44 +03:00
QuasarAppUtils::Warning);
2019-09-07 12:01:20 +03:00
return false;
}
setTargetDir();
return true;
}
2019-09-14 13:59:11 +03:00
bool ConfigParser::setBinDir(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!",
QuasarAppUtils::Debug);
2019-09-07 12:01:20 +03:00
return false;
}
2020-04-04 16:21:44 +03:00
QuasarAppUtils::Params::log("setBinDir check path: " + dir,
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;
2020-01-12 16:43:03 +03:00
for (const auto &file : list) {
2019-09-07 12:01:20 +03:00
if (file.isDir()) {
result |= setBinDir(file.absoluteFilePath(), recursive);
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) ||
name.contains(".so", Qt::CaseInsensitive) || name.contains(".exe", Qt::CaseInsensitive)) {
result = true;
2019-11-13 18:18:44 +03:00
2020-01-02 19:27:40 +03:00
_config.targetsEdit().unite(createTarget(QDir::fromNativeSeparators(file.absoluteFilePath())));
2019-09-12 21:42:10 +03:00
2019-09-07 12:01:20 +03:00
}
2019-09-12 21:42:10 +03:00
}
2019-09-07 12:01:20 +03:00
return result;
}
2020-01-01 23:44:16 +03:00
QHash<QString, TargetInfo> 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)) {
return {{libinfo.fullPath(), libinfo}};
}
2020-01-12 16:43:03 +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")) {
auto list = QuasarAppUtils::Params::getStrArg("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
2019-09-24 15:11:30 +03:00
if (!QuasarAppUtils::Params::isEndable("deploySystem-with-libc")) {
2019-09-23 10:06:22 +03:00
2020-02-26 14:29:04 +03:00
envUnix.addEnv(Envirement::recursiveInvairement("/lib", 3));
envUnix.addEnv(Envirement::recursiveInvairement("/usr/lib", 3));
2019-09-24 15:11:30 +03:00
ruleUnix.prority = SystemLib;
2019-11-01 15:12:03 +03:00
ruleUnix.platform = Unix;
2019-09-24 15:11:30 +03:00
ruleUnix.enfirement = envUnix;
2019-09-23 10:06:22 +03:00
2019-09-24 15:11:30 +03:00
auto addRuleUnix = [&ruleUnix](const QString & lib) {
ruleUnix.label = lib;
return ruleUnix;
2019-09-23 10:06:22 +03:00
};
2019-09-24 15:11:30 +03:00
_config.ignoreList.addRule(addRuleUnix("libc"));
_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"));
2019-09-24 15:11:30 +03:00
_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"));
_config.ignoreList.addRule(addRuleUnix("/gconv/"));
_config.ignoreList.addRule(addRuleUnix("libnss"));
}
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")) {
auto ignoreList = QuasarAppUtils::Params::getStrArg("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-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 QFileInfo(list.join(':')).absoluteFilePath().remove('\r');
}
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()) {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("fail init qmake",
2019-11-14 17:35:21 +03:00
QuasarAppUtils::Error);
return false;
}
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("exec qmake fail!, try init qtDir from path:" + dir.absolutePath(),
2019-11-14 17:35:21 +03:00
QuasarAppUtils::Warning);
if (!setQtDir(dir.absolutePath())){
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("fail ini qmake",
2019-11-14 17:35:21 +03:00
QuasarAppUtils::Error);
return false;
}
}
return true;
}
bool ConfigParser::initQmake() {
auto qmake = QuasarAppUtils::Params::getStrArg("qmake");
QFileInfo info(qmake);
if (!info.isFile() || (info.baseName() != "qmake")) {
auto qtList = getQtPathesFromTargets();
if (qtList.isEmpty()) {
2020-01-28 13:51:00 +03:00
2020-01-28 15:25:35 +03:00
if (!QuasarAppUtils::Params::isEndable("noCheckPATH") && isNeededQt()) {
auto env = QProcessEnvironment::systemEnvironment();
auto proc = DeployCore::findProcess(env.value("PATH"), "qmake");
2020-04-04 15:43:46 +03:00
if (proc.isEmpty()) {
QuasarAppUtils::Params::log("The deployment target requir Qt libs, but init qmake is failed.",
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-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("deploy only C libs because qmake is not found",
QuasarAppUtils::Info);
2019-11-14 17:35:21 +03:00
return true;
2020-01-12 16:43:03 +03:00
}
if (qtList.size() > 1) {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("Your deployment targets were compiled by different qmake,"
2019-11-14 17:35:21 +03:00
"qt auto-capture is not possible. Use the -qmake flag to solve this problem.",
QuasarAppUtils::Error);
return false;
}
auto qt = *qtList.begin();
if (qt.right(3).compare("lib", Qt::CaseInsensitive)) {
return initQmakePrivate(QFileInfo(qt + "/../bin/qmake").absoluteFilePath());
}
return initQmakePrivate(QFileInfo(qt + "/qmake").absoluteFilePath());
}
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) ||
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-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"))) {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("get qt bin fail!");
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"))) {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("get qt lib fail!");
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"))) {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("get qt qml fail!");
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"))) {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("get qt plugins fail!");
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"))) {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("get qt libexec fail!");
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"))) {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("get qt translations fail!");
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"))) {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("get qt resources fail!");
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
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
}
2019-09-14 13:59:11 +03:00
void ConfigParser::setExtraPath(const QStringList &value) {
2019-09-07 12:01:20 +03:00
QDir dir;
2020-01-12 16:43:03 +03:00
for (const auto &i : value) {
2019-09-07 12:01:20 +03:00
QFileInfo info(i);
if (info.isDir()) {
2020-01-02 19:27:40 +03:00
if (_config.targets().contains(info.absoluteFilePath())) {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("skip the extra lib path because it is target!",
2019-11-05 13:17:52 +03:00
QuasarAppUtils::Info);
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
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log(i + " added like a path mask",
2019-11-05 13:17:52 +03:00
QuasarAppUtils::Info);
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"
2019-11-05 13:17:52 +03:00
" the path mask must be large 2 characters",
QuasarAppUtils::Warning);
2019-09-07 12:01:20 +03:00
}
}
}
2019-11-05 13:17:52 +03:00
void ConfigParser::setExtraNames(const QStringList &value) {
2020-01-12 16:43:03 +03:00
for (const auto &i : value) {
2019-11-05 13:17:52 +03:00
if (i.size() > 1) {
2019-12-20 17:25:20 +03:00
_config.extraPaths.addtExtraNamesMasks({i});
2019-11-05 13:17:52 +03:00
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log(i + " added like a file name mask",
2019-11-05 13:17:52 +03:00
QuasarAppUtils::Info);
} else {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log(i + " not added in file mask because"
2019-11-05 13:17:52 +03:00
" the file mask must be large 2 characters",
QuasarAppUtils::Warning);
}
}
}
bool ConfigParser::initPlugins() {
auto listExtraPlugin = QuasarAppUtils::Params::getStrArg("extraPlugin").
split(DeployCore::getSeparator(0), QString::SkipEmptyParts);
auto listEnablePlugins = QuasarAppUtils::Params::getStrArg("enablePlugins").
split(DeployCore::getSeparator(0), QString::SkipEmptyParts);
auto listDisablePlugins = QuasarAppUtils::Params::getStrArg("disablePlugins").
split(DeployCore::getSeparator(0), QString::SkipEmptyParts);
auto erroLog = [](const QString &flag){
QuasarAppUtils::Params::log(QString("Set %0 fail, because you try set %0 for not inited package."
" Use 'targetPackage' flag for init the packages").arg(flag),
QuasarAppUtils::Error);
};
2020-07-04 23:08:41 +03:00
if (listExtraPlugin.size() && !parsePackagesPrivate(_config.packagesEdit(),
listExtraPlugin,
&DistroModule::addExtraPlugins)) {
erroLog("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)) {
erroLog("enable plugins");
return false;
}
2020-07-04 23:08:41 +03:00
if (listDisablePlugins.size() && !parsePackagesPrivate(_config.packagesEdit(),
listDisablePlugins,
&DistroModule::addDisabledPlugins)) {
erroLog("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-01-04 16:39:25 +03:00
iDistribution *ConfigParser::getDistribution() {
if (QuasarAppUtils::Params::isEndable("qif")) {
2020-01-15 18:31:09 +03:00
return new QIF(_fileManager);
}
2020-01-04 16:39:25 +03:00
2020-01-15 18:31:09 +03:00
return new DefaultDistro(_fileManager);
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();
2019-12-18 13:49:07 +03:00
auto path = env.value("PATH");
2020-02-26 14:29:04 +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
2019-11-05 13:17:52 +03:00
dirs.append(getDirsRecursive("/lib", 5));
dirs.append(getDirsRecursive("/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) {
2020-04-04 15:43:46 +03:00
QuasarAppUtils::Params::log("system environment is empty",
QuasarAppUtils::Warning);
2019-09-07 12:01:20 +03:00
}
}
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-01-02 19:27:40 +03:00
QHash<QString, TargetInfo> temp;
2019-09-08 13:37:33 +03:00
bool result = true;
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
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
2019-09-15 17:38:47 +03:00
if (DeployCore::isLib(target)) {
2019-12-14 17:38:43 +03:00
targetPath += _config.getDistro(i.key()).getLibOutDir();
2019-09-15 17:38:47 +03:00
} else {
2019-12-14 17:38:43 +03:00
targetPath += _config.getDistro(i.key()).getBinOutDir();
2019-09-08 13:37:33 +03:00
}
2019-09-25 12:32:05 +03:00
if (!_fileManager->smartCopyFile(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();
2020-01-01 23:44:16 +03:00
temp.unite(moveTarget(i.value(), newTargetKey));
2019-09-08 13:37:33 +03:00
2020-02-26 16:51:28 +03:00
_config.packagesEdit()[i.value().getPackage()].addTarget(newTargetKey);
2019-12-27 20:23:55 +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;
}
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
2019-09-08 13:37:33 +03:00
#ifdef Q_OS_LINUX
_config.appDir = QuasarAppUtils::Params::getStrArg("appPath");
if (_config.appDir.right(4) == "/bin") {
_config.appDir = _config.appDir.left(_config.appDir.size() - 4);
}
#else
_config.appDir = QuasarAppUtils::Params::getStrArg("appPath");
#endif
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
}