From ed6fe5abc87b544e9637024b2ba7a0c202c66521 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Mon, 28 Mar 2022 10:08:32 +0200 Subject: [PATCH] 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 --- tests/auto/corelib/plugin/CMakeLists.txt | 8 ++-- .../plugin/qlibrary/lib/CMakeLists.txt | 13 ++++- .../plugin/qlibrary/lib2/CMakeLists.txt | 47 ++++++++++++------- .../plugin/qlibrary/tst/CMakeLists.txt | 40 +++------------- .../corelib/plugin/qlibrary/tst_qlibrary.cpp | 30 ++++-------- 5 files changed, 62 insertions(+), 76 deletions(-) diff --git a/tests/auto/corelib/plugin/CMakeLists.txt b/tests/auto/corelib/plugin/CMakeLists.txt index 06ed2361e71..f6b3d685112 100644 --- a/tests/auto/corelib/plugin/CMakeLists.txt +++ b/tests/auto/corelib/plugin/CMakeLists.txt @@ -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) diff --git a/tests/auto/corelib/plugin/qlibrary/lib/CMakeLists.txt b/tests/auto/corelib/plugin/qlibrary/lib/CMakeLists.txt index 3ae8d11b6c2..25292c0cc5e 100644 --- a/tests/auto/corelib/plugin/qlibrary/lib/CMakeLists.txt +++ b/tests/auto/corelib/plugin/qlibrary/lib/CMakeLists.txt @@ -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 $ "${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 + $ + "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so" + VERBATIM) + endif() else() #Win32 add_custom_command(TARGET mylib POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different diff --git a/tests/auto/corelib/plugin/qlibrary/lib2/CMakeLists.txt b/tests/auto/corelib/plugin/qlibrary/lib2/CMakeLists.txt index 9caf22f4f9e..902c53ea844 100644 --- a/tests/auto/corelib/plugin/qlibrary/lib2/CMakeLists.txt +++ b/tests/auto/corelib/plugin/qlibrary/lib2/CMakeLists.txt @@ -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 + $ + "${CMAKE_CURRENT_BINARY_DIR}/../system.qt.test.mylib.so" + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ + "${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 $ - "${CMAKE_CURRENT_BINARY_DIR}/../system.qt.test.mylib.so" - COMMAND ${CMAKE_COMMAND} -E copy_if_different - $ - "${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 diff --git a/tests/auto/corelib/plugin/qlibrary/tst/CMakeLists.txt b/tests/auto/corelib/plugin/qlibrary/tst/CMakeLists.txt index 73c05aeebe5..ee50a7f581e 100644 --- a/tests/auto/corelib/plugin/qlibrary/tst/CMakeLists.txt +++ b/tests/auto/corelib/plugin/qlibrary/tst/CMakeLists.txt @@ -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() diff --git a/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp b/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp index 6ecbf393e2c..e59752f2fba 100644 --- a/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp +++ b/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp @@ -104,9 +104,6 @@ enum QLibraryOperation { QString sys_qualifiedLibraryName(const QString &fileName); QString directory; -#ifdef Q_OS_ANDROID - QSharedPointer 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 }