This commit is contained in:
Andrei Yankovich 2019-03-18 10:33:03 +03:00
parent 467a49da08
commit cc80354c0d
9 changed files with 180 additions and 101 deletions

View File

@ -45,7 +45,9 @@ SOURCES += \
windependenciesscanner.cpp \ windependenciesscanner.cpp \
../qtTools/src/windeployqt/elfreader.cpp \ ../qtTools/src/windeployqt/elfreader.cpp \
../qtTools/src/windeployqt/utils.cpp \ ../qtTools/src/windeployqt/utils.cpp \
pe.cpp pe.cpp \
igetlibinfo.cpp \
structs.cpp
HEADERS += \ HEADERS += \
deploy.h \ deploy.h \
@ -54,6 +56,8 @@ HEADERS += \
windependenciesscanner.h\ windependenciesscanner.h\
../qtTools/src/windeployqt/elfreader.h \ ../qtTools/src/windeployqt/elfreader.h \
../qtTools/src/windeployqt/utils.h \ ../qtTools/src/windeployqt/utils.h \
pe.h pe.h \
igetlibinfo.h \
structs.h
win32: LIBS += -lshlwapi win32: LIBS += -lshlwapi

1
Deploy/igetlibinfo.cpp Normal file
View File

@ -0,0 +1 @@
#include "igetlibinfo.h"

17
Deploy/igetlibinfo.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef IGETLIBINFO_H
#define IGETLIBINFO_H
#include "structs.h"
class IGetLibInfo
{
public:
IGetLibInfo() = default;
virtual LibInfo&& getLibInfo(const QString& lib) = 0;
virtual ~IGetLibInfo() = 0;
};
#endif // IGETLIBINFO_H

View File

@ -1,8 +1,7 @@
#include "pe.h" #include "pe.h"
#include <QFile> #include <QFile>
#include <QFileInfo>
bool PE::fillMetaInfo(LIB_META_INFO &info, const QString &file) { bool PE::fillMetaInfo(LIB_META_INFO &info, const QString &file) {
QFile f(file); QFile f(file);
@ -69,24 +68,34 @@ bool PE::fillMetaInfo(LIB_META_INFO &info, const QString &file) {
return true; return true;
} }
//TODO is sucks rewrite! bool PE::is32bit(const QString &file, const LIB_META_INFO * info) {
bool PE::is32bit(const QString &file) {
LIB_META_INFO meta; if (!info) {
LIB_META_INFO meta;
if (!fillMetaInfo(meta, file)) { if (!fillMetaInfo(meta, file)) {
return false; return false;
}
return static_cast<RunType>(meta.type) == RunType::_32bit;
} }
return static_cast<RunType>(meta.type) == RunType::_32bit; return static_cast<RunType>(info->type) == RunType::_32bit;
} }
bool PE::dependecies(QStringList &list, const QString &file) { bool PE::dependecies(QStringList &list, const QString &file,
// TODO const LIB_META_INFO * info) {
LIB_META_INFO meta; LIB_META_INFO meta;
if (!fillMetaInfo(meta, file)) { if (!info) {
return false;
if (!fillMetaInfo(meta, file)) {
return false;
}
} else {
meta = std::move(*info);
} }
QFile f(file); QFile f(file);
@ -102,7 +111,7 @@ bool PE::dependecies(QStringList &list, const QString &file) {
return false; return false;
} }
QByteArray data = f.read(meta.sizeImportTable); auto data = f.read(meta.sizeImportTable).split(char(0x0));
f.close(); f.close();
@ -110,13 +119,39 @@ bool PE::dependecies(QStringList &list, const QString &file) {
return false; return false;
} }
// TODO for (QString i : data) {
if (i.contains(".dll")) {
list.push_back(i);
}
}
return true; return true;
} }
PE::PE() PE::PE() {
{
} }
LibInfo &&PE::getLibInfo(const QString &lib) {
LibInfo info;
LIB_META_INFO meta;
if (!fillMetaInfo(meta, lib)) {
return std::move(info);
}
info.name = QFileInfo(lib).fileName();
info.path = QFileInfo(lib).filePath();
if (static_cast<RunType>(meta.type) == RunType::_32bit) {
info.platform = Platform::Win32;
} else if (static_cast<RunType>(meta.type) == RunType::_64bit) {
info.platform = Platform::Win64;
} else {
info.platform = Platform::UnknownPlatform;
}
dependecies(info.dependncies, lib, &meta);
return std::move(info);
}

