From 0b16c7a8a5522e3bc7414130dc609763bc2f4e3d Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Tue, 26 Jul 2011 15:14:20 +0200 Subject: Fix typo. Reviewed-by: TrustMe --- tools/macdeployqt/shared/shared.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/macdeployqt/shared/shared.cpp b/tools/macdeployqt/shared/shared.cpp index c411683..74dd4a4 100644 --- a/tools/macdeployqt/shared/shared.cpp +++ b/tools/macdeployqt/shared/shared.cpp @@ -350,18 +350,18 @@ DeploymentInfo deployQtFrameworks(QList frameworks, LogNormal(); LogNormal() << "Deploying Qt frameworks found inside:" << binaryPath; QStringList copiedFrameworks; - DeploymentInfo deploymenInfo; + DeploymentInfo deploymentInfo; while (frameworks.isEmpty() == false) { const FrameworkInfo framework = frameworks.takeFirst(); copiedFrameworks.append(framework.frameworkName); // Get the qt path from one of the Qt frameworks; - if (deploymenInfo.qtPath.isNull() && framework.frameworkName.contains("Qt") + if (deploymentInfo.qtPath.isNull() && framework.frameworkName.contains("Qt") && framework.frameworkDirectory.contains("/lib")) { - deploymenInfo.qtPath = framework.frameworkDirectory; - deploymenInfo.qtPath.chop(5); // remove "/lib/" + deploymentInfo.qtPath = framework.frameworkDirectory; + deploymentInfo.qtPath.chop(5); // remove "/lib/" } if (framework.installName.startsWith("/@executable_path/")) { @@ -394,8 +394,8 @@ DeploymentInfo deployQtFrameworks(QList frameworks, } } } - deploymenInfo.deployedFrameworks = copiedFrameworks; - return deploymenInfo; + deploymentInfo.deployedFrameworks = copiedFrameworks; + return deploymentInfo; } DeploymentInfo deployQtFrameworks(const QString &appBundlePath, bool useDebugLibs) -- cgit v0.12 From 2ccef4f57f036a486cb96904298a8b4673ff0aec Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Tue, 26 Jul 2011 16:00:58 +0200 Subject: Guard macdeployqt against @rpath and @loader_path too. Reviewed-by: TrustMe --- tools/macdeployqt/shared/shared.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/macdeployqt/shared/shared.cpp b/tools/macdeployqt/shared/shared.cpp index 74dd4a4..bb37f0b 100644 --- a/tools/macdeployqt/shared/shared.cpp +++ b/tools/macdeployqt/shared/shared.cpp @@ -111,7 +111,7 @@ FrameworkInfo parseOtoolLibraryLine(const QString &line, bool useDebugLibs) // Don't deploy system libraries. if (trimmed.startsWith("/System/Library/") || (trimmed.startsWith("/usr/lib/") && trimmed.contains("libQt") == false) // exception for libQtuitools and libQtlucene - || trimmed.startsWith("@executable_path")) + || trimmed.startsWith("@executable_path") || trimmed.startsWith("@loader_path") || trimmed.startsWith("@rpath")) return info; enum State {QtPath, FrameworkName, DylibName, Version, End}; @@ -238,7 +238,7 @@ QList getQtFrameworks(const QString &path, bool useDebugLibs) QStringList outputLines = output.split("\n"); outputLines.removeFirst(); // remove line containing the binary path if (path.contains(".framework") || path.contains(".dylib")) - outputLines.removeFirst(); // frameworks and dylibs lists themselves as a dependency. + outputLines.removeFirst(); // frameworks and dylibs print install name of themselves first. return getQtFrameworks(outputLines, useDebugLibs); } -- cgit v0.12 From 4bda273330f6705b79cf18c3ea8ef294f58a5239 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Tue, 26 Jul 2011 17:03:03 +0200 Subject: Make mac(deploy|change)qt handle dylibs that use Qt inside an app bundle. Needed e.g. for Qt Creator, which is a bundle of plugins. Reviewed-by: TrustMe --- tools/macdeployqt/shared/shared.cpp | 67 ++++++++++++++++++++++++++++--------- tools/macdeployqt/shared/shared.h | 5 +-- 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/tools/macdeployqt/shared/shared.cpp b/tools/macdeployqt/shared/shared.cpp index bb37f0b..30c493f 100644 --- a/tools/macdeployqt/shared/shared.cpp +++ b/tools/macdeployqt/shared/shared.cpp @@ -84,6 +84,7 @@ inline QDebug operator<<(QDebug debug, const ApplicationBundleInfo &info) { debug << "Application bundle path" << info.path << "\n"; debug << "Binary path" << info.binaryPath << "\n"; + debug << "Additional libraries" << info.libraryPaths << "\n"; return debug; } @@ -208,6 +209,21 @@ QString findAppBinary(const QString &appBundlePath) return QString(); } +QStringList findAppLibraries(const QString &appBundlePath) +{ + QStringList result; + // dylibs + QDirIterator iter(appBundlePath, QStringList() << QString::fromLatin1("*.dylib"), + QDir::Files, QDirIterator::Subdirectories); + + while (iter.hasNext()) { + iter.next(); + result << iter.fileInfo().filePath(); + } + return result; +} + + QList getQtFrameworks(const QStringList &otoolLines, bool useDebugLibs) { QList libraries; @@ -243,6 +259,21 @@ QList getQtFrameworks(const QString &path, bool useDebugLibs) return getQtFrameworks(outputLines, useDebugLibs); } +QList getQtFrameworksForPaths(const QStringList &paths, bool useDebugLibs) +{ + QList result; + QSet existing; + foreach (const QString &path, paths) { + foreach (const FrameworkInfo &info, getQtFrameworks(path, useDebugLibs)) { + if (!existing.contains(info.frameworkPath)) { // avoid duplicates + existing.insert(info.frameworkPath); + result << info; + } + } + } + return result; +} + // copies everything _inside_ sourcePath to destinationPath void recursiveCopy(const QString &sourcePath, const QString &destinationPath) { @@ -312,13 +343,14 @@ void changeIdentification(const QString &id, const QString &binaryPath) runInstallNameTool(QStringList() << "-id" << id << binaryPath); } -void changeInstallName(const QString &oldName, const QString &newName, const QString &binaryPath) +void changeInstallName(const QString &oldName, const QString &newName, const QStringList &binaryPaths) { LogDebug() << "Using install_name_tool:"; - LogDebug() << " in" << binaryPath; + LogDebug() << " in" << binaryPaths; LogDebug() << " change reference" << oldName; LogDebug() << " to" << newName; - runInstallNameTool(QStringList() << "-change" << oldName << newName << binaryPath); + foreach (const QString &path, binaryPaths) + runInstallNameTool(QStringList() << "-change" << oldName << newName << path); } void runStrip(const QString &binaryPath) @@ -345,10 +377,10 @@ void runStrip(const QString &binaryPath) a list of actually deployed frameworks. */ DeploymentInfo deployQtFrameworks(QList frameworks, - const QString &bundlePath, const QString &binaryPath, bool useDebugLibs) + const QString &bundlePath, const QStringList &binaryPaths, bool useDebugLibs) { LogNormal(); - LogNormal() << "Deploying Qt frameworks found inside:" << binaryPath; + LogNormal() << "Deploying Qt frameworks found inside:" << binaryPaths; QStringList copiedFrameworks; DeploymentInfo deploymentInfo; @@ -370,7 +402,7 @@ DeploymentInfo deployQtFrameworks(QList frameworks, } // Install_name_tool the new id into the binary - changeInstallName(framework.installName, framework.deployedInstallName, binaryPath); + changeInstallName(framework.installName, framework.deployedInstallName, binaryPaths); // Copy farmework to app bundle. const QString deployedBinaryPath = copyFramework(framework, bundlePath); @@ -386,7 +418,7 @@ DeploymentInfo deployQtFrameworks(QList frameworks, QList dependencies = getQtFrameworks(deployedBinaryPath, useDebugLibs); foreach (FrameworkInfo dependency, dependencies) { - changeInstallName(dependency.installName, dependency.deployedInstallName, deployedBinaryPath); + changeInstallName(dependency.installName, dependency.deployedInstallName, QStringList() << deployedBinaryPath); // Deploy framework if necessary. if (copiedFrameworks.contains(dependency.frameworkName) == false && frameworks.contains(dependency) == false) { @@ -403,7 +435,9 @@ DeploymentInfo deployQtFrameworks(const QString &appBundlePath, bool useDebugLib ApplicationBundleInfo applicationBundle; applicationBundle.path = appBundlePath; applicationBundle.binaryPath = findAppBinary(appBundlePath); - QList frameworks = getQtFrameworks(applicationBundle.binaryPath, useDebugLibs); + applicationBundle.libraryPaths = findAppLibraries(appBundlePath); + QStringList allBinaryPaths = QStringList() << applicationBundle.binaryPath << applicationBundle.libraryPaths; + QList frameworks = getQtFrameworksForPaths(allBinaryPaths, useDebugLibs); if (frameworks.isEmpty()) { LogWarning(); LogWarning() << "Could not find any external Qt frameworks to deploy in" << appBundlePath; @@ -411,7 +445,7 @@ DeploymentInfo deployQtFrameworks(const QString &appBundlePath, bool useDebugLib LogWarning() << "If so, you will need to rebuild" << appBundlePath << "before trying again."; return DeploymentInfo(); } else { - return deployQtFrameworks(frameworks, applicationBundle.path, applicationBundle.binaryPath, useDebugLibs); + return deployQtFrameworks(frameworks, applicationBundle.path, allBinaryPaths, useDebugLibs); } } @@ -477,11 +511,11 @@ void deployPlugins(const ApplicationBundleInfo &appBundleInfo, const QString &pl if (pluginName.contains("libphonon_qt7")) { changeInstallName("/System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo", "/System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore", - destinationPath); + QStringList() << destinationPath); } QList frameworks = getQtFrameworks(destinationPath, useDebugLibs); - deployQtFrameworks(frameworks, appBundleInfo.path, destinationPath, useDebugLibs); + deployQtFrameworks(frameworks, appBundleInfo.path, QStringList() << destinationPath, useDebugLibs); } } // foreach plugins @@ -527,9 +561,9 @@ void deployPlugins(const QString &appBundlePath, DeploymentInfo deploymentInfo, } -void changeQtFrameworks(const QList frameworks, const QString &appBinaryPath, const QString &absoluteQtPath) +void changeQtFrameworks(const QList frameworks, const QStringList &binaryPaths, const QString &absoluteQtPath) { - LogNormal() << "Changing" << appBinaryPath << "to link against"; + LogNormal() << "Changing" << binaryPaths << "to link against"; LogNormal() << "Qt in" << absoluteQtPath; QString finalQtPath = absoluteQtPath; @@ -539,21 +573,22 @@ void changeQtFrameworks(const QList frameworks, const QString &ap foreach (FrameworkInfo framework, frameworks) { const QString oldBinaryId = framework.installName; const QString newBinaryId = finalQtPath + framework.frameworkName + framework.binaryPath; - changeInstallName(oldBinaryId, newBinaryId, appBinaryPath); + changeInstallName(oldBinaryId, newBinaryId, binaryPaths); } } void changeQtFrameworks(const QString appPath, const QString &qtPath, bool useDebugLibs) { const QString appBinaryPath = findAppBinary(appPath); - const QList frameworks = getQtFrameworks(appBinaryPath, useDebugLibs); + const QStringList libraryPaths = findAppLibraries(appPath); + const QList frameworks = getQtFrameworksForPaths(QStringList() << appBinaryPath << libraryPaths, useDebugLibs); if (frameworks.isEmpty()) { LogWarning(); LogWarning() << "Could not find any _external_ Qt frameworks to change in" << appPath; return; } else { const QString absoluteQtPath = QDir(qtPath).absolutePath(); - changeQtFrameworks(frameworks, appBinaryPath, absoluteQtPath); + changeQtFrameworks(frameworks, QStringList() << appBinaryPath << libraryPaths, absoluteQtPath); } } diff --git a/tools/macdeployqt/shared/shared.h b/tools/macdeployqt/shared/shared.h index 5eec3cf..ab9ada2 100644 --- a/tools/macdeployqt/shared/shared.h +++ b/tools/macdeployqt/shared/shared.h @@ -77,6 +77,7 @@ class ApplicationBundleInfo public: QString path; QString binaryPath; + QStringList libraryPaths; }; class DeploymentInfo @@ -91,7 +92,7 @@ public: inline QDebug operator<<(QDebug debug, const ApplicationBundleInfo &info); void changeQtFrameworks(const QString appPath, const QString &qtPath, bool useDebugLibs); -void changeQtFrameworks(const QList frameworks, const QString &appBinaryPath, const QString &qtPath); +void changeQtFrameworks(const QList frameworks, const QStringList &binaryPaths, const QString &qtPath); FrameworkInfo parseOtoolLibraryLine(const QString &line, bool useDebugLibs); QString findAppBinary(const QString &appBundlePath); @@ -103,7 +104,7 @@ DeploymentInfo deployQtFrameworks(QList frameworks, const QString void createQtConf(const QString &appBundlePath); void deployPlugins(const QString &appBundlePath, DeploymentInfo deploymentInfo, bool useDebugLibs); void changeIdentification(const QString &id, const QString &binaryPath); -void changeInstallName(const QString &oldName, const QString &newName, const QString &binaryPath); +void changeInstallName(const QString &oldName, const QString &newName, const QStringList &binaryPaths); QString findAppBinary(const QString &appBundlePath); void createDiskImage(const QString &appBundlePath); -- cgit v0.12