Android: activate tst_QLibrary

On Android we demand the libraries to always start with "lib" and
end with ".so" extension. Also Android does not support versioned
libraries.

This patch updates CMakeLists.txt to fulfill these requirements,
and also omits some unsupported test cases.

This allows to enable this test for Android in CMakeLists.txt

Task-number: QTBUG-87438
Pick-to: 6.3 6.2
Change-Id: Iec30acdefe00c471acc7139cd255b3389e31d22b
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
Ivan Solovev 2022-03-28 10:08:32 +02:00
parent 5cbb93adc7
commit ed6fe5abc8
5 changed files with 62 additions and 76 deletions

View File

@ -4,9 +4,11 @@ if(QT_BUILD_SHARED_LIBS)
add_subdirectory(qfactoryloader)
endif()
add_subdirectory(quuid)
# QTBUG-87438 # special case
if(QT_FEATURE_library AND NOT ANDROID)
add_subdirectory(qpluginloader)
if(QT_FEATURE_library)
# QTBUG-87438 # special case
if(NOT ANDROID)
add_subdirectory(qpluginloader)
endif()
add_subdirectory(qlibrary)
endif()
if(QT_BUILD_SHARED_LIBS AND QT_FEATURE_library)

View File

@ -37,7 +37,8 @@ if (MACOS)
"${CMAKE_CURRENT_BINARY_DIR}/*dylib"
"${CMAKE_CURRENT_BINARY_DIR}/../")
elseif (UNIX)
add_custom_command(TARGET mylib POST_BUILD
if (NOT ANDROID)
add_custom_command(TARGET mylib POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:mylib>
"${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so.1.0.0"
@ -48,6 +49,16 @@ elseif (UNIX)
"libmylib.so.1.0.0"
"${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so1"
VERBATIM)
else()
# Android does not use symlinks. Also, according to our conventions,
# libraries on Android MUST be named in the following pattern:
# lib*.so
add_custom_command(TARGET mylib POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:mylib>
"${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so"
VERBATIM)
endif()
else() #Win32
add_custom_command(TARGET mylib POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different

View File

@ -40,25 +40,36 @@ if(WIN32)
endif()
if (UNIX)
add_custom_command(TARGET mylib2 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
if(NOT ANDROID)
add_custom_command(TARGET mylib2 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:mylib2>
"${CMAKE_CURRENT_BINARY_DIR}/../system.qt.test.mylib.so"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:mylib2>
"${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so.2.0.0"
COMMAND ${CMAKE_COMMAND} -E create_symlink
"libmylib.so.2.0.0"
"${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so.2"
COMMAND ${CMAKE_COMMAND} -E remove
"${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so"
COMMAND ${CMAKE_COMMAND} -E create_symlink
"libmylib.so.2.0.0"
"${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so"
COMMAND ${CMAKE_COMMAND} -E create_symlink
"libmylib.so.2.0.0"
"${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so2"
VERBATIM)
else()
# Android does not use symlinks. Also, according to our conventions,
# libraries on Android MUST be named in the following pattern:
# lib*.so
add_custom_command(TARGET mylib2 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:mylib2>
"${CMAKE_CURRENT_BINARY_DIR}/../system.qt.test.mylib.so"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:mylib2>
"${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so.2.0.0"
COMMAND ${CMAKE_COMMAND} -E create_symlink
"libmylib.so.2.0.0"
"${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so.2"
COMMAND ${CMAKE_COMMAND} -E remove
"${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so"
COMMAND ${CMAKE_COMMAND} -E create_symlink
"libmylib.so.2.0.0"
"${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so"
COMMAND ${CMAKE_COMMAND} -E create_symlink
"libmylib.so.2.0.0"
"${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so2"
VERBATIM)
"${CMAKE_CURRENT_BINARY_DIR}/../libsystem.qt.test.mylib.so"
VERBATIM)
endif()
else() #Win32
add_custom_command(TARGET mylib2 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different

View File

@ -15,39 +15,13 @@ qt_internal_add_test(tst_qlibrary
LIBRARIES mylib mylib2 # special case
)
## Scopes:
#####################################################################
add_dependencies(tst_qlibrary mylib mylib2)
if(ANDROID)
# special case begin
set_source_files_properties(
${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so
PROPERTIES QT_RESOURCE_TARGET_DEPENDENCY mylib
)
set_source_files_properties(
${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so2
${CMAKE_CURRENT_BINARY_DIR}/../system.qt.test.mylib.so
PROPERTIES QT_RESOURCE_TARGET_DEPENDENCY mylib2
)
# special case end
# Resources:
set(qmake_libs_resource_files
# special case begin
#libmylib.prl
libmylib.so
libmylib.so2
system.qt.test.mylib.so
# special case end
)
list(TRANSFORM qmake_libs_resource_files PREPEND "${CMAKE_CURRENT_BINARY_DIR}/../")
qt_internal_add_resource(tst_qlibrary "qmake_libs"
PREFIX
"android_test_data"
BASE
"${CMAKE_CURRENT_BINARY_DIR}/.."
FILES
${qmake_libs_resource_files}
)
list(APPEND extra_libs
"${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so")
list(APPEND extra_libs
"${CMAKE_CURRENT_BINARY_DIR}/../libsystem.qt.test.mylib.so")
set_target_properties(tst_qlibrary PROPERTIES
QT_ANDROID_EXTRA_LIBS "${extra_libs}")
endif()

View File

@ -104,9 +104,6 @@ enum QLibraryOperation {
QString sys_qualifiedLibraryName(const QString &fileName);
QString directory;
#ifdef Q_OS_ANDROID
QSharedPointer<QTemporaryDir> temporaryDir;
#endif
private slots:
void initTestCase();
@ -141,24 +138,9 @@ typedef int (*VersionFunction)(void);
void tst_QLibrary::initTestCase()
{
#ifdef Q_OS_ANDROID
auto tempDir = QEXTRACTTESTDATA("android_test_data");
QVERIFY2(QDir::setCurrent(tempDir->path()), qPrintable("Could not chdir to " + tempDir->path()));
// copy :/library_path into ./library_path
QVERIFY(QDir().mkdir("library_path"));
QDirIterator iterator(":/library_path", QDirIterator::Subdirectories);
while (iterator.hasNext()) {
iterator.next();
QFileInfo sourceFileInfo(iterator.path());
QFileInfo targetFileInfo("./library_path/" + sourceFileInfo.fileName());
if (!targetFileInfo.exists()) {
QDir().mkpath(targetFileInfo.path());
QVERIFY(QFile::copy(sourceFileInfo.filePath(), targetFileInfo.filePath()));
}
}
directory = tempDir->path();
temporaryDir = std::move(tempDir);
const QStringList paths = QCoreApplication::libraryPaths();
QVERIFY(!paths.isEmpty());
directory = paths.first();
#else
// chdir to our testdata directory, and use relative paths in some tests.
QString testdatadir = QFileInfo(QFINDTESTDATA("library_path")).absolutePath();
@ -224,7 +206,10 @@ void tst_QLibrary::load_data()
QTest::newRow( "ok03 (with many dots)" ) << appDir + "/system.qt.test.mylib.dll" << true;
# elif defined Q_OS_UNIX
QTest::newRow( "ok01 (with suffix)" ) << appDir + "/libmylib" SUFFIX << true;
#ifndef Q_OS_ANDROID
// We do not support non-standard suffixes on Android
QTest::newRow( "ok02 (with non-standard suffix)" ) << appDir + "/libmylib.so2" << true;
#endif
QTest::newRow( "ok03 (with many dots)" ) << appDir + "/system.qt.test.mylib.so" << true;
# endif // Q_OS_UNIX
}
@ -438,7 +423,10 @@ void tst_QLibrary::loadHints_data()
QTest::newRow( "ok03 (with many dots)" ) << appDir + "/system.qt.test.mylib.dll" << int(lh) << true;
# elif defined Q_OS_UNIX
QTest::newRow( "ok01 (with suffix)" ) << appDir + "/libmylib" SUFFIX << int(lh) << true;
#ifndef Q_OS_ANDROID
// We do not support non-standard suffixes on Android
QTest::newRow( "ok02 (with non-standard suffix)" ) << appDir + "/libmylib.so2" << int(lh) << true;
#endif
QTest::newRow( "ok03 (with many dots)" ) << appDir + "/system.qt.test.mylib.so" << int(lh) << true;
# endif // Q_OS_UNIX
}