@@ -1012,6 +1012,53 @@ final class BackgroundIndexingTests: XCTestCase {
1012
1012
)
1013
1013
}
1014
1014
1015
+ func testUseSwiftSDKFlagsDuringPreparation( ) async throws {
1016
+ try await SkipUnless . canSwiftPMCompileForIOS ( )
1017
+
1018
+ var options = SourceKitLSPOptions . testDefault ( )
1019
+ options. swiftPMOrDefault. swiftSDK = " arm64-apple-ios "
1020
+ let project = try await SwiftPMTestProject (
1021
+ files: [
1022
+ " Lib/Lib.swift " : """
1023
+ #if os(iOS)
1024
+ public func foo() -> Int { 1 }
1025
+ #endif
1026
+ """ ,
1027
+ " Client/Client.swift " : """
1028
+ import Lib
1029
+
1030
+ func test() -> String {
1031
+ return foo()
1032
+ }
1033
+ """ ,
1034
+ ] ,
1035
+ manifest: """
1036
+ let package = Package(
1037
+ name: " MyLibrary " ,
1038
+ targets: [
1039
+ .target(name: " Lib " ),
1040
+ .target(name: " Client " , dependencies: [ " Lib " ]),
1041
+ ]
1042
+ )
1043
+ """ ,
1044
+ options: options,
1045
+ enableBackgroundIndexing: true
1046
+ )
1047
+
1048
+ // Check that we get an error about the return type of `foo` (`Int`) not being convertible to the return type of
1049
+ // `test` (`String`), which indicates that `Lib` had `foo` and was thus compiled for iOS
1050
+ let ( uri, _) = try project. openDocument ( " Client.swift " )
1051
+ let diagnostics = try await project. testClient. send (
1052
+ DocumentDiagnosticsRequest ( textDocument: TextDocumentIdentifier ( uri) )
1053
+ )
1054
+ XCTAssert (
1055
+ ( diagnostics. fullReport? . items ?? [ ] ) . contains ( where: {
1056
+ $0. message == " Cannot convert return expression of type 'Int' to return type 'String' "
1057
+ } ) ,
1058
+ " Did not get expected diagnostic: \( diagnostics) "
1059
+ )
1060
+ }
1061
+
1015
1062
func testLibraryUsedByExecutableTargetAndPackagePlugin( ) async throws {
1016
1063
try await SkipUnless . swiftPMStoresModulesForTargetAndHostInSeparateFolders ( )
1017
1064
let project = try await SwiftPMTestProject (
0 commit comments