mirror of
https://github.com/QuasarApp/CQtDeployer.git
synced 2025-04-27 02:04:33 +00:00
test PE Lib
This commit is contained in:
parent
a80d2062b4
commit
7b35a196cc
@ -44,7 +44,8 @@ SOURCES += \
|
||||
deployutils.cpp \
|
||||
windependenciesscanner.cpp \
|
||||
../qtTools/src/windeployqt/elfreader.cpp \
|
||||
../qtTools/src/windeployqt/utils.cpp
|
||||
../qtTools/src/windeployqt/utils.cpp \
|
||||
pe.cpp
|
||||
|
||||
HEADERS += \
|
||||
deploy.h \
|
||||
@ -52,6 +53,7 @@ HEADERS += \
|
||||
deployutils.h \
|
||||
windependenciesscanner.h\
|
||||
../qtTools/src/windeployqt/elfreader.h \
|
||||
../qtTools/src/windeployqt/utils.h
|
||||
../qtTools/src/windeployqt/utils.h \
|
||||
pe.h
|
||||
|
||||
win32: LIBS += -lshlwapi
|
||||
|
@ -396,13 +396,10 @@ void Deploy::extract(const QString &file, bool isExtractPlugins) {
|
||||
auto sufix = info.completeSuffix();
|
||||
|
||||
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);
|
||||
extractWindowsLib(file, isExtractPlugins);
|
||||
}
|
||||
else if (sufix.isEmpty() || sufix.contains("so", Qt::CaseSensitive)) {
|
||||
extractLinuxLib(file, isExtractPlugins);
|
||||
extractLib(file, isExtractPlugins);
|
||||
} else {
|
||||
QuasarAppUtils::Params::verboseLog("file with sufix " + sufix + " not supported!");
|
||||
}
|
||||
@ -613,72 +610,7 @@ QString Deploy::filterQmlPath(const QString &path) {
|
||||
return "";
|
||||
}
|
||||
|
||||
void Deploy::extractLinuxLib(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) {
|
||||
void Deploy::extractLib(const QString &file, bool isExtractPlugins) {
|
||||
qInfo() << "extract lib :" << file;
|
||||
|
||||
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)) {
|
||||
QtLibs << line;
|
||||
extractWindowsLib(line, isExtractPlugins);
|
||||
extractLib(line, isExtractPlugins);
|
||||
if (isExtractPlugins) {
|
||||
extractPlugins(line);
|
||||
}
|
||||
@ -711,7 +643,7 @@ void Deploy::extractWindowsLib(const QString &file, bool isExtractPlugins) {
|
||||
if ((onlyCLibs || QuasarAppUtils::Params::isEndable("deploy-not-qt")) &&
|
||||
!noQTLibs.contains(line)) {
|
||||
noQTLibs << line;
|
||||
extractWindowsLib(line, isExtractPlugins);
|
||||
extractLib(line, isExtractPlugins);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -797,6 +729,8 @@ bool Deploy::smartMoveTargets() {
|
||||
|
||||
targets = temp;
|
||||
|
||||
winScaner.setEnvironment(deployEnvironment);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -86,8 +86,7 @@ class DEPLOYSHARED_EXPORT Deploy {
|
||||
bool extractQmlAll();
|
||||
bool extractQmlFromSource(const QString &sourceDir);
|
||||
QString filterQmlPath(const QString &path);
|
||||
void extractLinuxLib(const QString & file, bool isExtractPlugins);
|
||||
void extractWindowsLib(const QString & file, bool isExtractPlugins);
|
||||
void extractLib(const QString & file, bool isExtractPlugins);
|
||||
|
||||
void addEnv(const QString& dir);
|
||||
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() {}
|
||||
|
||||
QMap<QString, QString> WinDependenciesScanner::qMakeAll(QString *errorMessage, const QString& binary)
|
||||
{
|
||||
QByteArray stdOut;
|
||||
QByteArray stdErr;
|
||||
unsigned long exitCode = 0;
|
||||
if (!runProcess(binary, QStringList(QStringLiteral("-query")), QString(), &exitCode, &stdOut, &stdErr, errorMessage))
|
||||
return QMap<QString, QString>();
|
||||
if (exitCode) {
|
||||
*errorMessage = binary + QStringLiteral(" returns ") + QString::number(exitCode)
|
||||
+ QStringLiteral(": ") + QString::fromLocal8Bit(stdErr);
|
||||
return QMap<QString, QString>();
|
||||
}
|
||||
const QString output = QString::fromLocal8Bit(stdOut).trimmed().remove(QLatin1Char('\r'));
|
||||
QMap<QString, QString> result;
|
||||
const int size = output.size();
|
||||
for (int pos = 0; pos < size; ) {
|
||||
const int colonPos = output.indexOf(QLatin1Char(':'), pos);
|
||||
if (colonPos < 0)
|
||||
break;
|
||||
int endPos = output.indexOf(QLatin1Char('\n'), colonPos + 1);
|
||||
if (endPos < 0)
|
||||
endPos = size;
|
||||
const QString key = output.mid(pos, colonPos - pos);
|
||||
const QString value = output.mid(colonPos + 1, endPos - colonPos - 1);
|
||||
result.insert(key, value);
|
||||
pos = endPos + 1;
|
||||
}
|
||||
QFile qconfigPriFile(result.value(QStringLiteral("QT_HOST_DATA")) + QStringLiteral("/mkspecs/qconfig.pri"));
|
||||
if (qconfigPriFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
while (true) {
|
||||
const QByteArray line = qconfigPriFile.readLine();
|
||||
if (line.isEmpty())
|
||||
break;
|
||||
if (line.startsWith("QT_LIBINFIX")) {
|
||||
const int pos = line.indexOf('=');
|
||||
if (pos >= 0) {
|
||||
const QString infix = QString::fromUtf8(line.right(line.size() - pos - 1).trimmed());
|
||||
if (!infix.isEmpty())
|
||||
result.insert(QLatin1String(qmakeInfixKey), infix);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
std::wcerr << "Warning: Unable to read " << QDir::toNativeSeparators(qconfigPriFile.fileName())
|
||||
<< ": " << qconfigPriFile.errorString()<< '\n';
|
||||
}
|
||||
return result;
|
||||
//QMap<QString, QString> WinDependenciesScanner::qMakeAll(QString *errorMessage, const QString& binary)
|
||||
//{
|
||||
// QByteArray stdOut;
|
||||
// QByteArray stdErr;
|
||||
// unsigned long exitCode = 0;
|
||||
// if (!runProcess(binary, QStringList(QStringLiteral("-query")), QString(), &exitCode, &stdOut, &stdErr, errorMessage))
|
||||
// return QMap<QString, QString>();
|
||||
// if (exitCode) {
|
||||
// *errorMessage = binary + QStringLiteral(" returns ") + QString::number(exitCode)
|
||||
// + QStringLiteral(": ") + QString::fromLocal8Bit(stdErr);
|
||||
// return QMap<QString, QString>();
|
||||
// }
|
||||
// const QString output = QString::fromLocal8Bit(stdOut).trimmed().remove(QLatin1Char('\r'));
|
||||
// QMap<QString, QString> result;
|
||||
// const int size = output.size();
|
||||
// for (int pos = 0; pos < size; ) {
|
||||
// const int colonPos = output.indexOf(QLatin1Char(':'), pos);
|
||||
// if (colonPos < 0)
|
||||
// break;
|
||||
// int endPos = output.indexOf(QLatin1Char('\n'), colonPos + 1);
|
||||
// if (endPos < 0)
|
||||
// endPos = size;
|
||||
// const QString key = output.mid(pos, colonPos - pos);
|
||||
// const QString value = output.mid(colonPos + 1, endPos - colonPos - 1);
|
||||
// result.insert(key, value);
|
||||
// pos = endPos + 1;
|
||||
// }
|
||||
// QFile qconfigPriFile(result.value(QStringLiteral("QT_HOST_DATA")) + QStringLiteral("/mkspecs/qconfig.pri"));
|
||||
// if (qconfigPriFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
// while (true) {
|
||||
// const QByteArray line = qconfigPriFile.readLine();
|
||||
// if (line.isEmpty())
|
||||
// break;
|
||||
// if (line.startsWith("QT_LIBINFIX")) {
|
||||
// const int pos = line.indexOf('=');
|
||||
// if (pos >= 0) {
|
||||
// const QString infix = QString::fromUtf8(line.right(line.size() - pos - 1).trimmed());
|
||||
// if (!infix.isEmpty())
|
||||
// result.insert(QLatin1String(qmakeInfixKey), infix);
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// std::wcerr << "Warning: Unable to read " << QDir::toNativeSeparators(qconfigPriFile.fileName())
|
||||
// << ": " << qconfigPriFile.errorString()<< '\n';
|
||||
// }
|
||||
// return result;
|
||||
//}
|
||||
|
||||
bool WinDependenciesScanner::fillLibInfo(LibInfo &info, const QString &file) {
|
||||
|
||||
}
|
||||
|
||||
void WinDependenciesScanner::setEnvironment(const QStringList &env) {
|
||||
@ -186,3 +190,13 @@ QStringList WinDependenciesScanner::scan(const QString &path, Platform platfr,
|
||||
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 "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 {
|
||||
private:
|
||||
QStringList _env;
|
||||
@ -20,6 +31,8 @@ private:
|
||||
Platform platformFromMkSpec(const QString &xSpec);
|
||||
QMap<QString, QString> qMakeAll(QString *errorMessage,
|
||||
const QString &binary = "qmake");
|
||||
|
||||
bool fillLibInfo(LibInfo& info ,const QString& file);
|
||||
public:
|
||||
explicit WinDependenciesScanner();
|
||||
|
||||
|
@ -17,6 +17,8 @@ chmod a+rx $BASE_DIR/wrapper/bin/desktop-launch
|
||||
echo "Start static build"
|
||||
$BASE_DIR/staticBuild.sh Q_OS_LINUX_SNAP
|
||||
|
||||
chmod a+rx $BASE_DIR/distro/cqtdeployer
|
||||
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo ""
|
||||
|
Loading…
x
Reference in New Issue
Block a user