diff --git a/Deploy/configparser.cpp b/Deploy/configparser.cpp index f5cf750..82bb6d0 100644 --- a/Deploy/configparser.cpp +++ b/Deploy/configparser.cpp @@ -230,7 +230,8 @@ bool ConfigParser::loadFromFile(const QString& confFile) { bool ConfigParser::parseQtDeployMode() { - if (QuasarAppUtils::Params::isEndable("deploySystem-with-libc")) { + if (QuasarAppUtils::Params::isEndable("deploySystem-with-libc") || + QuasarAppUtils::Params::isEndable("deploySystem-with-winapi")) { QuasarAppUtils::Params::setEnable("deploySystem", true ); } diff --git a/Deploy/dependenciesscanner.cpp b/Deploy/dependenciesscanner.cpp index d5d06d2..45caeb1 100644 --- a/Deploy/dependenciesscanner.cpp +++ b/Deploy/dependenciesscanner.cpp @@ -12,6 +12,7 @@ #include #include #include +#include "pathutils.h" DependenciesScanner::DependenciesScanner() {} @@ -127,20 +128,34 @@ void DependenciesScanner::recursiveDep(LibInfo &lib, QSet &res) { recursiveDep(*dep, listDep); dep->allDep = listDep; + lib.setWinApi(lib.getWinApi() | dep->getWinApi()); _scanedLibs.insert(dep->fullPath(), *dep); res.unite(listDep); } else { + lib.setWinApi(lib.getWinApi() | scanedLib.getWinApi()); res.unite(scanedLib.allDep); } } } } +void DependenciesScanner::addToWinAPI(const QString &lib) { +#ifdef Q_OS_WIN + if (QuasarAppUtils::Params::isEndable("deploySystem-with-winapi")) { + WinAPI api = _peScaner.getAPIModule(lib); + if (api != WinAPI::NoWinAPI) { + _winAPI.insert(api, lib); + } + } +#else + Q_UNUSED(lib) +#endif +} + void DependenciesScanner::setEnvironment(const QStringList &env) { QDir dir; - QSet winAPI; for (auto i : env) { dir.setPath(i); @@ -153,16 +168,12 @@ void DependenciesScanner::setEnvironment(const QStringList &env) { QDir::Files | QDir::NoDotAndDotDot | QDir::Hidden); for (auto i : list) { - if (i.fileName().contains(APU_MS_WIN , Qt::CaseInsensitive)) { - winAPI.insert(i.fileName().toUpper()); - } - + addToWinAPI(i.absoluteFilePath()); _EnvLibs.insertMulti(i.fileName().toUpper(), i.absoluteFilePath()); } } - _peScaner.setWinApiPlugins(winAPI); } @@ -177,6 +188,18 @@ QSet DependenciesScanner::scan(const QString &path) { recursiveDep(info, result); + for (auto i = _winAPI.begin(); i != _winAPI.end(); ++i) { + if ((info.getWinApi() & i.key()) != WinAPI::NoWinAPI) { + + for (auto apiLib :_winAPI.values(i.key())) { + LibInfo info; + if (fillLibInfo(info, apiLib)) { + result.insert(info); + } + } + } + } + return result; } diff --git a/Deploy/dependenciesscanner.h b/Deploy/dependenciesscanner.h index 6769061..f2c4aab 100644 --- a/Deploy/dependenciesscanner.h +++ b/Deploy/dependenciesscanner.h @@ -34,12 +34,18 @@ private: PE _peScaner; ELF _elfScaner; +#ifdef Q_OS_WIN + QMultiHash _winAPI; +#endif + PrivateScaner getScaner(const QString& lib) const; QMultiMap getLibsFromEnvirement(const QString& libName) const; void recursiveDep(LibInfo& lib, QSet &res); + void addToWinAPI(const QString& lib); + public: explicit DependenciesScanner(); diff --git a/Deploy/deploycore.cpp b/Deploy/deploycore.cpp index 2110bbb..8ccc5ba 100644 --- a/Deploy/deploycore.cpp +++ b/Deploy/deploycore.cpp @@ -162,7 +162,7 @@ QString DeployCore::help() { { "" }, { "Options:" }, { " help / h : Shows help." }, - { " noOverwrite : Prevents replacing existing files." }, + { " 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."}, @@ -173,8 +173,9 @@ QString DeployCore::help() { { " | WARNING: this flag supports 'so', 'dll' and 'exe' files only." }, { " | Use '-bin' flag if you want to deploy linux binary files" }, { " -qmlDir [params] : Qml data dir. For example -qmlDir ~/my/project/qml" }, - { " deploySystem : Deploys all libs" }, - { " deploySystem-with-libc : Skip Deploys system core libs libs" }, + { " deploySystem : Deploys all libs (Skip Deploys system core libs)" }, + { " deploySystem-with-libc : Deploys all libs with Libc (Linux only, not snap)" }, + { " deploySystem-with-winapi : Deploys all libs with win-api (Windows only)" }, { " -qmake [params] : Qmake path." }, { " | For example -qmake ~/Qt/5.14.0/gcc_64/bin/qmake" }, { " -ignore [list,params] : The list of libs to ignore." }, @@ -229,6 +230,7 @@ QStringList DeployCore::helpKeys() { "qmlDir", "deploySystem", "deploySystem-with-libc", + "deploySystem-with-winapi", "qmake", "ignore", "ignoreEnv", @@ -414,3 +416,7 @@ bool DeployCore::isExtraLib(const QString &lib) { QFileInfo info(lib); return _config->extraPaths.contains(info.absoluteFilePath()); } + +uint qHash(WinAPI i) { + return static_cast(i); +} diff --git a/Deploy/deploycore.h b/Deploy/deploycore.h index 8e91894..90fe8f5 100644 --- a/Deploy/deploycore.h +++ b/Deploy/deploycore.h @@ -50,6 +50,19 @@ enum LibPriority : int { NotFile = 0xF, }; +enum class WinAPI : quint8 { + NoWinAPI = 0x00, + Other = 0x01, + Core = 0x02, + Devices = 0x04, + Eventing = 0x08, + Crt = 0x10, + Security = 0x20, + Base = 0x40 +}; + +uint qHash (WinAPI i); + enum class RunMode: int { Info, Deploy, diff --git a/Deploy/libinfo.cpp b/Deploy/libinfo.cpp index 8add465..1854ee2 100644 --- a/Deploy/libinfo.cpp +++ b/Deploy/libinfo.cpp @@ -94,6 +94,14 @@ void LibInfo::setQtPath(const QString &value) qtPath = value; } +WinAPI LibInfo::getWinApi() const { + return _winApi; +} + +void LibInfo::setWinApi(WinAPI winApi) { + _winApi = winApi; +} + QString LibInfo::fullPath() const { return path + "/" + name; } diff --git a/Deploy/libinfo.h b/Deploy/libinfo.h index 12046cd..7c6c779 100644 --- a/Deploy/libinfo.h +++ b/Deploy/libinfo.h @@ -20,6 +20,7 @@ private: QSet dependncies; QString qtPath; LibPriority priority = NotFile; + WinAPI _winApi = WinAPI::NoWinAPI; public: @@ -53,6 +54,8 @@ public: void setPriority(const LibPriority &value); QString getQtPath() const; void setQtPath(const QString &value); + WinAPI getWinApi() const; + void setWinApi(WinAPI winApi); }; uint qHash(const LibInfo& info); diff --git a/Deploy/pe.cpp b/Deploy/pe.cpp index 95c4ade..4245b3a 100644 --- a/Deploy/pe.cpp +++ b/Deploy/pe.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -65,21 +66,46 @@ bool PE::getDep(peparse::parsed_pe_internal * internal, LibInfo &res) const { } } - if (res.getName().contains(APU_MS_WIN, Qt::CaseInsensitive)) { - res.addDependncies(_apimswin); + return res.getDependncies().size() || !imports.size(); +} + +WinAPI PE::getAPIModule(const QString &libName) const { + if (libName.contains(API_MS_WIN, Qt::CaseInsensitive)) { + if (libName.contains(API_MS_WIN_CORE, Qt::CaseInsensitive)) { + return WinAPI::Core; + } + + if (libName.contains(API_MS_WIN_EVENTING, Qt::CaseInsensitive)) { + return WinAPI::Eventing; + } + + if (libName.contains(API_MS_WIN_DEVICES, Qt::CaseInsensitive)) { + return WinAPI::Devices; + } + + if (libName.contains(API_MS_WIN_CRT, Qt::CaseInsensitive)) { + return WinAPI::Crt; + } + + if (libName.contains(API_MS_WIN_SECURITY, Qt::CaseInsensitive)) { + return WinAPI::Security; + } + + if (libName.contains(API_MS_WIN_BASE, Qt::CaseInsensitive)) { + return WinAPI::Base; + } + + return WinAPI::Other; + } - return res.getDependncies().size() || !imports.size(); + return WinAPI::NoWinAPI; } PE::PE(): IGetLibInfo () { } -void PE::setWinApiPlugins(const QSet &keys) { - _apimswin = keys; -} - bool PE::getLibInfo(const QString &lib, LibInfo &info) const { auto parsedPeLib = peparse::ParsePEFromFile(lib.toLatin1()); @@ -104,6 +130,8 @@ bool PE::getLibInfo(const QString &lib, LibInfo &info) const { peparse::DestructParsedPE(parsedPeLib); + info.setWinApi(getAPIModule(info.getName())); + return info.isValid(); } diff --git a/Deploy/pe.h b/Deploy/pe.h index 0896e68..34312a3 100644 --- a/Deploy/pe.h +++ b/Deploy/pe.h @@ -13,7 +13,13 @@ #include #include "igetlibinfo.h" -#define APU_MS_WIN "api-ms-win" +#define API_MS_WIN "api-ms-win-" +#define API_MS_WIN_CORE "-core-" +#define API_MS_WIN_EVENTING "-Eventing-" +#define API_MS_WIN_DEVICES "-devices-" +#define API_MS_WIN_CRT "-crt-" +#define API_MS_WIN_SECURITY "-security-" +#define API_MS_WIN_BASE "-base-" namespace peparse { struct parsed_pe_internal; @@ -24,8 +30,6 @@ private: bool getDep(peparse::parsed_pe_internal *, LibInfo &res) const; - QSet _apimswin; - public: enum class RunType: unsigned short { @@ -35,12 +39,7 @@ public: _ROM = 0x107, }; PE(); - - /** - * @brief setWinApiPlugins - * @param keys set values of api-ms-win libs - */ - void setWinApiPlugins(const QSet& keys); + WinAPI getAPIModule(const QString &libName) const; bool getLibInfo(const QString& lib, LibInfo& info) const override; diff --git a/UnitTests/tst_deploytest.cpp b/UnitTests/tst_deploytest.cpp index 964a154..b09bdb9 100644 --- a/UnitTests/tst_deploytest.cpp +++ b/UnitTests/tst_deploytest.cpp @@ -44,9 +44,9 @@ private: QStringList getFilesFromDir(const QString& dir); - void runTestParams(const QStringList &list, QSet *tree = nullptr, bool noWarnings = false); + void runTestParams(const QStringList &list, QSet *tree = nullptr, bool noWarnings = false, bool onlySize = false); - void checkResults(const QSet &tree, bool noWarnings); + void checkResults(const QSet &tree, bool noWarnings, bool onlySize = false); public: deploytest(); /** @@ -744,7 +744,7 @@ void deploytest::testSetTargetDir() { } -void deploytest::runTestParams(const QStringList &list, QSet* tree, bool noWarnings) { +void deploytest::runTestParams(const QStringList &list, QSet* tree, bool noWarnings, bool onlySize) { QuasarAppUtils::Params::parseParams(list); @@ -752,7 +752,7 @@ void deploytest::runTestParams(const QStringList &list, QSet* tree, boo QVERIFY(deploy.run() == 0); if (tree) { - checkResults(*tree, noWarnings); + checkResults(*tree, noWarnings, onlySize); } #ifdef WITH_SNAP @@ -790,7 +790,7 @@ void deploytest::runTestParams(const QStringList &list, QSet* tree, boo #endif } -void deploytest::checkResults(const QSet &tree, bool noWarnings) { +void deploytest::checkResults(const QSet &tree, bool noWarnings , bool onlySize) { TestUtils utils; QVERIFY(DeployCore::_config); @@ -800,6 +800,11 @@ void deploytest::checkResults(const QSet &tree, bool noWarnings) { auto comapre = utils.compareTree(resultTree, tree); + if (onlySize) { + QVERIFY(resultTree.size() > tree.size()); + return; + } + if (comapre.size() != 0) { bool bug = false; @@ -1624,6 +1629,12 @@ void deploytest::testSystemLib() { "deploySystem" }, &comapareTree, true); + runTestParams({"-bin", bin, "clear" , + "-qmake", qmake, + "deploySystem-with-winapi" + }, &comapareTree, true, true); + + #endif }