mirror of
https://github.com/QuasarApp/CQtDeployer.git
synced 2025-05-10 16:39:35 +00:00
DeployClass Refactor
This commit is contained in:
parent
fe44b9fb82
commit
7754377dfb
@ -7,7 +7,7 @@
|
||||
|
||||
#include "deploy.h"
|
||||
#include "quasarapp.h"
|
||||
#include "deployutils.h"
|
||||
#include "deploycore.h"
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
@ -23,14 +23,14 @@ int main(int argc, const char *argv[]) {
|
||||
|
||||
if (!QuasarAppUtils::Params::parseParams(argc, argv)) {
|
||||
qWarning() << "wrong parametrs";
|
||||
DeployUtils::help();
|
||||
DeployCore::help();
|
||||
exit(0);
|
||||
};
|
||||
QuasarAppUtils::Params::setEnable("noWriteInFileLog", true);
|
||||
|
||||
Deploy deploy;
|
||||
|
||||
if (!DeployUtils::parseQt(&deploy)) {
|
||||
if (!DeployCore::parseQt(&deploy)) {
|
||||
qCritical() << "error parse imput data";
|
||||
exit(1);
|
||||
}
|
||||
|
@ -45,9 +45,11 @@ include('$$PWD/../pe/pe-parser-library/pe-parser-library.pri')
|
||||
|
||||
|
||||
SOURCES += \
|
||||
copypastemanager.cpp \
|
||||
deploy.cpp \
|
||||
deploycore.cpp \
|
||||
deployedfiles.cpp \
|
||||
deployparams.cpp \
|
||||
deployutils.cpp \
|
||||
pe.cpp \
|
||||
igetlibinfo.cpp \
|
||||
dependenciesscanner.cpp \
|
||||
@ -58,10 +60,12 @@ SOURCES += \
|
||||
libinfo.cpp
|
||||
|
||||
HEADERS += \
|
||||
copypastemanager.h \
|
||||
deploy.h \
|
||||
deploy_global.h \
|
||||
deploycore.h \
|
||||
deployedfiles.h \
|
||||
deployparams.h \
|
||||
deployutils.h \
|
||||
pe.h \
|
||||
igetlibinfo.h \
|
||||
dependenciesscanner.h \
|
||||
@ -70,3 +74,5 @@ HEADERS += \
|
||||
pluginsparser.h \
|
||||
qml.h \
|
||||
libinfo.h
|
||||
|
||||
STATECHARTS +=
|
||||
|
244
Deploy/copypastemanager.cpp
Normal file
244
Deploy/copypastemanager.cpp
Normal file
@ -0,0 +1,244 @@
|
||||
#include "copypastemanager.h"
|
||||
#include <QDir>
|
||||
#include <quasarapp.h>
|
||||
#include "deploycore.h"
|
||||
#include "deployedfiles.h"
|
||||
#include <fstream>
|
||||
|
||||
CopyPasteManager::CopyPasteManager(DeployedFiles *deplyed) {
|
||||
assert(deplyed);
|
||||
_deployedFiles = deplyed;
|
||||
}
|
||||
|
||||
bool CopyPasteManager::initDir(const QString &path) {
|
||||
|
||||
if (!QFileInfo::exists(path)) {
|
||||
_deployedFiles->addToDeployed(path);
|
||||
if (!QDir().mkpath(path)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CopyPasteManager::fileActionPrivate(const QString &file, const QString &target,
|
||||
QStringList *masks, bool isMove) {
|
||||
|
||||
auto info = QFileInfo(file);
|
||||
|
||||
bool copy = !masks;
|
||||
if (masks) {
|
||||
for (auto mask : *masks) {
|
||||
if (info.absoluteFilePath().contains(mask)) {
|
||||
copy = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!copy) {
|
||||
QuasarAppUtils::Params::verboseLog(((isMove)? "skip move :": "skip copy :" + file));
|
||||
return false;
|
||||
}
|
||||
|
||||
auto name = info.fileName();
|
||||
info.setFile(target + QDir::separator() + name);
|
||||
|
||||
if (!initDir(info.absolutePath())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (QFileInfo(file).absoluteFilePath() ==
|
||||
QFileInfo(target + QDir::separator() + name).absoluteFilePath()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (QuasarAppUtils::Params::isEndable("always-overwrite") &&
|
||||
info.exists() && !removeFile( target + QDir::separator() + name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
qInfo() << ((isMove)? "move :": "copy :") << file;
|
||||
|
||||
QFile sourceFile(file);
|
||||
|
||||
if (!((isMove)?
|
||||
sourceFile.rename(target + QDir::separator() + name):
|
||||
sourceFile.copy(target + QDir::separator() + name))) {
|
||||
|
||||
QuasarAppUtils::Params::verboseLog("Qt Operation fail " + file + " >> " + target + QDir::separator() + name +
|
||||
" Qt error: " + sourceFile.errorString(),
|
||||
QuasarAppUtils::Warning);
|
||||
|
||||
std::ifstream src(file.toStdString(),
|
||||
std::ios::binary);
|
||||
std::ofstream dst((target + QDir::separator() + name).toStdString(),
|
||||
std::ios::binary);
|
||||
|
||||
dst << src.rdbuf();
|
||||
|
||||
if (!QFileInfo::exists(target + QDir::separator() + name)) {
|
||||
QuasarAppUtils::Params::verboseLog("std Operation fail file not copied. "
|
||||
"Сheck if you have access to the target dir",
|
||||
QuasarAppUtils::Error);
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
_deployedFiles->addToDeployed(target + QDir::separator() + name);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CopyPasteManager::removeFile(const QString &file) {
|
||||
return removeFile(QFileInfo (file));
|
||||
}
|
||||
|
||||
bool CopyPasteManager::smartCopyFile(const QString &file, const QString &target,
|
||||
const QString& targetDir, QStringList *mask) {
|
||||
if (file.contains(targetDir)) {
|
||||
if (!moveFile(file, target, mask)) {
|
||||
QuasarAppUtils::Params::verboseLog(" file not moved! try copy");
|
||||
|
||||
if (!copyFile(file, target, mask)) {
|
||||
qCritical() << "not copy target to bin dir " << file;
|
||||
return false;
|
||||
};
|
||||
};
|
||||
} else {
|
||||
if (!copyFile(file, target, mask)) {
|
||||
qCritical() << "not copy target to bin dir " << file;
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CopyPasteManager::moveFile(const QString &file, const QString &target, QStringList *masks) {
|
||||
return fileActionPrivate(file, target, masks, true);
|
||||
}
|
||||
|
||||
bool CopyPasteManager::copyFolder(const QString &from, const QString &to, const QStringList &filter,
|
||||
QStringList *listOfCopiedItems, QStringList *mask) {
|
||||
|
||||
QDir fromDir(from);
|
||||
|
||||
auto list = fromDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries);
|
||||
|
||||
for (auto &&item : list) {
|
||||
if (QFileInfo(item).isDir()) {
|
||||
|
||||
copyFolder(item.absoluteFilePath(), to + "/" + item.fileName(), filter, listOfCopiedItems, mask);
|
||||
} else {
|
||||
|
||||
QString skipFilter = "";
|
||||
for (auto && i: filter) {
|
||||
if (item.fileName().contains(i)) {
|
||||
skipFilter = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!skipFilter.isEmpty()) {
|
||||
QuasarAppUtils::Params::verboseLog(
|
||||
item.absoluteFilePath() + " ignored by filter " + skipFilter,
|
||||
QuasarAppUtils::VerboseLvl::Info);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!copyFile(item.absoluteFilePath(), to , mask)) {
|
||||
QuasarAppUtils::Params::verboseLog(
|
||||
"not copied file " + to + "/" + item.fileName(),
|
||||
QuasarAppUtils::VerboseLvl::Warning);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (listOfCopiedItems) {
|
||||
*listOfCopiedItems << to + "/" + item.fileName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CopyPasteManager::clear(bool force, const QString& targetDir) {
|
||||
qInfo() << "clear start!";
|
||||
|
||||
if (force) {
|
||||
qInfo() << "clear force! " << targetDir;
|
||||
|
||||
if (QDir(targetDir).removeRecursively()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QuasarAppUtils::Params::verboseLog("Remove target Dir fail, try remove old deployemend files",
|
||||
QuasarAppUtils::Warning);
|
||||
}
|
||||
|
||||
auto deployedFiles = _deployedFiles->getDeployedFiles();
|
||||
QMap<int, QFileInfo> sortedOldData;
|
||||
for (auto& i :deployedFiles) {
|
||||
sortedOldData.insertMulti(i.size(), QFileInfo(i));
|
||||
}
|
||||
|
||||
for (auto it = sortedOldData.end(); it != sortedOldData.begin(); --it) {
|
||||
|
||||
auto index = it - 1;
|
||||
|
||||
if (index.value().isFile()) {
|
||||
if (removeFile(index.value())) {
|
||||
qInfo() << "Remove " << index.value().absoluteFilePath() << " becouse it is deployed file";
|
||||
}
|
||||
|
||||
} else {
|
||||
QDir qdir(index.value().absoluteFilePath());
|
||||
if (!qdir.entryList(QDir::NoDotAndDotDot | QDir::AllEntries).count()) {
|
||||
qdir.removeRecursively();
|
||||
qInfo() << "Remove " << index.value().absoluteFilePath() << " becouse it is empty";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deployedFiles.clear();
|
||||
}
|
||||
|
||||
void CopyPasteManager::copyFiles(const QStringList &files, const QString& targetDir) {
|
||||
for (auto file : files) {
|
||||
QFileInfo target(file);
|
||||
auto targetPath = targetDir + QDir::separator() + "lib";
|
||||
if (target.completeSuffix().contains("dll", Qt::CaseInsensitive) ||
|
||||
target.completeSuffix().contains("exe", Qt::CaseInsensitive)) {
|
||||
|
||||
targetPath = targetDir;
|
||||
}
|
||||
|
||||
if (!smartCopyFile(file, targetPath, targetDir)) {
|
||||
QuasarAppUtils::Params::verboseLog(file + " not copied");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CopyPasteManager::copyFile(const QString &file, const QString &target,
|
||||
QStringList *masks) {
|
||||
|
||||
return fileActionPrivate(file, target, masks, false);
|
||||
}
|
||||
|
||||
bool CopyPasteManager::removeFile(const QFileInfo &file) {
|
||||
|
||||
if (!QFile::remove(file.absoluteFilePath())) {
|
||||
QuasarAppUtils::Params::verboseLog("Qt Operation fail (remove file) " + file.absoluteFilePath(),
|
||||
QuasarAppUtils::Warning);
|
||||
|
||||
if (remove(file.absoluteFilePath().toLatin1())) {
|
||||
QuasarAppUtils::Params::verboseLog("std Operation fail file not removed." + file.absoluteFilePath(),
|
||||
QuasarAppUtils::Error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
52
Deploy/copypastemanager.h
Normal file
52
Deploy/copypastemanager.h
Normal file
@ -0,0 +1,52 @@
|
||||
#ifndef COPYPASTEMANAGER_H
|
||||
#define COPYPASTEMANAGER_H
|
||||
#include <QFileInfo>
|
||||
#include <QStringList>
|
||||
#include <deploy_global.h>
|
||||
|
||||
|
||||
class DeployedFiles;
|
||||
|
||||
class DEPLOYSHARED_EXPORT CopyPasteManager
|
||||
{
|
||||
private:
|
||||
bool fileActionPrivate(const QString &file, const QString &target,
|
||||
QStringList *mask, bool isMove);
|
||||
|
||||
bool initDir(const QString &path);
|
||||
|
||||
DeployedFiles * _deployedFiles = nullptr;
|
||||
|
||||
public:
|
||||
CopyPasteManager(DeployedFiles * deplyed);
|
||||
|
||||
void copyFiles(const QStringList &files, const QString &targetDir);
|
||||
bool copyFile(const QString &file, const QString &target,
|
||||
QStringList *mask = nullptr);
|
||||
|
||||
bool removeFile(const QString &file);
|
||||
bool removeFile(const QFileInfo &file);
|
||||
|
||||
/**
|
||||
* @brief smartCopyFile
|
||||
* @param file
|
||||
* @param target
|
||||
* @param mask
|
||||
* @return if file in target dir try move file else copy
|
||||
*/
|
||||
bool smartCopyFile(const QString &file, const QString &target, const QString &targetDir,
|
||||
QStringList *mask = nullptr);
|
||||
|
||||
bool moveFile(const QString &file, const QString &target,
|
||||
QStringList *mask = nullptr);
|
||||
|
||||
bool copyFolder(const QString &from, const QString &to,
|
||||
const QStringList &filter = QStringList(),
|
||||
QStringList *listOfCopiedItems = nullptr,
|
||||
QStringList *mask = nullptr);
|
||||
|
||||
void clear(bool);
|
||||
|
||||
};
|
||||
|
||||
#endif // COPYPASTEMANAGER_H
|
@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "dependenciesscanner.h"
|
||||
#include "deployutils.h"
|
||||
#include "deploycore.h"
|
||||
#include "quasarapp.h"
|
||||
#include <QList>
|
||||
#include <QDir>
|
||||
@ -16,10 +16,10 @@ DependenciesScanner::DependenciesScanner() {}
|
||||
|
||||
void DependenciesScanner::clearScaned() {
|
||||
_scanedLibs.clear();
|
||||
_qtModules = DeployUtils::QtModule::NONE;
|
||||
_qtModules = DeployCore::QtModule::NONE;
|
||||
}
|
||||
|
||||
DeployUtils::QtModule DependenciesScanner::getQtModules() const
|
||||
DeployCore::QtModule DependenciesScanner::getQtModules() const
|
||||
{
|
||||
return _qtModules;
|
||||
}
|
||||
@ -56,7 +56,7 @@ QMultiMap<LibPriority, LibInfo> DependenciesScanner::getLibsFromEnvirement(
|
||||
continue;
|
||||
}
|
||||
|
||||
info.setPriority(DeployUtils::getLibPriority(info.fullPath()));
|
||||
info.setPriority(DeployCore::getLibPriority(info.fullPath()));
|
||||
|
||||
res.insertMulti(info.getPriority(), info);
|
||||
}
|
||||
@ -124,7 +124,7 @@ void DependenciesScanner::recursiveDep(LibInfo &lib, QSet<LibInfo> &res) {
|
||||
|
||||
dep->allDep = listDep;
|
||||
_scanedLibs.insert(dep->fullPath(), *dep);
|
||||
DeployUtils::addQtModule(_qtModules, dep->fullPath());
|
||||
DeployCore::addQtModule(_qtModules, dep->fullPath());
|
||||
|
||||
res.unite(listDep);
|
||||
} else {
|
||||
|
@ -27,7 +27,7 @@ class DEPLOYSHARED_EXPORT DependenciesScanner {
|
||||
|
||||
private:
|
||||
|
||||
DeployUtils::QtModule _qtModules;
|
||||
DeployCore::QtModule _qtModules;
|
||||
|
||||
QStringList _env;
|
||||
QMultiHash<QString, QString> _EnvLibs;
|
||||
@ -54,7 +54,7 @@ public:
|
||||
|
||||
friend class deploytest;
|
||||
void clearScaned();
|
||||
DeployUtils::QtModule getQtModules() const;
|
||||
DeployCore::QtModule getQtModules() const;
|
||||
};
|
||||
|
||||
#endif // WINDEPENDENCIESSCANNER_H
|
||||
|
@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "deploy.h"
|
||||
#include "deployutils.h"
|
||||
#include "deploycore.h"
|
||||
#include "pluginsparser.h"
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
@ -65,18 +65,6 @@ void Deploy::setQmake(const QString &value) {
|
||||
QuasarAppUtils::Params::verboseLog("translations = " + translationDir);
|
||||
}
|
||||
|
||||
bool Deploy::initDir(const QString &path) {
|
||||
|
||||
if (!QFileInfo::exists(path)) {
|
||||
addToDeployed(path);
|
||||
if (!QDir().mkpath(path)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Deploy::setTargetDir(const QString &target) {
|
||||
|
||||
if (target.size() && QFileInfo(target).isDir()) {
|
||||
@ -92,7 +80,7 @@ void Deploy::setTargetDir(const QString &target) {
|
||||
bool Deploy::deployMSVC() {
|
||||
qInfo () << "try deploy msvc";
|
||||
|
||||
auto msvcInstaller = DeployUtils::getVCredist(qmake);
|
||||
auto msvcInstaller = DeployCore::getVCredist(qmake);
|
||||
|
||||
if (msvcInstaller.isEmpty()) {
|
||||
return false;
|
||||
@ -120,13 +108,13 @@ bool Deploy::setTargets(const QStringList &value) {
|
||||
}
|
||||
else if (targetInfo.isDir()) {
|
||||
if (!setBinDir(i)) {
|
||||
DeployUtils::verboseLog(i + " du not contains executable binaries!");
|
||||
DeployCore::verboseLog(i + " du not contains executable binaries!");
|
||||
continue;
|
||||
}
|
||||
isfillList = true;
|
||||
|
||||
} else {
|
||||
DeployUtils::verboseLog(targetInfo.absoluteFilePath() + " not exits!");
|
||||
DeployCore::verboseLog(targetInfo.absoluteFilePath() + " not exits!");
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,10 +140,10 @@ bool Deploy::setTargetsRecursive(const QString &dir) {
|
||||
bool Deploy::setBinDir(const QString &dir, bool recursive) {
|
||||
QDir d(dir);
|
||||
if (dir.isEmpty() || !d.exists()) {
|
||||
DeployUtils::verboseLog(dir + " dir not exits!");
|
||||
DeployCore::verboseLog(dir + " dir not exits!");
|
||||
return false;
|
||||
}
|
||||
DeployUtils::verboseLog("setBinDir check path: " + dir);
|
||||
DeployCore::verboseLog("setBinDir check path: " + dir);
|
||||
QFileInfoList list;
|
||||
|
||||
if (recursive) {
|
||||
@ -310,7 +298,7 @@ void Deploy::deploy() {
|
||||
PluginsParser pluginsParser(&scaner);
|
||||
|
||||
QStringList plugins;
|
||||
pluginsParser.scan(DeployUtils::qtDir + "/plugins", plugins);
|
||||
pluginsParser.scan(DeployCore::qtDir + "/plugins", plugins);
|
||||
copyPlugins(plugins);
|
||||
|
||||
if (deployQml && !extractQml()) {
|
||||
@ -328,7 +316,7 @@ void Deploy::deploy() {
|
||||
}
|
||||
|
||||
if (!QuasarAppUtils::Params::isEndable("noTranslations")) {
|
||||
if (!copyTranslations(DeployUtils::extractTranslation(neadedLibs))) {
|
||||
if (!copyTranslations(DeployCore::extractTranslation(neadedLibs))) {
|
||||
qWarning() << " copy TR ERROR";
|
||||
}
|
||||
}
|
||||
@ -357,14 +345,14 @@ void Deploy::deploy() {
|
||||
settings.setValue(targetDir, deployedFiles);
|
||||
}
|
||||
|
||||
QString Deploy::getQtDir() const { return DeployUtils::qtDir; }
|
||||
QString Deploy::getQtDir() const { return DeployCore::qtDir; }
|
||||
|
||||
void Deploy::setQtDir(const QString &value) {
|
||||
DeployUtils::qtDir = QDir::fromNativeSeparators(value);
|
||||
addEnv(DeployUtils::qtDir);
|
||||
DeployCore::qtDir = QDir::fromNativeSeparators(value);
|
||||
addEnv(DeployCore::qtDir);
|
||||
|
||||
addEnv(DeployUtils::qtDir + "/lib");
|
||||
addEnv(DeployUtils::qtDir + "/bin");
|
||||
addEnv(DeployCore::qtDir + "/lib");
|
||||
addEnv(DeployCore::qtDir + "/bin");
|
||||
|
||||
}
|
||||
|
||||
@ -380,7 +368,7 @@ void Deploy::setExtraPath(const QStringList &value) {
|
||||
}
|
||||
|
||||
dir.setPath(info.absoluteFilePath());
|
||||
DeployUtils::extraPaths.push_back(
|
||||
DeployCore::extraPaths.push_back(
|
||||
QDir::fromNativeSeparators(info.absoluteFilePath()));
|
||||
addEnv(recursiveInvairement(0, dir));
|
||||
} else {
|
||||
@ -410,157 +398,6 @@ int Deploy::find(const QString &str, const QStringList &list) const {
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool Deploy::fileActionPrivate(const QString &file, const QString &target,
|
||||
QStringList *masks, bool isMove) {
|
||||
|
||||
auto info = QFileInfo(file);
|
||||
|
||||
bool copy = !masks;
|
||||
if (masks) {
|
||||
for (auto mask : *masks) {
|
||||
if (info.absoluteFilePath().contains(mask)) {
|
||||
copy = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!copy) {
|
||||
QuasarAppUtils::Params::verboseLog(((isMove)? "skip move :": "skip copy :" + file));
|
||||
return false;
|
||||
}
|
||||
|
||||
auto name = info.fileName();
|
||||
info.setFile(target + QDir::separator() + name);
|
||||
|
||||
if (!initDir(info.absolutePath())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (QFileInfo(file).absoluteFilePath() ==
|
||||
QFileInfo(target + QDir::separator() + name).absoluteFilePath()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (QuasarAppUtils::Params::isEndable("always-overwrite") &&
|
||||
info.exists() && !removeFile( target + QDir::separator() + name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
qInfo() << ((isMove)? "move :": "copy :") << file;
|
||||
|
||||
QFile sourceFile(file);
|
||||
|
||||
if (!((isMove)?
|
||||
sourceFile.rename(target + QDir::separator() + name):
|
||||
sourceFile.copy(target + QDir::separator() + name))) {
|
||||
|
||||
QuasarAppUtils::Params::verboseLog("Qt Operation fail " + file + " >> " + target + QDir::separator() + name +
|
||||
" Qt error: " + sourceFile.errorString(),
|
||||
QuasarAppUtils::Warning);
|
||||
|
||||
std::ifstream src(file.toStdString(),
|
||||
std::ios::binary);
|
||||
std::ofstream dst((target + QDir::separator() + name).toStdString(),
|
||||
std::ios::binary);
|
||||
|
||||
dst << src.rdbuf();
|
||||
|
||||
if (!QFileInfo::exists(target + QDir::separator() + name)) {
|
||||
QuasarAppUtils::Params::verboseLog("std Operation fail file not copied. "
|
||||
"Сheck if you have access to the target dir",
|
||||
QuasarAppUtils::Error);
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
addToDeployed(target + QDir::separator() + name);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Deploy::copyFiles(const QStringList &files) {
|
||||
for (auto file : files) {
|
||||
QFileInfo target(file);
|
||||
auto targetPath = targetDir + QDir::separator() + "lib";
|
||||
if (target.completeSuffix().contains("dll", Qt::CaseInsensitive) ||
|
||||
target.completeSuffix().contains("exe", Qt::CaseInsensitive)) {
|
||||
|
||||
targetPath = targetDir;
|
||||
}
|
||||
|
||||
if (!smartCopyFile(file, targetPath)) {
|
||||
QuasarAppUtils::Params::verboseLog(file + " not copied");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Deploy::copyFile(const QString &file, const QString &target,
|
||||
QStringList *masks) {
|
||||
|
||||
return fileActionPrivate(file, target, masks, false);
|
||||
}
|
||||
|
||||
bool Deploy::removeFile(const QFileInfo &file) {
|
||||
|
||||
if (!QFile::remove(file.absoluteFilePath())) {
|
||||
QuasarAppUtils::Params::verboseLog("Qt Operation fail (remove file) " + file.absoluteFilePath(),
|
||||
QuasarAppUtils::Warning);
|
||||
|
||||
if (remove(file.absoluteFilePath().toLatin1())) {
|
||||
QuasarAppUtils::Params::verboseLog("std Operation fail file not removed." + file.absoluteFilePath(),
|
||||
QuasarAppUtils::Error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Deploy::removeFile(const QString &file) {
|
||||
return removeFile(QFileInfo (file));
|
||||
}
|
||||
|
||||
bool Deploy::smartCopyFile(const QString &file, const QString &target, QStringList *mask) {
|
||||
if (file.contains(targetDir)) {
|
||||
if (!moveFile(file, target, mask)) {
|
||||
QuasarAppUtils::Params::verboseLog(" file not moved! try copy");
|
||||
|
||||
if (!copyFile(file, target, mask)) {
|
||||
qCritical() << "not copy target to bin dir " << file;
|
||||
return false;
|
||||
};
|
||||
};
|
||||
} else {
|
||||
if (!copyFile(file, target, mask)) {
|
||||
qCritical() << "not copy target to bin dir " << file;
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Deploy::moveFile(const QString &file, const QString &target, QStringList *masks) {
|
||||
return fileActionPrivate(file, target, masks, true);
|
||||
}
|
||||
|
||||
void Deploy::extract(const QString &file) {
|
||||
QFileInfo info(file);
|
||||
|
||||
auto sufix = info.completeSuffix();
|
||||
|
||||
if (sufix.contains("dll", Qt::CaseSensitive) ||
|
||||
sufix.contains("exe", Qt::CaseSensitive) ||
|
||||
sufix.isEmpty() || sufix.contains("so", Qt::CaseSensitive)) {
|
||||
|
||||
extractLib(file);
|
||||
} else {
|
||||
QuasarAppUtils::Params::verboseLog("file with sufix " + sufix + " not supported!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QString Deploy::recursiveInvairement(int depch, QDir &dir) {
|
||||
|
||||
char separator = ':';
|
||||
@ -650,49 +487,7 @@ bool Deploy::copyTranslations(QStringList list) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Deploy::copyFolder(const QString &from, const QString &to, const QStringList &filter,
|
||||
QStringList *listOfCopiedItems, QStringList *mask) {
|
||||
|
||||
QDir fromDir(from);
|
||||
|
||||
auto list = fromDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries);
|
||||
|
||||
for (auto &&item : list) {
|
||||
if (QFileInfo(item).isDir()) {
|
||||
|
||||
copyFolder(item.absoluteFilePath(), to + "/" + item.fileName(), filter, listOfCopiedItems, mask);
|
||||
} else {
|
||||
|
||||
QString skipFilter = "";
|
||||
for (auto && i: filter) {
|
||||
if (item.fileName().contains(i)) {
|
||||
skipFilter = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!skipFilter.isEmpty()) {
|
||||
QuasarAppUtils::Params::verboseLog(
|
||||
item.absoluteFilePath() + " ignored by filter " + skipFilter,
|
||||
QuasarAppUtils::VerboseLvl::Info);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!copyFile(item.absoluteFilePath(), to , mask)) {
|
||||
QuasarAppUtils::Params::verboseLog(
|
||||
"not copied file " + to + "/" + item.fileName(),
|
||||
QuasarAppUtils::VerboseLvl::Warning);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (listOfCopiedItems) {
|
||||
*listOfCopiedItems << to + "/" + item.fileName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QFileInfoList Deploy::findFilesInsideDir(const QString &name,
|
||||
const QString &dirpath) {
|
||||
@ -859,10 +654,10 @@ QStringList Deploy::extractImportsFromDir(const QString &filepath) {
|
||||
QProcessEnvironment env;
|
||||
|
||||
env.insert("LD_LIBRARY_PATH", concatEnv());
|
||||
env.insert("QML_IMPORT_PATH", DeployUtils::qtDir + "/qml");
|
||||
env.insert("QML2_IMPORT_PATH", DeployUtils::qtDir + "/qml");
|
||||
env.insert("QT_PLUGIN_PATH", DeployUtils::qtDir + "/plugins");
|
||||
env.insert("QT_QPA_PLATFORM_PLUGIN_PATH", DeployUtils::qtDir + "/plugins/platforms");
|
||||
env.insert("QML_IMPORT_PATH", DeployCore::qtDir + "/qml");
|
||||
env.insert("QML2_IMPORT_PATH", DeployCore::qtDir + "/qml");
|
||||
env.insert("QT_PLUGIN_PATH", DeployCore::qtDir + "/plugins");
|
||||
env.insert("QT_QPA_PLATFORM_PLUGIN_PATH", DeployCore::qtDir + "/plugins/platforms");
|
||||
|
||||
p.setProcessEnvironment(env);
|
||||
p.setProgram(externQmlScaner);
|
||||
@ -996,109 +791,20 @@ bool Deploy::extractQml() {
|
||||
}
|
||||
}
|
||||
|
||||
void Deploy::clear(bool force) {
|
||||
void Deploy::extract(const QString &file) {
|
||||
QFileInfo info(file);
|
||||
|
||||
qInfo() << "clear start!";
|
||||
auto sufix = info.completeSuffix();
|
||||
|
||||
if (force) {
|
||||
qInfo() << "clear force! " << targetDir;
|
||||
if (sufix.contains("dll", Qt::CaseSensitive) ||
|
||||
sufix.contains("exe", Qt::CaseSensitive) ||
|
||||
sufix.isEmpty() || sufix.contains("so", Qt::CaseSensitive)) {
|
||||
|
||||
if (QDir(targetDir).removeRecursively()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QuasarAppUtils::Params::verboseLog("Remove target Dir fail, try remove old deployemend files",
|
||||
QuasarAppUtils::Warning);
|
||||
}
|
||||
|
||||
deployedFiles = settings.value(targetDir, QStringList()).toStringList();
|
||||
QMap<int, QFileInfo> sortedOldData;
|
||||
for (auto& i :deployedFiles) {
|
||||
sortedOldData.insertMulti(i.size(), QFileInfo(i));
|
||||
}
|
||||
|
||||
for (auto it = sortedOldData.end(); it != sortedOldData.begin(); --it) {
|
||||
|
||||
auto index = it - 1;
|
||||
|
||||
if (index.value().isFile()) {
|
||||
if (removeFile(index.value())) {
|
||||
qInfo() << "Remove " << index.value().absoluteFilePath() << " becouse it is deployed file";
|
||||
}
|
||||
|
||||
} else {
|
||||
QDir qdir(index.value().absoluteFilePath());
|
||||
if (!qdir.entryList(QDir::NoDotAndDotDot | QDir::AllEntries).count()) {
|
||||
qdir.removeRecursively();
|
||||
qInfo() << "Remove " << index.value().absoluteFilePath() << " becouse it is empty";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deployedFiles.clear();
|
||||
|
||||
}
|
||||
|
||||
bool Deploy::strip(const QString &dir) {
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
Q_UNUSED(dir);
|
||||
return true;
|
||||
#else
|
||||
QFileInfo info(dir);
|
||||
|
||||
if (!info.exists()) {
|
||||
QuasarAppUtils::Params::verboseLog("dir not exits!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (info.isDir()) {
|
||||
QDir d(dir);
|
||||
auto list = d.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
|
||||
bool res = false;
|
||||
for (auto &&i : list) {
|
||||
res = strip(i.absoluteFilePath()) || res;
|
||||
}
|
||||
|
||||
return res;
|
||||
extractLib(file);
|
||||
} else {
|
||||
|
||||
auto sufix = info.completeSuffix();
|
||||
if (!sufix.contains("so") && !sufix.contains("dll")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QProcess P;
|
||||
P.setProgram("strip");
|
||||
P.setArguments(QStringList() << info.absoluteFilePath());
|
||||
P.start();
|
||||
|
||||
if (!P.waitForStarted())
|
||||
return false;
|
||||
if (!P.waitForFinished())
|
||||
return false;
|
||||
|
||||
return P.exitCode() == 0;
|
||||
QuasarAppUtils::Params::verboseLog("file with sufix " + sufix + " not supported!");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Deploy::addToDeployed(const QString& path) {
|
||||
auto info = QFileInfo(path);
|
||||
if (info.isFile() || !info.exists()) {
|
||||
deployedFiles += info.absoluteFilePath();
|
||||
|
||||
auto completeSufix = info.completeSuffix();
|
||||
if (info.isFile() && (completeSufix.isEmpty() || completeSufix.toLower() == "run"
|
||||
|| completeSufix.toLower() == "sh")) {
|
||||
|
||||
if (!QFile::setPermissions(path, static_cast<QFile::Permission>(0x7777))) {
|
||||
QuasarAppUtils::Params::verboseLog("permishens set fail", QuasarAppUtils::Warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Deploy::initEnvirement() {
|
||||
@ -1138,7 +844,6 @@ QStringList Deploy::getDirsRecursive(const QString &path) {
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
Deploy::Deploy() {
|
||||
#ifdef Q_OS_LINUX
|
||||
appDir = QuasarAppUtils::Params::getStrArg("appPath");
|
||||
|
@ -19,7 +19,6 @@ class DEPLOYSHARED_EXPORT Deploy {
|
||||
private:
|
||||
bool deployQml = false;
|
||||
int depchLimit = 0;
|
||||
QStringList deployedFiles;
|
||||
|
||||
QSettings settings;
|
||||
QString externQmlScaner = "";
|
||||
@ -48,27 +47,7 @@ class DEPLOYSHARED_EXPORT Deploy {
|
||||
DependenciesScanner scaner;
|
||||
|
||||
int find(const QString& str, const QStringList& list) const;
|
||||
bool fileActionPrivate(const QString &file, const QString &target,
|
||||
QStringList *mask, bool isMove);
|
||||
|
||||
void copyFiles(const QStringList &files);
|
||||
bool copyFile(const QString &file, const QString &target,
|
||||
QStringList *mask = nullptr);
|
||||
bool removeFile(const QString &file);
|
||||
bool removeFile(const QFileInfo &file);
|
||||
|
||||
/**
|
||||
* @brief smartCopyFile
|
||||
* @param file
|
||||
* @param target
|
||||
* @param mask
|
||||
* @return if file in target dir try move file else copy
|
||||
*/
|
||||
bool smartCopyFile(const QString &file, const QString &target,
|
||||
QStringList *mask = nullptr);
|
||||
|
||||
bool moveFile(const QString &file, const QString &target,
|
||||
QStringList *mask = nullptr);
|
||||
void extract(const QString &file);
|
||||
QString recursiveInvairement(int depch, QDir &dir);
|
||||
bool copyPlugin(const QString &plugin);
|
||||
@ -76,16 +55,10 @@ class DEPLOYSHARED_EXPORT Deploy {
|
||||
bool copyTranslations(QStringList list);
|
||||
|
||||
bool createQConf();
|
||||
bool copyFolder(const QString &from, const QString &to,
|
||||
const QStringList &filter = QStringList(),
|
||||
QStringList *listOfCopiedItems = nullptr,
|
||||
QStringList *mask = nullptr);
|
||||
|
||||
bool extractQml();
|
||||
|
||||
bool strip(const QString &dir);
|
||||
|
||||
bool addToDeployed(const QString& path);
|
||||
QStringList extractImportsFromDir(const QString &dirpath);
|
||||
QFileInfoList findFilesInsideDir(const QString &name, const QString &dirpath);
|
||||
bool extractQmlAll();
|
||||
@ -99,7 +72,6 @@ class DEPLOYSHARED_EXPORT Deploy {
|
||||
bool isLib(const QFileInfo &file);
|
||||
bool setBinDir(const QString& dir, bool recursive = false);
|
||||
|
||||
bool initDir(const QString &path);
|
||||
bool deployMSVC();
|
||||
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "deploy.h"
|
||||
#include "deployutils.h"
|
||||
#include "deploycore.h"
|
||||
#include "quasarapp.h"
|
||||
|
||||
#include <QDebug>
|
||||
@ -14,11 +14,11 @@
|
||||
#include <QFileInfo>
|
||||
#include <QLibraryInfo>
|
||||
|
||||
QString DeployUtils::qtDir = "";
|
||||
QStringList DeployUtils::extraPaths = QStringList();
|
||||
QString DeployCore::qtDir = "";
|
||||
QStringList DeployCore::extraPaths = QStringList();
|
||||
|
||||
|
||||
QtModuleEntry DeployUtils::qtModuleEntries[] = {
|
||||
QtModuleEntry DeployCore::qtModuleEntries[] = {
|
||||
{ QtBluetoothModule, "bluetooth", "Qt5Bluetooth", nullptr },
|
||||
{ QtConcurrentModule, "concurrent", "Qt5Concurrent", "qtbase" },
|
||||
{ QtCoreModule, "core", "Qt5Core", "qtbase" },
|
||||
@ -73,11 +73,11 @@ QtModuleEntry DeployUtils::qtModuleEntries[] = {
|
||||
{ QtWebViewModule, "webview", "Qt5WebView", nullptr }
|
||||
};
|
||||
|
||||
DeployUtils::QtModule DeployUtils::getQtModule(const QString& path) {
|
||||
auto priority = DeployUtils::getLibPriority(path);
|
||||
DeployCore::QtModule DeployCore::getQtModule(const QString& path) {
|
||||
auto priority = DeployCore::getLibPriority(path);
|
||||
|
||||
if (priority != QtLib) {
|
||||
return DeployUtils::QtModule::NONE;
|
||||
return DeployCore::QtModule::NONE;
|
||||
}
|
||||
|
||||
int modulesCount = sizeof (qtModuleEntries) / sizeof (QtModuleEntry);
|
||||
@ -86,19 +86,19 @@ DeployUtils::QtModule DeployUtils::getQtModule(const QString& path) {
|
||||
|
||||
for (int i = 0; i < modulesCount; ++i) {
|
||||
if (lIbName.contains(qtModuleEntries[i].libraryName)) {
|
||||
return static_cast<DeployUtils::QtModule>(qtModuleEntries[i].module);
|
||||
return static_cast<DeployCore::QtModule>(qtModuleEntries[i].module);
|
||||
}
|
||||
}
|
||||
|
||||
return DeployUtils::QtModule::NONE;
|
||||
return DeployCore::QtModule::NONE;
|
||||
}
|
||||
|
||||
void DeployUtils::addQtModule(DeployUtils::QtModule &module, const QString &path) {
|
||||
module = static_cast<DeployUtils::QtModule>(
|
||||
void DeployCore::addQtModule(DeployCore::QtModule &module, const QString &path) {
|
||||
module = static_cast<DeployCore::QtModule>(
|
||||
static_cast<quint64>(module) | static_cast<quint64>(getQtModule(path)));
|
||||
}
|
||||
|
||||
LibPriority DeployUtils::getLibPriority(const QString &lib) {
|
||||
LibPriority DeployCore::getLibPriority(const QString &lib) {
|
||||
|
||||
if (!QFileInfo(lib).isFile()) {
|
||||
return NotFile;
|
||||
@ -115,14 +115,14 @@ LibPriority DeployUtils::getLibPriority(const QString &lib) {
|
||||
return SystemLib;
|
||||
}
|
||||
|
||||
void DeployUtils::verboseLog(const QString &str) {
|
||||
void DeployCore::verboseLog(const QString &str) {
|
||||
if (QuasarAppUtils::Params::isEndable("verbose")) {
|
||||
qDebug() << str;
|
||||
}
|
||||
}
|
||||
|
||||
#define C(X) QuasarAppUtils::Params::isEndable(X)
|
||||
RunMode DeployUtils::getMode() {
|
||||
RunMode DeployCore::getMode() {
|
||||
if (C("help") || C("h") || C("v") || C("version")) {
|
||||
return RunMode::Info;
|
||||
}
|
||||
@ -138,7 +138,7 @@ RunMode DeployUtils::getMode() {
|
||||
return RunMode::Info;
|
||||
}
|
||||
|
||||
void DeployUtils::help() {
|
||||
void DeployCore::help() {
|
||||
|
||||
QStringList help = {
|
||||
{ "CQtDeployer version: " + getAppVersion()},
|
||||
@ -187,7 +187,7 @@ void DeployUtils::help() {
|
||||
|
||||
}
|
||||
|
||||
bool DeployUtils::parseQtClearMode(Deploy *deploy) {
|
||||
bool DeployCore::parseQtClearMode(Deploy *deploy) {
|
||||
deploy->setTargetDir("./");
|
||||
deploy->clear(QuasarAppUtils::Params::isEndable("force-clear"));
|
||||
|
||||
@ -195,20 +195,20 @@ bool DeployUtils::parseQtClearMode(Deploy *deploy) {
|
||||
|
||||
}
|
||||
|
||||
bool DeployUtils::parseQtInfoMode() {
|
||||
bool DeployCore::parseQtInfoMode() {
|
||||
|
||||
if ((QuasarAppUtils::Params::isEndable("v") ||
|
||||
QuasarAppUtils::Params::isEndable("version"))) {
|
||||
DeployUtils::printVersion();
|
||||
DeployCore::printVersion();
|
||||
return true;
|
||||
}
|
||||
|
||||
DeployUtils::help();
|
||||
DeployCore::help();
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool DeployUtils::parseQtDeployMode(Deploy *deploy) {
|
||||
bool DeployCore::parseQtDeployMode(Deploy *deploy) {
|
||||
auto bin = QuasarAppUtils::Params::getStrArg("bin").split(',');
|
||||
|
||||
if (!deploy->setTargets(bin)) {
|
||||
@ -301,7 +301,7 @@ bool DeployUtils::parseQtDeployMode(Deploy *deploy) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeployUtils::parseQt(Deploy *deploy) {
|
||||
bool DeployCore::parseQt(Deploy *deploy) {
|
||||
switch (getMode()) {
|
||||
case RunMode::Info: {
|
||||
qInfo() << "selected info mode" ;
|
||||
@ -343,7 +343,7 @@ bool DeployUtils::parseQt(Deploy *deploy) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QStringList DeployUtils::extractTranslation(const QStringList &libs) {
|
||||
QStringList DeployCore::extractTranslation(const QStringList &libs) {
|
||||
QSet<QString> res;
|
||||
const size_t qtModulesCount = sizeof(qtModuleEntries) / sizeof(QtModuleEntry);
|
||||
|
||||
@ -358,11 +358,11 @@ QStringList DeployUtils::extractTranslation(const QStringList &libs) {
|
||||
return res.toList();
|
||||
}
|
||||
|
||||
QString DeployUtils::getAppVersion() {
|
||||
QString DeployCore::getAppVersion() {
|
||||
return APP_VERSION;
|
||||
}
|
||||
|
||||
QString DeployUtils::getQtVersion() {
|
||||
QString DeployCore::getQtVersion() {
|
||||
#ifdef QT_VERSION_STR
|
||||
return QT_VERSION_STR;
|
||||
#else
|
||||
@ -370,12 +370,12 @@ QString DeployUtils::getQtVersion() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void DeployUtils::printVersion() {
|
||||
void DeployCore::printVersion() {
|
||||
qInfo() << "CQtDeployer: " + getAppVersion();
|
||||
qInfo() << "Qt: " + getQtVersion();
|
||||
}
|
||||
|
||||
MSVCVersion DeployUtils::getMSVC(const QString &_qmake) {
|
||||
MSVCVersion DeployCore::getMSVC(const QString &_qmake) {
|
||||
QFileInfo qmake(_qmake);
|
||||
|
||||
int res = MSVCVersion::MSVC_Unknown;
|
||||
@ -431,7 +431,7 @@ MSVCVersion DeployUtils::getMSVC(const QString &_qmake) {
|
||||
return static_cast<MSVCVersion>(res);
|
||||
}
|
||||
|
||||
QString DeployUtils::getVCredist(const QString &_qmake) {
|
||||
QString DeployCore::getVCredist(const QString &_qmake) {
|
||||
auto msvc = getMSVC(_qmake);
|
||||
|
||||
QFileInfo qmake(_qmake);
|
||||
@ -458,7 +458,7 @@ QString DeployUtils::getVCredist(const QString &_qmake) {
|
||||
return "";
|
||||
}
|
||||
|
||||
QString DeployUtils::getMSVCName(MSVCVersion msvc) {
|
||||
QString DeployCore::getMSVCName(MSVCVersion msvc) {
|
||||
if (msvc | MSVCVersion::MSVC_13) {
|
||||
return "msvc2013";
|
||||
} else if (msvc | MSVCVersion::MSVC_15) {
|
||||
@ -472,7 +472,7 @@ QString DeployUtils::getMSVCName(MSVCVersion msvc) {
|
||||
return "";
|
||||
}
|
||||
|
||||
QString DeployUtils::getMSVCVersion(MSVCVersion msvc) {
|
||||
QString DeployCore::getMSVCVersion(MSVCVersion msvc) {
|
||||
if (msvc | MSVCVersion::MSVC_x32) {
|
||||
return "x86";
|
||||
} else if (msvc | MSVCVersion::MSVC_x64) {
|
||||
@ -482,13 +482,13 @@ QString DeployUtils::getMSVCVersion(MSVCVersion msvc) {
|
||||
return "";
|
||||
}
|
||||
|
||||
bool DeployUtils::isQtLib(const QString &lib) {
|
||||
bool DeployCore::isQtLib(const QString &lib) {
|
||||
QFileInfo info(lib);
|
||||
return !qtDir.isEmpty() && info.absoluteFilePath().contains(qtDir);
|
||||
|
||||
}
|
||||
|
||||
bool DeployUtils::isExtraLib(const QString &lib) {
|
||||
bool DeployCore::isExtraLib(const QString &lib) {
|
||||
QFileInfo info(lib);
|
||||
|
||||
for (auto i : extraPaths) {
|
@ -53,7 +53,7 @@ enum class RunMode: int {
|
||||
|
||||
class Deploy;
|
||||
|
||||
class DEPLOYSHARED_EXPORT DeployUtils
|
||||
class DEPLOYSHARED_EXPORT DeployCore
|
||||
{
|
||||
|
||||
private:
|
||||
@ -121,7 +121,7 @@ public:
|
||||
Qt3DExtrasModule = 0x0008000000000000
|
||||
};
|
||||
|
||||
DeployUtils() = delete;
|
||||
DeployCore() = delete;
|
||||
|
||||
static QString qtDir;
|
||||
static QStringList extraPaths;
|
||||
@ -133,8 +133,8 @@ public:
|
||||
static bool isQtLib(const QString &lib);
|
||||
static bool isExtraLib(const QString &lib);
|
||||
static LibPriority getLibPriority(const QString &lib);
|
||||
static DeployUtils::QtModule getQtModule(const QString& path);
|
||||
static void addQtModule(DeployUtils::QtModule& module, const QString& path);
|
||||
static DeployCore::QtModule getQtModule(const QString& path);
|
||||
static void addQtModule(DeployCore::QtModule& module, const QString& path);
|
||||
|
||||
static void verboseLog(const QString &str);
|
||||
static RunMode getMode();
|
133
Deploy/deployedfiles.cpp
Normal file
133
Deploy/deployedfiles.cpp
Normal file
@ -0,0 +1,133 @@
|
||||
#include "deployedfiles.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QProcess>
|
||||
#include <quasarapp.h>
|
||||
#include <QDebug>
|
||||
|
||||
QSet<QString> DeployedFiles::getDeployedFiles() const {
|
||||
return deployedFiles;
|
||||
}
|
||||
|
||||
void DeployedFiles::setDeployedFiles(const QSet<QString> &value) {
|
||||
deployedFiles = value;
|
||||
}
|
||||
|
||||
QStringList DeployedFiles::getDeployedFilesStringList() const {
|
||||
return deployedFiles.toList();
|
||||
}
|
||||
|
||||
void DeployedFiles::setDeployedFiles(const QStringList &value) {
|
||||
deployedFiles.clear();
|
||||
deployedFiles.fromList(value);
|
||||
}
|
||||
|
||||
DeployedFiles::DeployedFiles(const QStringList& from) {
|
||||
setDeployedFiles(from);
|
||||
}
|
||||
|
||||
bool DeployedFiles::addToDeployed(const QString& path) {
|
||||
auto info = QFileInfo(path);
|
||||
if (info.isFile() || !info.exists()) {
|
||||
deployedFiles += info.absoluteFilePath();
|
||||
|
||||
auto completeSufix = info.completeSuffix();
|
||||
if (info.isFile() && (completeSufix.isEmpty() || completeSufix.toLower() == "run"
|
||||
|| completeSufix.toLower() == "sh")) {
|
||||
|
||||
if (!QFile::setPermissions(path, static_cast<QFile::Permission>(0x7777))) {
|
||||
QuasarAppUtils::Params::verboseLog("permishens set fail", QuasarAppUtils::Warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeployedFiles::strip(const QString &dir) {
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
Q_UNUSED(dir);
|
||||
return true;
|
||||
#else
|
||||
QFileInfo info(dir);
|
||||
|
||||
if (!info.exists()) {
|
||||
QuasarAppUtils::Params::verboseLog("dir not exits!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (info.isDir()) {
|
||||
QDir d(dir);
|
||||
auto list = d.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
|
||||
bool res = false;
|
||||
for (auto &&i : list) {
|
||||
res = strip(i.absoluteFilePath()) || res;
|
||||
}
|
||||
|
||||
return res;
|
||||
} else {
|
||||
|
||||
auto sufix = info.completeSuffix();
|
||||
if (!sufix.contains("so") && !sufix.contains("dll")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QProcess P;
|
||||
P.setProgram("strip");
|
||||
P.setArguments(QStringList() << info.absoluteFilePath());
|
||||
P.start();
|
||||
|
||||
if (!P.waitForStarted())
|
||||
return false;
|
||||
if (!P.waitForFinished())
|
||||
return false;
|
||||
|
||||
return P.exitCode() == 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void DeployedFiles::clear(bool force, const QString& targetDir) {
|
||||
|
||||
qInfo() << "clear start!";
|
||||
|
||||
if (force) {
|
||||
qInfo() << "clear force! " << targetDir;
|
||||
|
||||
if (QDir(targetDir).removeRecursively()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QuasarAppUtils::Params::verboseLog("Remove target Dir fail, try remove old deployemend files",
|
||||
QuasarAppUtils::Warning);
|
||||
}
|
||||
|
||||
QMap<int, QFileInfo> sortedOldData;
|
||||
for (auto& i :deployedFiles) {
|
||||
sortedOldData.insertMulti(i.size(), QFileInfo(i));
|
||||
}
|
||||
|
||||
for (auto it = sortedOldData.end(); it != sortedOldData.begin(); --it) {
|
||||
|
||||
auto index = it - 1;
|
||||
|
||||
if (index.value().isFile()) {
|
||||
if (removeFile(index.value())) {
|
||||
qInfo() << "Remove " << index.value().absoluteFilePath() << " becouse it is deployed file";
|
||||
}
|
||||
|
||||
} else {
|
||||
QDir qdir(index.value().absoluteFilePath());
|
||||
if (!qdir.entryList(QDir::NoDotAndDotDot | QDir::AllEntries).count()) {
|
||||
qdir.removeRecursively();
|
||||
qInfo() << "Remove " << index.value().absoluteFilePath() << " becouse it is empty";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deployedFiles.clear();
|
||||
|
||||
}
|
24
Deploy/deployedfiles.h
Normal file
24
Deploy/deployedfiles.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef DEPLOYEDFILES_H
|
||||
#define DEPLOYEDFILES_H
|
||||
#include <QSet>
|
||||
#include <QStringList>
|
||||
#include <deploy_global.h>
|
||||
|
||||
class DEPLOYSHARED_EXPORT DeployedFiles
|
||||
{
|
||||
private:
|
||||
QSet<QString> deployedFiles;
|
||||
|
||||
public:
|
||||
DeployedFiles(const QStringList& from);
|
||||
bool addToDeployed(const QString& path);
|
||||
bool strip(const QString &dir);
|
||||
|
||||
QSet<QString> getDeployedFiles() const;
|
||||
void setDeployedFiles(const QSet<QString> &value);
|
||||
|
||||
QStringList getDeployedFilesStringList() const;
|
||||
void setDeployedFiles(const QStringList &value);
|
||||
};
|
||||
|
||||
#endif // DEPLOYEDFILES_H
|
@ -1,7 +1,7 @@
|
||||
#ifndef IGETLIBINFO_H
|
||||
#define IGETLIBINFO_H
|
||||
|
||||
#include "deployutils.h"
|
||||
#include "deploycore.h"
|
||||
#include "libinfo.h"
|
||||
|
||||
class IGetLibInfo
|
||||
|
@ -1,6 +1,6 @@
|
||||
#ifndef LIBINFO_H
|
||||
#define LIBINFO_H
|
||||
#include "deployutils.h"
|
||||
#include "deploycore.h"
|
||||
|
||||
|
||||
class DEPLOYSHARED_EXPORT LibInfo {
|
||||
|
@ -11,39 +11,39 @@ PluginsParser::PluginsParser(DependenciesScanner* scaner)
|
||||
|
||||
static const PluginModuleMapping pluginModuleMappings[] =
|
||||
{
|
||||
{"qml1tooling", DeployUtils::QtModule::QtDeclarativeModule},
|
||||
{"gamepads", DeployUtils::QtModule::QtGamePadModule},
|
||||
{"accessible", DeployUtils::QtModule::QtGuiModule},
|
||||
{"iconengines", DeployUtils::QtModule::QtGuiModule},
|
||||
{"imageformats", DeployUtils::QtModule::QtGuiModule},
|
||||
{"platforms", DeployUtils::QtModule::QtGuiModule},
|
||||
{"platforminputcontexts", DeployUtils::QtModule::QtGuiModule},
|
||||
{"virtualkeyboard", DeployUtils::QtModule::QtGuiModule},
|
||||
{"geoservices", DeployUtils::QtModule::QtLocationModule},
|
||||
{"audio", DeployUtils::QtModule::QtMultimediaModule},
|
||||
{"mediaservice", DeployUtils::QtModule::QtMultimediaModule},
|
||||
{"playlistformats", DeployUtils::QtModule::QtMultimediaModule},
|
||||
{"bearer", DeployUtils::QtModule::QtNetworkModule},
|
||||
{"position", DeployUtils::QtModule::QtPositioningModule},
|
||||
{"printsupport", DeployUtils::QtModule::QtPrintSupportModule},
|
||||
{"scenegraph", DeployUtils::QtModule::QtQuickModule},
|
||||
{"qmltooling", DeployUtils::QtModule::QtQuickModule | DeployUtils::QtModule::QtQmlToolingModule},
|
||||
{"sensors", DeployUtils::QtModule::QtSensorsModule},
|
||||
{"sensorgestures", DeployUtils::QtModule::QtSensorsModule},
|
||||
{"canbus", DeployUtils::QtModule::QtSerialBusModule},
|
||||
{"sqldrivers", DeployUtils::QtModule::QtSqlModule},
|
||||
{"texttospeech", DeployUtils::QtModule::QtTextToSpeechModule},
|
||||
{"qtwebengine", DeployUtils::QtModule::QtWebEngineModule | DeployUtils::QtModule::QtWebEngineCoreModule | DeployUtils::QtModule::QtWebEngineWidgetsModule},
|
||||
{"styles", DeployUtils::QtModule::QtWidgetsModule},
|
||||
{"sceneparsers", DeployUtils::QtModule::Qt3DRendererModule},
|
||||
{"renderplugins", DeployUtils::QtModule::Qt3DRendererModule},
|
||||
{"geometryloaders", DeployUtils::QtModule::Qt3DRendererModule},
|
||||
{"webview", DeployUtils::QtModule::QtWebViewModule},
|
||||
{"xcbglintegrations", DeployUtils::QtModule::QtGuiModule},
|
||||
{"wayland-decoration-client", DeployUtils::QtModule::QtGuiModule},
|
||||
{"wayland-graphics-integration-client", DeployUtils::QtModule::QtGuiModule},
|
||||
{"wayland-graphics-integration-server", DeployUtils::QtModule::QtGuiModule},
|
||||
{"wayland-shell-integration", DeployUtils::QtModule::QtGuiModule},
|
||||
{"qml1tooling", DeployCore::QtModule::QtDeclarativeModule},
|
||||
{"gamepads", DeployCore::QtModule::QtGamePadModule},
|
||||
{"accessible", DeployCore::QtModule::QtGuiModule},
|
||||
{"iconengines", DeployCore::QtModule::QtGuiModule},
|
||||
{"imageformats", DeployCore::QtModule::QtGuiModule},
|
||||
{"platforms", DeployCore::QtModule::QtGuiModule},
|
||||
{"platforminputcontexts", DeployCore::QtModule::QtGuiModule},
|
||||
{"virtualkeyboard", DeployCore::QtModule::QtGuiModule},
|
||||
{"geoservices", DeployCore::QtModule::QtLocationModule},
|
||||
{"audio", DeployCore::QtModule::QtMultimediaModule},
|
||||
{"mediaservice", DeployCore::QtModule::QtMultimediaModule},
|
||||
{"playlistformats", DeployCore::QtModule::QtMultimediaModule},
|
||||
{"bearer", DeployCore::QtModule::QtNetworkModule},
|
||||
{"position", DeployCore::QtModule::QtPositioningModule},
|
||||
{"printsupport", DeployCore::QtModule::QtPrintSupportModule},
|
||||
{"scenegraph", DeployCore::QtModule::QtQuickModule},
|
||||
{"qmltooling", DeployCore::QtModule::QtQuickModule | DeployCore::QtModule::QtQmlToolingModule},
|
||||
{"sensors", DeployCore::QtModule::QtSensorsModule},
|
||||
{"sensorgestures", DeployCore::QtModule::QtSensorsModule},
|
||||
{"canbus", DeployCore::QtModule::QtSerialBusModule},
|
||||
{"sqldrivers", DeployCore::QtModule::QtSqlModule},
|
||||
{"texttospeech", DeployCore::QtModule::QtTextToSpeechModule},
|
||||
{"qtwebengine", DeployCore::QtModule::QtWebEngineModule | DeployCore::QtModule::QtWebEngineCoreModule | DeployCore::QtModule::QtWebEngineWidgetsModule},
|
||||
{"styles", DeployCore::QtModule::QtWidgetsModule},
|
||||
{"sceneparsers", DeployCore::QtModule::Qt3DRendererModule},
|
||||
{"renderplugins", DeployCore::QtModule::Qt3DRendererModule},
|
||||
{"geometryloaders", DeployCore::QtModule::Qt3DRendererModule},
|
||||
{"webview", DeployCore::QtModule::QtWebViewModule},
|
||||
{"xcbglintegrations", DeployCore::QtModule::QtGuiModule},
|
||||
{"wayland-decoration-client", DeployCore::QtModule::QtGuiModule},
|
||||
{"wayland-graphics-integration-client", DeployCore::QtModule::QtGuiModule},
|
||||
{"wayland-graphics-integration-server", DeployCore::QtModule::QtGuiModule},
|
||||
{"wayland-shell-integration", DeployCore::QtModule::QtGuiModule},
|
||||
|
||||
|
||||
};
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include <QtTest>
|
||||
#include <quasarapp.h>
|
||||
#include <deployutils.h>
|
||||
#include <deploycore.h>
|
||||
#include <deploy.h>
|
||||
#include <dependenciesscanner.h>
|
||||
#include <qml.h>
|
||||
@ -303,32 +303,32 @@ void deploytest::testDeployUtils() {
|
||||
QString qtDir = "./test/Qt/5.12/";
|
||||
QStringList extraPathes = QStringList() << QFileInfo("./test/extraPath/").absoluteFilePath();
|
||||
|
||||
DeployUtils::qtDir = QFileInfo(qtDir).absoluteFilePath();
|
||||
DeployUtils::extraPaths = extraPathes;
|
||||
DeployCore::qtDir = QFileInfo(qtDir).absoluteFilePath();
|
||||
DeployCore::extraPaths = extraPathes;
|
||||
|
||||
// qt Dir
|
||||
QVERIFY(DeployUtils::isQtLib("./test/Qt/5.12/myLib.so"));
|
||||
QVERIFY(!DeployUtils::isQtLib("/myQtDur/Qt/5.11/myLib.so"));
|
||||
QVERIFY(!DeployUtils::isQtLib("/mQtDur/Qt/5.12/myLib.so"));
|
||||
QVERIFY(DeployUtils::isQtLib("./test/Qt/5.12/myLib/testlibs/mylib.so"));
|
||||
QVERIFY(DeployCore::isQtLib("./test/Qt/5.12/myLib.so"));
|
||||
QVERIFY(!DeployCore::isQtLib("/myQtDur/Qt/5.11/myLib.so"));
|
||||
QVERIFY(!DeployCore::isQtLib("/mQtDur/Qt/5.12/myLib.so"));
|
||||
QVERIFY(DeployCore::isQtLib("./test/Qt/5.12/myLib/testlibs/mylib.so"));
|
||||
|
||||
// extra Dir
|
||||
QVERIFY(!DeployUtils::isExtraLib("./test/Qt/5.12/myLib.so"));
|
||||
QVERIFY(!DeployUtils::isExtraLib("/myQtDur/Qt/5.11/myLib.so"));
|
||||
QVERIFY(!DeployUtils::isExtraLib("/mQtDur/Qt/5.12/myLib.so"));
|
||||
QVERIFY(!DeployUtils::isExtraLib("./test/Qt/5.12/myLib/testlibs/mylib.so"));
|
||||
QVERIFY(!DeployCore::isExtraLib("./test/Qt/5.12/myLib.so"));
|
||||
QVERIFY(!DeployCore::isExtraLib("/myQtDur/Qt/5.11/myLib.so"));
|
||||
QVERIFY(!DeployCore::isExtraLib("/mQtDur/Qt/5.12/myLib.so"));
|
||||
QVERIFY(!DeployCore::isExtraLib("./test/Qt/5.12/myLib/testlibs/mylib.so"));
|
||||
|
||||
QVERIFY(DeployUtils::isExtraLib("./test/extraPath/Qt/5.12/myLib.so"));
|
||||
QVERIFY(DeployUtils::isExtraLib("./test/extraPath/Qt/5/myLib.so"));
|
||||
QVERIFY(DeployUtils::isExtraLib("./test/extraPath/myLib.so"));
|
||||
QVERIFY(DeployUtils::isExtraLib("./test/extraPath/Qt/5.12/myLib/testlibs/mylib.so"));
|
||||
QVERIFY(DeployCore::isExtraLib("./test/extraPath/Qt/5.12/myLib.so"));
|
||||
QVERIFY(DeployCore::isExtraLib("./test/extraPath/Qt/5/myLib.so"));
|
||||
QVERIFY(DeployCore::isExtraLib("./test/extraPath/myLib.so"));
|
||||
QVERIFY(DeployCore::isExtraLib("./test/extraPath/Qt/5.12/myLib/testlibs/mylib.so"));
|
||||
|
||||
//getLibPriority
|
||||
|
||||
QVERIFY(DeployUtils::getLibPriority("./tst/Qt/5.12/generalLib.so") == NotFile);
|
||||
QVERIFY(DeployUtils::getLibPriority("./test/Qt/5.12/generalLib.so") == QtLib);
|
||||
QVERIFY(DeployUtils::getLibPriority("./test/extraPath/ExtraLib.so") == ExtraLib);
|
||||
QVERIFY(DeployUtils::getLibPriority("./test/extra/ExtraLib.so") == SystemLib);
|
||||
QVERIFY(DeployCore::getLibPriority("./tst/Qt/5.12/generalLib.so") == NotFile);
|
||||
QVERIFY(DeployCore::getLibPriority("./test/Qt/5.12/generalLib.so") == QtLib);
|
||||
QVERIFY(DeployCore::getLibPriority("./test/extraPath/ExtraLib.so") == ExtraLib);
|
||||
QVERIFY(DeployCore::getLibPriority("./test/extra/ExtraLib.so") == SystemLib);
|
||||
}
|
||||
|
||||
void deploytest::testDeployTarget() {
|
||||
@ -578,7 +578,7 @@ void deploytest::testMSVC() {
|
||||
file.close();
|
||||
|
||||
|
||||
auto msvc = DeployUtils::getMSVC(testqmakepath);
|
||||
auto msvc = DeployCore::getMSVC(testqmakepath);
|
||||
|
||||
QVERIFY(msvc & MSVCVersion::MSVC_17);
|
||||
QVERIFY(msvc & MSVCVersion::MSVC_x64);
|
||||
@ -858,7 +858,7 @@ void deploytest::testTranslations() {
|
||||
|
||||
};
|
||||
|
||||
DeployUtils::qtDir = QFileInfo("./test/QtDir/").absoluteFilePath();
|
||||
DeployCore::qtDir = QFileInfo("./test/QtDir/").absoluteFilePath();
|
||||
|
||||
|
||||
Deploy *deploy = new Deploy();
|
||||
@ -874,7 +874,7 @@ void deploytest::testTranslations() {
|
||||
deploy->translationDir = QFileInfo("./test/QtDir/translations/").absoluteFilePath();
|
||||
deploy->targetDir = QFileInfo("./test/deploy/").absoluteFilePath();
|
||||
|
||||
auto trans = DeployUtils::extractTranslation(libList);
|
||||
auto trans = DeployCore::extractTranslation(libList);
|
||||
QVERIFY(trans.size() == 2);
|
||||
QVERIFY(deploy->copyTranslations(trans));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user