code format

This commit is contained in:
2022-12-14 14:13:52 +03:00
parent 430a41fefc
commit c2b8a8d6da
297 changed files with 27331 additions and 24162 deletions

View File

@@ -1,26 +1,26 @@
/*
PIP - Platform Independent Primitives
Deploy tool
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Deploy tool
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "picli.h"
#include "pidir.h"
#include "piprocess.h"
#include "piiostream.h"
#include "piprocess.h"
#define DELIM "::"
@@ -31,15 +31,15 @@ PIString qplatforms;
void setCommands() {
#ifdef WINDOWS
cmd_copy = "copy /y ";
cmd_copy = "copy /y ";
cmd_copydir = "copy /y ";
cmd_suffix = " 1> NUL";
qplatforms = "windows";
cmd_suffix = " 1> NUL";
qplatforms = "windows";
#else
cmd_copy = "cp -f ";
cmd_copy = "cp -f ";
cmd_copydir = "cp -rf ";
# ifdef MAC_OS
qplatforms = "cocoa";
qplatforms = "cocoa";
# else
qplatforms = "xcb";
# endif
@@ -64,11 +64,13 @@ void usage() {
piCout << "Default regexp set by \"*=<regexp>\".";
piCout << "\"*=\" disable optional plugins.";
piCout << "";
piCout << Green << Bold << "Usage:" << Default << "\"deploy_tool [-hvfC] [--dependencies [--prefix <text>]] "
"[--qt-plugins-dir <d>] [-s <search_path>] [--ignore <libs>] [-S <styles>] "
"[-l <ldd>] [-D <dpkg>] [--dpkg-workdir <d>] [-L <readelf> | -W <objdump> | -M <otool>] "
"[--name-tool <pathS>] [--rpath] [-d <depth>] [-q <qtdir>] [-a <add_libs>] [-S <styles>] "
"[-P <platforms>] [--qt-plugins <d>] [--qt-modules <l>] [--qt-conf-dir <d>] -o <out_path> <file> [<file2> ...]\"" << NewLine;
piCout << Green << Bold << "Usage:" << Default
<< "\"deploy_tool [-hvfC] [--dependencies [--prefix <text>]] "
"[--qt-plugins-dir <d>] [-s <search_path>] [--ignore <libs>] [-S <styles>] "
"[-l <ldd>] [-D <dpkg>] [--dpkg-workdir <d>] [-L <readelf> | -W <objdump> | -M <otool>] "
"[--name-tool <pathS>] [--rpath] [-d <depth>] [-q <qtdir>] [-a <add_libs>] [-S <styles>] "
"[-P <platforms>] [--qt-plugins <d>] [--qt-modules <l>] [--qt-conf-dir <d>] -o <out_path> <file> [<file2> ...]\""
<< NewLine;
piCout << Green << Bold << "Details:";
piCout << Bold << "Debug control";
piCout << "-h, --help " << Green << "- display this message and exit";
@@ -76,7 +78,8 @@ void usage() {
piCout << "";
piCout << Bold << "Processing control";
piCout << "-f, --fake " << Green << "- don`t copy, only print";
piCout << "-s <search_path> " << Green << "- set search pathes for system libraries, may be separated by \"" DELIM "\", default \"/usr/lib\"";
piCout << "-s <search_path> " << Green
<< "- set search pathes for system libraries, may be separated by \"" DELIM "\", default \"/usr/lib\"";
piCout << "--ignore <libs> " << Green << "- ignore libraries names, may be separated by \"" DELIM "\", default \"\"";
piCout << "-l <ldd> " << Green << "- \"ldd\" path, default \"/usr/bin/ldd\"";
piCout << "-L <readelf> " << Green << "- \"readelf\" path, overrides \"ldd\"";
@@ -105,7 +108,8 @@ void usage() {
piCout << "";
piCout << Bold << "Input control";
piCout << "<file> ... " << Green << "- executable to process";
piCout << "-a <add_libs> " << Green << "- additional libs, separated by \"" DELIM "\". Libraries will be searched in <search_path>";
piCout << "-a <add_libs> " << Green
<< "- additional libs, separated by \"" DELIM "\". Libraries will be searched in <search_path>";
}
struct QtDep {
@@ -113,24 +117,27 @@ struct QtDep {
PIString lib;
PIStringList plugins;
};
QtDep qt_deps[] = {
QtDep("core" , PIStringList() << "platforms"),
QtDep("gui" , PIStringList() << "imageformats"),
QtDep("widgets" , PIStringList() << "styles"),
QtDep("sql" , PIStringList() << "sqldrivers"),
QtDep("positioning" , PIStringList() << "position"),
QtDep("location" , PIStringList() << "geoservices"),
QtDep("multimedia" , PIStringList() << "audio" << "mediaservice" << "playlistformats"),
QtDep("printsupport" , PIStringList() << "printsupport"),
QtDep("virtualkeyboard", PIStringList() << "platforminputcontexts"),
QtDep("sensors" , PIStringList() << "sensors" << "sensorgestures"),
QtDep("texttospeech" , PIStringList() << "texttospeech"),
QtDep("serialbus" , PIStringList() << "canbus"),
QtDep()
};
QtDep qt_deps[] = {QtDep("core", PIStringList() << "platforms"),
QtDep("gui", PIStringList() << "imageformats"),
QtDep("widgets", PIStringList() << "styles"),
QtDep("sql", PIStringList() << "sqldrivers"),
QtDep("positioning", PIStringList() << "position"),
QtDep("location", PIStringList() << "geoservices"),
QtDep("multimedia",
PIStringList() << "audio"
<< "mediaservice"
<< "playlistformats"),
QtDep("printsupport", PIStringList() << "printsupport"),
QtDep("virtualkeyboard", PIStringList() << "platforminputcontexts"),
QtDep("sensors",
PIStringList() << "sensors"
<< "sensorgestures"),
QtDep("texttospeech", PIStringList() << "texttospeech"),
QtDep("serialbus", PIStringList() << "canbus"),
QtDep()};
int depth = 8;
int depth = 8;
bool fake = false, is_ldd = true, is_deps = false, need_qt = false, make_qt_format = true, rpath = false, win_target = false;
PIString ldd, readelf, objdump, otool, dpkg, nametool, strip, out_dir, qt_dir, dpkg_workdir;
PIString qt_pref, qt_suff, qt_conf_dir, qt_plugins_dir, target_dir;
@@ -141,9 +148,8 @@ PIMap<PIString, PIStringList> qt_filters;
PIString findLib(const PIString & l) {
if (PIFile::isExists(l)) return l;
piForeachC (PIString & s, lib_dirs) {
if (PIFile::isExists(s + l))
return s + l;
piForeachC(PIString & s, lib_dirs) {
if (PIFile::isExists(s + l)) return s + l;
if (win_target || l.toLowerCase().endsWith("dll")) {
PIFile::FileInfo info(l);
PIString fn = info.baseName(), fe = info.extension(), nn;
@@ -166,7 +172,6 @@ PIString findLib(const PIString & l) {
if (PIFile::isExists(nn)) return nn;
nn = s + fn.toUpperCase() + "." + fe.toUpperCase();
if (PIFile::isExists(nn)) return nn;
}
}
return "";
@@ -176,7 +181,7 @@ PIString findLib(const PIString & l) {
PIString frameworkName(const PIString & l) {
if (!l.contains(".framework/")) return "";
PIStringList ll = l.split("/");
piForeachRC (PIString & _f, ll) {
piForeachRC(PIString & _f, ll) {
if (_f.endsWith(".framework")) {
return _f;
}
@@ -218,22 +223,37 @@ PIStringList filter(const PIString & in, const PIString & f) {
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) {
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) {
if (qt_deps[i].lib.isEmpty()) break;
if (qt_deps[i].lib == base) {
qt_plugins << qt_deps[i].plugins;
//piCout << "add qt plugins" << qt_deps[i].plugins << "now" << qt_plugins;
// piCout << "add qt plugins" << qt_deps[i].plugins << "now" << qt_plugins;
need_qt = true;
qt_libs << lib;
if (make_qt_format) {
make_qt_format = false;
qt_pref = pref;
qt_suff = suff;
qt_pref = pref;
qt_suff = suff;
}
break;
}
@@ -262,28 +282,30 @@ void procLdd(PIString file, bool ext_lib = false, int cur_depth = 0) {
for (PIString & l: lines) {
l.cutRight(1);
l.cutLeft(l.find('[') + 1);
l.trim();//.append('.').prepend('.');
l.trim(); //.append('.').prepend('.');
}
}
if (!objdump.isEmpty()) {
PIString out = execute(objdump + " -p \"" + file + "\"");
lines = filter(out, "DLL Name:");
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 (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) {
piForeach(PIString & l, lines) {
l = l.left(l.find('('));
l.trim();//.append('.').prepend('.');
l.trim(); //.append('.').prepend('.');
}
}
}
piForeachC (PIString & sl, lines) {
piForeachC(PIString & sl, lines) {
PIString l = sl.trimmed();
if (!otool.isEmpty()) {
PIString fname = frameworkName(l);
@@ -297,26 +319,25 @@ void procLdd(PIString file, bool ext_lib = false, int cur_depth = 0) {
if (is_ldd) {
if (!l.contains("=>")) continue;
l.cutLeft(l.find("=>") + 2);
if (l.contains("("))
l.cutRight(l.length() - l.find("("));
if (l.contains("(")) l.cutRight(l.length() - l.find("("));
l.trim();
if (l.toLowerCase() == "not found") {
miss_libs << sl.left(sl.find("=>")).trim();
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/")) {
PIFile::FileInfo fi;
fi.path = l;
l = fi.name();
l = fi.name();
}
}
PIString flp = findLib(l);
if (flp.isEmpty()) {
//piCout << "Can`t find" << l;
// piCout << "Can`t find" << l;
miss_libs << l;
continue;
}
@@ -324,10 +345,10 @@ void procLdd(PIString file, bool ext_lib = false, int cur_depth = 0) {
}
if (all_libs[l]) continue;
PIFile::FileInfo fi;
fi.path = l;
fi.path = l;
PIString lname = fi.baseName();
if (lname.startsWith("lib")) lname.cutLeft(3);
//piCout << "check ignore" << lname << ignore_libs;
// piCout << "check ignore" << lname << ignore_libs;
if (ignore_libs.contains(lname)) {
continue;
}
@@ -336,9 +357,8 @@ void procLdd(PIString file, bool ext_lib = false, int cur_depth = 0) {
all_libs << l;
}
PIVector<PIString> clibs = cur_libs.toVector();
if (!clibs.isEmpty())
piCout << " new dependencies:\n -" << PIStringList(clibs).join("\n - ");
piForeachC (PIString & l, clibs) {
if (!clibs.isEmpty()) piCout << " new dependencies:\n -" << PIStringList(clibs).join("\n - ");
piForeachC(PIString & l, clibs) {
procLdd(l, false, cur_depth);
}
}
@@ -348,7 +368,8 @@ void copyWildcard(const PIString & from, const PIString & to) {
if (fake) return;
PIDir(to).make();
#ifdef WINDOWS
PIFile::FileInfo fi; fi.path = from;
PIFile::FileInfo fi;
fi.path = from;
system(("robocopy \"" + fi.dir() + "\" \"" + to + "\" \"" + fi.name() + "\" /NJH /NJS /NP /NDL /NS /NC /NFL 1> NUL").data());
#else
system((cmd_copy + from + " \"" + to + "/\"" + cmd_suffix).data());
@@ -357,7 +378,7 @@ void copyWildcard(const PIString & from, const PIString & to) {
void procQt() {
//piCout << "qmake ...";
// piCout << "qmake ...";
PIString vs;
if (qt_dir.isEmpty()) {
vs = execute("qmake -v");
@@ -367,11 +388,10 @@ void procQt() {
}
} else
vs = "QMake version ?.?\nUsing Qt version ?.?.? in " + qt_dir;
PIStringList vsl = vs.split("\n");
PIStringList vsl = vs.split("\n");
PIStringList pdirs = qt_plugins.toVector();
if (!fake)
PIDir(qt_plugins_dir).make(true);
piForeach (PIString l, vsl) {
if (!fake) PIDir(qt_plugins_dir).make(true);
piForeach(PIString l, vsl) {
if (l.trim().contains("Qt version")) {
l.cutLeft(l.find("Qt version") + 10).trim();
PIString qv = l.takeWord();
@@ -380,7 +400,7 @@ void procQt() {
piCout << "Qt" << qv << "in" << qloc;
PIString qdir;
PIStringList suffixes({".", "..", "qt5", "../qt5", "qt6", "../qt6"});
piForeachC (PIString s, suffixes) {
piForeachC(PIString s, suffixes) {
PIString qd = qloc + "/" + s + "/plugins/";
if (piDebug) PICout(AddSpaces) << "Qt plugins root try" << qd << "...";
if (PIDir::isExists(qd + "platforms")) {
@@ -390,15 +410,14 @@ void procQt() {
}
piCout << " no";
}
if (qdir.isEmpty())
break;
piForeachC (PIString & plugin, pdirs) {
if (qdir.isEmpty()) break;
piForeachC(PIString & plugin, pdirs) {
PIStringList filters = qt_filters[plugin];
piForeachC (PIString & f, filters) {
piForeachC(PIString & f, filters) {
if (f.isEmpty()) continue;
copyWildcard(qdir + plugin + "/" + f, qt_plugins_dir + plugin);
PIVector<PIFile::FileInfo> copied = PIDir(qt_plugins_dir + plugin).entries();
piForeachC (PIFile::FileInfo & fi, copied) {
piForeachC(PIFile::FileInfo & fi, copied) {
if (fi.isFile()) {
procLdd(fi.path);
plugin_libs << fi.path;
@@ -414,20 +433,18 @@ void procQt() {
bool procDpkg(const PIString & l) {
PIString dpkgdir;
if (!dpkg_workdir.isEmpty())
dpkgdir = " --admindir=" + dpkg_workdir;
if (!dpkg_workdir.isEmpty()) dpkgdir = " --admindir=" + dpkg_workdir;
PIFile::FileInfo fi;
fi.path = l;
fi.path = l;
PIString cmd = dpkg + dpkgdir + " -S " + fi.name() + " 2> /dev/null";
//PICout(true) << cmd;
PIString vs = execute(cmd);
// PICout(true) << cmd;
PIString vs = execute(cmd);
if (!vs.isEmpty()) {
vs = vs.left(vs.find(":"));
if (!vs.isEmpty())
all_deps << vs;
if (!vs.isEmpty()) all_deps << vs;
return true;
}
//piCout << "No dep on" << l;
// piCout << "No dep on" << l;
return false;
}
@@ -437,31 +454,31 @@ void patchNameTool() {
PIStringList clibs = all_libs.toVector(), flibs = framework_libs.toVector(), patch_list;
PIStringList dlibs;
PIString libname, cmd;
//PICout(DefaultControls) << "start patch" << clibs;
// PICout(DefaultControls) << "start patch" << clibs;
PIFile::FileInfo fi;
patch_list = input_files;
patch_list << plugin_libs;
piForeach (PIString l, clibs) {
piForeach(PIString l, clibs) {
fi.path = l;
patch_list << (out_dir + fi.name());
}
piForeach (PIString local_lib, patch_list) {
piForeach(PIString local_lib, patch_list) {
execute("chmod +w \"" + local_lib + "\"");
fi.path = local_lib;
cmd = nametool + " -id \"@executable_path/../Frameworks/" + fi.name() + "\"";
cmd = nametool + " -id \"@executable_path/../Frameworks/" + fi.name() + "\"";
cmd += " \"" + local_lib + "\" 2> /dev/null";
//piCout << " " << cmd;
// piCout << " " << cmd;
execute(cmd);
}
piForeach (PIString f, flibs) {
piForeach(PIString f, flibs) {
PIString fl = findLib(frameworkName(f));
if (fl.isEmpty()) continue;
patch_list << (out_dir + frameworkName(f) + "/" + frameworkInternalPath(f));
//PICout(DefaultControls) << "map" << f << "->" << (out_dir + frameworkName(f) + "/" + frameworkInternalPath(f));
// PICout(DefaultControls) << "map" << f << "->" << (out_dir + frameworkName(f) + "/" + frameworkInternalPath(f));
}
piForeach (PIString local_lib, patch_list) {
piForeach(PIString local_lib, patch_list) {
dlibs = filter(execute(otool + " -L \"" + local_lib + "\""), "(");
piForeach (PIString & l, dlibs) {
piForeach(PIString & l, dlibs) {
l = l.left(l.find('('));
l.trim();
}
@@ -469,12 +486,12 @@ void patchNameTool() {
execute("chmod +w \"" + local_lib + "\"");
}
piCout << "patch" << local_lib;
piForeach (PIString sys_lib, dlibs) {
piForeach(PIString sys_lib, dlibs) {
sys_lib.cutRight(1).trim();
fi.path = sys_lib;
libname = fi.name();
fi.path = sys_lib;
libname = fi.name();
PIString fl = findLib(libname), fname = frameworkName(sys_lib);
//piCout << " check" << sys_lib << fl;
// piCout << " check" << sys_lib << fl;
PIString new_path;
if (all_libs.contains(fl) || all_libs.contains(sys_lib)) {
new_path = "@executable_path/../Frameworks/" + libname;
@@ -491,12 +508,12 @@ void patchNameTool() {
cmd = nametool + " -change \"" + sys_lib + "\"";
cmd += " \"" + new_path + "\"";
cmd += " \"" + local_lib + "\" 2> /dev/null";
//piCout << " *" << cmd;
// piCout << " *" << cmd;
execute(cmd);
}
}
}
piForeach (PIString bin, input_files) {
piForeach(PIString bin, input_files) {
cmd = nametool + " -add_rpath \"@executable_path/../Frameworks\"";
cmd += " \"" + bin + "\" 2> /dev/null";
execute(cmd);
@@ -507,10 +524,9 @@ void patchNameTool() {
void patchRPathFile(const PIFile::FileInfo & file) {
PIString fo = execute("file \"" + file.path + "\"");
if (!fo.contains("ELF")) return;
PIString rp = "\\$ORIGIN:\\$ORIGIN/lib";
PIString rp = "\\$ORIGIN:\\$ORIGIN/lib";
PIString arp = PIDir(file.dir()).relative(out_dir);
if (!arp.isEmpty() && arp != "." && arp != "lib")
rp.append(":\\$ORIGIN/" + arp);
if (!arp.isEmpty() && arp != "." && arp != "lib") rp.append(":\\$ORIGIN/" + arp);
PIString cmd = "patchelf --set-rpath \"" + rp + "\" \"" + file.path + "\" 2> /dev/null";
piCout << "set rpath" << file.path << "to" << rp;
execute(cmd);
@@ -520,9 +536,9 @@ void patchRPathFile(const PIFile::FileInfo & file) {
void patchRPath() {
PIStringList dirs({out_dir, target_dir, qt_plugins_dir});
dirs.removeDuplicates().removeStrings(PIString());
piForeachC (PIString & d, dirs) {
piForeachC(PIString & d, dirs) {
PIVector<PIFile::FileInfo> files = PIDir(d).allEntries();
piForeachC (PIFile::FileInfo & f, files) {
piForeachC(PIFile::FileInfo & f, files) {
if (f.isDir()) continue;
patchRPathFile(f.path);
}
@@ -532,7 +548,7 @@ void patchRPath() {
int main(int argc, char * argv[]) {
PICLI cli(argc, argv);
//piCout << cli.rawArguments();
// piCout << cli.rawArguments();
cli.setOptionalArgumentsCount(-1);
cli.addArgument("help");
cli.addArgument("verbose");
@@ -567,26 +583,24 @@ int main(int argc, char * argv[]) {
}
setCommands();
fake = cli.hasArgument("fake");
piDebug = cli.hasArgument("verbose");
is_deps = cli.hasArgument("dependencies");
out_dir = cli.argumentValue("output");
lib_dirs = cli.argumentValue("search_path").split(DELIM);
add_libs = cli.argumentValue("add_libs").split(DELIM);
fake = cli.hasArgument("fake");
piDebug = cli.hasArgument("verbose");
is_deps = cli.hasArgument("dependencies");
out_dir = cli.argumentValue("output");
lib_dirs = cli.argumentValue("search_path").split(DELIM);
add_libs = cli.argumentValue("add_libs").split(DELIM);
ignore_libs = cli.argumentValue("ignore").split(DELIM);
qt_dir = cli.argumentValue("qtdir");
ldd = cli.argumentValue("ldd");
readelf = cli.argumentValue("Lreadelf");
objdump = cli.argumentValue("Wobjdump");
otool = cli.argumentValue("Motool");
nametool = cli.argumentValue("name-tool");
strip = cli.argumentValue("strip");
rpath = cli.hasArgument("rpath");
if (nametool.isEmpty())
nametool = "install_name_tool";
if (strip.isEmpty())
strip = "strip";
dpkg = cli.argumentValue("Dpkg");
qt_dir = cli.argumentValue("qtdir");
ldd = cli.argumentValue("ldd");
readelf = cli.argumentValue("Lreadelf");
objdump = cli.argumentValue("Wobjdump");
otool = cli.argumentValue("Motool");
nametool = cli.argumentValue("name-tool");
strip = cli.argumentValue("strip");
rpath = cli.hasArgument("rpath");
if (nametool.isEmpty()) nametool = "install_name_tool";
if (strip.isEmpty()) strip = "strip";
dpkg = cli.argumentValue("Dpkg");
dpkg_workdir = cli.argumentValue("dpkg-workdir");
#ifdef WINDOWS
readelf.replaceAll("/", "\\");
@@ -595,8 +609,7 @@ int main(int argc, char * argv[]) {
nametool.replaceAll("/", "\\");
dpkg.replaceAll("/", "\\");
#endif
if (dpkg.isEmpty())
dpkg = "/usr/bin/dpkg";
if (dpkg.isEmpty()) dpkg = "/usr/bin/dpkg";
int etcnt = 0;
if (!readelf.isEmpty()) ++etcnt;
if (!objdump.isEmpty()) ++etcnt;
@@ -611,7 +624,7 @@ int main(int argc, char * argv[]) {
if (!qroot.endsWith("/")) qroot.append("/");
lib_dirs << (qroot + "bin") << (qroot + "lib") << (qroot + "Frameworks");
}
piForeach (PIString & s, lib_dirs) {
piForeach(PIString & s, lib_dirs) {
s.trim();
if (!s.endsWith("/")) s += "/";
}
@@ -621,26 +634,25 @@ int main(int argc, char * argv[]) {
out_dir.replaceAll("//", "/");
for (int i = 0; ; ++i) {
for (int i = 0;; ++i) {
if (qt_deps[i].lib.isEmpty()) break;
qt_deps[i].plugins.forEach([](const PIString & p){qt_filters[p] = PIStringList("*");});
qt_deps[i].plugins.forEach([](const PIString & p) { qt_filters[p] = PIStringList("*"); });
}
if (!cli.argumentValue("Platforms").isEmpty())
qplatforms = cli.argumentValue("Platforms");
if (!cli.argumentValue("Platforms").isEmpty()) qplatforms = cli.argumentValue("Platforms");
if (platforms.contains("windows")) win_target = true;
platforms = qplatforms.split(",");
styles = cli.argumentValue("Styles").split(",");
styles = cli.argumentValue("Styles").split(",");
if (styles.isEmpty()) styles << "";
PIStringList qpd = cli.argumentValue("qt-plugins").toLowerCase().split(DELIM);
piForeachC (PIString & qp, qpd) {
piForeachC(PIString & qp, qpd) {
int _i = qp.find('=');
if (_i < 0) continue;
PIString pname = qp.left(_i).trim();
PIString pname = qp.left(_i).trim();
PIStringList pfilt = qp.mid(_i + 1).trim().split(",");
if (pname == "*") {
for (int i = 0; ; ++i) {
for (int i = 0;; ++i) {
if (qt_deps[i].lib.isEmpty()) break;
qt_deps[i].plugins.forEach([&pfilt](const PIString & p){qt_filters[p] = pfilt;});
qt_deps[i].plugins.forEach([&pfilt](const PIString & p) { qt_filters[p] = pfilt; });
}
} else {
qt_plugins << pname;
@@ -648,10 +660,10 @@ int main(int argc, char * argv[]) {
}
}
qt_filters["platforms"] = platforms;
qt_filters["styles" ] = styles ;
qt_filters["styles"] = styles;
qt_add_libs = cli.argumentValue("qt-modules").split(DELIM);
qt_conf_dir = cli.argumentValue("qt-conf-dir").trim();
qt_add_libs = cli.argumentValue("qt-modules").split(DELIM);
qt_conf_dir = cli.argumentValue("qt-conf-dir").trim();
if (qt_conf_dir.isEmpty()) qt_conf_dir = out_dir;
if (!qt_conf_dir.endsWith("/")) qt_conf_dir += "/";
qt_plugins_dir = cli.argumentValue("qt-plugins-dir").trim();
@@ -663,58 +675,51 @@ int main(int argc, char * argv[]) {
auto it = qt_filters.makeIterator();
while (it.next())
it.value().forEach([](PIString & i){
it.value().forEach([](PIString & i) {
if (!i.startsWith("*")) i.prepend("*");
if (!i.endsWith("*")) i.append("*");
});
//PICout(PICoutManipulators::DefaultControls) << qt_filters;
// PICout(PICoutManipulators::DefaultControls) << qt_filters;
if (!fake)
PIDir(out_dir).make();
if (!cli.argumentValue("depth").isEmpty())
depth = cli.argumentValue("depth").toInt();
if (!fake) PIDir(out_dir).make();
if (!cli.argumentValue("depth").isEmpty()) depth = cli.argumentValue("depth").toInt();
cli.optionalArguments().forEach([](const PIString & a){
cli.optionalArguments().forEach([](const PIString & a) {
if (PIDir::isExists(a)) {
if (target_dir.isEmpty())
target_dir = a;
PIDir(a).allEntries().forEach([](const PIFile::FileInfo & fi){
if (fi.isFile())
input_files << fi.path;
if (target_dir.isEmpty()) target_dir = a;
PIDir(a).allEntries().forEach([](const PIFile::FileInfo & fi) {
if (fi.isFile()) input_files << fi.path;
});
} else {
if (target_dir.isEmpty())
target_dir = PIFile::FileInfo(a).dir();
if (PIFile::isExists(a))
input_files << a;
if (target_dir.isEmpty()) target_dir = PIFile::FileInfo(a).dir();
if (PIFile::isExists(a)) input_files << a;
}
});
//piCout << files;
// piCout << files;
if (depth > 0) {
input_files.forEach([](const PIString & f){procLdd(f);});
qt_add_libs.forEach([](const PIString & f){
input_files.forEach([](const PIString & f) { procLdd(f); });
qt_add_libs.forEach([](const PIString & f) {
PIString l = findLib(qt_pref + f + qt_suff);
if (l.isEmpty()) return;
procLdd(l, true);
checkQtLib(f);
});
}
piForeach (PIString & s, add_libs) {
piForeach(PIString & s, add_libs) {
if (s.isEmpty()) continue;
PIString alib = findLib(s);
if (alib.isEmpty()) continue;
piCout << s << "->" << alib;
procLdd(alib, true);
if (!all_libs[alib])
all_libs << alib;
if (!all_libs[alib]) all_libs << alib;
}
if (need_qt) {
bool need_qt_plugins = true;
if (is_deps) { // if Qt in system, then no plugins copy
PIVector<PIString> qlibs = qt_libs.toVector();
piCout << "check for installed Qt" << qlibs;
piForeach (PIString l, qlibs) {
piForeach(PIString l, qlibs) {
l = findLib(l);
if (l.isEmpty()) continue;
if (procDpkg(l)) {
@@ -735,7 +740,7 @@ int main(int argc, char * argv[]) {
pp = "PlugIns";
lp = "Resources/lang";
}
//piCout << pp;
// piCout << pp;
PIIOTextStream ts(&qtc);
ts << "[Paths]\n\tPlugins = " << pp << "\n\tTranslations = " << lp << "\n";
}
@@ -746,15 +751,14 @@ int main(int argc, char * argv[]) {
out_dir.replaceAll("/", "\\");
#endif
PIVector<PIString> clibs = all_libs.toVector();
piForeach (PIString l, clibs) {
piForeach(PIString l, clibs) {
PIFile::FileInfo fi;
fi.path = l;
#ifdef WINDOWS
l.replaceAll("/", "\\");
#endif
bool need_cp = true;
if (is_deps)
need_cp = !procDpkg(l);
if (is_deps) need_cp = !procDpkg(l);
if (need_cp) {
piCout << "copy" << l;
if (!fake) {
@@ -767,31 +771,26 @@ int main(int argc, char * argv[]) {
}
}
PIVector<PIString> fwdirs = frameworks.toVector();
piForeachC (PIString & f, fwdirs) {
piForeachC(PIString & f, fwdirs) {
PIString fd = findLib(f);
if (!fd.isEmpty()) {
piCout << "copy framework" << f;
if (!fake)
system((cmd_copydir + "\"" + fd + "\" \"" + out_dir + "\"" + cmd_suffix).data());
if (!fake) system((cmd_copydir + "\"" + fd + "\" \"" + out_dir + "\"" + cmd_suffix).data());
} else
miss_frameworks << f;
}
if (!otool.isEmpty())
patchNameTool();
if (!otool.isEmpty()) patchNameTool();
if (rpath)
patchRPath();
if (rpath) patchRPath();
if (is_deps) {
PICout(PICoutManipulators::AddNone) << cli.argumentValue("prefix");
PICout(PICoutManipulators::AddNewLine) << PIStringList(all_deps.toVector()).join(", ");
} else {
piCout << "copied" << clibs.size_s() << "files";
if (!miss_libs.isEmpty())
piCout << "Missing libraries:\n -" << PIStringList(miss_libs.toVector()).join("\n - ");
if (!miss_frameworks.isEmpty())
piCout << "Missing frameworks:\n -" << PIStringList(miss_frameworks.toVector()).join("\n - ");
if (!miss_libs.isEmpty()) piCout << "Missing libraries:\n -" << PIStringList(miss_libs.toVector()).join("\n - ");
if (!miss_frameworks.isEmpty()) piCout << "Missing frameworks:\n -" << PIStringList(miss_frameworks.toVector()).join("\n - ");
}
return 0;