From 7dfda6f5f91a0eb81a51ff305f79b2fe791f206a Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Tue, 16 Sep 2014 01:25:55 -0400 Subject: [PATCH] macdeployqt: Correctly determine the application bundle's executable path. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This handles cases where the executable is named differently from the wrapper, or the application bundle is an iOS bundle, where there is no Contents subdirectory. Change-Id: I76d665de64be3a0f802dae4f520815490273f90a Reviewed-by: Morten Johan Sørvig --- src/macdeployqt/macchangeqt/macchangeqt.pro | 1 + src/macdeployqt/macdeployqt/macdeployqt.pro | 1 + src/macdeployqt/shared/shared.cpp | 34 ++++++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/macdeployqt/macchangeqt/macchangeqt.pro b/src/macdeployqt/macchangeqt/macchangeqt.pro index 3d5be8d..2eafd3e 100644 --- a/src/macdeployqt/macchangeqt/macchangeqt.pro +++ b/src/macdeployqt/macchangeqt/macchangeqt.pro @@ -1,3 +1,4 @@ SOURCES += main.cpp ../shared/shared.cpp +LIBS += -framework CoreFoundation load(qt_app) diff --git a/src/macdeployqt/macdeployqt/macdeployqt.pro b/src/macdeployqt/macdeployqt/macdeployqt.pro index 3d5be8d..2eafd3e 100644 --- a/src/macdeployqt/macdeployqt/macdeployqt.pro +++ b/src/macdeployqt/macdeployqt/macdeployqt.pro @@ -1,3 +1,4 @@ SOURCES += main.cpp ../shared/shared.cpp +LIBS += -framework CoreFoundation load(qt_app) diff --git a/src/macdeployqt/shared/shared.cpp b/src/macdeployqt/shared/shared.cpp index d2eeea0..c1797c3 100644 --- a/src/macdeployqt/shared/shared.cpp +++ b/src/macdeployqt/shared/shared.cpp @@ -54,6 +54,10 @@ #include #include "shared.h" +#ifdef Q_OS_DARWIN +#include +#endif + bool runStripEnabled = true; bool alwaysOwerwriteEnabled = false; int logLevel = 1; @@ -84,7 +88,6 @@ QDebug operator<<(QDebug debug, const FrameworkInfo &info) } const QString bundleFrameworkDirectory = "Contents/Frameworks"; -const QString bundleBinaryDirectory = "Contents/MacOS"; inline QDebug operator<<(QDebug debug, const ApplicationBundleInfo &info) { @@ -230,8 +233,33 @@ FrameworkInfo parseOtoolLibraryLine(const QString &line, bool useDebugLibs) QString findAppBinary(const QString &appBundlePath) { - QString appName = QFileInfo(appBundlePath).completeBaseName(); - QString binaryPath = appBundlePath + "/Contents/MacOS/" + appName; + QString binaryPath; + +#ifdef Q_OS_DARWIN + CFStringRef bundlePath = appBundlePath.toCFString(); + CFURLRef bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, bundlePath, + kCFURLPOSIXPathStyle, true); + CFRelease(bundlePath); + CFBundleRef bundle = CFBundleCreate(kCFAllocatorDefault, bundleURL); + if (bundle) { + CFURLRef executableURL = CFBundleCopyExecutableURL(bundle); + if (executableURL) { + CFURLRef absoluteExecutableURL = CFURLCopyAbsoluteURL(executableURL); + if (absoluteExecutableURL) { + CFStringRef executablePath = CFURLCopyFileSystemPath(absoluteExecutableURL, + kCFURLPOSIXPathStyle); + if (executablePath) { + binaryPath = QString::fromCFString(executablePath); + CFRelease(executablePath); + } + CFRelease(absoluteExecutableURL); + } + CFRelease(executableURL); + } + CFRelease(bundle); + } + CFRelease(bundleURL); +#endif if (QFile::exists(binaryPath)) return binaryPath; -- 2.7.4