File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 12
12
import TSCBasic
13
13
import SwiftOptions
14
14
15
+ @_spi ( Testing) public func isIosMacInterface( _ path: VirtualPath ) throws -> Bool {
16
+ let data = try localFileSystem. readFileContents ( path) . cString
17
+ let myStrings = data. components ( separatedBy: . newlines)
18
+ let prefix = " // swift-module-flags: "
19
+ if let argLine = myStrings. first ( where: { $0. hasPrefix ( prefix) } ) {
20
+ let args = argLine. dropFirst ( prefix. count) . components ( separatedBy: " " )
21
+ if let idx = args. firstIndex ( of: " -target " ) , idx + 1 < args. count {
22
+ return args [ idx + 1 ] . contains ( " macabi " )
23
+ }
24
+ }
25
+ return false
26
+ }
27
+
15
28
func isIosMac( _ path: VirtualPath ) -> Bool {
16
29
// Infer macabi interfaces by the file name.
17
30
// FIXME: more robust way to do this.
@@ -432,7 +445,7 @@ extension Driver {
432
445
commandLine. appendFlag ( . parseStdlib)
433
446
}
434
447
// Add macabi-specific search path.
435
- if isIosMac ( inputPath. path. file) {
448
+ if try isIosMacInterface ( inputPath. path. file) {
436
449
commandLine. appendFlag ( . Fsystem)
437
450
commandLine. append ( . path( iosMacFrameworksSearchPath) )
438
451
}
Original file line number Diff line number Diff line change @@ -5030,6 +5030,17 @@ final class SwiftDriverTests: XCTestCase {
5030
5030
}
5031
5031
}
5032
5032
5033
+ func testIsIosMacInterface( ) throws {
5034
+ try withTemporaryFile { file in
5035
+ try localFileSystem. writeFileContents ( file. path) { $0 <<< " // swift-module-flags: -target x86_64-apple-ios15.0-macabi " }
5036
+ XCTAssertTrue ( try isIosMacInterface ( VirtualPath . absolute ( file. path) ) )
5037
+ }
5038
+ try withTemporaryFile { file in
5039
+ try localFileSystem. writeFileContents ( file. path) { $0 <<< " // swift-module-flags: -target arm64e-apple-macos12.0 " }
5040
+ XCTAssertFalse ( try isIosMacInterface ( VirtualPath . absolute ( file. path) ) )
5041
+ }
5042
+ }
5043
+
5033
5044
func testSupportedFeatureJson( ) throws {
5034
5045
let driver = try Driver ( args: [ " swiftc " , " -emit-module " , " foo.swift " ] )
5035
5046
XCTAssertFalse ( driver. supportedFrontendFeatures. isEmpty)
You can’t perform that action at this time.
0 commit comments