diff --git a/Deploy/Deploy.pro b/Deploy/Deploy.pro index 0ba6dbd..b114a0b 100644 --- a/Deploy/Deploy.pro +++ b/Deploy/Deploy.pro @@ -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 diff --git a/Deploy/windependenciesscanner.cpp b/Deploy/dependenciesscanner.cpp similarity index 58% rename from Deploy/windependenciesscanner.cpp rename to Deploy/dependenciesscanner.cpp index ff8e9bd..12a9db4 100644 --- a/Deploy/windependenciesscanner.cpp +++ b/Deploy/dependenciesscanner.cpp @@ -5,21 +5,46 @@ * of this license document, but changing it is not allowed. */ -#include "windependenciesscanner.h" +#include "dependenciesscanner.h" #include "deployutils.h" #include #include #include -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() { } diff --git a/Deploy/windependenciesscanner.h b/Deploy/dependenciesscanner.h similarity index 64% rename from Deploy/windependenciesscanner.h rename to Deploy/dependenciesscanner.h index 7c028f1..23005f5 100644 --- a/Deploy/windependenciesscanner.h +++ b/Deploy/dependenciesscanner.h @@ -12,24 +12,36 @@ #include #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 _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 diff --git a/Deploy/deploy.cpp b/Deploy/deploy.cpp index 74e0a7b..ef26677 100644 --- a/Deploy/deploy.cpp +++ b/Deploy/deploy.cpp @@ -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(); diff --git a/Deploy/deploy.h b/Deploy/deploy.h index fd6f382..8da8892 100644 --- a/Deploy/deploy.h +++ b/Deploy/deploy.h @@ -11,7 +11,7 @@ #include #include #include -#include +#include #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); diff --git a/Deploy/igetlibinfo.cpp b/Deploy/igetlibinfo.cpp index bdecc16..25b0563 100644 --- a/Deploy/igetlibinfo.cpp +++ b/Deploy/igetlibinfo.cpp @@ -1 +1,2 @@ #include "igetlibinfo.h" + diff --git a/Deploy/igetlibinfo.h b/Deploy/igetlibinfo.h index 3ebfbdc..b02d6a4 100644 --- a/Deploy/igetlibinfo.h +++ b/Deploy/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; }; diff --git a/Deploy/pe.cpp b/Deploy/pe.cpp index d719ad0..9202380 100644 --- a/Deploy/pe.cpp +++ b/Deploy/pe.cpp @@ -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(){ diff --git a/Deploy/pe.h b/Deploy/pe.h index 484fd99..0c270f3 100644 --- a/Deploy/pe.h +++ b/Deploy/pe.h @@ -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; diff --git a/Deploy/structs.cpp b/Deploy/structs.cpp index 4902060..ce5cf5b 100644 --- a/Deploy/structs.cpp +++ b/Deploy/structs.cpp @@ -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(); +} diff --git a/Deploy/structs.h b/Deploy/structs.h index d83328a..30ac2c5 100644 --- a/Deploy/structs.h +++ b/Deploy/structs.h @@ -20,6 +20,8 @@ struct LibInfo { bool operator == (const LibInfo& other); QString fullPath(); + + bool isValid() const; }; #endif // LIBINFO_H diff --git a/UnitTests/UnitTests.pro b/UnitTests/UnitTests.pro index 8296a8a..d048bcc 100644 --- a/UnitTests/UnitTests.pro +++ b/UnitTests/UnitTests.pro @@ -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 diff --git a/UnitTests/libcreator.cpp b/UnitTests/libcreator.cpp new file mode 100644 index 0000000..8f6a5e6 --- /dev/null +++ b/UnitTests/libcreator.cpp @@ -0,0 +1,196 @@ +#include "libcreator.h" + +#include +#include +#include + +const QMap &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& LibCreator::getLibsDep() const { + return libDep; +} + +LibCreator::~LibCreator() { + + for(auto &&lib : copyedLibs) { + QFile::remove(lib); + } + +} diff --git a/UnitTests/libcreator.h b/UnitTests/libcreator.h new file mode 100644 index 0000000..7543185 --- /dev/null +++ b/UnitTests/libcreator.h @@ -0,0 +1,30 @@ +#ifndef LIBCREATOR_H +#define LIBCREATOR_H + +#include +#include +#include +#include + +class LibCreator +{ +private: + QString path; + QStringList copyedLibs; + + QMap libDep; + QMap 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& getLibsDep() const; + ~LibCreator(); + const QMap& getLibplatform() const; +}; + +#endif // LIBCREATOR_H diff --git a/UnitTests/res.qrc b/UnitTests/res.qrc index 937c581..f78e57b 100644 --- a/UnitTests/res.qrc +++ b/UnitTests/res.qrc @@ -1,5 +1,15 @@ testRes/debugLibData + testRes/Unix/lib.so.1 + testRes/Unix/Start + testRes/win32/mingw/hanoi-towers.exe + testRes/win32/mingw/libEGL.dll + testRes/win32/msvc/qtaudio_windows.dll + testRes/win32/msvc/TestStart.exe + testRes/win64/mingw/cqtdeployer.exe + testRes/win64/mingw/Deploy.dll + testRes/win64/msvc/exe.exe + testRes/win64/msvc/lib.dll diff --git a/UnitTests/testRes/Unix/Start b/UnitTests/testRes/Unix/Start index 46ea1b7..bf391bd 100755 Binary files a/UnitTests/testRes/Unix/Start and b/UnitTests/testRes/Unix/Start differ diff --git a/UnitTests/tst_deploytest.cpp b/UnitTests/tst_deploytest.cpp index 39a5508..78ce8f7 100644 --- a/UnitTests/tst_deploytest.cpp +++ b/UnitTests/tst_deploytest.cpp @@ -9,11 +9,13 @@ #include #include #include -#include +#include +#include #include #include #include +#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"),