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-15 17:38:47 +03:00
|
|
|
#include "deploycore.h"
|
|
|
|
#include "metafilemanager.h"
|
|
|
|
|
|
|
|
#include <quasarapp.h>
|
|
|
|
#include <QDir>
|
|
|
|
#include <configparser.h>
|
|
|
|
#include "filemanager.h"
|
|
|
|
|
2019-12-09 15:13:00 +03:00
|
|
|
#include <assert.h>
|
2019-09-15 17:38:47 +03:00
|
|
|
|
|
|
|
bool MetaFileManager::createRunScriptWindows(const QString &target) {
|
|
|
|
|
2019-12-11 18:06:54 +03:00
|
|
|
auto cnf = DeployCore::_config;
|
|
|
|
|
|
|
|
if (!cnf->targets.contains(target)) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-12-14 17:38:43 +03:00
|
|
|
auto distro = cnf->getDistro(target);
|
2019-12-11 18:06:54 +03:00
|
|
|
|
|
|
|
if (distro.getBinOutDir() ==
|
|
|
|
distro.getLibOutDir() ) {
|
2019-09-15 17:38:47 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString content =
|
|
|
|
"@echo off \n"
|
|
|
|
"SET BASE_DIR=%~dp0\n"
|
2019-12-11 18:06:54 +03:00
|
|
|
"SET PATH=%BASE_DIR%" + distro.getLibOutDir() + ";%PATH%\n"
|
|
|
|
"start \"\" \"%BASE_DIR%" + distro.getBinOutDir() + "%0\" %1 \n";
|
2019-09-15 17:38:47 +03:00
|
|
|
|
|
|
|
content = content.arg(QFileInfo(target).fileName()).arg("%*");
|
|
|
|
content = QDir::toNativeSeparators(content);
|
|
|
|
|
2019-12-12 22:50:04 +03:00
|
|
|
QString fname = DeployCore::_config->getTargetDir(target) + QDir::separator() + QFileInfo(target).baseName()+ ".bat";
|
2019-09-15 17:38:47 +03:00
|
|
|
|
|
|
|
QFile F(fname);
|
|
|
|
if (!F.open(QIODevice::WriteOnly)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
F.write(content.toUtf8());
|
|
|
|
F.flush();
|
|
|
|
F.close();
|
|
|
|
|
|
|
|
_fileManager->addToDeployed(fname);
|
|
|
|
|
|
|
|
return F.setPermissions(QFileDevice::ExeOther | QFileDevice::WriteOther |
|
|
|
|
QFileDevice::ReadOther | QFileDevice::ExeUser |
|
|
|
|
QFileDevice::WriteUser | QFileDevice::ReadUser |
|
|
|
|
QFileDevice::ExeOwner | QFileDevice::WriteOwner |
|
|
|
|
QFileDevice::ReadOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MetaFileManager::createRunScriptLinux(const QString &target) {
|
2019-12-11 18:06:54 +03:00
|
|
|
auto cnf = DeployCore::_config;
|
|
|
|
|
|
|
|
if (!cnf->targets.contains(target)) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-12-14 17:38:43 +03:00
|
|
|
auto distro = cnf->getDistro(target);
|
2019-12-11 18:06:54 +03:00
|
|
|
|
2019-09-15 17:38:47 +03:00
|
|
|
QString content =
|
|
|
|
"#!/bin/sh\n"
|
|
|
|
"BASE_DIR=$(dirname \"$(readlink -f \"$0\")\")\n"
|
|
|
|
"export "
|
2019-12-11 18:06:54 +03:00
|
|
|
"LD_LIBRARY_PATH=\"$BASE_DIR\"" + distro.getLibOutDir() + ":\"$BASE_DIR\":$LD_LIBRARY_PATH\n"
|
|
|
|
"export QML_IMPORT_PATH=\"$BASE_DIR\"" + distro.getQmlOutDir() + ":QML_IMPORT_PATH\n"
|
|
|
|
"export QML2_IMPORT_PATH=\"$BASE_DIR\"" + distro.getQmlOutDir() + ":QML2_IMPORT_PATH\n"
|
|
|
|
"export QT_PLUGIN_PATH=\"$BASE_DIR\"" + distro.getPluginsOutDir() + ":QT_PLUGIN_PATH\n"
|
|
|
|
"export QTWEBENGINEPROCESS_PATH=\"$BASE_DIR\"" + distro.getBinOutDir() + "/QtWebEngineProcess\n"
|
2019-09-15 17:38:47 +03:00
|
|
|
"export QTDIR=\"$BASE_DIR\"\n"
|
|
|
|
"export "
|
2019-12-11 18:06:54 +03:00
|
|
|
"QT_QPA_PLATFORM_PLUGIN_PATH=\"$BASE_DIR\"" + distro.getPluginsOutDir() +
|
2019-09-15 17:38:47 +03:00
|
|
|
"/platforms:QT_QPA_PLATFORM_PLUGIN_PATH\n"
|
|
|
|
"%2"
|
2019-12-11 18:06:54 +03:00
|
|
|
"\"$BASE_DIR\"" + distro.getBinOutDir() + "%1 \"$@\"";
|
2019-09-15 17:38:47 +03:00
|
|
|
|
|
|
|
content = content.arg(QFileInfo(target).fileName());
|
|
|
|
int ld_index = DeployCore::find("ld-linux", _fileManager->getDeployedFilesStringList());
|
|
|
|
|
2019-09-24 15:11:30 +03:00
|
|
|
if (ld_index >= 0 && QuasarAppUtils::Params::isEndable("deploySystem-with-libc")) {
|
2019-09-15 17:38:47 +03:00
|
|
|
|
2019-12-11 18:06:54 +03:00
|
|
|
content = content.arg(QString("\nexport LD_PRELOAD=\"$BASE_DIR\"" + distro.getLibOutDir() + "%0\n").
|
2019-09-15 17:38:47 +03:00
|
|
|
arg(QFileInfo(_fileManager->getDeployedFilesStringList()[ld_index]).fileName()));
|
|
|
|
} else {
|
|
|
|
content = content.arg("");
|
|
|
|
}
|
|
|
|
|
2019-12-12 22:50:04 +03:00
|
|
|
QString fname = DeployCore::_config->getTargetDir(target) + QDir::separator() + QFileInfo(target).baseName()+ ".sh";
|
2019-09-15 17:38:47 +03:00
|
|
|
|
|
|
|
QFile F(fname);
|
|
|
|
if (!F.open(QIODevice::WriteOnly)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
F.write(content.toUtf8());
|
|
|
|
F.flush();
|
|
|
|
F.close();
|
|
|
|
|
|
|
|
_fileManager->addToDeployed(fname);
|
|
|
|
|
|
|
|
return F.setPermissions(QFileDevice::ExeOther | QFileDevice::WriteOther |
|
|
|
|
QFileDevice::ReadOther | QFileDevice::ExeUser |
|
|
|
|
QFileDevice::WriteUser | QFileDevice::ReadUser |
|
|
|
|
QFileDevice::ExeOwner | QFileDevice::WriteOwner |
|
|
|
|
QFileDevice::ReadOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
MetaFileManager::MetaFileManager(FileManager *manager):
|
|
|
|
_fileManager(manager)
|
|
|
|
{
|
|
|
|
assert(_fileManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MetaFileManager::createRunScript(const QString &target) {
|
|
|
|
|
|
|
|
QFileInfo info(target);
|
|
|
|
auto sufix = info.completeSuffix();
|
|
|
|
|
|
|
|
if (sufix.contains("exe", Qt::CaseSensitive)) {
|
|
|
|
return createRunScriptWindows(target);
|
|
|
|
}
|
|
|
|
|
2019-11-16 17:05:37 +03:00
|
|
|
if (sufix.isEmpty()) {
|
|
|
|
return createRunScriptLinux(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
2019-09-15 17:38:47 +03:00
|
|
|
}
|
|
|
|
|
2019-12-11 18:06:54 +03:00
|
|
|
bool MetaFileManager::createQConf(const QString &target) {
|
|
|
|
auto cnf = DeployCore::_config;
|
|
|
|
|
|
|
|
if (!cnf->targets.contains(target)) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-12-14 17:38:43 +03:00
|
|
|
auto distro = cnf->getDistro(target);
|
2019-09-15 17:38:47 +03:00
|
|
|
|
|
|
|
QString content =
|
|
|
|
"[Paths]\n"
|
2019-12-11 18:06:54 +03:00
|
|
|
"Prefix= ." + distro.getRootDir(distro.getBinOutDir()) + "\n"
|
|
|
|
"Libraries= ." + distro.getLibOutDir() + "\n"
|
|
|
|
"Plugins= ." + distro.getPluginsOutDir() + "\n"
|
|
|
|
"Imports= ." + distro.getQmlOutDir() + "\n"
|
|
|
|
"Translations= ." + distro.getTrOutDir() + "\n"
|
|
|
|
"Qml2Imports= ." + distro.getQmlOutDir() + "\n";
|
2019-09-15 17:38:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
content.replace("//", "/");
|
|
|
|
content = QDir::fromNativeSeparators(content);
|
|
|
|
|
2019-12-12 22:50:04 +03:00
|
|
|
QString fname = DeployCore::_config->getTargetDir(target) + distro.getBinOutDir() + "qt.conf";
|
2019-09-15 17:38:47 +03:00
|
|
|
|
|
|
|
QFile F(fname);
|
|
|
|
if (!F.open(QIODevice::WriteOnly)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
F.write(content.toUtf8());
|
|
|
|
F.flush();
|
|
|
|
F.close();
|
|
|
|
|
|
|
|
_fileManager->addToDeployed(fname);
|
|
|
|
|
|
|
|
return F.setPermissions(QFileDevice::ExeOther | QFileDevice::WriteOther |
|
|
|
|
QFileDevice::ReadOther | QFileDevice::ExeUser |
|
|
|
|
QFileDevice::WriteUser | QFileDevice::ReadUser |
|
|
|
|
QFileDevice::ExeOwner | QFileDevice::WriteOwner |
|
|
|
|
QFileDevice::ReadOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetaFileManager::createRunMetaFiles() {
|
|
|
|
|
|
|
|
for (auto i = DeployCore::_config->targets.cbegin(); i != DeployCore::_config->targets.cend(); ++i) {
|
|
|
|
|
2019-11-13 18:18:44 +03:00
|
|
|
if (!createRunScript(i.key())) {
|
2019-09-15 17:38:47 +03:00
|
|
|
qCritical() << "run script not created!";
|
|
|
|
}
|
|
|
|
|
2019-12-11 18:06:54 +03:00
|
|
|
if (!createQConf(i.key())) {
|
|
|
|
QuasarAppUtils::Params::verboseLog("create qt.conf failr", QuasarAppUtils::Warning);
|
|
|
|
}
|
2019-09-15 17:38:47 +03:00
|
|
|
}
|
2019-12-11 18:06:54 +03:00
|
|
|
|
|
|
|
|
2019-09-15 17:38:47 +03:00
|
|
|
}
|