From 6fad088ed31c142965b488cc13be29c92e1a7fa0 Mon Sep 17 00:00:00 2001 From: probonopd Date: Sat, 19 Nov 2016 13:19:01 +0100 Subject: [PATCH] Started FHS-like mode; not quite working yet --- linuxdeployqt/main.cpp | 54 +++++++++++++++++++++++++++++++----------- shared/shared.cpp | 31 ++++++++---------------- shared/shared.h | 3 +++ 3 files changed, 53 insertions(+), 35 deletions(-) diff --git a/linuxdeployqt/main.cpp b/linuxdeployqt/main.cpp index dfae9d5..de2f5f9 100644 --- a/linuxdeployqt/main.cpp +++ b/linuxdeployqt/main.cpp @@ -36,7 +36,7 @@ int main(int argc, char **argv) { QCoreApplication app(argc, argv); - QString appBinaryPath; + extern QString appBinaryPath; if (argc > 1) { appBinaryPath = QString::fromLocal8Bit(argv[1]); @@ -91,34 +91,58 @@ int main(int argc, char **argv) return 1; } - QDir dir; - // QString appDir = QDir::cleanPath(appFile + "/../" + appName + ".AppDir"); QString appDir = QDir::cleanPath(appBinaryPath + "/../"); - if (QDir().exists(appDir) == false) { qDebug() << "Error: Could not find AppDir" << appDir; return 1; } - QString appDirPath = appDir; - - QFile appRun(appDir + "/AppRun"); - - if(appRun.exists()){ - appRun.remove(); - } - QFile::link(appName, appDir + "/AppRun"); - bool plugins = true; bool appimage = false; extern bool runStripEnabled; extern bool bundleAllButCoreLibs; + extern bool fhsLikeMode; + extern QString fhsPrefix; extern bool alwaysOwerwriteEnabled; extern QStringList librarySearchPath; QStringList additionalExecutables; bool qmldirArgumentUsed = false; QStringList qmlDirs; + /* FHS-like mode is for an application that has been installed to a $PREFIX which is otherwise empty, e.g., /path/to/usr. + * In this case, we want to construct an AppDir in /path/to. */ + if (QDir().exists((QDir::cleanPath(appBinaryPath + "/../../bin"))) == true) { + fhsPrefix = QDir::cleanPath(appBinaryPath + "/../../"); + qDebug() << "FHS-like mode with PREFIX, fhsPrefix:" << fhsPrefix; + fhsLikeMode = true; + } else { + qDebug() << "Not using FHS-like mode, appBinaryPath:" << appBinaryPath; + } + + QString appDirPath; + if(fhsLikeMode == false){ + appDirPath = appDir; + } else { + appDirPath = QDir::cleanPath(fhsPrefix + "/../"); + } + qDebug() << "appDirPath:" << appDirPath; + + QString relativeBinPath; + if(fhsLikeMode == false){ + relativeBinPath = appName; + } else { + QString relativePrefix = fhsPrefix.replace(appDirPath+"/", ""); + relativeBinPath = relativePrefix + "/bin/" + appName; + } + qDebug() << "relativeBinPath:" << relativeBinPath; + + QFile appRun(appDirPath + "/AppRun"); + if(appRun.exists()){ + appRun.remove(); + } + + QFile::link(relativeBinPath, appDirPath + "/AppRun"); + for (int i = 2; i < argc; ++i) { QByteArray argument = QByteArray(argv[i]); if (argument == QByteArray("-no-plugins")) { @@ -175,8 +199,10 @@ int main(int argc, char **argv) } if (appimage) { - if(checkAppImagePrerequisites(appDirPath) == false) + if(checkAppImagePrerequisites(appDirPath) == false){ + LogError() << "checkAppImagePrerequisites failed\n"; return 1; + } } DeploymentInfo deploymentInfo = deployQtLibraries(appDirPath, additionalExecutables); diff --git a/shared/shared.cpp b/shared/shared.cpp index 6578f5f..6b43b7b 100644 --- a/shared/shared.cpp +++ b/shared/shared.cpp @@ -44,9 +44,11 @@ #include #include "shared.h" - +QString appBinaryPath; bool runStripEnabled = true; bool bundleAllButCoreLibs = false; +bool fhsLikeMode = false; +QString fhsPrefix; bool alwaysOwerwriteEnabled = false; QStringList librarySearchPath; bool appstoreCompliant = false; @@ -81,7 +83,7 @@ QDebug operator<<(QDebug debug, const LibraryInfo &info) return debug; } -const QString bundleLibraryDirectory = "lib"; // the same directory as the main executable; could define a relative subdirectory here +QString bundleLibraryDirectory; inline QDebug operator<<(QDebug debug, const AppDirInfo &info) { @@ -217,6 +219,9 @@ int containsHowOften(QStringList haystack, QString needle) { LibraryInfo parseLddLibraryLine(const QString &line, const QString &appDirPath, const QSet &rpaths) { + bundleLibraryDirectory= "lib"; // relative to bundle + LogDebug() << "bundleLibraryDirectory:" << bundleLibraryDirectory; + LibraryInfo info; QString trimmed = line.trimmed(); @@ -338,21 +343,6 @@ LibraryInfo parseLddLibraryLine(const QString &line, const QString &appDirPath, return info; } -QString findAppBinary(const QString &appDirPath) -{ - QString binaryPath; - - // FIXME: Do without the need for an AppRun symlink - // by passing appBinaryPath from main.cpp here - binaryPath = appDirPath + "/" + "AppRun"; - - if (QFile::exists(binaryPath)) - return binaryPath; - - LogError() << "Could not find bundle binary for" << appDirPath << "at" << binaryPath; - exit(1); -} - QStringList findAppLibraries(const QString &appDirPath) { QStringList result; @@ -648,7 +638,7 @@ void runStrip(const QString &binaryPath) void stripAppBinary(const QString &bundlePath) { - runStrip(findAppBinary(bundlePath)); + runStrip(appBinaryPath); } /* @@ -742,7 +732,7 @@ DeploymentInfo deployQtLibraries(const QString &appDirPath, const QStringList &a applicationBundle.path = appDirPath; LogDebug() << "applicationBundle.path:" << applicationBundle.path; - applicationBundle.binaryPath = findAppBinary(appDirPath); + applicationBundle.binaryPath = appBinaryPath; LogDebug() << "applicationBundle.binaryPath:" << applicationBundle.binaryPath; // Determine the location of the Qt to be bundled @@ -967,7 +957,7 @@ void deployPlugins(const QString &appDirPath, DeploymentInfo deploymentInfo) { AppDirInfo applicationBundle; applicationBundle.path = appDirPath; - applicationBundle.binaryPath = findAppBinary(appDirPath); + applicationBundle.binaryPath = appBinaryPath; const QString pluginDestinationPath = appDirPath + "/" + "plugins"; deployPlugins(applicationBundle, deploymentInfo.pluginPath, pluginDestinationPath, deploymentInfo); @@ -1139,7 +1129,6 @@ void changeQtLibraries(const QList libraries, const QStringList &bi void changeQtLibraries(const QString appPath, const QString &qtPath) { - const QString appBinaryPath = findAppBinary(appPath); const QStringList libraryPaths = findAppLibraries(appPath); const QList libraries = getQtLibrariesForPaths(QStringList() << appBinaryPath << libraryPaths, appPath, getBinaryRPaths(appBinaryPath, true)); if (libraries.isEmpty()) { diff --git a/shared/shared.h b/shared/shared.h index 60c0fd9..4347002 100644 --- a/shared/shared.h +++ b/shared/shared.h @@ -40,8 +40,11 @@ extern int logLevel; #define LogNormal() if (logLevel < 2) {} else qDebug() << "Log:" #define LogDebug() if (logLevel < 3) {} else qDebug() << "Log:" +extern QString appBinaryPath; extern bool runStripEnabled; extern bool bundleAllButCoreLibs; +extern bool fhsLikeMode; +extern QString fhsPrefix; class LibraryInfo {