From fcfe2a5f67f0045e8ed606f60330df5e24cf03b2 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Thu, 18 Feb 2016 01:06:49 -0800 Subject: [PATCH] Also search the main bundle plugin path for plugins on Apple OSes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The default value of QLibraryInfo::PluginsPath is $prefix/plugins, where $prefix is the path to the bundle's contents directory (for example, .../foo.app/Contents/ on OS X, or .../foo.app/ on iOS). On Apple platforms the directory is actually called "PlugIns". Plugins could previously be loaded on OS X by coincidence, but if the system is using an HFS+ Case Sensitive filesystem (and this is ALWAYS the case on iOS-like operating systems), the case mismatch would cause plugins in an application bundle not to be found/loaded. This change allows plugins to be located in application bundles on Apple platforms regardless of the HFS+ case sensitivity mode and without needing to specify a qt.conf file. Change-Id: Ie0a0f7448fbf5fb410aa77944ba0d01895bb05e3 Reviewed-by: Morten Johan Sørvig Reviewed-by: Oswald Buddenhagen --- src/corelib/kernel/qcoreapplication.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 79a3254a39..38efc44399 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -2498,6 +2498,26 @@ QStringList QCoreApplication::libraryPaths() } } +#ifdef Q_OS_DARWIN + // Check the main bundle's PlugIns directory as this is a standard location for Apple OSes. + // Note that the QLibraryInfo::PluginsPath below will coincidentally be the same as this value + // but with a different casing, so it can't be relied upon when the underlying filesystem + // is case sensitive (and this is always the case on newer OSes like iOS). + if (CFBundleRef bundleRef = CFBundleGetMainBundle()) { + if (QCFType urlRef = CFBundleCopyBuiltInPlugInsURL(bundleRef)) { + if (QCFType absoluteUrlRef = CFURLCopyAbsoluteURL(urlRef)) { + if (QCFString path = CFURLCopyFileSystemPath(absoluteUrlRef, kCFURLPOSIXPathStyle)) { + if (QFile::exists(path)) { + path = QDir(path).canonicalPath(); + if (!app_libpaths->contains(path)) + app_libpaths->append(path); + } + } + } + } + } +#endif // Q_OS_DARWIN + QString installPathPlugins = QLibraryInfo::location(QLibraryInfo::PluginsPath); if (QFile::exists(installPathPlugins)) { // Make sure we convert from backslashes to slashes.