Xcode, build-for-testing, test-without-building is broken since 3.25.0
Hi, Xcode has feature to build packages for testing and then run tests on separate node, so it's handy to parallelise tests. We use this feature with iOS, but it'a also reproducible with pure MacOS build: Consider the following configuration:
project (XCtestRunBug Swift)
cmake_minimum_required(VERSION 3.23.1)
file(WRITE ${CMAKE_BINARY_DIR}/foo.swift "public func foo() {}")
file(WRITE ${CMAKE_BINARY_DIR}/foo_test.swift "func foo() {}")
add_library(demo SHARED ${CMAKE_BINARY_DIR}/foo.swift)
set_target_properties(demo PROPERTIES
FRAMEWORK TRUE
XCODE_ATTRIBUTE_DEFINES_MODULE YES
XCODE_GENERATE_SCHEME YES)
find_package (XCTest REQUIRED)
xctest_add_bundle (demo-test-bundle demo)
target_sources(demo-test-bundle PRIVATE ${CMAKE_BINARY_DIR}/foo_test.swift)
Then the following sequence of actions:
# Configure
cmake . -B build -GXcode
# Build for testing
xcodebuild -project build/XCtestRunBug.xcodeproj -configuration Debug -scheme demo build-for-testing
# Move prebuilt file to another place
mv build build2
# Test without building
xcodebuild -xctestrun build2/build/demo_macosx13.1-arm64.xctestrun -destination platform=macOS test-without-building
# Prior cmake 3.25.0 the file xctestrun was in different place
# xcodebuild -xctestrun build2/demo_macosx13.1-arm64.xctestrun -destination platform=macOS test-without-building
I expect that tests are run. It was like this in cmake 3.24.4, but in cmake 3.25.0 (actually starting with rc1) I see the following errors:
xcodebuild: error: Failed to build workspace XCtestRunBug with scheme demo.
Reason: Cannot test target “demo-test-bundle” on “My Mac”: Missing test product at /blah/cmake-xctestrun/build/Debug/demo-test-bundle.xctest
Reason: Cannot test target “demo-test-bundle” on “My Mac”: Missing test product at /blah/cmake-xctestrun/build/Debug/demo-test-bundle.xctest
I found that file demo_macosx13.1-arm64.xctestrun
moved to different location (see above) and paths inside became absolute (while were relative to __TESTROOT__
). For example in cmake 3.24.4:
<key>DependentProductPaths</key>
<array>
<string>__TESTROOT__/Debug/demo-test-bundle.xctest</string>
<string>__TESTROOT__/Debug/demo.framework</string>
in cmake 3.25.0:
<key>DependentProductPaths</key>
<array>
<string>/blah/cmake-xctestrun/build/Debug/demo-test-bundle.xctest</string>
<string>/blah/cmake-xctestrun/build/Debug/demo.framework</string>
So it definitely is looking in wrong place. Manual replacing /blah/cmake-xctestrun
with __TESTROOT__
. doesn't make any difference, so something else seems broken.