summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2021-05-11 13:49:08 +0200
committerJoerg Bornemann <joerg.bornemann@qt.io>2021-05-17 19:14:44 +0200
commit76eefab088b64f9ba4e5f5c48612bfdd3552081d (patch)
tree9250339b31708224a5b49ade1e91d2c9c6e4392b /src
parent50c838d4b5cde32db6bfcf8dda4dfbf5c34b9b17 (diff)
Add proper dependencies to apk targets
Before, building ${target}_make_apk always re-built the apk, instead of rebuilding the apk only when inputs changed. This patch fixes that by moving the creation code from a custom target to a custom command with proper dependencies. The androidtestrunner tool now does not check for the existence of an apk anymore and always runs the make command that is supposed to build the apk. The ${target}_prepare_apk_dir target is not needed anymore by the Qt build but is still used by Qt Creator's Android support. Add a clarifying comment. Fixes: QTBUG-93431 Change-Id: I00d65d616fef9511b03b65f879c4bc6cb92dfc30 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/Qt6AndroidMacros.cmake41
-rw-r--r--src/tools/androidtestrunner/main.cpp37
2 files changed, 44 insertions, 34 deletions
diff --git a/src/corelib/Qt6AndroidMacros.cmake b/src/corelib/Qt6AndroidMacros.cmake
index ab793d3499..ceb894e2e7 100644
--- a/src/corelib/Qt6AndroidMacros.cmake
+++ b/src/corelib/Qt6AndroidMacros.cmake
@@ -288,35 +288,48 @@ function(qt6_android_add_apk_target target)
if(NOT QT_NO_GLOBAL_APK_TARGET)
if(NOT TARGET apk)
add_custom_target(apk
- DEPENDS ${target}_prepare_apk_dir
+ DEPENDS ${target}_make_apk
COMMENT "Building all apks"
)
endif()
- set(should_add_to_global_apk TRUE)
endif()
set(deployment_tool "${QT_HOST_PATH}/${QT6_HOST_INFO_BINDIR}/androiddeployqt")
- set(apk_dir "$<TARGET_PROPERTY:${target},BINARY_DIR>/android-build")
+ set(apk_final_dir "$<TARGET_PROPERTY:${target},BINARY_DIR>/android-build")
+ set(apk_intermediate_dir "${CMAKE_CURRENT_BINARY_DIR}/android-build")
+ set(apk_file_name "${target}.apk")
+ set(apk_final_file_path "${apk_final_dir}/${apk_file_name}")
+ set(apk_intermediate_file_path "${apk_intermediate_dir}/${apk_file_name}")
+
+ # This target is used by Qt Creator's Android support.
add_custom_target(${target}_prepare_apk_dir
DEPENDS ${target}
COMMAND ${CMAKE_COMMAND}
-E copy $<TARGET_FILE:${target}>
- "${apk_dir}/libs/${CMAKE_ANDROID_ARCH_ABI}/$<TARGET_FILE_NAME:${target}>"
+ "${apk_final_dir}/libs/${CMAKE_ANDROID_ARCH_ABI}/$<TARGET_FILE_NAME:${target}>"
COMMENT "Copying ${target} binary to apk folder"
)
- add_custom_target(${target}_make_apk
- DEPENDS ${target}_prepare_apk_dir
- COMMAND ${deployment_tool}
- --input ${deployment_file}
- --output ${apk_dir}
- --apk ${apk_dir}/${target}.apk
+ # Add custom command that creates the apk in an intermediate location.
+ # We need the intermediate location, because we cannot have target-dependent generator
+ # expressions in OUTPUT.
+ add_custom_command(OUTPUT "${apk_intermediate_file_path}"
+ COMMAND ${CMAKE_COMMAND}
+ -E copy "$<TARGET_FILE:${target}>"
+ "${apk_intermediate_dir}/libs/${CMAKE_ANDROID_ARCH_ABI}/$<TARGET_FILE_NAME:${target}>"
+ COMMAND "${deployment_tool}"
+ --input "${deployment_file}"
+ --output "${apk_intermediate_dir}"
+ --apk "${apk_intermediate_file_path}"
COMMENT "Creating APK for ${target}"
- )
+ DEPENDS "${target}" "${deployment_file}")
- if(should_add_to_global_apk)
- add_dependencies(apk "${target}_make_apk")
- endif()
+ # Create a ${target}_make_apk target to copy the apk from the intermediate to its final
+ # location. If the final and intermediate locations are identical, this is a no-op.
+ add_custom_target(${target}_make_apk
+ COMMAND "${CMAKE_COMMAND}"
+ -E copy_if_different "${apk_intermediate_file_path}" "${apk_final_file_path}"
+ DEPENDS "${apk_intermediate_file_path}")
endfunction()
if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS)
diff --git a/src/tools/androidtestrunner/main.cpp b/src/tools/androidtestrunner/main.cpp
index b10b7d0bf3..37e58d5257 100644
--- a/src/tools/androidtestrunner/main.cpp
+++ b/src/tools/androidtestrunner/main.cpp
@@ -446,26 +446,23 @@ int main(int argc, char *argv[])
return 1;
}
- if (!QFile::exists(g_options.apkPath)) {
- if (g_options.makeCommand.isEmpty()) {
- fprintf(stderr,
- "No apk found at \"%s\". Provide a make command with the \"--make\" parameter "
- "to generate it first.\n",
- qPrintable(g_options.apkPath));
- return 1;
- }
- if (!execCommand(g_options.makeCommand, nullptr, true)) {
- if (!g_options.skipAddInstallRoot) {
- // we need to run make INSTALL_ROOT=path install to install the application file(s) first
- if (!execCommand(QStringLiteral("%1 INSTALL_ROOT=%2 install")
- .arg(g_options.makeCommand, QDir::toNativeSeparators(g_options.buildPath)), nullptr, g_options.verbose)) {
- return 1;
- }
- } else {
- if (!execCommand(QStringLiteral("%1")
- .arg(g_options.makeCommand), nullptr, g_options.verbose)) {
- return 1;
- }
+ if (g_options.makeCommand.isEmpty()) {
+ fprintf(stderr,
+ "It is required to provide a make command with the \"--make\" parameter "
+ "to generate the apk.\n");
+ return 1;
+ }
+ if (!execCommand(g_options.makeCommand, nullptr, true)) {
+ if (!g_options.skipAddInstallRoot) {
+ // we need to run make INSTALL_ROOT=path install to install the application file(s) first
+ if (!execCommand(QStringLiteral("%1 INSTALL_ROOT=%2 install")
+ .arg(g_options.makeCommand, QDir::toNativeSeparators(g_options.buildPath)), nullptr, g_options.verbose)) {
+ return 1;
+ }
+ } else {
+ if (!execCommand(QStringLiteral("%1")
+ .arg(g_options.makeCommand), nullptr, g_options.verbose)) {
+ return 1;
}
}
}