CQtDeployer/Deploy/dependenciesscanner.cpp

186 lines
4.7 KiB
C++
Raw Normal View History

2019-01-26 07:54:56 +03:00
/*
* Copyright (C) 2018-2019 QuasarApp.
* 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-03-19 21:50:05 +03:00
#include "dependenciesscanner.h"
2019-09-03 18:15:05 +03:00
#include "deploycore.h"
2019-03-25 21:27:26 +03:00
#include "quasarapp.h"
#include "configparser.h"
2018-11-15 18:00:23 +03:00
#include <QList>
2018-11-18 17:22:05 +03:00
#include <QDir>
2018-11-26 16:17:46 +03:00
#include <QDebug>
2018-11-15 18:00:23 +03:00
2019-03-19 21:50:05 +03:00
DependenciesScanner::DependenciesScanner() {}
2018-11-15 18:00:23 +03:00
2019-04-05 14:23:42 +03:00
void DependenciesScanner::clearScaned() {
_scanedLibs.clear();
}
2019-03-17 18:42:07 +03:00
2019-03-19 21:50:05 +03:00
PrivateScaner DependenciesScanner::getScaner(const QString &lib) const {
2019-03-17 18:42:07 +03:00
2019-03-19 21:50:05 +03:00
QFileInfo info(lib);
auto sufix = info.completeSuffix();
2019-09-14 13:59:11 +03:00
if (sufix.compare("dll", Qt::CaseSensitive) == 0 ||
sufix.compare("exe", Qt::CaseSensitive) == 0) {
2019-03-19 21:50:05 +03:00
return PrivateScaner::PE;
} else if (sufix.isEmpty() || sufix.contains("so", Qt::CaseSensitive)) {
return PrivateScaner::ELF;
}
return PrivateScaner::UNKNOWN;
}
2019-08-24 17:56:42 +03:00
QMultiMap<LibPriority, LibInfo> DependenciesScanner::getLibsFromEnvirement(
2019-08-31 22:22:26 +03:00
const QString &libName) const {
2019-03-25 21:27:26 +03:00
2019-04-04 18:11:38 +03:00
auto values = _EnvLibs.values(libName.toUpper());
2019-08-24 17:56:42 +03:00
QMultiMap<LibPriority, LibInfo> res;
2019-03-25 21:27:26 +03:00
for (auto & lib : values) {
LibInfo info;
2019-09-26 13:18:10 +03:00
auto priority = (DeployCore::getLibPriority(lib));
if ((priority >= SystemLib) && !QuasarAppUtils::Params::isEndable("deploySystem")) {
continue;
}
2019-03-25 21:27:26 +03:00
if (!fillLibInfo(info, lib)) {
QuasarAppUtils::Params::verboseLog(
2019-04-06 14:42:22 +03:00
"error extract lib info from " + lib + "(" + libName + ")",
QuasarAppUtils::VerboseLvl::Warning);
2019-03-25 21:27:26 +03:00
continue;
}
2019-09-26 13:18:10 +03:00
info.setPriority(priority);
2019-03-25 21:27:26 +03:00
if (!DeployCore::_config->ignoreList.isIgnore(info)) {
res.insertMulti(info.getPriority(), info);
}
2019-03-25 21:27:26 +03:00
}
return res;
}
2019-08-31 22:22:26 +03:00
bool DependenciesScanner::fillLibInfo(LibInfo &info, const QString &file) const {
2019-03-19 21:50:05 +03:00
info.clear();
auto scaner = getScaner(file);
switch (scaner) {
case PrivateScaner::PE: {
return _peScaner.getLibInfo(file, info);
}
case PrivateScaner::ELF:
return _elfScaner.getLibInfo(file, info);
default: return false;
}
2018-12-09 17:35:07 +03:00
}
2019-08-31 22:22:26 +03:00
void DependenciesScanner::recursiveDep(LibInfo &lib, QSet<LibInfo> &res) {
2019-04-06 14:42:22 +03:00
QuasarAppUtils::Params::verboseLog("get recursive dependencies of " + lib.fullPath(),
QuasarAppUtils::Info);
2019-04-05 16:52:53 +03:00
if (_scanedLibs.contains(lib.fullPath())) {
auto scanedLib = _scanedLibs.value(lib.fullPath());
2019-04-05 14:23:42 +03:00
2019-04-05 16:52:53 +03:00
if (!scanedLib.isValid()) {
qCritical() << "no valid lib in scaned libs list!";
return;
}
2019-04-05 14:23:42 +03:00
2019-04-05 16:52:53 +03:00
res.unite(scanedLib.allDep);
2019-04-05 14:23:42 +03:00
2019-04-05 16:52:53 +03:00
return;
}
2019-04-05 14:23:42 +03:00
2019-04-05 16:52:53 +03:00
for (auto i : lib.dependncies) {
2019-04-05 14:23:42 +03:00
2019-04-04 18:11:38 +03:00
auto libs = getLibsFromEnvirement(i);
if (!libs.size()) {
QuasarAppUtils::Params::verboseLog("lib for dependese " + i + " not findet!!",
QuasarAppUtils::Warning);
continue;
}
auto dep = libs.begin();
while (dep != libs.end() &&
dep.value().platform != lib.platform) dep++;
2019-04-06 14:42:22 +03:00
if (dep != libs.end() && !res.contains(*dep)) {
res.insert(*dep);
2019-04-05 16:52:53 +03:00
LibInfo scanedLib = _scanedLibs.value(dep->fullPath());
if (!scanedLib.isValid()) {
2019-04-06 14:42:22 +03:00
auto listDep = res;
2019-04-05 16:52:53 +03:00
recursiveDep(*dep, listDep);
dep->allDep = listDep;
_scanedLibs.insert(dep->fullPath(), *dep);
res.unite(listDep);
} else {
res.unite(scanedLib.allDep);
}
2019-04-04 18:11:38 +03:00
}
}
}
2019-03-19 21:50:05 +03:00
void DependenciesScanner::setEnvironment(const QStringList &env) {
2018-11-18 17:22:05 +03:00
QDir dir;
2019-12-23 21:55:15 +03:00
QSet<QString> winAPI;
2018-11-23 14:56:55 +03:00
for (auto i : env) {
2018-12-09 17:35:07 +03:00
2018-11-18 17:22:05 +03:00
dir.setPath(i);
if (!dir.exists()) {
continue;
}
2019-12-23 15:23:01 +03:00
auto list = dir.entryInfoList(QStringList() << "*.dll" << "*.DLL"
2019-03-25 21:27:26 +03:00
<< "*.SO*" << "*.so*",
2019-12-23 13:41:11 +03:00
QDir::Files | QDir::NoDotAndDotDot | QDir::Hidden);
2018-11-18 17:22:05 +03:00
2018-11-23 14:56:55 +03:00
for (auto i : list) {
2019-12-23 21:55:15 +03:00
if (i.fileName().contains(APU_MS_WIN , Qt::CaseInsensitive)) {
winAPI.insert(i.fileName().toUpper());
}
2019-04-04 18:11:38 +03:00
_EnvLibs.insertMulti(i.fileName().toUpper(), i.absoluteFilePath());
2018-11-23 14:56:55 +03:00
}
2018-11-18 17:22:05 +03:00
}
2019-12-23 21:55:15 +03:00
_peScaner.setWinApiPlugins(winAPI);
2018-11-18 17:22:05 +03:00
}
2019-04-04 18:11:38 +03:00
QSet<LibInfo> DependenciesScanner::scan(const QString &path) {
QSet<LibInfo> result;
2018-11-18 17:22:05 +03:00
2019-03-25 21:27:26 +03:00
LibInfo info;
2018-11-26 16:17:46 +03:00
2019-03-25 21:27:26 +03:00
if (!fillLibInfo(info, path)) {
2018-11-26 16:17:46 +03:00
return result;
}
2018-11-18 17:22:05 +03:00
2019-04-04 18:11:38 +03:00
recursiveDep(info, result);
2018-11-23 14:56:55 +03:00
2018-11-18 17:22:05 +03:00
return result;
2018-11-15 18:00:23 +03:00
}
2018-11-23 14:56:55 +03:00
2019-03-19 21:50:05 +03:00
DependenciesScanner::~DependenciesScanner() {
2018-11-23 14:56:55 +03:00
}