fix beta tests bugs

* fix config file pathes
* fixed clear mode
* removed extra information on deploy and info modes
* added help for configFile
This commit is contained in:
Andrei Yankovich 2019-09-29 18:14:41 +03:00
parent 2257288cd1
commit df994058bd
10 changed files with 219 additions and 67 deletions

View File

@ -54,6 +54,7 @@ SOURCES += \
filemanager.cpp \
ignorerule.cpp \
metafilemanager.cpp \
pathutils.cpp \
pe.cpp \
igetlibinfo.cpp \
dependenciesscanner.cpp \
@ -74,6 +75,7 @@ HEADERS += \
filemanager.h \
ignorerule.h \
metafilemanager.h \
pathutils.h \
pe.h \
igetlibinfo.h \
dependenciesscanner.h \

View File

@ -12,6 +12,7 @@
#include <QProcess>
#include "deploycore.h"
#include "filemanager.h"
#include "pathutils.h"
#include "quasarapp.h"
bool ConfigParser::parseParams() {
@ -75,7 +76,7 @@ const DeployConfig *ConfigParser::config() const {
return &_config;
}
void ConfigParser::writeKey(const QString& key, QJsonObject& obj) const {
void ConfigParser::writeKey(const QString& key, QJsonObject& obj, const QString& confFileDir) const {
if (QuasarAppUtils::Params::isEndable(key)) {
auto list = QuasarAppUtils::Params::getStrArg(key).split(',');
@ -85,6 +86,12 @@ void ConfigParser::writeKey(const QString& key, QJsonObject& obj) const {
for (auto &i: list) {
QJsonValue val;
val = i;
if (PathUtils::isPath(i)) {
val = PathUtils::getRelativeLink(
QFileInfo(confFileDir).absoluteFilePath(),
QFileInfo(i).absoluteFilePath());
}
array.push_back(val);
}
@ -93,13 +100,24 @@ void ConfigParser::writeKey(const QString& key, QJsonObject& obj) const {
if (list.size() && list.first().isEmpty()) {
obj[key] = QJsonValue(true);
} else {
obj[key] = list.first();
auto val = list.first();
if (PathUtils::isPath(val)) {
val = PathUtils::getRelativeLink(
QFileInfo(confFileDir).absoluteFilePath(),
QFileInfo(val).absoluteFilePath());
}
obj[key] = val;
}
}
}
}
void ConfigParser::readKey(const QString& key, const QJsonObject& obj) const {
void ConfigParser::readKey(const QString& key, const QJsonObject& obj,
const QString& confFileDir) const {
if (!QuasarAppUtils::Params::isEndable(key)) {
if (obj[key].isArray()) {
@ -108,8 +126,15 @@ void ConfigParser::readKey(const QString& key, const QJsonObject& obj) const {
for (QJsonValue i : array) {
QString val = i.toString();
if (!val.isEmpty()) {
list.push_back(val);
if (PathUtils::isPath(val)) {
list.push_back(
QFileInfo(confFileDir + '/' + val).absoluteFilePath());
} else {
list.push_back(val);
}
}
}
@ -118,9 +143,15 @@ void ConfigParser::readKey(const QString& key, const QJsonObject& obj) const {
} else if (!obj[key].isUndefined()) {
QString val = obj[key].toString();
if (!val.isEmpty()) {
if (PathUtils::isPath(val)) {
val = QFileInfo(confFileDir + '/' + val).absoluteFilePath();
}
QuasarAppUtils::Params::setArg(key, val);
} else {
QuasarAppUtils::Params::setEnable(key, true);
auto value = obj[key].toBool(true);
QuasarAppUtils::Params::setEnable(key, value);
}
}
@ -131,7 +162,7 @@ bool ConfigParser::createFromDeploy(const QString& confFile) const {
QJsonObject obj;
for (auto &key :DeployCore::helpKeys()) {
writeKey(key, obj);
writeKey(key, obj, QFileInfo(confFile).absolutePath());
}
QJsonDocument doc(obj);
@ -151,6 +182,7 @@ bool ConfigParser::createFromDeploy(const QString& confFile) const {
bool ConfigParser::loadFromFile(const QString& confFile) {
QFile file(confFile);
QString confFilePath = QFileInfo(confFile).absolutePath();
if (file.open(QIODevice::ReadOnly)) {
auto doc = QJsonDocument::fromJson(file.readAll());
@ -162,7 +194,7 @@ bool ConfigParser::loadFromFile(const QString& confFile) {
auto obj = doc.object();
for (auto &key: obj.keys()) {
readKey(key, obj);
readKey(key, obj, confFilePath);
}
file.close();

View File

@ -84,9 +84,9 @@ private:
QStringList getDirsRecursive(const QString &path, int maxDepch = -1, int depch = 0);
void writeKey(const QString &key, QJsonObject &) const;
void readKey(const QString &key, const QJsonObject &obj) const;
QString getRelativeLink(const QString& from, const QString& to);
void writeKey(const QString &key, QJsonObject &, const QString &confFileDir) const;
void readKey(const QString &key, const QJsonObject &obj, const QString &confFileDir) const;
public:
ConfigParser(FileManager *filemanager);
bool parseParams();

View File

@ -164,6 +164,10 @@ QString DeployCore::help() {
{ " noOverwrite : Prevents replacing existing files." },
{ " -bin [list, params] : Deployable file or folder." },
{ " | For example -bin /my/project/bin/,/my/project/bin.exe" },
{ " -confFile [params] | The path to the json file with all deployment configurations."},
{ " : Using this file, you can add the necessary options,"},
{ " : thereby simplifying the command invocation in the console."},
{ " : However, the parameters in Kansol have a higher priority than in the file."},
{ " -binDir [params] : A folder which includes deployable files (recursive search)." },
{ " | WARNING: this flag supports 'so', 'dll' and 'exe' files only." },
{ " | Use '-bin' flag if you want to deploy linux binary files" },
@ -227,6 +231,11 @@ QStringList DeployCore::helpKeys() {
"targetDir",
"noStrip",
"noTranslations",
"qmlOut",
"libOut",
"trOut",
"pluginOut",
"binOut",
"version",
"verbose"
};
@ -282,10 +291,6 @@ bool DeployCore::isLib(const QFileInfo &file) {
|| file.completeSuffix().contains("dll", Qt::CaseInsensitive);
}
bool DeployCore::isPath(const QString &path) {
return path.contains('/') || path.contains('\\');
}
MSVCVersion DeployCore::getMSVC(const QString &_qmake) {
QFileInfo qmake(_qmake);

View File

@ -146,7 +146,6 @@ public:
static void printVersion();
static int find(const QString &str, const QStringList &list);
static bool isLib(const QFileInfo &file);
static bool isPath(const QString& path);
static bool isExecutable(const QFileInfo &file);
};

View File

@ -7,6 +7,7 @@
//#
#include "distrostruct.h"
#include "pathutils.h"
#include <quasarapp.h>
QString DistroStruct::getLibOutDir(const QString &basePath) const {
@ -82,59 +83,15 @@ void DistroStruct::init() {
}
QString DistroStruct::toFullPath(QString path) const {
path.replace('\\', '/');
int index = -1;
do {
path.replace("//", "/");
} while ((index = path.indexOf("//")) >= 0);
if (path.left(1) != '/') {
path.insert(0, '/');
}
if (path.right(1) != '/') {
path.insert(path.size(), '/');
}
return path;
return PathUtils::toFullPath(path);
}
QString DistroStruct::stripPath(QString path) const {
path.replace('\\', '/');
int index = -1;
do {
path.replace("//", "/");
} while ((index = path.indexOf("//")) >= 0);
if (path.left(1) == '/') {
path = path.right(path.size() - 1);
}
if (path.right(1) != '/') {
path = path.left(path.size() - 1);
}
return path;
return PathUtils::stripPath(path);
}
QString DistroStruct::getRelativePath(QString path) const {
path = toFullPath(path);
int left = path.indexOf('/', 0) + 1;
int righy = path.indexOf('/', left);
while (righy > 0) {
path.replace(left, righy - left, "..");
left = left + 3;
righy = path.indexOf('/', left);
}
return path;
return PathUtils::getReleativePath(path);
}
DistroStruct::DistroStruct() {

View File

@ -10,6 +10,7 @@
#include "pluginsparser.h"
#include "configparser.h"
#include "metafilemanager.h"
#include "pathutils.h"
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
@ -84,7 +85,7 @@ void Extracter::copyExtraPlugins() {
for (auto extraPlugin : DeployCore::_config->extraPlugins) {
if (!DeployCore::isPath(extraPlugin)) {
if (!PathUtils::isPath(extraPlugin)) {
extraPlugin = DeployCore::_config->qtDir + "/plugins/" + extraPlugin;
}

100
Deploy/pathutils.cpp Normal file
View File

@ -0,0 +1,100 @@
//#
//# Copyright (C) 2018-2019 QuasarApp.
//# Distributed under the lgplv3 software license, see the accompanying
//# Everyone is permitted to copy and distribute verbatim copies
//# of this license document, but changing it is not allowed.
//#
#include "pathutils.h"
#include <QFileInfo>
PathUtils::PathUtils()
{
}
QString PathUtils::toFullPath(QString path) {
path.replace('\\', '/');
int index = -1;
do {
path.replace("//", "/");
} while ((index = path.indexOf("//")) >= 0);
if (path.left(1) != '/') {
path.insert(0, '/');
}
if (path.right(1) != '/') {
path.insert(path.size(), '/');
}
return path;
}
QString PathUtils::getRelativeLink(QString from, QString to) {
bool isFile = QFileInfo(to).isFile();
from = toFullPath(from);
to = toFullPath(to);
int lastGeneralDir = 0;
int index = 0;
while (from.size() > index && to.size() > index && from[index] == to[index]) {
if (from[index] == '/') {
lastGeneralDir = index;
}
index++;
}
auto result = "." + getReleativePath(from.mid(lastGeneralDir)) +
to.mid(lastGeneralDir + 1);
if (isFile && result.right(1) == '/')
result = result.left(result.size() - 1);
return result;
}
// TODO ignore labels may be mistaken for a path, which will lead to improper eating
bool PathUtils::isPath(const QString &path) {
return path.contains('/') || path.contains('\\') || path == ".";
}
QString PathUtils::getReleativePath(QString path) {
path = toFullPath(path);
int left = path.indexOf('/', 0) + 1;
int righy = path.indexOf('/', left);
while (righy > 0) {
path.replace(left, righy - left, "..");
left = left + 3;
righy = path.indexOf('/', left);
}
return path;
}
QString PathUtils::stripPath(QString path) {
path.replace('\\', '/');
int index = -1;
do {
path.replace("//", "/");
} while ((index = path.indexOf("//")) >= 0);
if (path.left(1) == '/') {
path = path.right(path.size() - 1);
}
if (path.right(1) == '/') {
path = path.left(path.size() - 1);
}
return path;
}

28
Deploy/pathutils.h Normal file
View File

@ -0,0 +1,28 @@
//#
//# Copyright (C) 2018-2019 QuasarApp.
//# Distributed under the lgplv3 software license, see the accompanying
//# Everyone is permitted to copy and distribute verbatim copies
//# of this license document, but changing it is not allowed.
//#
#include <QString>
#ifndef PATHUTILS_H
#define PATHUTILS_H
/**
* @brief The PathUtils class
*
*/
class PathUtils
{
public:
PathUtils();
static QString toFullPath(QString path);
static QString getReleativePath(QString path);
static QString stripPath(QString path) ;
static QString getRelativeLink(QString from, QString to);
static bool isPath(const QString &path);
};
#endif // PATHUTILS_H

View File

@ -15,6 +15,7 @@
#include <configparser.h>
#include <QCryptographicHash>
#include <distrostruct.h>
#include <pathutils.h>
#include <QMap>
#include <QByteArray>
@ -67,6 +68,7 @@ private slots:
void testStrip();
void testExtractLib();
void testDistroStruct();
void testRelativeLink();
void testQmlExtrct();
void testSetTargetDir();
@ -571,6 +573,21 @@ void deploytest::testDistroStruct() {
}
}
void deploytest::testRelativeLink() {
auto cases = QList<QList<QString>>{
{"", "", "./"},
{"/media", "/etc", "./../etc/"},
{"/media///", "/etc///", "./../etc/"},
{"/media/etc/usr", "/media/etc", "./../"},
{"/media/etc", "/media/etc/usr", "./usr/"},
};
for (auto &i: cases) {
QVERIFY(PathUtils::getRelativeLink(i[0], i[1]) == i[2]);
}
}
void deploytest::testSetTargetDir() {
FileManager file;
@ -845,16 +862,27 @@ void deploytest::testConfFile() {
doc = doc.fromJson(data);
QVERIFY(!doc.isNull());
#ifdef Q_OS_UNIX
QVERIFY(!doc.isNull());
QVERIFY(data.contains("\"bin\": ["));
QVERIFY(data.contains("build/TestOnlyC"));
QVERIFY(data.contains("build/QtWidgetsProject"));
QVERIFY(data.contains("build/TestQMLWidgets"));
QVERIFY(data.contains("./TestOnlyC"));
QVERIFY(data.contains("./QtWidgetsProject"));
QVERIFY(data.contains("./TestQMLWidgets"));
QVERIFY(data.contains("\"clear\": true"));
#ifdef Q_OS_UNIX
runTestParams({"-confFile", TestBinDir + "/TestConf.json"}, &comapareTree);
#else
QVERIFY(!doc.isNull());
QVERIFY(data.contains("\"bin\": ["));
QVERIFY(data.contains("./TestOnlyC.exe"));
QVERIFY(data.contains("./QtWidgetsProject.exe"));
QVERIFY(data.contains("./TestQMLWidgets.exe"));
QVERIFY(data.contains("\"clear\": true"));
runTestParams({"-confFile", TestBinDir + "/TestConf.json"}, &comapareTree);
#endif