fix qml deploy

This commit is contained in:
Andrei Yankovich 2018-08-24 16:18:37 +03:00
parent 67990d3f84
commit 00762badab
3 changed files with 116 additions and 21 deletions

View File

@ -56,9 +56,7 @@ QString Deploy::getTarget() const {
return target;
}
bool Deploy::setTarget(const QString &value) {
target = value;
targetDir = QFileInfo(target).absolutePath();
bool Deploy::initDirs() {
if (!QFileInfo::exists(targetDir + QDir::separator() + "lib") &&
!QDir(targetDir).mkdir("lib")) {
@ -74,6 +72,18 @@ bool Deploy::setTarget(const QString &value) {
return true;
}
bool Deploy::setTarget(const QString &value) {
target = value;
if (target.isEmpty()) {
return false;
}
targetDir = QFileInfo(target).absolutePath();
return true;
}
bool Deploy::createRunScript() {
QString content =
@ -402,6 +412,16 @@ QStringList Deploy::findFilesInsideDir(const QString &name,
return files;
}
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);
return qmlDir + QDir::separator() + module;
}
return "";
}
QStringList Deploy::extractImportsFromFiles(const QStringList &filepath){
QProcess p;
p.setProgram(qmlScaner);
@ -427,7 +447,16 @@ QStringList Deploy::extractImportsFromFiles(const QStringList &filepath){
QStringList result;
for (auto object : array) {
result << object.toObject().value("path").toString();
auto module = filterQmlPath(object.toObject().value("path").toString());
if (module.isEmpty()) {
continue;
}
if (!result.contains(module)) {
result << module;
}
}
return result;
@ -437,15 +466,47 @@ QStringList Deploy::extractImportsFromDir(const QString &dirpath) {
auto files = findFilesInsideDir("*.qml", dirpath);
QStringList result;
for (auto file: files) {
result.append(extractImportsFromFile(file));
}
result.append(extractImportsFromFiles(files));
return result;
}
bool Deploy::extractQml() {
bool Deploy::extractQmlAll() {
if (!QFileInfo::exists(qmlDir)){
qWarning() << "qml dir wrong!";
return false;
}
QDir dir(qmlDir);
QDir dirTo(targetDir);
if (!dirTo.cd("qml")) {
if (!dirTo.mkdir("qml")) {
return false;
}
if (!dirTo.cd("qml")) {
return false;
}
}
QStringList listItems;
if (!copyFolder(dir, dirTo, ".so.debug", &listItems)) {
return false;
}
for (auto item : listItems) {
extract(item, false);
}
return true;
}
bool Deploy::extractQmlFromSource(const QString sourceDir) {
qInfo() << "run extract qml";
QDir dirTo(targetDir);
@ -459,29 +520,54 @@ bool Deploy::extractQml() {
}
}
auto plugins = extractImportsFromDir(qmlDir);
QStringList plugins = extractImportsFromDir(sourceDir);
for (auto plugin : plugins) {
for (auto plugin : plugins) {
QDir dir(plugin);
QStringList listItems;
QDir dir(plugin);
QStringList listItems;
if (!dirTo.cd(dir.dirName())) {
if (!dirTo.mkdir(dir.dirName())) {
return false;
}
if (!copyFolder(dir, dirTo, ".so.debug", &listItems)) {
return false;
}
if (!dirTo.cd(dir.dirName())) {
return false;
}
}
for (auto item : listItems) {
extract(item, false);
}
if (!copyFolder(dir, dirTo, ".so.debug", &listItems)) {
return false;
}
dirTo.cdUp();
for (auto item : listItems) {
extract(item, false);
}
}
return true;
}
bool Deploy::extractQml() {
if (QuasarAppUtils::isEndable("qmlDir")) {
return extractQmlFromSource(QuasarAppUtils::getStrArg("qmlDir"));
} else if (QuasarAppUtils::isEndable("allQmlDependes")){
return extractQmlAll();
} else {
return false;
}
return true;
}
void Deploy::clear() {
QDir dir(targetDir);
if (dir.cd("lib")) {

View File

@ -47,6 +47,9 @@ private:
QStringList extractImportsFromDir(const QString &dirpath);
QStringList findFilesInsideDir(const QString &name, const QString &dirpath);
QStringList extractImportsFromFiles(const QStringList &filepath);
bool extractQmlAll();
bool extractQmlFromSource(const QString sourceDir);
QString filterQmlPath(const QString &path);
public:
Deploy();
bool getDeployQml() const;
@ -65,6 +68,7 @@ public:
void clear();
bool initDirs();
};
#endif // DEPLOY_H

View File

@ -59,12 +59,17 @@ bool parseQt(Deploy& deploy) {
return false;
}
if (!deploy.setTarget(bin)) {
qCritical() << "error init targeet dir";
return false;
}
if (QuasarAppUtils::isEndable("clear")) {
qInfo() << "clear old data";
deploy.clear();
}
if (!deploy.setTarget(bin)) {
if (!deploy.initDirs()) {
qCritical() << "error init targeet dir";
return false;
}