CQtDeployer/Deploy/configparser.cpp

1037 lines
30 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 "pathutils.h"
2019-09-07 12:01:20 +03:00
#include "quasarapp.h"
2019-09-04 21:27:29 +03:00
2019-12-09 15:13:00 +03:00
#include <assert.h>
2019-12-28 15:06:43 +03:00
// this function init prefixes of project
// inputParamsList - list of parameters
// patern : value;prefix
// mainContainer - container for insert data, usually it is prefixes map.
// seterFunc - this is method of item of mainConteiner for set value from inputParamsList
// important : prefix in inputParamsList must be second.
#define initDistroPatern(inputParamsList, mainContainer, seterFunc) \
for (auto& str: inputParamsList) { \
auto targetVal = str.split(DeployCore::getSeparator(1)); \
mainContainer[targetVal.value(1, "")].seterFunc(targetVal.value(0, "")); \
}
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");
2019-10-17 12:42:55 +03:00
bool createFile = !(path.isEmpty() || QFile::exists(path));
2019-09-10 18:22:49 +03:00
if (path.isEmpty()) {
path = QFileInfo("./").absoluteFilePath();
}
loadFromFile(path);
2019-09-07 12:01:20 +03:00
switch (DeployCore::getMode()) {
case RunMode::Info: {
qInfo() << "selected info mode" ;
if (!parseQtInfoMode()) {
qCritical() << "info mode fail!";
return false;
}
2019-09-08 13:37:33 +03:00
DeployCore::_config = &_config;
2019-09-10 18:22:49 +03:00
break;
2019-09-07 12:01:20 +03:00
}
case RunMode::Clear: {
qInfo() << "selected clear mode" ;
if (!parseQtClearMode()) {
qCritical() << "clear mode fail!";
return false;
}
2019-09-08 13:37:33 +03:00
DeployCore::_config = &_config;
2019-09-10 18:22:49 +03:00
break;
2019-09-07 12:01:20 +03:00
}
case RunMode::Deploy: {
qInfo() << "selected deploy mode" ;
if (!parseQtDeployMode()) {
qCritical() << "deploy mode fail!";
return false;
}
2019-09-08 13:37:33 +03:00
DeployCore::_config = &_config;
2019-09-10 18:22:49 +03:00
break;
}
2019-09-07 12:01:20 +03:00
}
2019-10-16 14:25:44 +03:00
if (createFile && !createFromDeploy(path)) {
QuasarAppUtils::Params::verboseLog("Do not create a deploy config file in " + path,
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
}
QJsonValue ConfigParser::writeKeyArray(int separatorLvl, const QString &parameter,
const QString &confFileDir) const {
auto list = parameter.split(DeployCore::getSeparator(separatorLvl));
if (list.size() > 1) {
QJsonArray array;
for (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)) {
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;
for (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();
if (!val.isEmpty()) {
if (PathUtils::isPath(val)) {
QString path;
if (PathUtils::isAbsalutPath(val)) {
path = QFileInfo(val).absoluteFilePath();
} else {
path = QFileInfo(confFileDir + '/' + val).absoluteFilePath();
}
list.push_back(path);
} 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)) {
2019-09-12 17:00:50 +03:00
if (obj[key].isArray()) {
auto array = obj[key].toArray();
QuasarAppUtils::Params::setArg(key, readKeyArray(0, array, confFileDir));
2019-09-12 17:00:50 +03:00
2019-09-12 21:42:10 +03:00
} else if (!obj[key].isUndefined()) {
2019-09-12 17:00:50 +03:00
QString val = obj[key].toString();
if (!val.isEmpty()) {
if (PathUtils::isPath(val)) {
2019-10-16 18:07:36 +03:00
if (PathUtils::isAbsalutPath(val)) {
val = QFileInfo(val).absoluteFilePath();
} else {
val = QFileInfo(confFileDir + '/' + val).absoluteFilePath();
}
}
2019-09-12 17:00:50 +03:00
QuasarAppUtils::Params::setArg(key, val);
} else {
auto value = obj[key].toBool(true);
QuasarAppUtils::Params::setEnable(key, value);
2019-09-12 17:00:50 +03:00
}
}
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);
2019-09-10 15:40:12 +03:00
for (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
2019-09-10 15:40:12 +03:00
for (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
2019-12-13 23:05:07 +03:00
auto &mainDistro = _config.prefixes;
2019-12-09 17:28:56 +03:00
#ifdef Q_OS_LINUX
auto binOut = QuasarAppUtils::Params::getStrArg("binOut", "/bin").
split(DeployCore::getSeparator(0));
auto libOut = QuasarAppUtils::Params::getStrArg("libOut", "/lib").
split(DeployCore::getSeparator(0));
2019-12-09 17:28:56 +03:00
#else
auto binOut = QuasarAppUtils::Params::getStrArg("binOut", "/").
split(DeployCore::getSeparator(0));
auto libOut = QuasarAppUtils::Params::getStrArg("libOut", "/").
split(DeployCore::getSeparator(0));
2019-12-09 17:28:56 +03:00
#endif
auto qmlOut = QuasarAppUtils::Params::getStrArg("qmlOut", "/qml").
split(DeployCore::getSeparator(0));
auto trOut = QuasarAppUtils::Params::getStrArg("trOut", "/translations").
split(DeployCore::getSeparator(0));
auto pluginOut = QuasarAppUtils::Params::getStrArg("pluginOut", "/plugins").
split(DeployCore::getSeparator(0));
auto recOut = QuasarAppUtils::Params::getStrArg("recOut", "/resources").
split(DeployCore::getSeparator(0));
2019-12-09 17:28:56 +03:00
2019-12-10 18:43:01 +03:00
// init distro stucts for all targets
2019-12-28 15:06:43 +03:00
initDistroPatern(binOut, mainDistro, setBinOutDir);
initDistroPatern(libOut, mainDistro, setLibOutDir);
initDistroPatern(qmlOut, mainDistro, setQmlOutDir);
initDistroPatern(trOut, mainDistro, setTrOutDir);
initDistroPatern(pluginOut, mainDistro, setPluginsOutDir);
initDistroPatern(recOut, mainDistro, setResOutDir);
return true;
}
bool ConfigParser::initPrefixes() {
auto tar_prefixes_array = QuasarAppUtils::Params::getStrArg("targetPrefix", "").
split(DeployCore::getSeparator(0));
initDistroPatern(tar_prefixes_array, _config.prefixes, addTarget);
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").
split(DeployCore::getSeparator(0));
if (QuasarAppUtils::Params::isEndable("allQmlDependes")) {
_config.deployQml = true;
}
for (auto& str: qmlDir) {
if (QFileInfo::exists(str)) {
_config.deployQml = true;
auto targetVal = str.split(DeployCore::getSeparator(1));
_config.prefixes[targetVal.value(1, "")].addQmlInput(targetVal.value(0, ""));
} else {
QuasarAppUtils::Params::verboseLog("qml dir not exits!",
QuasarAppUtils::VerboseLvl::Warning);
}
}
return true;
}
2019-09-14 13:59:11 +03:00
bool ConfigParser::parseQtDeployMode() {
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");
if (!(setTargetsRecursive(binDir) || setTargets({"./"}))) {
qCritical() << "setTargetDir fail!";
return false;
}
}
initIgnoreEnvList();
initEnvirement();
initIgnoreList();
2019-12-27 20:23:55 +03:00
initDistroStruct();
2019-12-28 15:06:43 +03:00
initPrefixes();
2019-09-15 17:38:47 +03:00
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;
qWarning() << "recursiveDepth is invalid! use default value 0";
}
}
auto listLibDir = QuasarAppUtils::Params::getStrArg("libDir").
split(DeployCore::getSeparator(0));
auto listNamesMasks = QuasarAppUtils::Params::getStrArg("extraLibs").
split(DeployCore::getSeparator(0));
auto listExtraPlugin = QuasarAppUtils::Params::getStrArg("extraPlugin").
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);
2019-09-08 13:37:33 +03:00
setExtraPlugins(listExtraPlugin);
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
2019-12-15 18:30:24 +03:00
initQmlInput();
2019-09-08 13:37:33 +03:00
return true;
2019-09-07 12:01:20 +03:00
}
2019-09-14 13:59:11 +03:00
bool ConfigParser::parseQtInfoMode() {
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
}
2019-09-14 13:59:11 +03:00
bool ConfigParser::parseQtClearMode() {
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;
for (auto &i: _config.targets) {
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")) {
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());
qInfo () << "flag targetDir not used." << "use default target dir :" << _config.getTargetDir();
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;
for (auto &i : value) {
QFileInfo targetInfo(i);
if (i.isEmpty())
continue;
if (targetInfo.isFile()) {
auto sufix = targetInfo.completeSuffix();
2019-11-13 18:18:44 +03:00
_config.targets.unite(prepareTarget(QDir::fromNativeSeparators(i)));
2019-09-07 12:01:20 +03:00
isfillList = true;
}
else if (targetInfo.isDir()) {
if (!setBinDir(i)) {
DeployCore::verboseLog(i + " du not contains executable binaries!");
continue;
}
isfillList = true;
} else {
DeployCore::verboseLog(targetInfo.absoluteFilePath() + " not exits!");
}
}
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)) {
qWarning() << "setBinDir failed!";
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()) {
DeployCore::verboseLog(dir + " dir not exits!");
return false;
}
DeployCore::verboseLog("setBinDir check path: " + dir);
QFileInfoList list;
if (recursive) {
list = d.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
} else {
list = d.entryInfoList(QDir::Files | QDir::NoDotAndDotDot);
}
bool result = false;
for (auto &file : list) {
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
_config.targets.unite(prepareTarget(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;
}
2019-12-08 13:57:20 +03:00
QHash<QString, TargetInfo> ConfigParser::prepareTarget(const QString &target) {
TargetInfo libinfo;
2019-11-13 18:18:44 +03:00
auto key = target;
if (_scaner->fillLibInfo(libinfo, key)) {
return {{libinfo.fullPath(), libinfo}};
} else {
return {{key, {}}};
}
}
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
for (auto &i : list) {
_config.ignoreList.addRule(IgnoreData(i));
}
2019-09-07 12:01:20 +03:00
}
2019-09-24 15:11:30 +03:00
IgnoreData ruleUnix, ruleWin;
2019-09-23 10:06:22 +03:00
2019-09-24 15:11:30 +03:00
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
2019-09-24 15:11:30 +03:00
envUnix.addEnv(recursiveInvairement("/lib", 3), "", "");
envUnix.addEnv(recursiveInvairement("/usr/lib", 3), "", "");
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);
envWin.addEnv(recursiveInvairement(winPath + "/System32", 2), "", "");
envWin.addEnv(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"));
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
2019-09-07 12:01:20 +03:00
for (auto &i : ignoreList) {
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
_config.envirement.setIgnoreEnvList(ignoreEnvList);
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()) {
QuasarAppUtils::Params::verboseLog("fail init qmake",
QuasarAppUtils::Error);
return false;
}
QuasarAppUtils::Params::verboseLog("exec qmake fail!, try init qtDir from path:" + dir.absolutePath(),
QuasarAppUtils::Warning);
if (!setQtDir(dir.absolutePath())){
QuasarAppUtils::Params::verboseLog("fail ini qmake",
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()) {
qInfo() << "deploy only C libs because qmake is not found";
return true;
} else if (qtList.size() > 1) {
QuasarAppUtils::Params::verboseLog("Your deployment targets were compiled by different qmake,"
"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))) {
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)) {
QuasarAppUtils::Params::verboseLog("run qmake fail!");
return false;
}
QString qmakeData = proc.readAll();
auto list = qmakeData.split('\n');
for (auto &value : list) {
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
}
}
2019-12-23 10:12:23 +03:00
_config.envirement.addEnv(_config.qtDir.getLibs(), _config.appDir, _config.getTargetDir());
_config.envirement.addEnv(_config.qtDir.getBins(), _config.appDir, _config.getTargetDir());
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::verboseLog("get qt bin fail!");
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::verboseLog("get qt lib fail!");
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::verboseLog("get qt qml fail!");
} 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::verboseLog("get qt plugins fail!");
} 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::verboseLog("get qt libexec fail!");
} 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::verboseLog("get qt translations fail!");
} 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::verboseLog("get qt resources fail!");
} 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
2019-12-23 10:12:23 +03:00
_config.envirement.addEnv(_config.qtDir.getLibs(), _config.appDir, _config.getTargetDir());
_config.envirement.addEnv(_config.qtDir.getBins(), _config.appDir, _config.getTargetDir());
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;
for (auto i : value) {
QFileInfo info(i);
if (info.isDir()) {
2019-09-07 12:36:20 +03:00
if (_config.targets.contains(info.absoluteFilePath())) {
2019-11-05 13:17:52 +03:00
QuasarAppUtils::Params::verboseLog("skip the extra lib path becouse it is target!",
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
2019-12-14 17:38:43 +03:00
_config.envirement.addEnv(recursiveInvairement(dir), _config.appDir, _config.getTargetDir());
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::verboseLog(i + " added like a path mask",
QuasarAppUtils::Info);
2019-09-07 12:01:20 +03:00
} else {
2019-11-05 13:17:52 +03:00
QuasarAppUtils::Params::verboseLog(i + " not added in path mask becouse"
" 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) {
for (auto i : value) {
if (i.size() > 1) {
2019-12-20 17:25:20 +03:00
_config.extraPaths.addtExtraNamesMasks({i});
2019-11-05 13:17:52 +03:00
QuasarAppUtils::Params::verboseLog(i + " added like a file name mask",
QuasarAppUtils::Info);
} else {
QuasarAppUtils::Params::verboseLog(i + " not added in file mask becouse"
" the file mask must be large 2 characters",
QuasarAppUtils::Warning);
}
}
}
2019-09-14 13:59:11 +03:00
void ConfigParser::setExtraPlugins(const QStringList &value) {
2019-09-07 12:01:20 +03:00
for (auto i : value) {
2019-09-14 15:51:23 +03:00
if (!i.isEmpty())
_config.extraPlugins.append(i);
2019-09-07 12:01:20 +03:00
}
}
2019-09-24 15:11:30 +03:00
QString ConfigParser::recursiveInvairement(QDir &dir, int depch, int depchLimit ) {
2019-09-07 12:01:20 +03:00
char separator = ':';
#ifdef Q_OS_WIN
separator = ';';
#endif
2019-09-24 15:11:30 +03:00
if (depchLimit < 0) {
depchLimit = _config.depchLimit;
}
if (!dir.exists() || depch >= depchLimit) {
2019-09-07 12:01:20 +03:00
return dir.absolutePath();
}
QFileInfoList list = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
QString res = "";
for (QFileInfo &i : list) {
2019-09-15 11:11:16 +03:00
if (!dir.cd(i.fileName())) {
continue;
}
2019-09-24 15:11:30 +03:00
QString temp = recursiveInvairement(dir, depch + 1);
2019-09-07 12:01:20 +03:00
res += (res.size())? separator + temp: temp;
dir.cdUp();
}
res += (res.size())? separator + dir.absolutePath(): dir.absolutePath();
return res;
}
2019-09-24 15:11:30 +03:00
QString ConfigParser::recursiveInvairement(const QString &dir, int depch) {
2019-09-23 10:06:22 +03:00
QDir _dir(dir);
2019-09-24 15:11:30 +03:00
return recursiveInvairement(_dir, 0, depch);
2019-09-23 10:06:22 +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
for (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
}
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");
2019-12-14 17:38:43 +03:00
_config.envirement.addEnv(env.value("LD_LIBRARY_PATH"), _config.appDir, _config.getTargetDir());
2019-12-23 10:12:23 +03:00
_config.envirement.addEnv(path, _config.appDir, _config.getTargetDir());
2019-09-07 12:01:20 +03:00
2019-11-05 13:17:52 +03:00
QStringList dirs;
2019-09-24 15:11:30 +03:00
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
2019-09-07 12:01:20 +03:00
2019-11-05 13:17:52 +03:00
for (auto &&i : dirs) {
2019-12-14 17:38:43 +03:00
_config.envirement.addEnv(i, _config.appDir, _config.getTargetDir());
2019-09-07 12:01:20 +03:00
}
2019-09-07 12:36:20 +03:00
if (_config.envirement.size() < 2) {
2019-09-07 12:01:20 +03:00
qWarning() << "system environment is empty";
}
}
2019-09-14 13:59:11 +03:00
QStringList ConfigParser::getDirsRecursive(const QString &path, int maxDepch, int depch) {
2019-11-05 13:17:52 +03:00
return getSetDirsRecursive(path, maxDepch, depch).toList();
}
QSet<QString> ConfigParser::getSetDirsRecursive(const QString &path, int maxDepch, int depch) {
2019-09-07 12:01:20 +03:00
QDir dir(path);
2019-11-05 13:17:52 +03:00
QSet<QString> res = {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);
for (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
2019-11-13 18:18:44 +03:00
decltype (_config.targets) temp;
2019-09-08 13:37:33 +03:00
bool result = true;
for (auto i = _config.targets.cbegin(); i != _config.targets.cend(); ++i) {
2019-11-13 18:18:44 +03:00
QFileInfo target(i.key());
2019-09-08 13:37:33 +03:00
2019-12-14 17:38:43 +03:00
QString targetPath = _config.getTargetDir();
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-11-13 18:18:44 +03:00
temp.unite(prepareTarget(targetPath + "/" + target.fileName()));
2019-09-08 13:37:33 +03:00
2019-12-27 20:23:55 +03:00
_config.prefixes[i.value().getSufix()].addTarget(i.key());
2019-09-08 13:37:33 +03:00
}
_config.targets = temp;
return result;
}
2019-11-13 18:18:44 +03:00
ConfigParser::ConfigParser(FileManager *filemanager, DependenciesScanner* scaner):
_fileManager(filemanager),
_scaner(scaner) {
2019-09-08 13:37:33 +03:00
assert(_fileManager);
2019-11-13 18:18:44 +03:00
assert(_scaner);
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
2019-09-08 13:37:33 +03:00
QuasarAppUtils::Params::verboseLog("appDir = " + _config.appDir);
2019-09-04 21:27:29 +03:00
}