From b04935ed9f72d63304e0ac83a50a2f232076ae17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 7 Jan 2025 13:51:10 +0100 Subject: [PATCH] macOS: Enable crash reporting for tests via Swift Swift 5.9 includes built in crash reporting, printing stack traces, libraries, and registers to stdout/err. https://www.swift.org/blog/swift-5.9-backtraces/ As (Core)Foundation is written in Swift nowadays, we get this feature for free even in our "C++" apps, as we always link to CoreFoundation. To enable the feature the binary needs the com.apple.security.get-task-allow entitlement, so we add it for all our tests automatically. The final piece is to run the tests with SWIFT_BACKTRACE=enable=yes, but we'll do this in our CI provisioning, as setting it from within testlib doesn't seem to work. Pick-to: 6.8 Change-Id: I31090efee06460f45522093e17f900e76590b282 Reviewed-by: Alexandru Croitor (cherry picked from commit 9bebdc97f161cc58461530fa0171e0defc6cc1ee) Reviewed-by: Qt Cherry-pick Bot --- REUSE.toml | 2 +- cmake/QtBaseGlobalTargets.cmake | 10 +++++++++- cmake/QtTestHelpers.cmake | 14 ++++++++++++++ cmake/macos/test.entitlements.plist | 9 +++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 cmake/macos/test.entitlements.plist diff --git a/REUSE.toml b/REUSE.toml index 6cdfd9b8a95..a5b304ecade 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -24,7 +24,7 @@ SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR GPL-3.0-only" path = ["bin/*", "coin/**","libexec/*","**_clang-format", "**.cmake", "**.conf", "**.cmake.in", "**.prf", "libexec/qt-internal-configure-*", "config.tests/.qmake.conf", "**.pro", "**.pri", "**.yaml", "cmake/**.in", "cmake/ios/LaunchScreen.storyboard", - "cmake/**md", "**.yml", "**.dynlist", + "cmake/**md", "**.yml", "**.dynlist", "cmake/**.plist", "src/corelib/global/qconfig.cpp.in", "src/corelib/Qt6CoreConfigureFileTemplate.in", "**.cfg"] precedence = "closest" diff --git a/cmake/QtBaseGlobalTargets.cmake b/cmake/QtBaseGlobalTargets.cmake index dc14a6110cd..1e028c4a72c 100644 --- a/cmake/QtBaseGlobalTargets.cmake +++ b/cmake/QtBaseGlobalTargets.cmake @@ -366,7 +366,15 @@ if(APPLE) DESTINATION "${__GlobalConfig_build_dir}/${platform_shortname}" ) - if(IOS) + if(MACOS) + # Test entitlements + qt_copy_or_install(FILES "cmake/${platform_shortname}/test.entitlements.plist" + DESTINATION "${__GlobalConfig_install_dir}/${platform_shortname}" + ) + file(COPY "cmake/${platform_shortname}/test.entitlements.plist" + DESTINATION "${__GlobalConfig_build_dir}/${platform_shortname}" + ) + elseif(IOS) qt_copy_or_install(FILES "cmake/ios/LaunchScreen.storyboard" DESTINATION "${__GlobalConfig_install_dir}/ios" ) diff --git a/cmake/QtTestHelpers.cmake b/cmake/QtTestHelpers.cmake index 94cd99cd6df..c110409be7d 100644 --- a/cmake/QtTestHelpers.cmake +++ b/cmake/QtTestHelpers.cmake @@ -902,6 +902,20 @@ function(qt_internal_add_test name) endif() endif() + if(MACOS AND NOT CMAKE_GENERATOR STREQUAL "Xcode") + # Add com.apple.security.get-task-allow entitlement to each + # test binary, so we can hook into the Swift crash handling. + if(NOT arg_QMLTEST AND arg_SOURCES) + set(entitlements_file + "${__qt_internal_cmake_apple_support_files_path}/test.entitlements.plist") + add_custom_command(TARGET "${name}" + POST_BUILD COMMAND codesign --sign - + --entitlements "${entitlements_file}" + "$" + ) + endif() + endif() + qt_internal_add_test_finalizers("${name}") endfunction() diff --git a/cmake/macos/test.entitlements.plist b/cmake/macos/test.entitlements.plist new file mode 100644 index 00000000000..a8b9fdfb8c1 --- /dev/null +++ b/cmake/macos/test.entitlements.plist @@ -0,0 +1,9 @@ + + + + + com.apple.security.get-task-allow + + +