Fix QLibrary::isLibrary on Apple platforms
Add proper support for 'so' and 'bundle' suffixes. Qt wrongly assumes .so libraries are not versioned on Apple platforms, which is wrong. Also, the shared library .bundle which is what Apple recommends instead of .so, are also versioned (not to be confound with the different Core Foundation bundles, which are directory hierarchy). For more info, see http://docstore.mik.ua/orelly/unix3/mac/ch05_03.htm. Especially the part that reads: "Loadable modules, called bundles in Mac OS X, have the file type MH_BUNDLE. Most Unix-based software ports usually produce bundles with a .so extension, for the sake of consistency across platforms. Although Apple recommends giving bundles a .bundle extension, it isn't mandatory." Task-number: QTBUG-50446 Change-Id: Iacd5136397a12d65d83821434f332eb602550b4b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
b2ffc4d0a0
commit
9db8c171e7
|
|
@ -617,40 +617,34 @@ bool QLibrary::isLibrary(const QString &fileName)
|
|||
{
|
||||
#if defined(Q_OS_WIN)
|
||||
return fileName.endsWith(QLatin1String(".dll"), Qt::CaseInsensitive);
|
||||
#else
|
||||
#else // Generic Unix
|
||||
QString completeSuffix = QFileInfo(fileName).completeSuffix();
|
||||
if (completeSuffix.isEmpty())
|
||||
return false;
|
||||
const QVector<QStringRef> suffixes = completeSuffix.splitRef(QLatin1Char('.'));
|
||||
# if defined(Q_OS_DARWIN)
|
||||
|
||||
// On Mac, libs look like libmylib.1.0.0.dylib
|
||||
const QStringRef &lastSuffix = suffixes.at(suffixes.count() - 1);
|
||||
const QStringRef &firstSuffix = suffixes.at(0);
|
||||
|
||||
bool valid = (lastSuffix == QLatin1String("dylib")
|
||||
|| firstSuffix == QLatin1String("so")
|
||||
|| firstSuffix == QLatin1String("bundle"));
|
||||
|
||||
return valid;
|
||||
# else // Generic Unix
|
||||
QStringList validSuffixList;
|
||||
|
||||
# if defined(Q_OS_HPUX)
|
||||
# if defined(Q_OS_HPUX)
|
||||
/*
|
||||
See "HP-UX Linker and Libraries User's Guide", section "Link-time Differences between PA-RISC and IPF":
|
||||
"In PA-RISC (PA-32 and PA-64) shared libraries are suffixed with .sl. In IPF (32-bit and 64-bit),
|
||||
the shared libraries are suffixed with .so. For compatibility, the IPF linker also supports the .sl suffix."
|
||||
*/
|
||||
validSuffixList << QLatin1String("sl");
|
||||
# if defined __ia64
|
||||
validSuffixList << QLatin1String("so");
|
||||
# endif
|
||||
# elif defined(Q_OS_AIX)
|
||||
validSuffixList << QLatin1String("a") << QLatin1String("so");
|
||||
# elif defined(Q_OS_UNIX)
|
||||
# if defined __ia64
|
||||
validSuffixList << QLatin1String("so");
|
||||
# endif
|
||||
# elif defined(Q_OS_AIX)
|
||||
validSuffixList << QLatin1String("a") << QLatin1String("so");
|
||||
# elif defined(Q_OS_DARWIN)
|
||||
// On Apple platforms, dylib look like libmylib.1.0.0.dylib
|
||||
if (suffixes.last() == QLatin1String("dylib"))
|
||||
return true;
|
||||
|
||||
validSuffixList << QLatin1String("so") << QLatin1String("bundle");
|
||||
# elif defined(Q_OS_UNIX)
|
||||
validSuffixList << QLatin1String("so");
|
||||
# endif
|
||||
|
||||
// Examples of valid library names:
|
||||
// libfoo.so
|
||||
|
|
@ -669,9 +663,7 @@ bool QLibrary::isLibrary(const QString &fileName)
|
|||
if (i != suffixPos)
|
||||
suffixes.at(i).toInt(&valid);
|
||||
return valid;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
typedef const char * (*QtPluginQueryVerificationDataFunction)();
|
||||
|
|
|
|||
|
|
@ -302,15 +302,10 @@ void tst_QLibrary::isLibrary_data()
|
|||
QTest::newRow(".sl") << QString("mylib.sl") << sl_VALID;
|
||||
QTest::newRow(".so") << QString("mylib.so") << so_VALID;
|
||||
QTest::newRow(".so+version") << QString("mylib.so.0") << so_VALID;
|
||||
|
||||
// special tests:
|
||||
#ifndef Q_OS_MAC
|
||||
QTest::newRow("version+.so") << QString("libc-2.7.so") << so_VALID;
|
||||
QTest::newRow("version+.so+version") << QString("liboil-0.3.so.0.1.0") << so_VALID;
|
||||
#else
|
||||
QTest::newRow("version+.so") << QString("libc-2.7.so") << false;
|
||||
QTest::newRow("version+.so+version") << QString("liboil-0.3.so.0.1.0") << false;
|
||||
#endif
|
||||
|
||||
// special tests:
|
||||
#ifdef Q_OS_MAC
|
||||
QTest::newRow("good (libmylib.1.0.0.dylib)") << QString("libmylib.1.0.0.dylib") << true;
|
||||
QTest::newRow("good (libmylib.dylib)") << QString("libmylib.dylib") << true;
|
||||
|
|
|
|||
Loading…
Reference in New Issue