mirror of
https://github.com/QuasarApp/CQtDeployer.git
synced 2025-05-08 15:39:35 +00:00
fix #75 added suport strip command
This commit is contained in:
parent
b858144e41
commit
c3fa7fa43c
@ -158,17 +158,17 @@ bool Deploy::setBinDir(const QString &dir, bool recursive) {
|
||||
bool Deploy::createRunScript(const QString &target) {
|
||||
|
||||
QString content =
|
||||
"#!/bin/sh\n"
|
||||
"BASE_DIR=$(dirname \"$(readlink -f \"$0\")\")\n"
|
||||
"export "
|
||||
"LD_LIBRARY_PATH=\"$BASE_DIR\"/lib:\"$BASE_DIR\":$LD_LIBRARY_PATH\n"
|
||||
"export QML_IMPORT_PATH=\"$BASE_DIR\"/qml:QML_IMPORT_PATH\n"
|
||||
"export QML2_IMPORT_PATH=\"$BASE_DIR\"/qml:QML2_IMPORT_PATH\n"
|
||||
"export QT_PLUGIN_PATH=\"$BASE_DIR\"/plugins:QT_PLUGIN_PATH\n"
|
||||
"export "
|
||||
"QT_QPA_PLATFORM_PLUGIN_PATH=\"$BASE_DIR\"/plugins/"
|
||||
"platforms:QT_QPA_PLATFORM_PLUGIN_PATH\n"
|
||||
"\"$BASE_DIR\"/bin/%1 \"$@\"";
|
||||
"#!/bin/sh\n"
|
||||
"BASE_DIR=$(dirname \"$(readlink -f \"$0\")\")\n"
|
||||
"export "
|
||||
"LD_LIBRARY_PATH=\"$BASE_DIR\"/lib:\"$BASE_DIR\":$LD_LIBRARY_PATH\n"
|
||||
"export QML_IMPORT_PATH=\"$BASE_DIR\"/qml:QML_IMPORT_PATH\n"
|
||||
"export QML2_IMPORT_PATH=\"$BASE_DIR\"/qml:QML2_IMPORT_PATH\n"
|
||||
"export QT_PLUGIN_PATH=\"$BASE_DIR\"/plugins:QT_PLUGIN_PATH\n"
|
||||
"export "
|
||||
"QT_QPA_PLATFORM_PLUGIN_PATH=\"$BASE_DIR\"/plugins/"
|
||||
"platforms:QT_QPA_PLATFORM_PLUGIN_PATH\n"
|
||||
"\"$BASE_DIR\"/bin/%1 \"$@\"";
|
||||
|
||||
content = content.arg(QFileInfo(target).fileName());
|
||||
|
||||
@ -229,6 +229,10 @@ void Deploy::deploy() {
|
||||
copyFiles(noQTLibs);
|
||||
}
|
||||
|
||||
if (!QuasarAppUtils::Params::isEndable("noStrip") && !strip(targetDir)) {
|
||||
QuasarAppUtils::Params::verboseLog("strip failed!");
|
||||
}
|
||||
|
||||
settings.setValue(targetDir, deployedFiles);
|
||||
}
|
||||
|
||||
@ -308,7 +312,7 @@ bool Deploy::fileActionPrivate(const QString &file, const QString &target,
|
||||
}
|
||||
|
||||
if (QuasarAppUtils::Params::isEndable("always-overwrite") &&
|
||||
info.exists() && !QFile::remove(target + QDir::separator() + name)) {
|
||||
info.exists() && !QFile::remove(target + QDir::separator() + name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -377,7 +381,7 @@ 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)) {
|
||||
|
||||
winScaner.setEnvironment(deployEnvironment);
|
||||
extractWindowsLib(file, isExtractPlugins);
|
||||
@ -542,7 +546,7 @@ bool Deploy::copyFolder(const QString &from, const QString &to, const QStringLis
|
||||
}
|
||||
|
||||
QFileInfoList Deploy::findFilesInsideDir(const QString &name,
|
||||
const QString &dirpath) {
|
||||
const QString &dirpath) {
|
||||
QFileInfoList files;
|
||||
|
||||
QDir dir(dirpath);
|
||||
@ -566,7 +570,7 @@ QString Deploy::filterQmlPath(const QString &path) {
|
||||
if (path.contains(qmlDir)) {
|
||||
auto endIndex = path.indexOf(QDir::separator(), qmlDir.size() + 1);
|
||||
QString module =
|
||||
path.mid(qmlDir.size() + 1, endIndex - qmlDir.size() - 1);
|
||||
path.mid(qmlDir.size() + 1, endIndex - qmlDir.size() - 1);
|
||||
return qmlDir + QDir::separator() + module;
|
||||
}
|
||||
|
||||
@ -631,7 +635,7 @@ void Deploy::extractLinuxLib(const QString &file, bool isExtractPlugins) {
|
||||
}
|
||||
|
||||
if ((QuasarAppUtils::Params::isEndable("deploy-not-qt") || onlyCLibs) &&
|
||||
!noQTLibs.contains(line)) {
|
||||
!noQTLibs.contains(line)) {
|
||||
noQTLibs << line;
|
||||
extractLinuxLib(line, isExtractPlugins);
|
||||
}
|
||||
@ -669,7 +673,7 @@ void Deploy::extractWindowsLib(const QString &file, bool isExtractPlugins) {
|
||||
}
|
||||
|
||||
if ((onlyCLibs || QuasarAppUtils::Params::isEndable("deploy-not-qt")) &&
|
||||
!noQTLibs.contains(line)) {
|
||||
!noQTLibs.contains(line)) {
|
||||
noQTLibs << line;
|
||||
extractWindowsLib(line, isExtractPlugins);
|
||||
}
|
||||
@ -883,7 +887,7 @@ bool Deploy::extractQml() {
|
||||
|
||||
if (QuasarAppUtils::Params::isEndable("qmlDir")) {
|
||||
return extractQmlFromSource(
|
||||
QuasarAppUtils::Params::getStrArg("qmlDir"));
|
||||
QuasarAppUtils::Params::getStrArg("qmlDir"));
|
||||
|
||||
} else if (QuasarAppUtils::Params::isEndable("allQmlDependes")) {
|
||||
return extractQmlAll();
|
||||
@ -910,17 +914,48 @@ void Deploy::clear() {
|
||||
|
||||
}
|
||||
|
||||
void Deploy::strip(const QString &dir) {
|
||||
QProcess P;
|
||||
bool Deploy::strip(const QString &dir) {
|
||||
|
||||
P.setWorkingDirectory(dir);
|
||||
P.setArguments(QStringList() << "*");
|
||||
P.start("strip", QProcess::ReadOnly);
|
||||
#ifdef Q_OS_WIN
|
||||
return true;
|
||||
#else
|
||||
QFileInfo info(dir);
|
||||
|
||||
if (!P.waitForStarted())
|
||||
return;
|
||||
if (!P.waitForFinished())
|
||||
return;
|
||||
if (!info.exists()) {
|
||||
QuasarAppUtils::Params::verboseLog("dir not exits!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (info.isDir()) {
|
||||
QDir d(dir);
|
||||
auto list = d.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
|
||||
bool res = false;
|
||||
for (auto &&i : list) {
|
||||
res = res || strip(i.absoluteFilePath());
|
||||
}
|
||||
|
||||
return res;
|
||||
} else {
|
||||
|
||||
auto sufix = info.completeSuffix();
|
||||
if (!sufix.contains("so") && !sufix.contains("dll")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QProcess P;
|
||||
P.setProgram("strip");
|
||||
P.setArguments(QStringList() << info.absoluteFilePath());
|
||||
P.start();
|
||||
|
||||
if (!P.waitForStarted())
|
||||
return false;
|
||||
if (!P.waitForFinished())
|
||||
return false;
|
||||
|
||||
return P.exitCode() == 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Deploy::initEnvirement() {
|
||||
|
@ -75,7 +75,7 @@ class Deploy {
|
||||
|
||||
bool extractQml();
|
||||
|
||||
void strip(const QString &dir);
|
||||
bool strip(const QString &dir);
|
||||
|
||||
QStringList extractImportsFromDir(const QString &dirpath);
|
||||
QFileInfoList findFilesInsideDir(const QString &name, const QString &dirpath);
|
||||
@ -121,6 +121,8 @@ public:
|
||||
void setExtraPath(const QStringList &value);
|
||||
void setExtraPlugins(const QStringList &value);
|
||||
void setDepchLimit(int value);
|
||||
|
||||
friend class deploytest;
|
||||
};
|
||||
|
||||
#endif // DEPLOY_H
|
||||
|
@ -66,6 +66,7 @@ void DeployUtils::help() {
|
||||
qInfo() << " -extraPlugin[list,params]: set additional path for extraPlugin of app";
|
||||
qInfo() << " -recursiveDepth [params] : set Depth for recursive search of libs (default 0)";
|
||||
qInfo() << " -targetDir [params] : set target Dir for binaryes (default is path of first target)";
|
||||
qInfo() << " noStrip : skip strip step";
|
||||
|
||||
qInfo() << " verbose : show debug log";
|
||||
|
||||
|
@ -38,6 +38,7 @@ Key differences of this program:
|
||||
| -extraPlugin [list,params] | set additional path for extraPlugin of app |
|
||||
| -recursiveDepth [params] | set Depth for recursive search of libs (default 0) |
|
||||
| -targetDir [params] | set target Dir for binaryes (default is path of first target) |
|
||||
| noStrip | skip strip step |
|
||||
| verbose | show debug log |
|
||||
|
||||
|
||||
@ -95,7 +96,8 @@ Console QtDeployer является консольной реализацией
|
||||
| -extraPlugin [list,params] | Установить дополнительный путь для extraPlugin приложения |
|
||||
| -recursiveDepth [params] | Установит глубену поиска библиотек (по умолчанию 0) |
|
||||
| -targetDir [params] | Установит целевой коталог (по умолчанию это путь к первому развертываемому файлу)|
|
||||
| verbose | Показ дебаг лог |
|
||||
| noStrip | пропустить шаг strip |
|
||||
| verbose | Показ дебаг лога |
|
||||
|
||||
|
||||
#### Пример: cqtdeployer -bin myApp -qmlDir ~/MyAppProject/qml -qmake ~/Qt/5.11.1/gcc_64/bin/qmake clear
|
||||
|
@ -24,3 +24,6 @@ CONFIG -= app_bundle
|
||||
TEMPLATE = app
|
||||
|
||||
SOURCES += tst_deploytest.cpp
|
||||
|
||||
RESOURCES += \
|
||||
res.qrc
|
||||
|
5
UnitTests/res.qrc
Normal file
5
UnitTests/res.qrc
Normal file
@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file alias="debugLib">testRes/debugLibData</file>
|
||||
</qresource>
|
||||
</RCC>
|
BIN
UnitTests/testRes/debugLibData
Executable file
BIN
UnitTests/testRes/debugLibData
Executable file
Binary file not shown.
@ -11,7 +11,9 @@
|
||||
#include <deploy.h>
|
||||
#include <windependenciesscanner.h>
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QDir>
|
||||
#include <thread>
|
||||
// add necessary includes here
|
||||
|
||||
class deploytest : public QObject
|
||||
@ -26,8 +28,8 @@ private slots:
|
||||
void initTestCase();
|
||||
void cleanupTestCase();
|
||||
void testDeployUtils();
|
||||
void testDeploy();
|
||||
void testDeployScaner();
|
||||
void testDeployTarget();
|
||||
void testStrip();
|
||||
|
||||
};
|
||||
|
||||
@ -120,7 +122,7 @@ void deploytest::testDeployUtils() {
|
||||
|
||||
}
|
||||
|
||||
void deploytest::testDeploy() {
|
||||
void deploytest::testDeployTarget() {
|
||||
|
||||
Deploy *deploy = new Deploy();
|
||||
QStringList targets;
|
||||
@ -159,12 +161,41 @@ void deploytest::testDeploy() {
|
||||
|
||||
delete deploy;
|
||||
targets.clear();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void deploytest::testDeployScaner() {
|
||||
void deploytest::testStrip() {
|
||||
|
||||
QDir dir;
|
||||
dir.mkpath("./test/binTargetDir/");
|
||||
QFile testLib ("./test/binTargetDir/debugLib.so");
|
||||
|
||||
qint64 sizeBefor = 0;
|
||||
qint64 sizeAfter = 0;
|
||||
|
||||
if (testLib.open(QIODevice::ReadWrite| QIODevice::Truncate)) {
|
||||
QFile resData(":/debugLib");
|
||||
if (resData.open(QIODevice::ReadOnly)) {
|
||||
QByteArray tempData = resData.readAll();
|
||||
sizeBefor = tempData.size();
|
||||
testLib.write(tempData.data(), tempData.size());
|
||||
resData.close();
|
||||
}
|
||||
|
||||
testLib.close();
|
||||
}
|
||||
|
||||
Deploy *deploy = new Deploy();
|
||||
QVERIFY(deploy->strip("./test/binTargetDir"));
|
||||
|
||||
if (testLib.open(QIODevice::ReadOnly)) {
|
||||
sizeAfter = testLib.size();
|
||||
testLib.close();
|
||||
}
|
||||
|
||||
dir.setPath("./test/binTargetDir/");
|
||||
dir.removeRecursively();
|
||||
|
||||
QVERIFY(sizeBefor > sizeAfter);
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(deploytest)
|
||||
|
Loading…
x
Reference in New Issue
Block a user