mirror of
https://github.com/QuasarApp/CQtDeployer.git
synced 2025-04-27 02:04:33 +00:00
added tests for PE and ELF deployers
This commit is contained in:
parent
f27c40b931
commit
cda6172fa2
@ -42,16 +42,16 @@ include('$$PWD/../QuasarAppLib/QuasarLib.pri')
|
||||
SOURCES += \
|
||||
deploy.cpp \
|
||||
deployutils.cpp \
|
||||
windependenciesscanner.cpp \
|
||||
pe.cpp \
|
||||
igetlibinfo.cpp \
|
||||
structs.cpp
|
||||
structs.cpp \
|
||||
dependenciesscanner.cpp
|
||||
|
||||
HEADERS += \
|
||||
deploy.h \
|
||||
deploy_global.h \
|
||||
deployutils.h \
|
||||
windependenciesscanner.h\
|
||||
pe.h \
|
||||
igetlibinfo.h \
|
||||
structs.h
|
||||
structs.h \
|
||||
dependenciesscanner.h
|
||||
|
@ -5,21 +5,46 @@
|
||||
* of this license document, but changing it is not allowed.
|
||||
*/
|
||||
|
||||
#include "windependenciesscanner.h"
|
||||
#include "dependenciesscanner.h"
|
||||
#include "deployutils.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
|
||||
WinDependenciesScanner::WinDependenciesScanner() {}
|
||||
DependenciesScanner::DependenciesScanner() {}
|
||||
|
||||
|
||||
bool WinDependenciesScanner::fillLibInfo(LibInfo &info, const QString &file) {
|
||||
PrivateScaner DependenciesScanner::getScaner(const QString &lib) const {
|
||||
|
||||
QFileInfo info(lib);
|
||||
|
||||
auto sufix = info.completeSuffix();
|
||||
|
||||
if (sufix.contains("dll", Qt::CaseSensitive) ||
|
||||
sufix.contains("exe", Qt::CaseSensitive)) {
|
||||
return PrivateScaner::PE;
|
||||
} else if (sufix.isEmpty() || sufix.contains("so", Qt::CaseSensitive)) {
|
||||
return PrivateScaner::ELF;
|
||||
}
|
||||
|
||||
return PrivateScaner::UNKNOWN;
|
||||
}
|
||||
|
||||
void WinDependenciesScanner::setEnvironment(const QStringList &env) {
|
||||
bool DependenciesScanner::fillLibInfo(LibInfo &info, const QString &file) {
|
||||
|
||||
auto scaner = getScaner(file);
|
||||
|
||||
switch (scaner) {
|
||||
case PrivateScaner::PE: {
|
||||
return _peScaner.getLibInfo(file, info);
|
||||
}
|
||||
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
void DependenciesScanner::setEnvironment(const QStringList &env) {
|
||||
QDir dir;
|
||||
for (auto i : env) {
|
||||
|
||||
@ -44,18 +69,12 @@ void WinDependenciesScanner::setEnvironment(const QStringList &env) {
|
||||
|
||||
}
|
||||
|
||||
QStringList WinDependenciesScanner::scan(const QString &path, Platform platfr,
|
||||
const QString& qmake) {
|
||||
QStringList DependenciesScanner::scan(const QString &path) {
|
||||
QStringList result;
|
||||
|
||||
QString errorMessage;
|
||||
|
||||
if (platfr == Platform::UnknownPlatform) {
|
||||
|
||||
}
|
||||
|
||||
QStringList dep;
|
||||
// readExecutable(path, platfr, &errorMessage, &dep);
|
||||
|
||||
if (!errorMessage.isEmpty()) {
|
||||
qCritical() << errorMessage;
|
||||
@ -72,6 +91,6 @@ QStringList WinDependenciesScanner::scan(const QString &path, Platform platfr,
|
||||
return result;
|
||||
}
|
||||
|
||||
WinDependenciesScanner::~WinDependenciesScanner() {
|
||||
DependenciesScanner::~DependenciesScanner() {
|
||||
|
||||
}
|
@ -12,24 +12,36 @@
|
||||
#include <QStringList>
|
||||
#include "deploy_global.h"
|
||||
#include "structs.h"
|
||||
#include "pe.h"
|
||||
|
||||
enum class PrivateScaner: unsigned char {
|
||||
UNKNOWN,
|
||||
PE,
|
||||
ELF
|
||||
};
|
||||
|
||||
class DEPLOYSHARED_EXPORT DependenciesScanner {
|
||||
|
||||
|
||||
class DEPLOYSHARED_EXPORT WinDependenciesScanner {
|
||||
private:
|
||||
QStringList _env;
|
||||
QMap<QString, QString> _EnvLibs;
|
||||
|
||||
PE _peScaner;
|
||||
|
||||
PrivateScaner getScaner(const QString& lib) const;
|
||||
|
||||
bool fillLibInfo(LibInfo& info ,const QString& file);
|
||||
public:
|
||||
explicit WinDependenciesScanner();
|
||||
explicit DependenciesScanner();
|
||||
|
||||
void setEnvironment(const QStringList &env);
|
||||
|
||||
QStringList scan(const QString& path,
|
||||
Platform platfr = UnknownPlatform,
|
||||
const QString &qmake = "qmake");
|
||||
QStringList scan(const QString& path);
|
||||
|
||||
~WinDependenciesScanner();
|
||||
~DependenciesScanner();
|
||||
|
||||
friend class deploytest;
|
||||
};
|
||||
|
||||
#endif // WINDEPENDENCIESSCANNER_H
|
@ -613,7 +613,7 @@ QString Deploy::filterQmlPath(const QString &path) {
|
||||
void Deploy::extractLib(const QString &file, bool isExtractPlugins) {
|
||||
qInfo() << "extract lib :" << file;
|
||||
|
||||
auto data = winScaner.scan(file, Platform::UnknownPlatform, qmake);
|
||||
auto data = winScaner.scan(file);
|
||||
|
||||
for (QString &line : data) {
|
||||
line = line.simplified();
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <QSettings>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <windependenciesscanner.h>
|
||||
#include <dependenciesscanner.h>
|
||||
#include "deploy_global.h"
|
||||
|
||||
class DEPLOYSHARED_EXPORT Deploy {
|
||||
@ -45,7 +45,7 @@ class DEPLOYSHARED_EXPORT Deploy {
|
||||
|
||||
QString appDir;
|
||||
|
||||
WinDependenciesScanner winScaner;
|
||||
DependenciesScanner winScaner;
|
||||
|
||||
bool fileActionPrivate(const QString &file, const QString &target,
|
||||
QStringList *mask, bool isMove);
|
||||
|
@ -1 +1,2 @@
|
||||
#include "igetlibinfo.h"
|
||||
|
||||
|
@ -7,7 +7,7 @@ class IGetLibInfo
|
||||
{
|
||||
public:
|
||||
IGetLibInfo() = default;
|
||||
virtual LibInfo &&getLibInfo(const QString& lib) = 0;
|
||||
virtual bool getLibInfo(const QString& lib, LibInfo& info) = 0;
|
||||
virtual ~IGetLibInfo() = default;
|
||||
|
||||
};
|
||||
|
@ -132,12 +132,11 @@ PE::PE(): IGetLibInfo () {
|
||||
|
||||
}
|
||||
|
||||
LibInfo &&PE::getLibInfo(const QString &lib) {
|
||||
LibInfo info;
|
||||
bool PE::getLibInfo(const QString &lib, LibInfo &info) {
|
||||
LIB_META_INFO meta;
|
||||
|
||||
if (!fillMetaInfo(meta, lib)) {
|
||||
return std::move(info);
|
||||
return false;
|
||||
}
|
||||
|
||||
info.name = QFileInfo(lib).fileName();
|
||||
@ -153,7 +152,7 @@ LibInfo &&PE::getLibInfo(const QString &lib) {
|
||||
|
||||
dependecies(info.dependncies, lib, &meta);
|
||||
|
||||
return std::move(info);
|
||||
return info.isValid();
|
||||
}
|
||||
|
||||
PE::~PE(){
|
||||
|
@ -44,7 +44,7 @@ public:
|
||||
const LIB_META_INFO *info = nullptr);
|
||||
PE();
|
||||
|
||||
LibInfo &&getLibInfo(const QString& lib) override;
|
||||
bool getLibInfo(const QString& lib, LibInfo& info) override;
|
||||
|
||||
~PE() override;
|
||||
|
||||
|
@ -8,3 +8,8 @@ bool LibInfo::operator ==(const LibInfo &other) {
|
||||
QString LibInfo::fullPath() {
|
||||
return path + "/" + name;
|
||||
}
|
||||
|
||||
bool LibInfo::isValid() const {
|
||||
return platform != Platform::UnknownPlatform &&
|
||||
name.size() && path.size();
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ struct LibInfo {
|
||||
bool operator == (const LibInfo& other);
|
||||
|
||||
QString fullPath();
|
||||
|
||||
bool isValid() const;
|
||||
};
|
||||
|
||||
#endif // LIBINFO_H
|
||||
|
@ -23,7 +23,11 @@ CONFIG -= app_bundle
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
SOURCES += tst_deploytest.cpp
|
||||
SOURCES += tst_deploytest.cpp \
|
||||
libcreator.cpp
|
||||
|
||||
RESOURCES += \
|
||||
res.qrc
|
||||
|
||||
HEADERS += \
|
||||
libcreator.h
|
||||
|
196
UnitTests/libcreator.cpp
Normal file
196
UnitTests/libcreator.cpp
Normal file
@ -0,0 +1,196 @@
|
||||
#include "libcreator.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <dependenciesscanner.h>
|
||||
|
||||
const QMap<QString, Platform> &LibCreator::getLibplatform() const {
|
||||
return libplatform;
|
||||
}
|
||||
|
||||
void LibCreator::createLib(const QString &resLib,
|
||||
const QStringList &dep,
|
||||
Platform platform) {
|
||||
QFile lib(resLib);
|
||||
|
||||
if (lib.open(QIODevice::ReadOnly)) {
|
||||
|
||||
QFile target(path + "/" + QFileInfo(resLib).fileName());
|
||||
|
||||
if (target.open(QIODevice::ReadWrite)) {
|
||||
|
||||
auto data = lib.readAll();
|
||||
target.write(data.data(), data.size());
|
||||
|
||||
target.close();
|
||||
|
||||
copyedLibs.push_back(target.fileName());
|
||||
libDep.insert(resLib, dep);
|
||||
libplatform.insert(resLib, platform);
|
||||
}
|
||||
|
||||
lib.close();
|
||||
}
|
||||
}
|
||||
|
||||
void LibCreator::initLinux64() {
|
||||
createLib(":/linux64", {
|
||||
"libQuasarApp.so.1",
|
||||
"libServerProtocol.so.1",
|
||||
"libQt5Network.so.5",
|
||||
"libQt5Core.so.5",
|
||||
"libstdc++.so.6",
|
||||
"libgcc_s.so.1",
|
||||
"libc.so.6",
|
||||
"libgcc_s.so.1",
|
||||
"libQt5Core.so.5",
|
||||
"libc.so.6",
|
||||
"libQt5Network.so.5",
|
||||
"libstdc++.so.6:",
|
||||
},
|
||||
Platform::Unix);
|
||||
createLib(":/linux64.so", {
|
||||
"libQt5Core.so.5",
|
||||
"libpthread.so.0",
|
||||
"libstdc++.so.6",
|
||||
"libm.so.6",
|
||||
"libgcc_s.so.1",
|
||||
"libc.so.6",
|
||||
"libSignalProcessorCommon.so.1",
|
||||
"libc.so.6",
|
||||
"libQt5Core.so.5",
|
||||
},
|
||||
Platform::Unix);
|
||||
|
||||
}
|
||||
|
||||
void LibCreator::initWin32() {
|
||||
createLib(":/win32mingw.dll", {
|
||||
"libEGL.dll",
|
||||
"libgcc_s_dw2-1.dll",
|
||||
"KERNEL32.dll",
|
||||
"msvcrt.dll",
|
||||
"libGLESv2.dll",
|
||||
},
|
||||
Platform::Win32 );
|
||||
createLib(":/win32mingw.exe",{
|
||||
" Qt5Core.dll",
|
||||
" Qt5Gui.dll",
|
||||
" Qt5Qml.dll",
|
||||
" Qt5Widgets.dll",
|
||||
" libgcc_s_dw2-1.dll",
|
||||
" KERNEL32.dll",
|
||||
" msvcrt.dll",
|
||||
" SHELL32.dll",
|
||||
" libstdc++-6.dll",
|
||||
},
|
||||
Platform::Win32
|
||||
);
|
||||
createLib(":/win32msvc.dll",{
|
||||
"ole32.dll",
|
||||
"OLEAUT32.dll",
|
||||
"WINMM.dll",
|
||||
"Qt5Multimedia.dll",
|
||||
"Qt5Core.dll",
|
||||
"MSVCP120.dll",
|
||||
"MSVCR120.dll",
|
||||
"KERNEL32.dll",
|
||||
},
|
||||
Platform::Win32);
|
||||
createLib(":/win32msvc.exe", {
|
||||
"Qt5Core.dll",
|
||||
"ViewFortis.dll",
|
||||
"PocketProtocols.dll",
|
||||
"ModelsFortis.dll",
|
||||
"CommonBase.dll",
|
||||
"Services.dll",
|
||||
"SettingsMain.dll",
|
||||
"CommonUtils.dll",
|
||||
"CommonServices.dll",
|
||||
"PFDF_Services.dll",
|
||||
"DronTestControllers.dll",
|
||||
"DronTestView.dll",
|
||||
"DronTestModel.dll",
|
||||
"DronTestSettings.dll",
|
||||
"DronesProfiles.dll",
|
||||
"Qt5Widgets.dll",
|
||||
"Qt5Gui.dll",
|
||||
"MSVCP120.dll",
|
||||
"MSVCR120.dll",
|
||||
"KERNEL32.dll",
|
||||
"SHELL32.dll",
|
||||
|
||||
},
|
||||
Platform::Win32);
|
||||
|
||||
}
|
||||
|
||||
void LibCreator::initWin64() {
|
||||
createLib(":/win64mingw.dll", {
|
||||
"QuasarApp1.dll",
|
||||
"Qt5Core.dll",
|
||||
"libgcc_s_seh-1.dll",
|
||||
"KERNEL32.dll",
|
||||
"msvcrt.dll",
|
||||
"SHLWAPI.dll",
|
||||
"libstdc++-6.dll",
|
||||
},
|
||||
Platform::Win64);
|
||||
createLib(":/win64mingw.exe", {
|
||||
"Deploy.dll",
|
||||
"QuasarApp1.dll",
|
||||
"Qt5Core.dll",
|
||||
"libgcc_s_seh-1.dll",
|
||||
"KERNEL32.dll",
|
||||
"msvcrt.dll",
|
||||
"libstdc++-6.dll",
|
||||
},
|
||||
Platform::Win64);
|
||||
createLib(":/win64msvc.dll", {
|
||||
"Qt5Core.dll",
|
||||
"MSVCP140.dll",
|
||||
"KERNEL32.dll",
|
||||
"VCRUNTIME140.dll",
|
||||
"api-ms-win-crt-runtime-l1-1-0.dll",
|
||||
"api-ms-win-crt-heap-l1-1-0.dll",
|
||||
},
|
||||
Platform::Win64);
|
||||
createLib(":/win64msvc.exe", {
|
||||
"NetworkServiceEngine.dll",
|
||||
"qtservice.dll",
|
||||
"Qt5Core.dll",
|
||||
"KERNEL32.dll",
|
||||
"VCRUNTIME140.dll",
|
||||
"api-ms-win-crt-heap-l1-1-0.dll",
|
||||
"api-ms-win-crt-runtime-l1-1-0.dll",
|
||||
"api-ms-win-crt-math-l1-1-0.dll",
|
||||
"api-ms-win-crt-stdio-l1-1-0.dll",
|
||||
"api-ms-win-crt-locale-l1-1-0.dll",
|
||||
},
|
||||
Platform::Win64);
|
||||
|
||||
}
|
||||
|
||||
LibCreator::LibCreator(const QString &path) {
|
||||
|
||||
this->path = path;
|
||||
initWin32();
|
||||
initWin64();
|
||||
//initLinux64();
|
||||
}
|
||||
|
||||
const QStringList &LibCreator::getLibs() const {
|
||||
return copyedLibs;
|
||||
}
|
||||
|
||||
const QMap<QString, QStringList>& LibCreator::getLibsDep() const {
|
||||
return libDep;
|
||||
}
|
||||
|
||||
LibCreator::~LibCreator() {
|
||||
|
||||
for(auto &&lib : copyedLibs) {
|
||||
QFile::remove(lib);
|
||||
}
|
||||
|
||||
}
|
30
UnitTests/libcreator.h
Normal file
30
UnitTests/libcreator.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef LIBCREATOR_H
|
||||
#define LIBCREATOR_H
|
||||
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <dependenciesscanner.h>
|
||||
|
||||
class LibCreator
|
||||
{
|
||||
private:
|
||||
QString path;
|
||||
QStringList copyedLibs;
|
||||
|
||||
QMap<QString, QStringList> libDep;
|
||||
QMap<QString, Platform> libplatform;
|
||||
void createLib(const QString& resLib, const QStringList& dep, Platform platform);
|
||||
|
||||
void initLinux64();
|
||||
void initWin32();
|
||||
void initWin64();
|
||||
public:
|
||||
LibCreator(const QString& path);
|
||||
const QStringList &getLibs() const;
|
||||
const QMap<QString, QStringList>& getLibsDep() const;
|
||||
~LibCreator();
|
||||
const QMap<QString, Platform>& getLibplatform() const;
|
||||
};
|
||||
|
||||
#endif // LIBCREATOR_H
|
@ -1,5 +1,15 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file alias="debugLib">testRes/debugLibData</file>
|
||||
<file alias="linux64.so">testRes/Unix/lib.so.1</file>
|
||||
<file alias="linux64">testRes/Unix/Start</file>
|
||||
<file alias="win32mingw.exe">testRes/win32/mingw/hanoi-towers.exe</file>
|
||||
<file alias="win32mingw.dll">testRes/win32/mingw/libEGL.dll</file>
|
||||
<file alias="win32msvc.dll">testRes/win32/msvc/qtaudio_windows.dll</file>
|
||||
<file alias="win32msvc.exe">testRes/win32/msvc/TestStart.exe</file>
|
||||
<file alias="win64mingw.exe">testRes/win64/mingw/cqtdeployer.exe</file>
|
||||
<file alias="win64mingw.dll">testRes/win64/mingw/Deploy.dll</file>
|
||||
<file alias="win64msvc.exe">testRes/win64/msvc/exe.exe</file>
|
||||
<file alias="win64msvc.dll">testRes/win64/msvc/lib.dll</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
Binary file not shown.
@ -9,11 +9,13 @@
|
||||
#include <quasarapp.h>
|
||||
#include <deployutils.h>
|
||||
#include <deploy.h>
|
||||
#include <windependenciesscanner.h>
|
||||
#include <dependenciesscanner.h>
|
||||
|
||||
#include <QMap>
|
||||
#include <QByteArray>
|
||||
#include <QDir>
|
||||
#include <thread>
|
||||
#include "libcreator.h"
|
||||
// add necessary includes here
|
||||
|
||||
class deploytest : public QObject
|
||||
@ -40,6 +42,7 @@ private slots:
|
||||
void testTranslations();
|
||||
void testStrip();
|
||||
void testDeploy();
|
||||
void testExtractLib();
|
||||
|
||||
};
|
||||
|
||||
@ -283,6 +286,29 @@ void deploytest::testDeploy()
|
||||
delete deploy;
|
||||
}
|
||||
|
||||
void deploytest::testExtractLib() {
|
||||
LibCreator creator("./");
|
||||
auto libs = creator.getLibs();
|
||||
auto deb = creator.getLibsDep();
|
||||
auto platforms = creator.getLibplatform();
|
||||
|
||||
DependenciesScanner scaner;
|
||||
|
||||
LibInfo info;
|
||||
|
||||
for (auto &&lib : libs) {
|
||||
QVERIFY(scaner.fillLibInfo(info, lib));
|
||||
QVERIFY(info.isValid());
|
||||
QVERIFY(info.name == QFileInfo(lib).fileName());
|
||||
QVERIFY(info.path == QFileInfo(lib).absolutePath());
|
||||
QVERIFY(info.fullPath() == QFileInfo(lib).absoluteFilePath());
|
||||
QVERIFY(info.platform == platforms.value(lib));
|
||||
QVERIFY(info.dependncies == deb.value(lib));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void deploytest::testTranslations() {
|
||||
QStringList trList = {
|
||||
("./test/QtDir/translations/qtbase_ru.qm"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user