From 7ffc790e2ee003228802d0e91f6f0e97fa95165f Mon Sep 17 00:00:00 2001 From: Dinesh Manajipet Date: Fri, 9 Mar 2018 21:12:19 +0530 Subject: [PATCH 1/3] Added support for -excludeLibs command line option This helps us avoid pesky libraries which are optional by the main binary but may be dragged in by some other libraries like https://github.com/probonopd/linuxdeployqt/issues/235 Usage: -exclude-libs=libqsqlibase,libqsqlodbc,libqsqlpsql,libqsqltds --- tools/linuxdeployqt/main.cpp | 7 +++++ tools/linuxdeployqt/shared.cpp | 48 ++++++++++++++++++++-------------- tools/linuxdeployqt/shared.h | 1 + 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/tools/linuxdeployqt/main.cpp b/tools/linuxdeployqt/main.cpp index 1055476..ad6f818 100644 --- a/tools/linuxdeployqt/main.cpp +++ b/tools/linuxdeployqt/main.cpp @@ -82,6 +82,8 @@ int main(int argc, char **argv) qInfo() << " -no-copy-copyright-files : Skip deployment of copyright files."; qInfo() << " -extra-plugins= : List of extra plugins which should be deployed,"; qInfo() << " separated by comma."; + qInfo() << " -exclude-libs= : List of extra plugins which should be deployed,"; + qInfo() << " separated by comma."; qInfo() << " -version : Print version statement and exit."; qInfo() << ""; qInfo() << "linuxdeployqt takes an application as input and makes it"; @@ -207,6 +209,7 @@ int main(int argc, char **argv) QStringList qmlDirs; QString qmakeExecutable; extern QStringList extraQtPlugins; + extern QStringList excludeLibs; extern bool copyCopyrightFiles; /* FHS-like mode is for an application that has been installed to a $PREFIX which is otherwise empty, e.g., /path/to/usr. @@ -416,6 +419,10 @@ int main(int argc, char **argv) LogDebug() << "Argument found:" << argument; int index = argument.indexOf("="); extraQtPlugins = QString(argument.mid(index + 1)).split(","); + } else if (argument.startsWith("-exclude-libs=")) { + LogDebug() << "Argument found:" << argument; + int index = argument.indexOf("="); + excludeLibs = QString(argument.mid(index + 1)).split(","); } else if (argument.startsWith("-")) { LogError() << "Error: arguments must not start with --, only -" << "\n"; return 1; diff --git a/tools/linuxdeployqt/shared.cpp b/tools/linuxdeployqt/shared.cpp index be59ff6..6c85a87 100644 --- a/tools/linuxdeployqt/shared.cpp +++ b/tools/linuxdeployqt/shared.cpp @@ -58,6 +58,7 @@ int qtDetected = 0; bool qtDetectionComplete = 0; // As long as Qt is not detected yet, ldd may encounter "not found" messages, continue anyway bool deployLibrary = false; QStringList extraQtPlugins; +QStringList excludeLibs; bool copyCopyrightFiles = true; using std::cout; @@ -473,6 +474,7 @@ LibraryInfo parseLddLibraryLine(const QString &line, const QString &appDirPath, */ QStringList excludelist; + excludelist += excludeLibs; excludelist << "libasound.so.2" << "libcom_err.so.2" << "libcrypt.so.1" << "libc.so.6" << "libdl.so.2" << "libdrm.so.2" << "libexpat.so.1" << "libfontconfig.so.1" << "libgcc_s.so.1" << "libgdk_pixbuf-2.0.so.0" << "libgio-2.0.so.0" << "libglib-2.0.so.0" << "libGL.so.1" << "libgobject-2.0.so.0" << "libgpg-error.so.0" << "libICE.so.6" << "libkeyutils.so.1" << "libm.so.6" << "libnsl.so.1" << "libnss3.so" << "libnssutil3.so" << "libp11-kit.so.0" << "libpangoft2-1.0.so.0" << "libpangocairo-1.0.so.0" << "libpango-1.0.so.0" << "libpthread.so.0" << "libresolv.so.2" << "librt.so.1" << "libSM.so.6" << "libstdc++.so.6" << "libusb-1.0.so.0" << "libuuid.so.1" << "libX11.so.6" << "libxcb.so.1" << "libz.so.1"; LogDebug() << "excludelist:" << excludelist; if (! trimmed.contains("libicu")) { @@ -666,10 +668,13 @@ QList getQtLibrariesForPaths(const QStringList &paths, const QStrin QSet existing; foreach (const QString &path, paths) { - foreach (const LibraryInfo &info, getQtLibraries(path, appDirPath, rpaths)) { - if (!existing.contains(info.libraryPath)) { // avoid duplicates - existing.insert(info.libraryPath); - result << info; + if (!excludeLibs.contains(QFileInfo(path).baseName())) + { + foreach (const LibraryInfo &info, getQtLibraries(path, appDirPath, rpaths)) { + if (!existing.contains(info.libraryPath)) { // avoid duplicates + existing.insert(info.libraryPath); + result << info; + } } } } @@ -1017,7 +1022,7 @@ DeploymentInfo deployQtLibraries(QList libraries, deploymentInfo.qtPath = library.libraryDirectory; } - if(library.libraryName.contains("libQt") and library.libraryName.contains("Widgets.so")) { + if(library.libraryName.contains("libQt") and library.libraryName.contains("Widgets.so")) { deploymentInfo.requiresQtWidgetsLibrary = true; } @@ -1394,23 +1399,26 @@ void deployPlugins(const AppDirInfo &appDirInfo, const QString &pluginSourcePath foreach (const QString &plugin, pluginList) { sourcePath = pluginSourcePath + "/" + plugin; destinationPath = pluginDestinationPath + "/" + plugin; - QDir dir; - dir.mkpath(QFileInfo(destinationPath).path()); - QList libraries = getQtLibraries(sourcePath, appDirInfo.path, deploymentInfo.rpathsUsed); - LogDebug() << "Deploying plugin" << sourcePath; - if (copyFilePrintStatus(sourcePath, destinationPath)) { - runStrip(destinationPath); - deployQtLibraries(libraries, appDirInfo.path, QStringList() << destinationPath, deploymentInfo.useLoaderPath); - /* See whether this makes any difference */ - // Find out the relative path to the lib/ directory and set it as the rpath - QDir dir(destinationPath); - QString relativePath = dir.relativeFilePath(appDirInfo.path + "/" + libraries[0].libraryDestinationDirectory); - relativePath.remove(0, 3); // remove initial '../' - changeIdentification("$ORIGIN/" + relativePath, QFileInfo(destinationPath).canonicalFilePath()); + if(!excludeLibs.contains(QFileInfo(sourcePath).baseName())) + { + QDir dir; + dir.mkpath(QFileInfo(destinationPath).path()); + QList libraries = getQtLibraries(sourcePath, appDirInfo.path, deploymentInfo.rpathsUsed); + LogDebug() << "Deploying plugin" << sourcePath; + if (copyFilePrintStatus(sourcePath, destinationPath)) { + runStrip(destinationPath); + deployQtLibraries(libraries, appDirInfo.path, QStringList() << destinationPath, deploymentInfo.useLoaderPath); + /* See whether this makes any difference */ + // Find out the relative path to the lib/ directory and set it as the rpath + QDir dir(destinationPath); + QString relativePath = dir.relativeFilePath(appDirInfo.path + "/" + libraries[0].libraryDestinationDirectory); + relativePath.remove(0, 3); // remove initial '../' + changeIdentification("$ORIGIN/" + relativePath, QFileInfo(destinationPath).canonicalFilePath()); + } + LogDebug() << "copyCopyrightFile:" << sourcePath; + copyCopyrightFile(sourcePath); } - LogDebug() << "copyCopyrightFile:" << sourcePath; - copyCopyrightFile(sourcePath); } } diff --git a/tools/linuxdeployqt/shared.h b/tools/linuxdeployqt/shared.h index 3317521..5c07bcb 100644 --- a/tools/linuxdeployqt/shared.h +++ b/tools/linuxdeployqt/shared.h @@ -46,6 +46,7 @@ extern bool bundleAllButCoreLibs; extern bool fhsLikeMode; extern QString fhsPrefix; extern QStringList extraQtPlugins; +extern QStringList excludeLibs; class LibraryInfo { From b4af14575a7de2ced6aa17e45c5366d037e5549e Mon Sep 17 00:00:00 2001 From: Dinesh Manajipet Date: Fri, 9 Mar 2018 21:30:22 +0530 Subject: [PATCH 2/3] Updated help text --- tools/linuxdeployqt/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/linuxdeployqt/main.cpp b/tools/linuxdeployqt/main.cpp index ad6f818..9c65400 100644 --- a/tools/linuxdeployqt/main.cpp +++ b/tools/linuxdeployqt/main.cpp @@ -82,7 +82,7 @@ int main(int argc, char **argv) qInfo() << " -no-copy-copyright-files : Skip deployment of copyright files."; qInfo() << " -extra-plugins= : List of extra plugins which should be deployed,"; qInfo() << " separated by comma."; - qInfo() << " -exclude-libs= : List of extra plugins which should be deployed,"; + qInfo() << " -exclude-libs= : List of libraries which should be excluded,"; qInfo() << " separated by comma."; qInfo() << " -version : Print version statement and exit."; qInfo() << ""; From 7d795fd967beb87f6bdfa16be3797931f6ede55b Mon Sep 17 00:00:00 2001 From: Dinesh Manajipet Date: Sun, 1 Apr 2018 18:49:38 +0530 Subject: [PATCH 3/3] Add a warning message when there are libraries to be excluded --- tools/linuxdeployqt/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/linuxdeployqt/main.cpp b/tools/linuxdeployqt/main.cpp index af56672..1ed71c6 100644 --- a/tools/linuxdeployqt/main.cpp +++ b/tools/linuxdeployqt/main.cpp @@ -439,6 +439,11 @@ int main(int argc, char **argv) } } + if (!excludeLibs.isEmpty()) + { + qWarning() << "WARNING: Excluding the following libraries might break the AppImage. Please double-check the list:" << excludeLibs; + } + DeploymentInfo deploymentInfo = deployQtLibraries(appDirPath, additionalExecutables, qmakeExecutable);