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.
@@ -440,7 +453,7 @@ extension Driver {
440
453
commandLine. appendFlag ( . parseStdlib)
441
454
}
442
455
// Add macabi-specific search path.
443
- if isIosMac ( inputPath. path. file) {
456
+ if try isIosMacInterface ( inputPath. path. file) {
444
457
commandLine. appendFlag ( . Fsystem)
445
458
commandLine. append ( . path( iosMacFrameworksSearchPath) )
446
459
}
Original file line number Diff line number Diff line change @@ -4742,6 +4742,17 @@ final class SwiftDriverTests: XCTestCase {
4742
4742
}
4743
4743
}
4744
4744
4745
+ func testIsIosMacInterface( ) throws {
4746
+ try withTemporaryFile { file in
4747
+ try localFileSystem. writeFileContents ( file. path) { $0 <<< " // swift-module-flags: -target x86_64-apple-ios15.0-macabi " }
4748
+ XCTAssertTrue ( try isIosMacInterface ( VirtualPath . absolute ( file. path) ) )
4749
+ }
4750
+ try withTemporaryFile { file in
4751
+ try localFileSystem. writeFileContents ( file. path) { $0 <<< " // swift-module-flags: -target arm64e-apple-macos12.0 " }
4752
+ XCTAssertFalse ( try isIosMacInterface ( VirtualPath . absolute ( file. path) ) )
4753
+ }
4754
+ }
4755
+
4745
4756
func testSupportedFeatureJson( ) throws {
4746
4757
let driver = try Driver ( args: [ " swiftc " , " -emit-module " , " foo.swift " ] )
4747
4758
XCTAssertFalse ( driver. supportedFrontendFeatures. isEmpty)
You can’t perform that action at this time.
0 commit comments