2018-08-19 11:00:13 +03:00
|
|
|
/*
|
2019-01-26 07:54:56 +03:00
|
|
|
* Copyright (C) 2018-2019 QuasarApp.
|
2018-08-19 11:00:13 +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.
|
2018-10-24 17:26:42 +03:00
|
|
|
*/
|
2018-08-19 11:00:13 +03:00
|
|
|
|
2018-08-17 20:47:49 +03:00
|
|
|
#include "deploy.h"
|
2019-09-03 18:15:05 +03:00
|
|
|
#include "deploycore.h"
|
2019-08-31 22:55:02 +03:00
|
|
|
#include "pluginsparser.h"
|
2019-01-16 22:17:49 +03:00
|
|
|
#include <QCoreApplication>
|
2018-08-17 20:47:49 +03:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QDir>
|
2018-08-23 21:28:47 +03:00
|
|
|
#include <QDirIterator>
|
2018-10-24 17:26:42 +03:00
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
2018-08-23 21:28:47 +03:00
|
|
|
#include <QJsonArray>
|
2018-10-24 17:26:42 +03:00
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QProcess>
|
2018-12-15 20:51:25 +03:00
|
|
|
#include <QRegularExpression>
|
2018-10-24 17:26:42 +03:00
|
|
|
#include <quasarapp.h>
|
2019-08-24 01:04:36 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2018-08-17 20:47:49 +03:00
|
|
|
|
2019-05-16 19:02:52 +03:00
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
|
2018-10-24 17:26:42 +03:00
|
|
|
bool Deploy::getDeployQml() const { return deployQml; }
|
2018-08-17 20:47:49 +03:00
|
|
|
|
2018-10-24 17:26:42 +03:00
|
|
|
void Deploy::setDeployQml(bool value) { deployQml = value; }
|
2018-08-17 20:47:49 +03:00
|
|
|
|
2019-03-28 19:23:22 +03:00
|
|
|
QString Deploy::getQmlScaner() const { return externQmlScaner; }
|
2018-08-17 20:47:49 +03:00
|
|
|
|
2018-10-24 17:26:42 +03:00
|
|
|
QString Deploy::getQmake() const { return qmake; }
|
2018-08-17 20:47:49 +03:00
|
|
|
|
2019-09-04 12:01:33 +03:00
|
|
|
void Deploy::clear(bool force) {
|
|
|
|
_fileManager.clear(targetDir, force);
|
2018-08-17 20:47:49 +03:00
|
|
|
}
|
|
|
|
|
2019-03-28 12:36:21 +03:00
|
|
|
bool Deploy::deployMSVC() {
|
|
|
|
qInfo () << "try deploy msvc";
|
|
|
|
|
2019-09-03 18:15:05 +03:00
|
|
|
auto msvcInstaller = DeployCore::getVCredist(qmake);
|
2019-03-28 12:36:21 +03:00
|
|
|
|
|
|
|
if (msvcInstaller.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-09-04 12:01:33 +03:00
|
|
|
return _fileManager.copyFile(msvcInstaller, targetDir);
|
2019-03-28 12:36:21 +03:00
|
|
|
}
|
|
|
|
|
2018-12-15 20:51:25 +03:00
|
|
|
bool Deploy::createRunScript(const QString &target) {
|
2018-08-19 11:00:13 +03:00
|
|
|
|
|
|
|
QString content =
|
2019-01-26 22:27:36 +03:00
|
|
|
"#!/bin/sh\n"
|
|
|
|
"BASE_DIR=$(dirname \"$(readlink -f \"$0\")\")\n"
|
|
|
|
"export "
|
|
|
|
"LD_LIBRARY_PATH=\"$BASE_DIR\"/lib:\"$BASE_DIR\":$LD_LIBRARY_PATH\n"
|
|
|
|
"export QML_IMPORT_PATH=\"$BASE_DIR\"/qml:QML_IMPORT_PATH\n"
|
|
|
|
"export QML2_IMPORT_PATH=\"$BASE_DIR\"/qml:QML2_IMPORT_PATH\n"
|
|
|
|
"export QT_PLUGIN_PATH=\"$BASE_DIR\"/plugins:QT_PLUGIN_PATH\n"
|
2019-01-27 15:37:19 +03:00
|
|
|
"export QTDIR=\"$BASE_DIR\"\n"
|
2019-01-26 22:27:36 +03:00
|
|
|
"export "
|
|
|
|
"QT_QPA_PLATFORM_PLUGIN_PATH=\"$BASE_DIR\"/plugins/"
|
|
|
|
"platforms:QT_QPA_PLATFORM_PLUGIN_PATH\n"
|
2019-05-22 18:03:54 +03:00
|
|
|
"%2"
|
2019-01-26 22:27:36 +03:00
|
|
|
"\"$BASE_DIR\"/bin/%1 \"$@\"";
|
2018-08-19 11:00:13 +03:00
|
|
|
|
|
|
|
content = content.arg(QFileInfo(target).fileName());
|
2019-09-04 12:01:33 +03:00
|
|
|
int ld_index = find("ld-linux", _fileManager.getDeployedFilesStringList());
|
2019-05-23 18:31:51 +03:00
|
|
|
|
|
|
|
if (ld_index >= 0 && QuasarAppUtils::Params::isEndable("deploySystem") &&
|
|
|
|
!QuasarAppUtils::Params::isEndable("noLibc")) {
|
|
|
|
|
2019-05-23 21:40:16 +03:00
|
|
|
content = content.arg(QString("\nexport LD_PRELOAD=\"$BASE_DIR\"/lib/%0\n").
|
2019-09-04 12:01:33 +03:00
|
|
|
arg(QFileInfo(_fileManager.getDeployedFilesStringList()[ld_index]).fileName()));
|
2019-05-23 21:40:16 +03:00
|
|
|
} else {
|
|
|
|
content = content.arg("");
|
2019-05-22 18:03:54 +03:00
|
|
|
}
|
|
|
|
|
2019-05-23 21:40:16 +03:00
|
|
|
|
2018-12-15 20:51:25 +03:00
|
|
|
QString fname = targetDir + QDir::separator() + QFileInfo(target).baseName()+ ".sh";
|
2018-08-19 11:00:13 +03:00
|
|
|
|
|
|
|
QFile F(fname);
|
|
|
|
if (!F.open(QIODevice::WriteOnly)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
F.write(content.toUtf8());
|
|
|
|
F.flush();
|
|
|
|
F.close();
|
|
|
|
|
2019-09-04 12:01:33 +03:00
|
|
|
_fileManager.addToDeployed(fname);
|
2018-12-14 22:48:33 +03:00
|
|
|
|
2018-10-24 17:26:42 +03:00
|
|
|
return F.setPermissions(QFileDevice::ExeOther | QFileDevice::WriteOther |
|
|
|
|
QFileDevice::ReadOther | QFileDevice::ExeUser |
|
|
|
|
QFileDevice::WriteUser | QFileDevice::ReadUser |
|
|
|
|
QFileDevice::ExeOwner | QFileDevice::WriteOwner |
|
2018-09-08 12:28:35 +03:00
|
|
|
QFileDevice::ReadOwner);
|
2018-08-19 11:00:13 +03:00
|
|
|
}
|
|
|
|
|
2019-06-19 22:48:19 +03:00
|
|
|
bool Deploy::createQConf() {
|
2018-12-15 20:51:25 +03:00
|
|
|
|
2019-06-19 22:48:19 +03:00
|
|
|
QString content =
|
|
|
|
"[Paths]\n"
|
|
|
|
"Prefix= ./\n"
|
|
|
|
"Libraries= ./\n"
|
|
|
|
"Plugins= ./plugins\n"
|
|
|
|
"Imports= ./qml\n"
|
|
|
|
"Qml2Imports= ./qml\n";
|
|
|
|
|
|
|
|
|
|
|
|
QString fname = targetDir + QDir::separator() + "qt.conf";
|
|
|
|
|
|
|
|
QFile F(fname);
|
|
|
|
if (!F.open(QIODevice::WriteOnly)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
F.write(content.toUtf8());
|
|
|
|
F.flush();
|
|
|
|
F.close();
|
|
|
|
|
2019-09-04 12:01:33 +03:00
|
|
|
_fileManager.addToDeployed(fname);
|
2019-06-19 22:48:19 +03:00
|
|
|
|
|
|
|
return F.setPermissions(QFileDevice::ExeOther | QFileDevice::WriteOther |
|
|
|
|
QFileDevice::ReadOther | QFileDevice::ExeUser |
|
|
|
|
QFileDevice::WriteUser | QFileDevice::ReadUser |
|
|
|
|
QFileDevice::ExeOwner | QFileDevice::WriteOwner |
|
|
|
|
QFileDevice::ReadOwner);
|
2018-12-15 20:51:25 +03:00
|
|
|
}
|
|
|
|
|
2019-05-22 18:03:54 +03:00
|
|
|
|
2019-05-23 18:31:51 +03:00
|
|
|
|
2018-08-17 20:47:49 +03:00
|
|
|
void Deploy::deploy() {
|
|
|
|
qInfo() << "target deploy started!!";
|
2018-08-18 18:37:33 +03:00
|
|
|
|
2018-12-15 20:51:25 +03:00
|
|
|
smartMoveTargets();
|
|
|
|
|
|
|
|
for (auto i = targets.cbegin(); i != targets.cend(); ++i) {
|
|
|
|
extract(i.key());
|
|
|
|
}
|
2018-08-19 17:06:29 +03:00
|
|
|
|
2019-03-29 22:12:08 +03:00
|
|
|
if (deployQml && !extractQml()) {
|
2018-08-19 17:06:29 +03:00
|
|
|
qCritical() << "qml not extacted!";
|
|
|
|
}
|
|
|
|
|
2019-08-31 23:26:04 +03:00
|
|
|
PluginsParser pluginsParser(&scaner);
|
2019-08-31 22:55:02 +03:00
|
|
|
|
2019-08-31 23:26:04 +03:00
|
|
|
QStringList plugins;
|
2019-09-03 18:15:05 +03:00
|
|
|
pluginsParser.scan(DeployCore::qtDir + "/plugins", plugins);
|
2019-08-31 23:26:04 +03:00
|
|
|
copyPlugins(plugins);
|
2018-09-17 11:17:04 +03:00
|
|
|
|
2018-08-19 17:06:29 +03:00
|
|
|
|
2019-09-04 12:01:33 +03:00
|
|
|
_fileManager.copyFiles(neadedLibs, targetDir);
|
2018-08-17 20:47:49 +03:00
|
|
|
|
2019-04-04 18:11:38 +03:00
|
|
|
if (QuasarAppUtils::Params::isEndable("deploySystem")) {
|
2019-09-04 12:01:33 +03:00
|
|
|
_fileManager.copyFiles(systemLibs, targetDir);
|
2018-08-17 20:47:49 +03:00
|
|
|
}
|
|
|
|
|
2019-09-04 12:01:33 +03:00
|
|
|
if (!QuasarAppUtils::Params::isEndable("noStrip") && !_fileManager.strip(targetDir)) {
|
2019-01-26 22:27:36 +03:00
|
|
|
QuasarAppUtils::Params::verboseLog("strip failed!");
|
|
|
|
}
|
|
|
|
|
2019-03-29 22:12:08 +03:00
|
|
|
if (!QuasarAppUtils::Params::isEndable("noTranslations")) {
|
2019-09-03 18:15:05 +03:00
|
|
|
if (!copyTranslations(DeployCore::extractTranslation(neadedLibs))) {
|
2019-01-27 18:00:36 +03:00
|
|
|
qWarning() << " copy TR ERROR";
|
|
|
|
}
|
2019-01-27 15:37:19 +03:00
|
|
|
}
|
|
|
|
|
2019-03-28 12:36:21 +03:00
|
|
|
if (!deployMSVC()) {
|
|
|
|
QuasarAppUtils::Params::verboseLog("deploy msvc failed");
|
|
|
|
}
|
|
|
|
|
2019-06-19 22:48:19 +03:00
|
|
|
bool targetWindows = false;
|
|
|
|
|
2019-05-24 19:23:26 +03:00
|
|
|
for (auto i = targets.cbegin(); i != targets.cend(); ++i) {
|
2019-06-19 22:48:19 +03:00
|
|
|
|
|
|
|
if (QFileInfo(i.key()).completeSuffix() == "exe") {
|
|
|
|
targetWindows = true;
|
|
|
|
}
|
|
|
|
|
2019-05-24 19:23:26 +03:00
|
|
|
if (i.value() && !createRunScript(i.key())) {
|
|
|
|
qCritical() << "run script not created!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-19 22:48:19 +03:00
|
|
|
if (targetWindows && !createQConf()) {
|
|
|
|
QuasarAppUtils::Params::verboseLog("create qt.conf failr", QuasarAppUtils::Warning);
|
|
|
|
}
|
|
|
|
|
2019-09-04 12:01:33 +03:00
|
|
|
_fileManager.saveDeploymendFiles(targetDir);
|
|
|
|
|
2019-09-07 12:01:20 +03:00
|
|
|
qInfo() << "deploy done!";
|
2019-05-18 13:35:48 +03:00
|
|
|
|
|
|
|
|
2018-12-01 21:04:52 +03:00
|
|
|
}
|
2018-08-17 20:47:49 +03:00
|
|
|
|
2019-09-07 12:01:20 +03:00
|
|
|
QString Deploy::getQtDir() const { return DeployCore::qtDir; }
|
2018-09-19 14:53:51 +03:00
|
|
|
|
2018-10-24 17:26:42 +03:00
|
|
|
void Deploy::setDepchLimit(int value) { depchLimit = value; }
|
|
|
|
|
2019-05-23 21:40:16 +03:00
|
|
|
int Deploy::find(const QString &str, const QStringList &list) const {
|
|
|
|
for (int i = 0 ; i < list.size(); ++i) {
|
|
|
|
if (list[i].contains(str))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-08-18 18:37:33 +03:00
|
|
|
bool Deploy::copyPlugin(const QString &plugin) {
|
|
|
|
|
2018-08-19 17:06:29 +03:00
|
|
|
QStringList listItems;
|
|
|
|
|
2019-09-04 12:01:33 +03:00
|
|
|
if (!_fileManager.copyFolder(plugin, targetDir + "/plugins/" + QFileInfo(plugin).fileName(),
|
2018-12-24 18:25:05 +03:00
|
|
|
QStringList() << ".so.debug" << "d.dll", &listItems)) {
|
2018-08-19 17:06:29 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto item : listItems) {
|
2019-08-31 22:55:02 +03:00
|
|
|
extract(item);
|
2018-08-19 17:06:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2018-08-18 18:37:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Deploy::copyPlugins(const QStringList &list) {
|
|
|
|
for (auto plugin : list) {
|
2018-10-24 17:26:42 +03:00
|
|
|
if (!copyPlugin(plugin)) {
|
|
|
|
qWarning() << plugin << " not copied!";
|
2018-08-18 18:37:33 +03:00
|
|
|
}
|
|
|
|
}
|
2018-09-19 14:53:51 +03:00
|
|
|
QFileInfo info;
|
|
|
|
|
|
|
|
for (auto extraPlugin : extraPlugins) {
|
|
|
|
|
|
|
|
info.setFile(extraPlugin);
|
|
|
|
if (info.isDir()) {
|
2018-12-16 19:45:58 +03:00
|
|
|
|
2019-09-04 12:01:33 +03:00
|
|
|
_fileManager.copyFolder(info.absoluteFilePath(),
|
2018-12-16 19:45:58 +03:00
|
|
|
targetDir + "/plugins/" + info.baseName(),
|
2018-12-24 18:25:05 +03:00
|
|
|
QStringList() << ".so.debug" << "d.dll");
|
2018-09-19 14:53:51 +03:00
|
|
|
} else {
|
2019-09-04 12:01:33 +03:00
|
|
|
_fileManager.copyFile(info.absoluteFilePath(),
|
2018-10-24 17:26:42 +03:00
|
|
|
targetDir + QDir::separator() + "plugins");
|
2018-09-19 14:53:51 +03:00
|
|
|
extract(info.absoluteFilePath());
|
|
|
|
}
|
|
|
|
}
|
2018-08-18 18:37:33 +03:00
|
|
|
}
|
|
|
|
|
2019-01-27 15:37:19 +03:00
|
|
|
bool Deploy::copyTranslations(QStringList list) {
|
|
|
|
|
2019-01-27 18:00:36 +03:00
|
|
|
QDir dir(translationDir);
|
|
|
|
if (!dir.exists() || list.isEmpty()) {
|
2019-01-27 15:37:19 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList filters;
|
|
|
|
for (auto &&i: list) {
|
|
|
|
filters.push_back("*" + i + "*");
|
|
|
|
}
|
|
|
|
|
|
|
|
auto listItems = dir.entryInfoList(filters, QDir::Files | QDir::NoDotAndDotDot);
|
|
|
|
|
|
|
|
for (auto &&i: listItems) {
|
2019-09-04 12:01:33 +03:00
|
|
|
_fileManager.copyFile(i.absoluteFilePath(), targetDir + "/translations");
|
2019-01-27 15:37:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-18 18:37:33 +03:00
|
|
|
|
|
|
|
|
2018-12-15 20:51:25 +03:00
|
|
|
QFileInfoList Deploy::findFilesInsideDir(const QString &name,
|
2019-01-26 22:27:36 +03:00
|
|
|
const QString &dirpath) {
|
2018-12-15 20:51:25 +03:00
|
|
|
QFileInfoList files;
|
2018-08-18 22:36:28 +03:00
|
|
|
|
2018-08-23 21:28:47 +03:00
|
|
|
QDir dir(dirpath);
|
|
|
|
|
2018-12-15 20:51:25 +03:00
|
|
|
auto list = dir.entryInfoList( QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
|
|
|
|
|
|
|
|
for (auto && item :list) {
|
|
|
|
if (item.isFile()) {
|
|
|
|
if (item.fileName().contains(name)) {
|
|
|
|
files += item;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
files += findFilesInsideDir(name, item.absoluteFilePath());
|
|
|
|
}
|
|
|
|
}
|
2018-08-23 21:28:47 +03:00
|
|
|
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
2018-10-24 17:26:42 +03:00
|
|
|
QString Deploy::filterQmlPath(const QString &path) {
|
2018-08-24 16:18:37 +03:00
|
|
|
if (path.contains(qmlDir)) {
|
|
|
|
auto endIndex = path.indexOf(QDir::separator(), qmlDir.size() + 1);
|
2018-10-24 17:26:42 +03:00
|
|
|
QString module =
|
2019-01-26 22:27:36 +03:00
|
|
|
path.mid(qmlDir.size() + 1, endIndex - qmlDir.size() - 1);
|
2018-08-24 16:18:37 +03:00
|
|
|
return qmlDir + QDir::separator() + module;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2019-08-31 22:55:02 +03:00
|
|
|
void Deploy::extractLib(const QString &file) {
|
2018-11-23 14:56:55 +03:00
|
|
|
qInfo() << "extract lib :" << file;
|
2018-12-09 17:35:07 +03:00
|
|
|
|
2019-03-25 21:27:26 +03:00
|
|
|
auto data = scaner.scan(file);
|
2018-11-23 14:56:55 +03:00
|
|
|
|
2019-04-04 18:11:38 +03:00
|
|
|
for (auto &line : data) {
|
2018-11-23 14:56:55 +03:00
|
|
|
bool isIgnore = false;
|
|
|
|
for (auto ignore : ignoreList) {
|
2019-04-04 18:11:38 +03:00
|
|
|
if (line.fullPath().contains(ignore)) {
|
|
|
|
QuasarAppUtils::Params::verboseLog(line.fullPath() + " ignored by filter" + ignore);
|
2018-11-23 14:56:55 +03:00
|
|
|
isIgnore = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isIgnore) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-08-24 17:56:42 +03:00
|
|
|
if (line.getPriority() != LibPriority::SystemLib && !neadedLibs.contains(line.fullPath())) {
|
2019-04-04 18:11:38 +03:00
|
|
|
neadedLibs << line.fullPath();
|
|
|
|
} else if (QuasarAppUtils::Params::isEndable("deploySystem") &&
|
2019-08-24 17:56:42 +03:00
|
|
|
line.getPriority() == LibPriority::SystemLib &&
|
2019-04-04 18:11:38 +03:00
|
|
|
!systemLibs.contains(line.fullPath())) {
|
|
|
|
systemLibs << line.fullPath();
|
2018-11-23 14:56:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Deploy::addEnv(const QString &dir) {
|
|
|
|
|
2018-12-01 21:04:52 +03:00
|
|
|
char separator = ':';
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
separator = ';';
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (dir.contains(separator)) {
|
|
|
|
auto list = dir.split(separator);
|
2018-11-23 14:56:55 +03:00
|
|
|
for (auto i : list) {
|
|
|
|
addEnv(i);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-05 14:23:42 +03:00
|
|
|
auto path = QFileInfo(dir).absoluteFilePath();
|
|
|
|
|
2019-05-14 11:31:13 +03:00
|
|
|
for (QString & i :ignoreEnvList) {
|
|
|
|
if (path.contains(i)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-05 14:23:42 +03:00
|
|
|
if (path.contains(appDir)) {
|
|
|
|
QuasarAppUtils::Params::verboseLog("is cqtdeployer dir!: " + path + " app dir : " + appDir);
|
2019-01-16 22:17:49 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-05 14:23:42 +03:00
|
|
|
if (!QFileInfo(path).isDir()) {
|
|
|
|
QuasarAppUtils::Params::verboseLog("is not dir!! :" + path);
|
2018-11-23 14:56:55 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-05 14:23:42 +03:00
|
|
|
if (deployEnvironment.contains(path)) {
|
|
|
|
QuasarAppUtils::Params::verboseLog ("Environment alredy added: " + path);
|
2019-01-20 19:46:25 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-05 14:23:42 +03:00
|
|
|
if (path.contains(targetDir)) {
|
|
|
|
QuasarAppUtils::Params::verboseLog ("Skip paths becouse it is target : " + path);
|
2018-11-23 14:56:55 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-05 14:23:42 +03:00
|
|
|
deployEnvironment.push_back(QDir::fromNativeSeparators(path));
|
2018-11-23 14:56:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Deploy::concatEnv() const {
|
|
|
|
|
|
|
|
if (deployEnvironment.isEmpty()) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
QString result = deployEnvironment.first();
|
|
|
|
for (auto i: deployEnvironment) {
|
|
|
|
result += (":" + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-12-15 20:51:25 +03:00
|
|
|
bool Deploy::smartMoveTargets() {
|
|
|
|
|
|
|
|
QMap<QString, bool> temp;
|
|
|
|
bool result = true;
|
|
|
|
for (auto i = targets.cbegin(); i != targets.cend(); ++i) {
|
|
|
|
|
|
|
|
QFileInfo target(i.key());
|
2018-12-16 15:41:03 +03:00
|
|
|
auto targetPath = targetDir + (isLib(target) ? "/lib" : "/bin");
|
2018-12-15 20:51:25 +03:00
|
|
|
|
2018-12-15 18:30:20 +03:00
|
|
|
if (target.completeSuffix().contains("dll", Qt::CaseInsensitive) ||
|
|
|
|
target.completeSuffix().contains("exe", Qt::CaseInsensitive)) {
|
|
|
|
|
2018-12-16 15:41:03 +03:00
|
|
|
targetPath = targetDir;
|
2018-12-15 18:30:20 +03:00
|
|
|
|
|
|
|
}
|
2018-12-15 20:51:25 +03:00
|
|
|
|
2019-09-04 12:01:33 +03:00
|
|
|
if (!_fileManager.smartCopyFile(target.absoluteFilePath(), targetPath, targetDir)) {
|
2018-12-16 15:41:03 +03:00
|
|
|
result = false;
|
2019-01-14 18:01:22 +03:00
|
|
|
}
|
|
|
|
|
2018-12-16 15:41:03 +03:00
|
|
|
|
|
|
|
temp.insert(targetPath + "/" + target.fileName(), i.value());
|
2018-12-15 20:51:25 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
targets = temp;
|
|
|
|
|
2019-03-25 21:27:26 +03:00
|
|
|
scaner.setEnvironment(deployEnvironment);
|
2019-03-17 18:42:07 +03:00
|
|
|
|
2018-12-15 20:51:25 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Deploy::isLib(const QFileInfo &file) {
|
2018-12-15 18:30:20 +03:00
|
|
|
return file.completeSuffix().contains("so", Qt::CaseInsensitive)
|
|
|
|
|| file.completeSuffix().contains("dll", Qt::CaseInsensitive);
|
2018-12-15 20:51:25 +03:00
|
|
|
}
|
|
|
|
|
2018-12-14 22:48:33 +03:00
|
|
|
QStringList Deploy::extractImportsFromDir(const QString &filepath) {
|
2018-08-23 21:28:47 +03:00
|
|
|
QProcess p;
|
2019-01-21 22:45:04 +03:00
|
|
|
|
|
|
|
QProcessEnvironment env;
|
|
|
|
|
|
|
|
env.insert("LD_LIBRARY_PATH", concatEnv());
|
2019-09-03 18:15:05 +03:00
|
|
|
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");
|
2019-01-21 22:45:04 +03:00
|
|
|
|
|
|
|
p.setProcessEnvironment(env);
|
2019-03-28 19:23:22 +03:00
|
|
|
p.setProgram(externQmlScaner);
|
2018-10-24 17:26:42 +03:00
|
|
|
p.setArguments(QStringList()
|
2018-12-14 22:48:33 +03:00
|
|
|
<< "-rootPath" << filepath << "-importPath" << qmlDir);
|
2018-08-23 21:28:47 +03:00
|
|
|
p.start();
|
|
|
|
|
|
|
|
if (!p.waitForFinished()) {
|
|
|
|
qWarning() << filepath << " not scaning!";
|
|
|
|
return QStringList();
|
|
|
|
}
|
|
|
|
|
2019-01-21 22:45:04 +03:00
|
|
|
auto rawData = p.readAll();
|
|
|
|
|
|
|
|
if (p.exitCode()) {
|
|
|
|
qWarning() << "scaner error " << p.errorString() << "exitCode: " << p.exitCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
QuasarAppUtils::Params::verboseLog("rawData from extractImportsFromDir: " + rawData);
|
|
|
|
|
|
|
|
auto data = QJsonDocument::fromJson(rawData);
|
2018-08-23 21:28:47 +03:00
|
|
|
|
|
|
|
if (!data.isArray()) {
|
|
|
|
qWarning() << "wrong data from qml scaner! of " << filepath;
|
|
|
|
}
|
|
|
|
|
2018-10-24 17:26:42 +03:00
|
|
|
auto array = data.array();
|
2018-08-23 21:28:47 +03:00
|
|
|
|
|
|
|
QStringList result;
|
|
|
|
|
|
|
|
for (auto object : array) {
|
2018-08-24 16:18:37 +03:00
|
|
|
|
2018-09-08 12:18:00 +03:00
|
|
|
auto module = object.toObject().value("path").toString();
|
2018-08-24 16:18:37 +03:00
|
|
|
|
|
|
|
if (module.isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!result.contains(module)) {
|
|
|
|
result << module;
|
|
|
|
}
|
2018-08-18 22:36:28 +03:00
|
|
|
}
|
|
|
|
|
2018-08-23 21:28:47 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-08-24 16:18:37 +03:00
|
|
|
bool Deploy::extractQmlAll() {
|
|
|
|
|
2018-10-24 17:26:42 +03:00
|
|
|
if (!QFileInfo::exists(qmlDir)) {
|
2018-08-24 16:18:37 +03:00
|
|
|
qWarning() << "qml dir wrong!";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList listItems;
|
|
|
|
|
2019-09-04 12:01:33 +03:00
|
|
|
if (!_fileManager.copyFolder(qmlDir, targetDir + "/qml",
|
2018-12-24 18:25:05 +03:00
|
|
|
QStringList() << ".so.debug" << "d.dll",
|
|
|
|
&listItems)) {
|
2018-08-24 16:18:37 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto item : listItems) {
|
2019-08-31 22:55:02 +03:00
|
|
|
extract(item);
|
2018-08-24 16:18:37 +03:00
|
|
|
}
|
2018-08-19 17:06:29 +03:00
|
|
|
|
2018-09-08 12:18:00 +03:00
|
|
|
return true;
|
2018-08-24 16:18:37 +03:00
|
|
|
}
|
2018-08-23 21:28:47 +03:00
|
|
|
|
2019-01-21 21:41:22 +03:00
|
|
|
bool Deploy::extractQmlFromSource(const QString& sourceDir) {
|
|
|
|
|
|
|
|
QFileInfo info(sourceDir);
|
|
|
|
|
|
|
|
if (!info.isDir()) {
|
|
|
|
qCritical() << "extract qml fail! qml source dir not exits or is not dir " << sourceDir;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QuasarAppUtils::Params::verboseLog("extractQmlFromSource " + info.absoluteFilePath());
|
2018-09-08 12:18:00 +03:00
|
|
|
|
2018-10-24 17:26:42 +03:00
|
|
|
if (!QFileInfo::exists(qmlDir)) {
|
2018-09-08 12:18:00 +03:00
|
|
|
qWarning() << "qml dir wrong!";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-28 19:23:22 +03:00
|
|
|
QStringList plugins;
|
2018-09-08 12:18:00 +03:00
|
|
|
QStringList listItems;
|
2019-03-28 19:23:22 +03:00
|
|
|
QStringList filter;
|
2019-04-11 14:41:05 +03:00
|
|
|
filter << ".so.debug" << "d.dll" << ".pdb";
|
2019-03-28 19:23:22 +03:00
|
|
|
|
|
|
|
if (QuasarAppUtils::Params::isEndable("qmlExtern")) {
|
2018-08-24 16:18:37 +03:00
|
|
|
|
2019-08-31 22:55:02 +03:00
|
|
|
/// @todo remove in verison 1.3
|
2019-03-28 19:23:22 +03:00
|
|
|
qInfo() << "use extern qml scaner!";
|
|
|
|
|
|
|
|
plugins = extractImportsFromDir(info.absoluteFilePath());
|
2018-08-24 16:18:37 +03:00
|
|
|
|
2019-03-28 19:23:22 +03:00
|
|
|
} else {
|
|
|
|
qInfo() << "use own qml scaner!";
|
|
|
|
|
|
|
|
QML ownQmlScaner(qmlDir);
|
|
|
|
|
|
|
|
if (!ownQmlScaner.scan(plugins, info.absoluteFilePath())) {
|
|
|
|
QuasarAppUtils::Params::verboseLog("qml scaner run failed!");
|
|
|
|
return false;
|
|
|
|
}
|
2019-01-21 21:41:22 +03:00
|
|
|
}
|
|
|
|
|
2019-09-04 12:01:33 +03:00
|
|
|
if (!_fileManager.copyFolder(qmlDir, targetDir + "/qml",
|
2019-03-28 19:23:22 +03:00
|
|
|
filter , &listItems, &plugins)) {
|
2018-09-08 12:18:00 +03:00
|
|
|
return false;
|
|
|
|
}
|
2018-08-24 16:18:37 +03:00
|
|
|
|
2018-09-08 12:18:00 +03:00
|
|
|
for (auto item : listItems) {
|
2019-08-31 22:55:02 +03:00
|
|
|
extract(item);
|
2018-09-08 12:18:00 +03:00
|
|
|
}
|
2018-08-24 16:18:37 +03:00
|
|
|
|
2018-09-08 12:18:00 +03:00
|
|
|
return true;
|
2018-08-24 16:18:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Deploy::extractQml() {
|
|
|
|
|
2018-09-29 16:13:52 +03:00
|
|
|
if (QuasarAppUtils::Params::isEndable("qmlDir")) {
|
2018-10-24 17:26:42 +03:00
|
|
|
return extractQmlFromSource(
|
2019-01-26 22:27:36 +03:00
|
|
|
QuasarAppUtils::Params::getStrArg("qmlDir"));
|
2018-08-24 16:18:37 +03:00
|
|
|
|
2018-10-24 17:26:42 +03:00
|
|
|
} else if (QuasarAppUtils::Params::isEndable("allQmlDependes")) {
|
|
|
|
return extractQmlAll();
|
2018-08-24 16:18:37 +03:00
|
|
|
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-18 22:36:28 +03:00
|
|
|
}
|
|
|
|
|
2019-09-03 18:15:05 +03:00
|
|
|
void Deploy::extract(const QString &file) {
|
|
|
|
QFileInfo info(file);
|
2019-01-26 22:27:36 +03:00
|
|
|
|
2019-09-03 18:15:05 +03:00
|
|
|
auto sufix = info.completeSuffix();
|
2019-01-26 22:27:36 +03:00
|
|
|
|
2019-09-03 18:15:05 +03:00
|
|
|
if (sufix.contains("dll", Qt::CaseSensitive) ||
|
|
|
|
sufix.contains("exe", Qt::CaseSensitive) ||
|
|
|
|
sufix.isEmpty() || sufix.contains("so", Qt::CaseSensitive)) {
|
2019-01-26 22:27:36 +03:00
|
|
|
|
2019-09-03 18:15:05 +03:00
|
|
|
extractLib(file);
|
2019-01-26 22:27:36 +03:00
|
|
|
} else {
|
2019-09-03 18:15:05 +03:00
|
|
|
QuasarAppUtils::Params::verboseLog("file with sufix " + sufix + " not supported!");
|
2019-01-26 22:27:36 +03:00
|
|
|
}
|
2019-07-16 13:34:59 +03:00
|
|
|
|
2019-06-19 22:48:19 +03:00
|
|
|
}
|
|
|
|
|
2019-01-16 22:17:49 +03:00
|
|
|
Deploy::Deploy() {
|
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
appDir = QuasarAppUtils::Params::getStrArg("appPath");
|
|
|
|
|
|
|
|
if (appDir.right(4) == "/bin") {
|
|
|
|
appDir = appDir.left(appDir.size() - 4);
|
|
|
|
}
|
|
|
|
#else
|
2019-01-27 19:46:11 +03:00
|
|
|
appDir = QuasarAppUtils::Params::getStrArg("appPath");
|
2019-01-16 22:17:49 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
QuasarAppUtils::Params::verboseLog("appDir = " + appDir);
|
2019-05-25 19:09:43 +03:00
|
|
|
|
2019-01-16 22:17:49 +03:00
|
|
|
}
|
2018-11-23 14:56:55 +03:00
|
|
|
|