From f3f383f0979918a1eee290d3d942f46a68e3e450 Mon Sep 17 00:00:00 2001 From: Soheil Armin Date: Thu, 23 May 2024 16:09:46 +0300 Subject: [PATCH] Android: Add autotest to verify the content of an AAR target This will build a multi-abi Android AAR target and verifies its content using a customer target "verify_aar" by running zipinfo on the AAR, and comparing its content with a subset of files that are expected to be present in the package. Task-number: QTBUG-125483 Change-Id: I19ad132bbad1a75c40b00de173ca09ad56500076 Reviewed-by: Alexandru Croitor --- tests/auto/cmake/CMakeLists.txt | 15 ++++++ .../cmake/test_android_aar/CMakeLists.txt | 54 +++++++++++++++++++ tests/auto/cmake/test_android_aar/main.cpp | 4 ++ 3 files changed, 73 insertions(+) create mode 100644 tests/auto/cmake/test_android_aar/CMakeLists.txt create mode 100644 tests/auto/cmake/test_android_aar/main.cpp diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index b159de7c9ca..86db9540862 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -146,6 +146,21 @@ if(QT_BUILD_MINIMAL_ANDROID_MULTI_ABI_TESTS AND NOT NO_GUI) "-DTEST_ESCAPING_VALUE_ARG=${escaping_value}" "-DTEST_SPACES_VALUE_ARG=${spaces_value}" ) + + #Run test_android_aar only if the host is Unix and zipinfo is available + find_program(ZIPINFO_EXECUTABLE zipinfo) + if(CMAKE_HOST_UNIX AND ZIPINFO_EXECUTABLE) + _qt_internal_test_expect_pass(test_android_aar + BUILD_OPTIONS + ${multi_abi_vars} + --build-target verify_aar + ) + else() + message(WARNING + "Skipping test_android_aar CMake build test because \ + the host is not Unix or zipinfo is not found") + endif() + return() endif() diff --git a/tests/auto/cmake/test_android_aar/CMakeLists.txt b/tests/auto/cmake/test_android_aar/CMakeLists.txt new file mode 100644 index 00000000000..88cd5abf230 --- /dev/null +++ b/tests/auto/cmake/test_android_aar/CMakeLists.txt @@ -0,0 +1,54 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) + +project(test_android_aar) + +find_package(Qt6 COMPONENTS Core Gui REQUIRED) + +qt6_add_executable(test_aar main.cpp) + +# To support opening the project in QtCreator +if($CACHE{QT_USE_TARGET_ANDROID_BUILD_DIR}) + set(TARGET_ANDROID_BUILD_DIR ${CMAKE_BINARY_DIR}/android-build-test_aar) +else() + set(TARGET_ANDROID_BUILD_DIR ${CMAKE_BINARY_DIR}/android-build) +endif() + +# Add common libs for available ABIs that should be present in the aar package in a list +unset(aar_content_filepaths_to_verify) +foreach(abi IN LISTS QT_ANDROID_ABIS) + list(APPEND aar_content_filepaths_to_verify "jni/${abi}/libQt6Core_${abi}.so") + list(APPEND aar_content_filepaths_to_verify "jni/${abi}/libQt6Gui_${abi}.so") + list(APPEND aar_content_filepaths_to_verify + "jni/${abi}/libplugins_platforms_qtforandroid_${abi}.so") + list(APPEND aar_content_filepaths_to_verify "jni/${abi}/libtest_aar_${abi}.so") +endforeach() + +# Add a few ABI independent file that should be present in the aar package in a list +list(APPEND aar_content_filepaths_to_verify "libs/Qt6Android.jar") +list(APPEND aar_content_filepaths_to_verify "res/xml/qtprovider_paths.xml") +list(APPEND aar_content_filepaths_to_verify "AndroidManifest.xml") +list(JOIN aar_content_filepaths_to_verify "|" grep_pattern) + +# The overall number of lines we should expect to be filtered by grep regex +list(LENGTH aar_content_filepaths_to_verify expected_file_count) + +set(zipinfo_command "zipinfo -1 ${TARGET_ANDROID_BUILD_DIR}/test_aar.aar") + +# Runs zipinfo on the aar package, greps and outputs the number of matching lines +# and finally compares the expected number of lines with the output +add_custom_target(verify_aar + bash -c "${zipinfo_command} \ + | grep -Ecx '${grep_pattern}' \ + | grep -xq ${expected_file_count} \ + || { echo 'Error: The aar package is missing at least one file.'; exit 1; };" + COMMENT "Verifying aar package content" + VERBATIM +) + +# Build aar package before verification +add_dependencies(verify_aar aar) + +target_link_libraries(test_aar PRIVATE Qt::Core Qt::Gui) diff --git a/tests/auto/cmake/test_android_aar/main.cpp b/tests/auto/cmake/test_android_aar/main.cpp new file mode 100644 index 00000000000..90df9ee9379 --- /dev/null +++ b/tests/auto/cmake/test_android_aar/main.cpp @@ -0,0 +1,4 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +int main(int, char *[]) { return 0; }