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 <alexandru.croitor@qt.io>
(cherry picked from commit 9bebdc97f161cc58461530fa0171e0defc6cc1ee)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tor Arne Vestbø 2025-01-07 13:51:10 +01:00 committed by Qt Cherry-pick Bot
parent 0db648ba3b
commit b04935ed9f
4 changed files with 33 additions and 2 deletions

View File

@ -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"

View File

@ -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"
)

View File

@ -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}"
"$<TARGET_FILE:${name}>"
)
endif()
endif()
qt_internal_add_test_finalizers("${name}")
endfunction()

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.get-task-allow</key>
<true/>
</dict>
</plist>