Skip to content

Commit cd95abc

Browse files
authored
Merge pull request #296 from compnerd/system-foundation
build: support building against Foundation.framework
2 parents 6e9bdb6 + 074ff4c commit cd95abc

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
66
project(XCTest LANGUAGES Swift)
77

88
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
9+
option(USE_FOUNDATION_FRAMEWORK "Use Foundation.framework on Darwin" NO)
910

1011
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
1112
find_package(dispatch CONFIG REQUIRED)
@@ -46,6 +47,10 @@ add_library(XCTest
4647
Sources/XCTest/Public/Asynchronous/XCTWaiter.swift
4748
Sources/XCTest/Public/Asynchronous/XCTestCase+Asynchronous.swift
4849
Sources/XCTest/Public/Asynchronous/XCTestExpectation.swift)
50+
if(USE_FOUNDATION_FRAMEWORK)
51+
target_compile_definitions(XCTest PRIVATE
52+
USE_FOUNDATION_FRAMEWORK)
53+
endif()
4954
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
5055
target_link_libraries(XCTest PRIVATE
5156
dispatch

Sources/XCTest/Public/XCTestMain.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
// Note that we are re-exporting Foundation so tests importing XCTest don't need
1616
// to import it themselves. This is consistent with the behavior of Apple XCTest
1717
#if os(macOS)
18+
#if USE_FOUNDATION_FRAMEWORK
19+
@_exported import Foundation
20+
#else
1821
@_exported import SwiftFoundation
22+
#endif
1923
#else
2024
@_exported import Foundation
2125
#endif
@@ -92,7 +96,7 @@ public func XCTMain(_ testCases: [XCTestCaseEntry]) -> Never {
9296
let errMsg = "Error: Invalid option \"\(invalid)\"\n"
9397
FileHandle.standardError.write(errMsg.data(using: .utf8) ?? Data())
9498
}
95-
let exeName = CommandLine.arguments[0].lastPathComponent
99+
let exeName = URL(fileURLWithPath: CommandLine.arguments[0]).lastPathComponent
96100
let sampleTest = rootTestSuite.list().first ?? "Tests.FooTestCase/testFoo"
97101
let sampleTests = sampleTest.prefix(while: { $0 != "/" })
98102
print("""

0 commit comments

Comments
 (0)