View File

@ -2,6 +2,7 @@
#define PE_H #define PE_H
#include <QString> #include <QString>
#include "igetlibinfo.h"
struct LIB_META_INFO { struct LIB_META_INFO {
unsigned short mashine = 0x0; unsigned short mashine = 0x0;
@ -10,7 +11,7 @@ struct LIB_META_INFO {
unsigned int sizeImportTable = 0x0; unsigned int sizeImportTable = 0x0;
}; };
class PE { class PE : public IGetLibInfo {
private: private:
bool fillMetaInfo(LIB_META_INFO& info, const QString &file); bool fillMetaInfo(LIB_META_INFO& info, const QString &file);
@ -38,9 +39,15 @@ public:
constexpr static unsigned int INDEX_IMPORTS_32 = INDEX_MAGIC + 0x68; constexpr static unsigned int INDEX_IMPORTS_32 = INDEX_MAGIC + 0x68;
constexpr static unsigned int INDEX_IMPORTS_64 = INDEX_MAGIC + 0x78; constexpr static unsigned int INDEX_IMPORTS_64 = INDEX_MAGIC + 0x78;
bool is32bit(const QString& file); bool is32bit(const QString& file, const LIB_META_INFO *info = nullptr);
bool dependecies(QStringList& lisr, const QString& file); bool dependecies(QStringList& lisr, const QString& file,
const LIB_META_INFO *info = nullptr);
PE(); PE();
~PE();
// IGetLibInfo interface
public:
LibInfo &&getLibInfo(const QString& lib);
}; };
#endif // PE_H #endif // PE_H

10
Deploy/structs.cpp Normal file
View File

@ -0,0 +1,10 @@
#include "structs.h"
bool LibInfo::operator ==(const LibInfo &other) {
return platform == other.platform &&
name == other.name;
}
QString LibInfo::fullPath() {
return path + "/" + name;
}

25
Deploy/structs.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef LIBINFO_H
#define LIBINFO_H
#include <QString>
#include <QStringList>
enum Platform {
UnknownPlatform = 0x0,
Win32,
Win64,
Unix
};
struct LibInfo {
Platform platform = Platform::UnknownPlatform;
QString name;
QString path;
QStringList dependncies;
bool operator == (const LibInfo& other);
QString fullPath();
};
#endif // LIBINFO_H

View File

@ -13,48 +13,48 @@
#include <QDebug> #include <QDebug>
struct Options { //struct Options {
enum DebugDetection { // enum DebugDetection {
DebugDetectionAuto, // DebugDetectionAuto,
DebugDetectionForceDebug, // DebugDetectionForceDebug,
DebugDetectionForceRelease // DebugDetectionForceRelease
}; // };
enum AngleDetection { // enum AngleDetection {
AngleDetectionAuto, // AngleDetectionAuto,
AngleDetectionForceOn, // AngleDetectionForceOn,
AngleDetectionForceOff // AngleDetectionForceOff
}; // };
bool plugins = true; // bool plugins = true;
bool libraries = true; // bool libraries = true;
bool quickImports = true; // bool quickImports = true;
bool translations = true; // bool translations = true;
bool systemD3dCompiler = true; // bool systemD3dCompiler = true;
bool compilerRunTime = false; // bool compilerRunTime = false;
AngleDetection angleDetection = AngleDetectionAuto; // AngleDetection angleDetection = AngleDetectionAuto;
bool softwareRasterizer = true; // bool softwareRasterizer = true;
Platform platform = Windows; // Platform platform = Windows;
quint64 additionalLibraries = 0; // quint64 additionalLibraries = 0;
quint64 disabledLibraries = 0; // quint64 disabledLibraries = 0;
unsigned updateFileFlags = 0; // unsigned updateFileFlags = 0;
QStringList qmlDirectories; // Project's QML files. // QStringList qmlDirectories; // Project's QML files.
QString directory; // QString directory;
QString translationsDirectory; // Translations target directory // QString translationsDirectory; // Translations target directory
QString libraryDirectory; // QString libraryDirectory;
QString pluginDirectory; // QString pluginDirectory;
QStringList binaries; // QStringList binaries;
JsonOutput *json = nullptr; // JsonOutput *json = nullptr;
ListOption list = ListNone; // ListOption list = ListNone;
DebugDetection debugDetection = DebugDetectionAuto; // DebugDetection debugDetection = DebugDetectionAuto;
bool deployPdb = false; // bool deployPdb = false;
bool dryRun = false; // bool dryRun = false;
bool patchQt = true; // bool patchQt = true;
inline bool isWinRt() const { // inline bool isWinRt() const {
return platform == WinRtArm || platform == WinRtIntel; // return platform == WinRtArm || platform == WinRtIntel;
} // }
}; //};
WinDependenciesScanner::WinDependenciesScanner() {} WinDependenciesScanner::WinDependenciesScanner() {}
@ -137,24 +137,24 @@ void WinDependenciesScanner::setEnvironment(const QStringList &env) {
} }
Platform WinDependenciesScanner::platformFromMkSpec(const QString &xSpec) //Platform WinDependenciesScanner::platformFromMkSpec(const QString &xSpec)
{ //{
if (xSpec == QLatin1String("linux-g++")) // if (xSpec == QLatin1String("linux-g++"))
return Unix; // return Unix;
if (xSpec.startsWith(QLatin1String("win32-"))) // if (xSpec.startsWith(QLatin1String("win32-")))
return xSpec.contains(QLatin1String("g++")) ? WindowsMinGW : Windows; // return xSpec.contains(QLatin1String("g++")) ? WindowsMinGW : Windows;
if (xSpec.startsWith(QLatin1String("winrt-x"))) // if (xSpec.startsWith(QLatin1String("winrt-x")))
return WinRtIntel; // return WinRtIntel;
if (xSpec.startsWith(QLatin1String("winrt-arm"))) // if (xSpec.startsWith(QLatin1String("winrt-arm")))
return WinRtArm; // return WinRtArm;
if (xSpec.startsWith(QLatin1String("wince"))) { // if (xSpec.startsWith(QLatin1String("wince"))) {
if (xSpec.contains(QLatin1String("-x86-"))) // if (xSpec.contains(QLatin1String("-x86-")))
return WinCEIntel; // return WinCEIntel;
if (xSpec.contains(QLatin1String("-arm"))) // if (xSpec.contains(QLatin1String("-arm")))
return WinCEArm; // return WinCEArm;
} // }
return UnknownPlatform; // return UnknownPlatform;
} //}
QStringList WinDependenciesScanner::scan(const QString &path, Platform platfr, QStringList WinDependenciesScanner::scan(const QString &path, Platform platfr,
const QString& qmake) { const QString& qmake) {
@ -170,7 +170,7 @@ QStringList WinDependenciesScanner::scan(const QString &path, Platform platfr,
} }
QStringList dep; QStringList dep;
readExecutable(path, platfr, &errorMessage, &dep); // readExecutable(path, platfr, &errorMessage, &dep);
if (!errorMessage.isEmpty()) { if (!errorMessage.isEmpty()) {
qCritical() << errorMessage; qCritical() << errorMessage;
@ -190,13 +190,3 @@ QStringList WinDependenciesScanner::scan(const QString &path, Platform platfr,
WinDependenciesScanner::~WinDependenciesScanner() { WinDependenciesScanner::~WinDependenciesScanner() {
} }
bool LibInfo::operator ==(const LibInfo &other) {
return platform == other.platform &&
name == other.name &&
is32bit == other.is32bit;
}
QString LibInfo::fullPath() {
return path + "/" + name;
}

View File

@ -10,19 +10,9 @@
#include <QMultiMap> #include <QMultiMap>
#include <QStringList> #include <QStringList>
#include "../qtTools/src/windeployqt/utils.h"
#include "deploy_global.h" #include "deploy_global.h"
#include "structs.h"
struct LibInfo {
Platform platform = Platform::UnknownPlatform;
bool is32bit = false;
QString name;
QString path;
bool operator == (const LibInfo& other);
QString fullPath();
};
class DEPLOYSHARED_EXPORT WinDependenciesScanner { class DEPLOYSHARED_EXPORT WinDependenciesScanner {
private: private: