mirror of
https://github.com/QuasarApp/CQtDeployer.git
synced 2025-05-01 12:09:36 +00:00
test PE Lib
This commit is contained in:
parent
a80d2062b4
commit
7b35a196cc
@ -44,7 +44,8 @@ SOURCES += \
|
|||||||
deployutils.cpp \
|
deployutils.cpp \
|
||||||
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
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
deploy.h \
|
deploy.h \
|
||||||
@ -52,6 +53,7 @@ HEADERS += \
|
|||||||
deployutils.h \
|
deployutils.h \
|
||||||
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
|
||||||
|
|
||||||
win32: LIBS += -lshlwapi
|
win32: LIBS += -lshlwapi
|
||||||
|
@ -396,13 +396,10 @@ void Deploy::extract(const QString &file, bool isExtractPlugins) {
|
|||||||
auto sufix = info.completeSuffix();
|
auto sufix = info.completeSuffix();
|
||||||
|
|
||||||
if (sufix.contains("dll", Qt::CaseSensitive) ||
|
if (sufix.contains("dll", Qt::CaseSensitive) ||
|
||||||
sufix.contains("exe", Qt::CaseSensitive)) {
|
sufix.contains("exe", Qt::CaseSensitive) ||
|
||||||
|
sufix.isEmpty() || sufix.contains("so", Qt::CaseSensitive)) {
|
||||||
|
|
||||||
winScaner.setEnvironment(deployEnvironment);
|
extractLib(file, isExtractPlugins);
|
||||||
extractWindowsLib(file, isExtractPlugins);
|
|
||||||
}
|
|
||||||
else if (sufix.isEmpty() || sufix.contains("so", Qt::CaseSensitive)) {
|
|
||||||
extractLinuxLib(file, isExtractPlugins);
|
|
||||||
} else {
|
} else {
|
||||||
QuasarAppUtils::Params::verboseLog("file with sufix " + sufix + " not supported!");
|
QuasarAppUtils::Params::verboseLog("file with sufix " + sufix + " not supported!");
|
||||||
}
|
}
|
||||||
@ -613,72 +610,7 @@ QString Deploy::filterQmlPath(const QString &path) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Deploy::extractLinuxLib(const QString &file, bool isExtractPlugins) {
|
void Deploy::extractLib(const QString &file, bool isExtractPlugins) {
|
||||||
qInfo() << "extract lib :" << file;
|
|
||||||
|
|
||||||
QProcessEnvironment env;
|
|
||||||
|
|
||||||
env.insert("LD_LIBRARY_PATH", concatEnv());
|
|
||||||
env.insert("QML_IMPORT_PATH", DeployUtils::qtDir + "/qml");
|
|
||||||
env.insert("QML2_IMPORT_PATH", DeployUtils::qtDir + "/qml");
|
|
||||||
env.insert("QT_PLUGIN_PATH", DeployUtils::qtDir + "/plugins");
|
|
||||||
env.insert("QT_QPA_PLATFORM_PLUGIN_PATH", DeployUtils::qtDir + "/plugins/platforms");
|
|
||||||
|
|
||||||
QProcess P;
|
|
||||||
P.setProcessEnvironment(env);
|
|
||||||
P.start("ldd " + file, QProcess::ReadOnly);
|
|
||||||
|
|
||||||
if (!P.waitForStarted())
|
|
||||||
return;
|
|
||||||
if (!P.waitForFinished())
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto data = QString(P.readAll());
|
|
||||||
|
|
||||||
for (QString &line : data.split("\n", QString::SkipEmptyParts)) {
|
|
||||||
line = line.simplified();
|
|
||||||
auto innerlist = line.split(" ");
|
|
||||||
|
|
||||||
if (innerlist.count() < 3) {
|
|
||||||
QuasarAppUtils::Params::verboseLog(" the lib is not found: " + line);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
line = innerlist[2];
|
|
||||||
|
|
||||||
if (!line.startsWith("/")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isIgnore = false;
|
|
||||||
for (auto ignore : ignoreList) {
|
|
||||||
if (line.contains(ignore)) {
|
|
||||||
QuasarAppUtils::Params::verboseLog(line + " ignored by filter" + ignore);
|
|
||||||
isIgnore = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isIgnore) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((DeployUtils::isQtLib(line) || DeployUtils::isExtraLib(line)) && !QtLibs.contains(line)) {
|
|
||||||
QtLibs << line;
|
|
||||||
extractLinuxLib(line, isExtractPlugins);
|
|
||||||
if (isExtractPlugins) {
|
|
||||||
extractPlugins(line);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((QuasarAppUtils::Params::isEndable("deploy-not-qt") || onlyCLibs) &&
|
|
||||||
!noQTLibs.contains(line)) {
|
|
||||||
noQTLibs << line;
|
|
||||||
extractLinuxLib(line, isExtractPlugins);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Deploy::extractWindowsLib(const QString &file, bool isExtractPlugins) {
|
|
||||||
qInfo() << "extract lib :" << file;
|
qInfo() << "extract lib :" << file;
|
||||||
|
|
||||||
auto data = winScaner.scan(file, Platform::UnknownPlatform, qmake);
|
auto data = winScaner.scan(file, Platform::UnknownPlatform, qmake);
|
||||||
@ -701,7 +633,7 @@ void Deploy::extractWindowsLib(const QString &file, bool isExtractPlugins) {
|
|||||||
|
|
||||||
if ((DeployUtils::isQtLib(line) || DeployUtils::isExtraLib(line)) && !QtLibs.contains(line)) {
|
if ((DeployUtils::isQtLib(line) || DeployUtils::isExtraLib(line)) && !QtLibs.contains(line)) {
|
||||||
QtLibs << line;
|
QtLibs << line;
|
||||||
extractWindowsLib(line, isExtractPlugins);
|
extractLib(line, isExtractPlugins);
|
||||||
if (isExtractPlugins) {
|
if (isExtractPlugins) {
|
||||||
extractPlugins(line);
|
extractPlugins(line);
|
||||||
}
|
}
|
||||||
@ -711,7 +643,7 @@ void Deploy::extractWindowsLib(const QString &file, bool isExtractPlugins) {
|
|||||||
if ((onlyCLibs || QuasarAppUtils::Params::isEndable("deploy-not-qt")) &&
|
if ((onlyCLibs || QuasarAppUtils::Params::isEndable("deploy-not-qt")) &&
|
||||||
!noQTLibs.contains(line)) {
|
!noQTLibs.contains(line)) {
|
||||||
noQTLibs << line;
|
noQTLibs << line;
|
||||||
extractWindowsLib(line, isExtractPlugins);
|
extractLib(line, isExtractPlugins);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -797,6 +729,8 @@ bool Deploy::smartMoveTargets() {
|
|||||||
|
|
||||||
targets = temp;
|
targets = temp;
|
||||||
|
|
||||||
|
winScaner.setEnvironment(deployEnvironment);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,8 +86,7 @@ class DEPLOYSHARED_EXPORT Deploy {
|
|||||||
bool extractQmlAll();
|
bool extractQmlAll();
|
||||||
bool extractQmlFromSource(const QString &sourceDir);
|
bool extractQmlFromSource(const QString &sourceDir);
|
||||||
QString filterQmlPath(const QString &path);
|
QString filterQmlPath(const QString &path);
|
||||||
void extractLinuxLib(const QString & file, bool isExtractPlugins);
|
void extractLib(const QString & file, bool isExtractPlugins);
|
||||||
void extractWindowsLib(const QString & file, bool isExtractPlugins);
|
|
||||||
|
|
||||||
void addEnv(const QString& dir);
|
void addEnv(const QString& dir);
|
||||||
QString concatEnv() const;
|
QString concatEnv() const;
|
||||||
|
37
Deploy/pe.cpp
Normal file
37
Deploy/pe.cpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#include "pe.h"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
|
bool PE::is32bit(const QString &file) {
|
||||||
|
QFile f(file);
|
||||||
|
|
||||||
|
if (!f.open(QIODevice::ReadOnly)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!f.seek(INDEX_PE_MAGIC)) {
|
||||||
|
f.close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned short PE = 0x0;
|
||||||
|
f.read(reinterpret_cast<char*>(&PE), sizeof (unsigned short));
|
||||||
|
|
||||||
|
if (PE != PE_MAGIC) {
|
||||||
|
f.close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
f.close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PE::dependecies(QStringList &lisr, const QString &file)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
PE::PE()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
40
Deploy/pe.h
Normal file
40
Deploy/pe.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#ifndef PE_H
|
||||||
|
#define PE_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
struct LIB_META_INFO {
|
||||||
|
unsigned int
|
||||||
|
}
|
||||||
|
|
||||||
|
class PE
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum class MashineTypesS: unsigned short {
|
||||||
|
IMAGE_FILE_MACHINE_UNKNOWN = 0x0,
|
||||||
|
IMAGE_FILE_MACHINE_AMD64 = 0x8664, // x64
|
||||||
|
IMAGE_FILE_MACHINE_ARM = 0x1c0, // ARM little endian
|
||||||
|
IMAGE_FILE_MACHINE_ARM64 = 0xaa64, // ARM64 little endian
|
||||||
|
IMAGE_FILE_MACHINE_ARMNT = 0x1c4, // ARM Thumb-2 little endian
|
||||||
|
IMAGE_FILE_MACHINE_I386 = 0x14c, // Intel 386 or later processors and compatible processors
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class RunType: unsigned short {
|
||||||
|
_UNKNOWN = 0x0,
|
||||||
|
_32bit = 0x10B,
|
||||||
|
_64bit = 0x20B,
|
||||||
|
_ROM = 0x107,
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr static unsigned int PE_MAGIC = 0x00004550;
|
||||||
|
constexpr static unsigned int INDEX_PE_MAGIC = 0x80;
|
||||||
|
|
||||||
|
bool is32bit(const QString& file);
|
||||||
|
bool dependecies(QStringList& lisr, const QString& file);
|
||||||
|
PE();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PE_H
|
@ -58,54 +58,58 @@ struct Options {
|
|||||||
|
|
||||||
WinDependenciesScanner::WinDependenciesScanner() {}
|
WinDependenciesScanner::WinDependenciesScanner() {}
|
||||||
|
|
||||||
QMap<QString, QString> WinDependenciesScanner::qMakeAll(QString *errorMessage, const QString& binary)
|
//QMap<QString, QString> WinDependenciesScanner::qMakeAll(QString *errorMessage, const QString& binary)
|
||||||
{
|
//{
|
||||||
QByteArray stdOut;
|
// QByteArray stdOut;
|
||||||
QByteArray stdErr;
|
// QByteArray stdErr;
|
||||||
unsigned long exitCode = 0;
|
// unsigned long exitCode = 0;
|
||||||
if (!runProcess(binary, QStringList(QStringLiteral("-query")), QString(), &exitCode, &stdOut, &stdErr, errorMessage))
|
// if (!runProcess(binary, QStringList(QStringLiteral("-query")), QString(), &exitCode, &stdOut, &stdErr, errorMessage))
|
||||||
return QMap<QString, QString>();
|
// return QMap<QString, QString>();
|
||||||
if (exitCode) {
|
// if (exitCode) {
|
||||||
*errorMessage = binary + QStringLiteral(" returns ") + QString::number(exitCode)
|
// *errorMessage = binary + QStringLiteral(" returns ") + QString::number(exitCode)
|
||||||
+ QStringLiteral(": ") + QString::fromLocal8Bit(stdErr);
|
// + QStringLiteral(": ") + QString::fromLocal8Bit(stdErr);
|
||||||
return QMap<QString, QString>();
|
// return QMap<QString, QString>();
|
||||||
}
|
// }
|
||||||
const QString output = QString::fromLocal8Bit(stdOut).trimmed().remove(QLatin1Char('\r'));
|
// const QString output = QString::fromLocal8Bit(stdOut).trimmed().remove(QLatin1Char('\r'));
|
||||||
QMap<QString, QString> result;
|
// QMap<QString, QString> result;
|
||||||
const int size = output.size();
|
// const int size = output.size();
|
||||||
for (int pos = 0; pos < size; ) {
|
// for (int pos = 0; pos < size; ) {
|
||||||
const int colonPos = output.indexOf(QLatin1Char(':'), pos);
|
// const int colonPos = output.indexOf(QLatin1Char(':'), pos);
|
||||||
if (colonPos < 0)
|
// if (colonPos < 0)
|
||||||
break;
|
// break;
|
||||||
int endPos = output.indexOf(QLatin1Char('\n'), colonPos + 1);
|
// int endPos = output.indexOf(QLatin1Char('\n'), colonPos + 1);
|
||||||
if (endPos < 0)
|
// if (endPos < 0)
|
||||||
endPos = size;
|
// endPos = size;
|
||||||
const QString key = output.mid(pos, colonPos - pos);
|
// const QString key = output.mid(pos, colonPos - pos);
|
||||||
const QString value = output.mid(colonPos + 1, endPos - colonPos - 1);
|
// const QString value = output.mid(colonPos + 1, endPos - colonPos - 1);
|
||||||
result.insert(key, value);
|
// result.insert(key, value);
|
||||||
pos = endPos + 1;
|
// pos = endPos + 1;
|
||||||
}
|
// }
|
||||||
QFile qconfigPriFile(result.value(QStringLiteral("QT_HOST_DATA")) + QStringLiteral("/mkspecs/qconfig.pri"));
|
// QFile qconfigPriFile(result.value(QStringLiteral("QT_HOST_DATA")) + QStringLiteral("/mkspecs/qconfig.pri"));
|
||||||
if (qconfigPriFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
// if (qconfigPriFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
while (true) {
|
// while (true) {
|
||||||
const QByteArray line = qconfigPriFile.readLine();
|
// const QByteArray line = qconfigPriFile.readLine();
|
||||||
if (line.isEmpty())
|
// if (line.isEmpty())
|
||||||
break;
|
// break;
|
||||||
if (line.startsWith("QT_LIBINFIX")) {
|
// if (line.startsWith("QT_LIBINFIX")) {
|
||||||
const int pos = line.indexOf('=');
|
// const int pos = line.indexOf('=');
|
||||||
if (pos >= 0) {
|
// if (pos >= 0) {
|
||||||
const QString infix = QString::fromUtf8(line.right(line.size() - pos - 1).trimmed());
|
// const QString infix = QString::fromUtf8(line.right(line.size() - pos - 1).trimmed());
|
||||||
if (!infix.isEmpty())
|
// if (!infix.isEmpty())
|
||||||
result.insert(QLatin1String(qmakeInfixKey), infix);
|
// result.insert(QLatin1String(qmakeInfixKey), infix);
|
||||||
}
|
// }
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
std::wcerr << "Warning: Unable to read " << QDir::toNativeSeparators(qconfigPriFile.fileName())
|
// std::wcerr << "Warning: Unable to read " << QDir::toNativeSeparators(qconfigPriFile.fileName())
|
||||||
<< ": " << qconfigPriFile.errorString()<< '\n';
|
// << ": " << qconfigPriFile.errorString()<< '\n';
|
||||||
}
|
// }
|
||||||
return result;
|
// return result;
|
||||||
|
//}
|
||||||
|
|
||||||
|
bool WinDependenciesScanner::fillLibInfo(LibInfo &info, const QString &file) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WinDependenciesScanner::setEnvironment(const QStringList &env) {
|
void WinDependenciesScanner::setEnvironment(const QStringList &env) {
|
||||||
@ -186,3 +190,13 @@ 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;
|
||||||
|
}
|
||||||
|
@ -13,6 +13,17 @@
|
|||||||
#include "../qtTools/src/windeployqt/utils.h"
|
#include "../qtTools/src/windeployqt/utils.h"
|
||||||
#include "deploy_global.h"
|
#include "deploy_global.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:
|
||||||
QStringList _env;
|
QStringList _env;
|
||||||
@ -20,6 +31,8 @@ private:
|
|||||||
Platform platformFromMkSpec(const QString &xSpec);
|
Platform platformFromMkSpec(const QString &xSpec);
|
||||||
QMap<QString, QString> qMakeAll(QString *errorMessage,
|
QMap<QString, QString> qMakeAll(QString *errorMessage,
|
||||||
const QString &binary = "qmake");
|
const QString &binary = "qmake");
|
||||||
|
|
||||||
|
bool fillLibInfo(LibInfo& info ,const QString& file);
|
||||||
public:
|
public:
|
||||||
explicit WinDependenciesScanner();
|
explicit WinDependenciesScanner();
|
||||||
|
|
||||||
|
@ -17,6 +17,8 @@ chmod a+rx $BASE_DIR/wrapper/bin/desktop-launch
|
|||||||
echo "Start static build"
|
echo "Start static build"
|
||||||
$BASE_DIR/staticBuild.sh Q_OS_LINUX_SNAP
|
$BASE_DIR/staticBuild.sh Q_OS_LINUX_SNAP
|
||||||
|
|
||||||
|
chmod a+rx $BASE_DIR/distro/cqtdeployer
|
||||||
|
|
||||||
if [ $? -eq 0 ]
|
if [ $? -eq 0 ]
|
||||||
then
|
then
|
||||||
echo ""
|
echo ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user