git-svn-id: svn://db.shs.com.ru/pip@977 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2020-03-24 22:00:24 +00:00
parent 9123b3c857
commit 93746d19b9

View File

@@ -30,10 +30,17 @@ void usage() {
piCout << Cyan << "Version PIP" << Bold << PIPVersion(); piCout << Cyan << "Version PIP" << Bold << PIPVersion();
piCout << ""; piCout << "";
piCout << "Copy all dependencies of <file> to directory <out_path>"; piCout << "Copy all dependencies of <file> to directory <out_path>";
piCout << "If <file> depend on QtCore library, then copy all basic Qt plugins, "; piCout << "You can specify any file or directory as <file>.";
piCout << "In case of directory it will be scan recursively.";
piCout << "";
piCout << "If QtCore dependency found, copy all basic Qt plugins,";
piCout << "<styles> and <platforms>"; piCout << "<styles> and <platforms>";
piCout << ""; piCout << "";
piCout << Green << Bold << "Usage:" << Default << "\"deploy_tool [-hvfC] [--dependencies [--prefix <text>]] [-p <qt_plugins>] [-s <search_path>] [-S <styles>] [-l <ldd>] [-D <dpkg>] [-L <readelf> | -W <objdump> | -M <otool>] [-d <depth>] [-q <qtdir>] [-a <add_libs>] [-S <styles>] [-P <platforms>] -o <out_path> <file> [<file2> ...]\"" << NewLine; piCout << Green << Bold << "Usage:" << Default << "\"deploy_tool [-hvfC] [--dependencies [--prefix <text>]] "
"[-p <qt_plugins>] [-s <search_path>] [-S <styles>] [-l <ldd>] "
"[-D <dpkg>] [-L <readelf> | -W <objdump> | -M <otool>] "
"[-d <depth>] [-q <qtdir>] [-a <add_libs>] [-S <styles>] "
"[-P <platforms>] [--sql <drivers>] -o <out_path> <file> [<file2> ...]\"" << NewLine;
piCout << Green << Bold << "Details:"; piCout << Green << Bold << "Details:";
piCout << Bold << "Debug control"; piCout << Bold << "Debug control";
piCout << "-h " << Green << "- display this message and exit"; piCout << "-h " << Green << "- display this message and exit";
@@ -47,7 +54,7 @@ void usage() {
piCout << "-W <objdump> " << Green << "- \"objdump\" path, overrides \"ldd\""; piCout << "-W <objdump> " << Green << "- \"objdump\" path, overrides \"ldd\"";
piCout << "-M <otool> " << Green << "- \"otool\" path, overrides \"ldd\""; piCout << "-M <otool> " << Green << "- \"otool\" path, overrides \"ldd\"";
piCout << "-D <dpkg> " << Green << "- \"dpkg\" path, default \"/usr/bin/dpkg\""; piCout << "-D <dpkg> " << Green << "- \"dpkg\" path, default \"/usr/bin/dpkg\"";
piCout << "-d <depth> " << Green << "- dependepcies depth, default 1"; piCout << "-d <depth> " << Green << "- maximum dependepcies depth, default 5";
piCout << "-q <qtdir> " << Green << "- path where Qt root dir, default takes from \"qmake -v\""; piCout << "-q <qtdir> " << Green << "- path where Qt root dir, default takes from \"qmake -v\"";
piCout << "-C, --Conf " << Green << "- make \"qt.conf\""; piCout << "-C, --Conf " << Green << "- make \"qt.conf\"";
//piCout << "-Q, --Qt-force " << Green << "- force add Qt root dir, default takes from \"qmake -v\""; //piCout << "-Q, --Qt-force " << Green << "- force add Qt root dir, default takes from \"qmake -v\"";
@@ -60,17 +67,39 @@ void usage() {
piCout << ""; piCout << "";
piCout << Bold << "Input control"; piCout << Bold << "Input control";
piCout << "<file> ... " << Green << "- executable to process"; piCout << "<file> ... " << Green << "- executable to process";
piCout << "-S <styles> " << Green << "- add Qt styles (e.g. \"oxygen,breeze\"), default \"\""; piCout << "-S <styles> " << Green << "- set Qt styles (e.g. \"oxygen,breeze\"), default \"*\"";
piCout << "-P <platforms> " << Green << "- add Qt platforms (e.g. \"win,mini\"), default by host system"; piCout << "-P <platforms> " << Green << "- set Qt platforms (e.g. \"win,mini\"), default by host system";
piCout << "-a <add_libs> " << Green << "- additional libs, separated by \";\""; piCout << "--sql <drivers> " << Green << "- set Qt sql drivers (e.g. \"sqlite\"), default \"*\"";
piCout << "-a <add_libs> " << Green << "- additional libs, separated by \";\". Libraries will be searched in <search_path>";
} }
struct QtDep {
QtDep(const PIString & l = PIString(), const PIStringList & p = PIStringList()): lib(l), plugins(p) {}
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()
};
int depth = 1;
bool need_qt = false, fake = false, is_ldd = true, is_deps = false; int depth = 5;
bool fake = false, is_ldd = true, is_deps = false, need_qt = false;
PIString ldd, readelf, objdump, otool, dpkg, out_dir, qt_dir, out_plugins_dir; PIString ldd, readelf, objdump, otool, dpkg, out_dir, qt_dir, out_plugins_dir;
PIStringList styles, lib_dirs, add_libs, platforms; PIStringList styles, lib_dirs, add_libs, platforms, sqldrivers;
PISet<PIString> all_libs, miss_libs, all_deps, frameworks, miss_frameworks; PISet<PIString> all_libs, miss_libs, all_deps, frameworks, miss_frameworks, qt_plugins;
PIString findLib(const PIString & l) { PIString findLib(const PIString & l) {
@@ -84,6 +113,42 @@ PIString findLib(const PIString & l) {
} }
PIString execute(const PIString & cmd) {
FILE * fp = popen(cmd.dataAscii(), "r");
PIString ret;
if (fp) {
const int sz = 256;
char in[sz];
memset(in, 0, sz);
while (true) {
int r = fread(in, 1, sz, fp);
if (r <= 0) break;
ret += PIString(in, r);
}
pclose(fp);
}
return ret;
}
void checkQtLib(PIString lib) {
if (lib.startsWith("lib")) lib.cutLeft(3);
if (lib.startsWith("qt5")) lib.cutLeft(3);
if (lib.startsWith("qt")) lib.cutLeft(2);
if (lib.find(".")) lib = lib.left(lib.find("."));
//piCout << "checkQt" << lib;
for (int i = 0; ; ++i) {
if (qt_deps[i].lib.isEmpty()) break;
if (qt_deps[i].lib == lib) {
qt_plugins << qt_deps[i].plugins;
//piCout << "add qt plugins" << qt_deps[i].plugins << "now" << qt_plugins;
need_qt = true;
break;
}
}
}
void procLdd(PIString file, bool ext_lib = false, int cur_depth = 0) { void procLdd(PIString file, bool ext_lib = false, int cur_depth = 0) {
++cur_depth; ++cur_depth;
if (cur_depth > depth) return; if (cur_depth > depth) return;
@@ -97,11 +162,7 @@ void procLdd(PIString file, bool ext_lib = false, int cur_depth = 0) {
} }
PIStringList lines; PIStringList lines;
if (is_ldd) { if (is_ldd) {
PIProcess proc; lines = execute(ldd + " " + file).split("\n");
proc.setGrabOutput(true);
proc.exec(ldd, file);
proc.waitForFinish(5000);
lines = PIString(proc.readOutput()).split("\n");
} else { } else {
PIString cmd; PIString cmd;
if (!readelf.isEmpty()) { if (!readelf.isEmpty()) {
@@ -117,20 +178,7 @@ void procLdd(PIString file, bool ext_lib = false, int cur_depth = 0) {
cmd += " | grep -o \".*(\""; cmd += " | grep -o \".*(\"";
} }
//piCout << cmd; //piCout << cmd;
FILE * fp = popen(cmd.dataAscii(), "r"); lines = execute(cmd).split("\n");
PIString vs;
if (fp) {
const int sz = 256;
char in[sz];
memset(in, 0, sz);
while (true) {
int r = fread(in, 1, sz, fp);
if (r <= 0) break;
vs += PIString(in, r);
}
pclose(fp);
}
lines = vs.split("\n");
if (!objdump.isEmpty()) { if (!objdump.isEmpty()) {
piForeach (PIString & l, lines) { piForeach (PIString & l, lines) {
l.trim().cutLeft(9).trim(); l.trim().cutLeft(9).trim();
@@ -157,8 +205,7 @@ void procLdd(PIString file, bool ext_lib = false, int cur_depth = 0) {
} }
} }
frameworks << l; frameworks << l;
if (l.contains("QtCore") || l.contains("Qt5Core")) checkQtLib(l.toLowerCase());
need_qt = true;
continue; continue;
} }
} }
@@ -173,7 +220,7 @@ void procLdd(PIString file, bool ext_lib = false, int cur_depth = 0) {
continue; continue;
} }
} else { } else {
l.cutLeft(1).cutRight(1); l.cutLeft(1).cutRight(1).trim();
if (l.isEmpty()) continue; if (l.isEmpty()) continue;
if (!otool.isEmpty()) { if (!otool.isEmpty()) {
PIFile::FileInfo fi; PIFile::FileInfo fi;
@@ -182,25 +229,24 @@ void procLdd(PIString file, bool ext_lib = false, int cur_depth = 0) {
} }
PIString flp = findLib(l); PIString flp = findLib(l);
if (flp.isEmpty()) { if (flp.isEmpty()) {
piCout << "Can`t find" << l; //piCout << "Can`t find" << l;
miss_libs << l;
continue; continue;
} }
l = flp; l = flp;
} }
if (all_libs[l]) continue; if (all_libs[l]) continue;
if (!need_qt) { PIFile::FileInfo fi;
PIFile::FileInfo fi; fi.path = l;
fi.path = l; checkQtLib(fi.name().toLowerCase());
PIString ln = fi.name();
if (ln.contains("QtCore") || ln.contains("Qt5Core"))
need_qt = true;
}
cur_libs << l; cur_libs << l;
all_libs << l; all_libs << l;
} }
PIVector<PIString> clibs = cur_libs.toVector(); PIVector<PIString> clibs = cur_libs.toVector();
if (!clibs.isEmpty())
piCout << " new dependencies:\n -" << PIStringList(clibs).join("\n - ");
piForeachC (PIString & l, clibs) { piForeachC (PIString & l, clibs) {
procLdd(l, cur_depth); procLdd(l, false, cur_depth);
} }
} }
@@ -221,14 +267,7 @@ void procQt() {
//piCout << "qmake ..."; //piCout << "qmake ...";
PIString vs; PIString vs;
if (qt_dir.isEmpty()) { if (qt_dir.isEmpty()) {
FILE * fp = popen("qmake -v", "r"); vs = execute("qmake -v");
if (fp) {
char in[1024];
memset(in, 0, 1024);
if (fread(in, 1, 1024, fp))
vs = in;
pclose(fp);
}
if (vs.isEmpty()) { if (vs.isEmpty()) {
piCout << "Can`t exec \"qmake -v\"!"; piCout << "Can`t exec \"qmake -v\"!";
return; return;
@@ -236,8 +275,7 @@ void procQt() {
} else } else
vs = "QMake version ?.?\nUsing Qt version ?.?.? in " + qt_dir; vs = "QMake version ?.?\nUsing Qt version ?.?.? in " + qt_dir;
PIStringList vsl = vs.split("\n"); PIStringList vsl = vs.split("\n");
PIStringList pdirs; PIStringList pdirs = qt_plugins.toVector();
pdirs << "imageformats" << "sqldrivers";
if (!fake && !is_deps) if (!fake && !is_deps)
PIDir(out_plugins_dir).make(true); PIDir(out_plugins_dir).make(true);
piForeach (PIString l, vsl) { piForeach (PIString l, vsl) {
@@ -259,42 +297,29 @@ void procQt() {
else else
qdir += "/plugins/"; qdir += "/plugins/";
#endif #endif
piForeachC (PIString & p, pdirs) { piForeachC (PIString & plugin, pdirs) {
copyWildcard(qdir + p + "/*", out_plugins_dir + p); PIStringList filters("*");
if (plugin == "platforms") filters = platforms;
if (plugin == "styles") filters = styles;
if (plugin == "sqldrivers") filters = sqldrivers;
piForeachC (PIString & f, filters) {
copyWildcard(qdir + plugin + "/" + f, out_plugins_dir + plugin);
PIVector<PIFile::FileInfo> copied = PIDir(out_plugins_dir + plugin).entries();
piForeachC (PIFile::FileInfo & fi, copied) {
if (fi.isFile())
procLdd(fi.path);
}
}
} }
piForeachC (PIString & s, platforms) { piBreak;
copyWildcard(qdir + "platforms/*" + s + "*", out_plugins_dir + "platforms");
}
piForeachC (PIString & s, styles) {
copyWildcard(qdir + "styles/*" + s + "*", out_plugins_dir + "styles");
}
}
}
pdirs << "platforms" << "styles";
piForeachC (PIString & p, pdirs) {
PIVector<PIFile::FileInfo> fil = PIDir(out_plugins_dir + p).entries();
piForeachC (PIFile::FileInfo & f, fil) {
if (f.isFile())
procLdd(f.path);
} }
} }
} }
bool procDpkg(const PIString & l) { bool procDpkg(const PIString & l) {
PIString vs, cmd = dpkg + " -S " + l + " 2> /dev/null"; PIString cmd = dpkg + " -S " + l + " 2> /dev/null";
FILE * fp = popen(cmd.dataAscii(), "r"); PIString vs = execute(cmd);
if (fp) {
const int sz = 256;
char in[sz];
memset(in, 0, sz);
while (true) {
int r = fread(in, 1, sz, fp);
if (r <= 0) break;
vs += PIString(in, r);
}
pclose(fp);
}
if (!vs.isEmpty()) { if (!vs.isEmpty()) {
vs = vs.left(vs.find(":")); vs = vs.left(vs.find(":"));
if (!vs.isEmpty()) if (!vs.isEmpty())
@@ -321,6 +346,7 @@ int main(int argc, char * argv[]) {
cli.addArgument("search_path", true); cli.addArgument("search_path", true);
cli.addArgument("Styles", true); cli.addArgument("Styles", true);
cli.addArgument("Platforms", true); cli.addArgument("Platforms", true);
cli.addArgument("sql", PIChar('\0'), true);
cli.addArgument("ldd", true); cli.addArgument("ldd", true);
cli.addArgument("Lreadelf", true); cli.addArgument("Lreadelf", true);
cli.addArgument("Wobjdump", true); cli.addArgument("Wobjdump", true);
@@ -329,7 +355,7 @@ int main(int argc, char * argv[]) {
cli.addArgument("depth", true); cli.addArgument("depth", true);
cli.addArgument("qtdir", true); cli.addArgument("qtdir", true);
cli.addArgument("add_libs", true); cli.addArgument("add_libs", true);
if (cli.hasArgument("help") || cli.argumentValue("output").isEmpty() || (cli.optionalArguments().size_s() < 1)) { if (cli.hasArgument("help") || cli.argumentValue("output").isEmpty() || cli.optionalArguments().isEmpty()) {
usage(); usage();
return 0; return 0;
} }
@@ -338,7 +364,6 @@ int main(int argc, char * argv[]) {
fake = cli.hasArgument("fake"); fake = cli.hasArgument("fake");
piDebug = cli.hasArgument("verbose"); piDebug = cli.hasArgument("verbose");
is_deps = cli.hasArgument("dependencies"); is_deps = cli.hasArgument("dependencies");
PIString bin = cli.optionalArguments()[0];
out_dir = cli.argumentValue("output"); out_dir = cli.argumentValue("output");
lib_dirs = cli.argumentValue("search_path").split(";"); lib_dirs = cli.argumentValue("search_path").split(";");
add_libs = cli.argumentValue("add_libs").split(";"); add_libs = cli.argumentValue("add_libs").split(";");
@@ -350,7 +375,8 @@ int main(int argc, char * argv[]) {
dpkg = cli.argumentValue("Dpkg"); dpkg = cli.argumentValue("Dpkg");
if (dpkg.isEmpty()) if (dpkg.isEmpty())
dpkg = "/usr/bin/dpkg"; dpkg = "/usr/bin/dpkg";
out_plugins_dir = out_dir + "plugins/"; out_plugins_dir = out_dir;
if (!out_plugins_dir.endsWith("/")) out_plugins_dir.append('/');
if (!cli.argumentValue("pqt_out_plugins").isEmpty()) { if (!cli.argumentValue("pqt_out_plugins").isEmpty()) {
out_plugins_dir = cli.argumentValue("pqt_out_plugins"); out_plugins_dir = cli.argumentValue("pqt_out_plugins");
if (!out_plugins_dir.endsWith("/")) if (!out_plugins_dir.endsWith("/"))
@@ -365,23 +391,45 @@ int main(int argc, char * argv[]) {
return 1; return 1;
} }
if (etcnt > 0) is_ldd = false; if (etcnt > 0) is_ldd = false;
if (!cli.argumentValue("Platforms").isEmpty())
qplatforms = cli.argumentValue("Platforms");
platforms = qplatforms.split(",");
piForeach (PIString & s, lib_dirs) { piForeach (PIString & s, lib_dirs) {
if (!s.endsWith("/")) s += "/"; if (!s.endsWith("/")) s += "/";
} }
if (out_dir.isEmpty()) out_dir = "."; if (out_dir.isEmpty()) out_dir = ".";
if (!out_dir.endsWith("/")) out_dir += "/"; if (!out_dir.endsWith("/")) out_dir += "/";
if (ldd.isEmpty()) ldd = "/usr/bin/ldd"; if (ldd.isEmpty()) ldd = "/usr/bin/ldd";
if (!cli.argumentValue("Platforms").isEmpty())
qplatforms = cli.argumentValue("Platforms");
platforms = qplatforms.split(",");
styles = cli.argumentValue("Styles").split(","); styles = cli.argumentValue("Styles").split(",");
if (styles.isEmpty()) styles << "";
sqldrivers = cli.argumentValue("sql").split(",");
if (sqldrivers.isEmpty()) sqldrivers << "";
platforms .forEachInplace([](PIString i)->PIString{if (!i.startsWith("*")) i.prepend("*"); if (!i.endsWith("*")) i.append("*"); return i;});
styles .forEachInplace([](PIString i)->PIString{if (!i.startsWith("*")) i.prepend("*"); if (!i.endsWith("*")) i.append("*"); return i;});
sqldrivers.forEachInplace([](PIString i)->PIString{if (!i.startsWith("*")) i.prepend("*"); if (!i.endsWith("*")) i.append("*"); return i;});
if (!fake) if (!fake)
PIDir(out_dir).make(); PIDir(out_dir).make();
if (!cli.argumentValue("depth").isEmpty()) if (!cli.argumentValue("depth").isEmpty())
depth = cli.argumentValue("depth").toInt(); depth = cli.argumentValue("depth").toInt();
PIStringList files;
cli.optionalArguments().forEach([&](const PIString & a){
if (PIDir::isExists(a)) {
PIDir(a).allEntries().forEach([&](const PIFile::FileInfo & fi){
if (fi.isFile())
files << fi.path;
});
} else {
if (PIFile::isExists(a))
files << a;
}
});
//piCout << files;
if (depth > 0) if (depth > 0)
procLdd(bin); files.forEach([&](const PIString & f){procLdd(f);});
piForeach (PIString & s, add_libs) { piForeach (PIString & s, add_libs) {
if (s.isEmpty()) continue; if (s.isEmpty()) continue;
piCout << s << "->" << findLib(s); piCout << s << "->" << findLib(s);
@@ -424,9 +472,9 @@ int main(int argc, char * argv[]) {
} else { } else {
piCout << "copied" << clibs.size_s() << "files"; piCout << "copied" << clibs.size_s() << "files";
if (!miss_libs.isEmpty()) if (!miss_libs.isEmpty())
piCout << "Missing libraries:\n - " << PIStringList(miss_libs.toVector()).join("\n - "); piCout << "Missing libraries:\n -" << PIStringList(miss_libs.toVector()).join("\n - ");
if (!miss_frameworks.isEmpty()) if (!miss_frameworks.isEmpty())
piCout << "Missing frameworks:\n - " << PIStringList(miss_frameworks.toVector()).join("\n - "); piCout << "Missing frameworks:\n -" << PIStringList(miss_frameworks.toVector()).join("\n - ");
} }
return 0; return 0;