2019-09-23 16:46:57 +03:00
|
|
|
/*
|
2021-01-05 13:17:11 +03:00
|
|
|
* Copyright (C) 2018-2021 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;
|
|
|
|
|
2020-01-02 19:27:40 +03:00
|
|
|
if (!cnf->targets().contains(target)) {
|
2019-12-11 18:06:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
2019-12-14 17:38:43 +03:00
|
|
|
auto distro = cnf->getDistro(target);
|
2019-12-11 18:06:54 +03:00
|
|
|
|
2021-01-08 22:02:50 +03:00
|
|
|
QFileInfo targetInfo(target);
|
|
|
|
|
|
|
|
QString content;
|
|
|
|
auto runScript = cnf->getRunScript(targetInfo.fileName());
|
|
|
|
if (runScript.size()) {
|
|
|
|
auto script = QFile(runScript);
|
|
|
|
if (!script.open(QIODevice::ReadOnly)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
content = script.readAll();
|
|
|
|
script.close();
|
2019-09-15 17:38:47 +03:00
|
|
|
|
2021-01-08 22:02:50 +03:00
|
|
|
} else {
|
2021-01-11 19:15:50 +03:00
|
|
|
auto systemLibsDir = distro.getLibOutDir() + DeployCore::systemLibsFolderName();
|
|
|
|
|
2021-01-08 22:02:50 +03:00
|
|
|
content =
|
|
|
|
"@echo off \n"
|
|
|
|
"SET BASE_DIR=%~dp0\n"
|
2021-01-11 19:15:50 +03:00
|
|
|
"SET PATH=%BASE_DIR%" + distro.getLibOutDir() + ";%PATH%;" + systemLibsDir + "\n"
|
2021-01-08 22:02:50 +03:00
|
|
|
"%2\n"
|
|
|
|
"call \"%BASE_DIR%" + distro.getBinOutDir() + "%0\" %1 \n";
|
2019-09-15 17:38:47 +03:00
|
|
|
|
2021-01-08 22:02:50 +03:00
|
|
|
content = content.arg(targetInfo.fileName()).arg("%*");
|
|
|
|
content = content.arg(generateCustoScriptBlok(true));
|
2019-12-27 12:51:03 +03:00
|
|
|
|
2021-01-08 22:02:50 +03:00
|
|
|
content = QDir::toNativeSeparators(content);
|
|
|
|
}
|
2019-09-15 17:38:47 +03:00
|
|
|
|
2021-01-08 22:02:50 +03:00
|
|
|
QString fname = DeployCore::_config->getTargetDir(target) + QDir::separator() + targetInfo.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;
|
|
|
|
|
2020-01-02 19:27:40 +03:00
|
|
|
if (!cnf->targets().contains(target)) {
|
2019-12-11 18:06:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
2019-12-14 17:38:43 +03:00
|
|
|
auto distro = cnf->getDistro(target);
|
2019-12-11 18:06:54 +03:00
|
|
|
|
2021-01-08 22:02:50 +03:00
|
|
|
QFileInfo targetInfo(target);
|
|
|
|
|
|
|
|
QString content;
|
|
|
|
auto runScript = cnf->getRunScript(targetInfo.fileName());
|
|
|
|
if (runScript.size()) {
|
|
|
|
auto script = QFile(runScript);
|
|
|
|
if (!script.open(QIODevice::ReadOnly)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
content = script.readAll();
|
|
|
|
script.close();
|
|
|
|
|
2019-09-15 17:38:47 +03:00
|
|
|
} else {
|
2021-01-11 19:15:50 +03:00
|
|
|
|
|
|
|
auto systemLibsDir = distro.getLibOutDir() + DeployCore::systemLibsFolderName();
|
|
|
|
|
2021-01-08 22:02:50 +03:00
|
|
|
content =
|
|
|
|
"#!/bin/sh\n"
|
|
|
|
"BASE_DIR=$(dirname \"$(readlink -f \"$0\")\")\n"
|
|
|
|
"export "
|
2021-01-11 19:15:50 +03:00
|
|
|
"LD_LIBRARY_PATH=\"$BASE_DIR\"" + distro.getLibOutDir() + ":\"$BASE_DIR\":$LD_LIBRARY_PATH:" + systemLibsDir + "\n"
|
2021-01-08 22:02:50 +03:00
|
|
|
"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"
|
|
|
|
"export QTDIR=\"$BASE_DIR\"\n"
|
|
|
|
"export "
|
|
|
|
"QT_QPA_PLATFORM_PLUGIN_PATH=\"$BASE_DIR\"" + distro.getPluginsOutDir() +
|
|
|
|
"platforms:$QT_QPA_PLATFORM_PLUGIN_PATH\n"
|
|
|
|
"%2"
|
|
|
|
"%3\n"
|
|
|
|
"\"$BASE_DIR" + distro.getBinOutDir() + "%1\" \"$@\"\n";
|
|
|
|
|
|
|
|
content = content.arg(targetInfo.fileName());
|
|
|
|
auto deployedFies = _fileManager->getDeployedFilesStringList();
|
|
|
|
int ld_index = DeployCore::find("ld-linux", deployedFies);
|
|
|
|
|
|
|
|
if (ld_index >= 0 && QuasarAppUtils::Params::isEndable("deploySystem-with-libc")) {
|
|
|
|
|
|
|
|
content = content.arg(QString("\nexport LD_PRELOAD=\"$BASE_DIR\"" + distro.getLibOutDir() + "%0\n").
|
|
|
|
arg(QFileInfo(deployedFies[ld_index]).fileName()));
|
|
|
|
} else {
|
|
|
|
content = content.arg("");
|
|
|
|
}
|
|
|
|
|
|
|
|
content = content.arg(generateCustoScriptBlok(false));
|
2019-09-15 17:38:47 +03:00
|
|
|
|
2021-01-08 22:02:50 +03:00
|
|
|
}
|
2019-12-27 12:51:03 +03:00
|
|
|
|
2021-01-08 22:02:50 +03:00
|
|
|
QString fname = DeployCore::_config->getTargetDir(target) + QDir::separator() + targetInfo.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);
|
|
|
|
}
|
|
|
|
|
2019-12-27 12:51:03 +03:00
|
|
|
QString MetaFileManager::generateCustoScriptBlok(bool bat) const {
|
|
|
|
QString res = "";
|
|
|
|
|
|
|
|
QString commentMarker = "# ";
|
|
|
|
if (bat) {
|
|
|
|
commentMarker = ":: ";
|
|
|
|
}
|
|
|
|
|
|
|
|
auto cstSh = QuasarAppUtils::Params::getStrArg("customScript", "");
|
|
|
|
if (cstSh.size()) {
|
|
|
|
res = "\n" +
|
|
|
|
commentMarker + "Begin Custom Script (generated by customScript flag)\n"
|
|
|
|
"%0\n" +
|
|
|
|
commentMarker + "End Custom Script\n"
|
|
|
|
"\n";
|
|
|
|
|
|
|
|
res = res.arg(cstSh);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-09-15 17:38:47 +03:00
|
|
|
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;
|
|
|
|
|
2020-01-02 19:27:40 +03:00
|
|
|
if (!cnf->targets().contains(target)) {
|
2019-12-11 18:06:54 +03:00
|
|
|
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"
|
2020-03-19 16:36:54 +03:00
|
|
|
"Prefix= ." + distro.getRootDir(distro.getBinOutDir()) + "\n"
|
2019-12-11 18:06:54 +03:00
|
|
|
"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() {
|
|
|
|
|
2020-01-02 19:27:40 +03:00
|
|
|
for (auto i = DeployCore::_config->targets().cbegin(); i != DeployCore::_config->targets().cend(); ++i) {
|
2019-09-15 17:38:47 +03:00
|
|
|
|
2019-11-13 18:18:44 +03:00
|
|
|
if (!createRunScript(i.key())) {
|
2020-04-04 15:43:46 +03:00
|
|
|
QuasarAppUtils::Params::log("run script not created!",
|
|
|
|
QuasarAppUtils::Error);
|
2019-09-15 17:38:47 +03:00
|
|
|
}
|
|
|
|
|
2019-12-11 18:06:54 +03:00
|
|
|
if (!createQConf(i.key())) {
|
2020-04-04 15:43:46 +03:00
|
|
|
QuasarAppUtils::Params::log("create qt.conf failr", QuasarAppUtils::Warning);
|
2019-12-11 18:06:54 +03:00
|
|
|
}
|
2019-09-15 17:38:47 +03:00
|
|
|
}
|
|
|
|
}
|