4
1
mirror of https://github.com/QuasarApp/CQtDeployer.git synced 2025-05-10 16:39:35 +00:00

added deploy c++ libs

This commit is contained in:
Andrei Yankovich 2018-08-17 20:47:49 +03:00
parent c33c5db003
commit 34ba411532
9 changed files with 407 additions and 0 deletions

1
.gitignore vendored

@ -28,6 +28,7 @@ ui_*.h
*.jsc
Makefile*
*build-*
build/*
# Qt unit tests
target_wrapper.*

3
.gitmodules vendored Normal file

@ -0,0 +1,3 @@
[submodule "QuasarAppLib"]
path = QuasarAppLib
url = git@github.com:QuasarApp/QuasarAppLib.git

7
CDQ.pro Normal file

@ -0,0 +1,7 @@
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS += CDQ \
QuasarAppLib
QuasarAppLib.file = $$PWD/QuasarAppLib/QuasarApp.pro

73
CDQ/.gitignore vendored Normal file

@ -0,0 +1,73 @@
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------
*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash
# qtcreator generated files
*.pro.user*
# xemacs temporary files
*.flc
# Vim temporary files
.*.swp
# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*
# MinGW generated files
*.Debug
*.Release
# Python byte code
*.pyc
# Binaries
# --------
*.dll
*.exe

29
CDQ/CDQ.pro Normal file

@ -0,0 +1,29 @@
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
include('./../QuasarAppLib/deploy.pri');
include('./../QuasarAppLib/QuasarLib.pri');
TARGET = CDQ
SOURCES += \
main.cpp \
deploy.cpp
HEADERS += \
deploy.h
QMAKE_LFLAGS += -Wl,-rpath,"'$$DESTDIR'"

151
CDQ/deploy.cpp Normal file

@ -0,0 +1,151 @@
#include "deploy.h"
#include <QFileInfo>
#include <QDebug>
#include <QDir>
#include <QFile>
#include <quasarapp.h>
#include <QProcess>
bool Deploy::getDeployQml() const {
return deployQml;
}
void Deploy::setDeployQml(bool value) {
deployQml = value;
}
QString Deploy::getQmlScaner() const {
return qmlScaner;
}
void Deploy::setQmlScaner(const QString &value) {
qmlScaner = value;
deployQml = QFileInfo(qmlScaner).isFile();
}
QString Deploy::getQmake() const {
return qmake;
}
void Deploy::setQmake(const QString &value) {
qmake = value;
}
QString Deploy::getTarget() const {
return target;
}
bool Deploy::setTarget(const QString &value) {
target = value;
targetDir = QFileInfo(target).path();
if (!QDir(targetDir).mkdir("lib")){
return false;
}
if (QuasarAppUtils::isEndable("qmlDir") &&
!QDir(targetDir).mkdir("qml")){
return false;
}
return true;
}
void Deploy::deploy() {
qInfo() << "target deploy started!!";
extract(target);
copyFiles(QtLibs, targetDir + QDir::separator() + "lib");
if (QuasarAppUtils::isEndable("deploy-not-qt")) {
copyFiles(noQTLibs, targetDir + QDir::separator() + "lib");
}
}
QString Deploy::getQtDir() const {
return qtDir;
}
void Deploy::setQtDir(const QString &value) {
qtDir = value;
}
bool Deploy::isQtLib(const QString &lib) const {
QFileInfo info(lib);
return info.path().contains(qtDir);
}
void Deploy::copyFiles(const QStringList &files , const QString& target) {
for (auto file : files) {
if (!copyFile(file, target)) {
qWarning() << file + " not copied";
}
}
}
bool Deploy::copyFile(const QString &file, const QString& target) {
auto info = QFileInfo(file);
auto name = info.baseName();
if (QuasarAppUtils::isEndable("always-overwrite") &&
!QFile::remove(target + QDir::separator() + name)){
return false;
}
qInfo() << "copy :" << target + QDir::separator() + name;
return QFile::copy(file, target + QDir::separator() + name);
}
void Deploy::extract(const QString &file) {
qInfo() << "extract lib :" << file;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("LD_LIBRARY_PATH", qtDir + "/lib");
env.insert("QML_IMPORT_PATH", qtDir + "/qml");
env.insert("QML2_IMPORT_PATH", qtDir + "/qml");
env.insert("QT_PLUGIN_PATH", qtDir + "/plugins");
env.insert("QT_QPA_PLATFORM_PLUGIN_PATH", 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());
QStringList libs;
for (QString &line : data.split("\n", QString::SkipEmptyParts)) {
line = line.simplified();
auto innerlist = line.split(" ");
if (innerlist.count() < 3) continue;
line = innerlist[2];
if (!line.startsWith("/")) {
continue;
}
if (isQtLib(line) && !QtLibs.contains(line)) {
QtLibs << line;
extract(line);
}
if (QuasarAppUtils::isEndable("deploy-not-qt")) {
noQTLibs << line;
extract(line);
}
}
}
Deploy::Deploy(){
}

43
CDQ/deploy.h Normal file

@ -0,0 +1,43 @@
#ifndef DEPLOY_H
#define DEPLOY_H
#include <QString>
#include <QStringList>
class Deploy
{
private:
bool deployQml = false;
QString qmlScaner = "";
QString qmake = "";
QString qtDir = "";
QString target = "";
QString targetDir = "";
QStringList QtLibs;
QStringList noQTLibs;
QStringList qmlLibs;
bool isQtLib(const QString& lib) const;
void copyFiles(const QStringList &files, const QString &target);
bool copyFile(const QString& file, const QString &target);
void extract(const QString& file);
public:
Deploy();
bool getDeployQml() const;
void setDeployQml(bool value);
QString getQmlScaner() const;
void setQmlScaner(const QString &value);
QString getQmake() const;
void setQmake(const QString &value);
QString getTarget() const;
bool setTarget(const QString &value);
void deploy();
QString getQtDir() const;
void setQtDir(const QString &value);
};
#endif // DEPLOY_H

99
CDQ/main.cpp Normal file

@ -0,0 +1,99 @@
#include <QCoreApplication>
#include "quasarapp.h"
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include "deploy.h"
#include <QList>
void help() {
qInfo() << "";
qInfo() << "Usage: CDQ <app-binary> [options]";
qInfo() << "";
qInfo() << "Options:";
qInfo() << " -help / -h : show help.";
qInfo() << " -always-overwrite : Copy files even if the target file exists.";
qInfo() << " -bin : deployment binry.";
qInfo() << " -qmlDir : qml datadir. for example ~/Qt/5.11.1/gcc_64/qml";
qInfo() << " -noStrip : no strip deployed lib";
qInfo() << " -deploy-not-qt : deploy all libs";
qInfo() << " -qmake : qmake path. for example";
qInfo() << " | for example ~/Qt/5.11.1/gcc_64/bin/qmake";
}
bool parseQt(Deploy& deploy) {
auto qmake = QuasarAppUtils::getStrArg("qmake");
QString basePath = "";
QFileInfo info(qmake);
if (!info.isFile() || (info.baseName() != "qmake")) {
return false;
}
basePath = info.path();
deploy.setQmake(qmake);
auto bin = QuasarAppUtils::getStrArg("bin");
info.setFile(bin);
if (!info.isFile()) {
return false;
}
if (!deploy.setTarget(bin)) {
qCritical() << "error init targeet dir";
return false;
}
auto qmlDir = QuasarAppUtils::getStrArg("qmlDir");
QDir dir(basePath);
if (qmlDir.isEmpty()) {
deploy.setDeployQml(false);
} else {
auto scaners = dir.entryList(QStringList() << "qmlimportscanner");
if (!scaners.size()) {
qWarning () << "qmlimportscanner not installed";
} else {
deploy.setQmlScaner(scaners.first());
}
}
if (!dir.cdUp()) {
return false;
}
deploy.setQtDir(dir.path());
return true;
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
if (!QuasarAppUtils::parseParams(argc, argv)) {
qWarning() << "wrong parametrs";
help();
exit(0);
};
if (QuasarAppUtils::isEndable("h") ||
QuasarAppUtils::isEndable("help")) {
help();
exit(0);
}
Deploy deploy;
if (!parseQt(deploy)) {
qCritical() << "qt parse error";
help();
exit(1);
}
deploy.deploy();
return a.exec();
}

1
QuasarAppLib Submodule

@ -0,0 +1 @@
Subproject commit 8e899fecfb563d676b5ea036f03ea4b61c5ceb2f