From eb6d378de271b4e4038d426bc3f93d4f29d761c2 Mon Sep 17 00:00:00 2001 From: peri4 Date: Mon, 31 Jan 2022 19:55:23 +0300 Subject: [PATCH] deploy tool unchained from "grep" and support qt6 --- utils/deploy_tool/main.cpp | 76 +++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 43 deletions(-) diff --git a/utils/deploy_tool/main.cpp b/utils/deploy_tool/main.cpp index 37abc816..4ef02a34 100644 --- a/utils/deploy_tool/main.cpp +++ b/utils/deploy_tool/main.cpp @@ -207,10 +207,19 @@ PIString execute(const PIString & cmd) { } +PIStringList filter(const PIString & in, const PIString & f) { + PIStringList ret, lines = in.split("\n"); + for (const PIString & l: lines) + if (l.contains(f)) ret << l.trimmed(); + return ret; +} + + void checkQtLib(PIString lib) { PIString base = lib.toLowerCase(), pref, suff; if (base.startsWith("lib")) {pref += "lib"; base.cutLeft(3);} if (base.startsWith("qt5")) {pref += "Qt5"; base.cutLeft(3);} + if (base.startsWith("qt6")) {pref += "Qt6"; base.cutLeft(3);} if (base.startsWith("qt" )) {pref += "Qt" ; base.cutLeft(2);} if (base.find('.') >= 0) {suff = base.right(base.size_s() - base.find('.')); base = base.left(base.find('.'));} for (int i = 0; ; ++i) { @@ -244,44 +253,34 @@ void procLdd(PIString file, bool ext_lib = false, int cur_depth = 0) { } PIStringList lines; if (is_ldd) { - lines = execute(ldd + " " + file).split("\n"); + lines = execute(ldd + " \"" + file + "\"").split("\n"); } else { PIString cmd; if (!readelf.isEmpty()) { - cmd = readelf + " -a " + file; - cmd += " | grep \"Shared library:\" | grep -oG \"\\[.*\\]\""; + lines = filter(execute(readelf + " -a \"" + file + "\""), "Shared library:"); + for (PIString & l: lines) { + l.cutRight(1); + l.cutLeft(l.find('[') + 1); + l.trim();//.append('.').prepend('.'); + } } if (!objdump.isEmpty()) { - cmd = objdump + " -p " + file; - cmd += " | grep \"DLL Name:\""; - lines = execute(cmd).split("\n"); - cmd = objdump + " -p " + file; - cmd += " | grep \"NEEDED\""; - lines << execute(cmd).split("\n"); - cmd.clear(); - } - if (!otool.isEmpty()) { - cmd = otool + " -L " + file; - cmd += " | grep -o \".*(\""; - } - //piCout << cmd; - if (!cmd.isEmpty()) - lines = execute(cmd).split("\n"); - if (!objdump.isEmpty()) { - piForeach (PIString & l, lines) { - l.trim(); - if (l.startsWith("DLL")) l.cutLeft(9).trim(); - else l.cutLeft(6).trim(); - l.append('.').prepend('.'); + PIString out = execute(objdump + " -p \"" + file + "\""); + lines = filter(out, "DLL Name:"); + lines << filter(out, "NEEDED"); + for (PIString & l: lines) { + if (l.startsWith("DLL")) l.cutLeft(9); + else l.cutLeft(6); + l.trim();//.append('.').prepend('.'); } } if (!otool.isEmpty()) { + lines = filter(execute(otool + " -L \"" + file + "\""), "("); piForeach (PIString & l, lines) { - l.trim().cutRight(1).trim(); - l.append('.').prepend('.'); + l = l.left(l.find('(')); + l.trim();//.append('.').prepend('.'); } } - //piCout << "readelf:" << vs; } piForeachC (PIString & sl, lines) { PIString l = sl.trimmed(); @@ -305,7 +304,7 @@ void procLdd(PIString file, bool ext_lib = false, int cur_depth = 0) { continue; } } else { - l.cutLeft(1).cutRight(1).trim(); + //l.cutLeft(1).cutRight(1).trim(); if (l.isEmpty()) continue; if (!otool.isEmpty()) { if (!l.startsWith("/usr/local/")) { @@ -379,7 +378,7 @@ void procQt() { PIString qloc = l.trim(); piCout << "Qt" << qv << "in" << qloc; PIString qdir; - PIStringList suffixes({".", "..", "qt5", "../qt5"}); + PIStringList suffixes({".", "..", "qt5", "../qt5", "qt6", "../qt6"}); piForeachC (PIString s, suffixes) { PIString qd = qloc + "/" + s + "/plugins/"; if (piDebug) PICout(AddSpaces) << "Qt plugins root try" << qd << "..."; @@ -392,17 +391,6 @@ void procQt() { } if (qdir.isEmpty()) break; -/*#ifdef WINDOWS - if (qt_dir.isEmpty()) - qdir += "/../plugins/"; - else - qdir += "/plugins/"; -#else - if (qt_dir.isEmpty()) - qdir += "/qt5/plugins/"; - else - qdir += "/plugins/"; -#endif*/ piForeachC (PIString & plugin, pdirs) { PIStringList filters = qt_filters[plugin]; piForeachC (PIString & f, filters) { @@ -471,9 +459,11 @@ void patchNameTool() { //PICout(DefaultControls) << "map" << f << "->" << (out_dir + frameworkName(f) + "/" + frameworkInternalPath(f)); } piForeach (PIString local_lib, patch_list) { - cmd = otool + " -L \"" + local_lib; - cmd += "\" | grep -o \".*(\""; - dlibs = execute(cmd).split("\n"); + dlibs = filter(execute(otool + " -L \"" + local_lib + "\""), "("); + piForeach (PIString & l, dlibs) { + l = l.left(l.find('(')); + l.trim(); + } if (!dlibs.isEmpty()) { execute("chmod +w \"" + local_lib + "\""); }