1111//===----------------------------------------------------------------------===//
1212import TSCBasic
1313import SwiftOptions
14+ import Foundation
1415
1516@_spi ( Testing) public func isIosMacInterface( _ path: VirtualPath ) throws -> Bool {
1617 let data = try localFileSystem. readFileContents ( path) . cString
@@ -241,14 +242,54 @@ public struct PrebuiltModuleInput {
241242 }
242243}
243244
245+ public class SwiftAdopter : Codable {
246+ public let name : String
247+ public let moduleDir : String
248+ public let hasInterface : Bool
249+ public let hasModule : Bool
250+ public let isFramework : Bool
251+ public let isPrivate : Bool
252+ init ( _ name: String , _ moduleDir: AbsolutePath , _ hasInterface: AbsolutePath ? , _ hasModule: AbsolutePath ? ) {
253+ self . name = name
254+ self . moduleDir = SwiftAdopter . relativeToSDK ( moduleDir)
255+ self . hasInterface = hasInterface != nil
256+ self . hasModule = hasModule != nil
257+ self . isFramework = self . moduleDir. contains ( " \( name) .framework " )
258+ self . isPrivate = self . moduleDir. contains ( " PrivateFrameworks " )
259+ }
260+ static func relativeToSDK( _ fullPath: AbsolutePath ) -> String {
261+ var SDKDir : AbsolutePath = fullPath
262+ while ( SDKDir . extension != " sdk " ) {
263+ SDKDir = SDKDir . parentDirectory
264+ }
265+ assert ( SDKDir . extension == " sdk " )
266+ SDKDir = SDKDir . parentDirectory
267+ return fullPath. relative ( to: SDKDir) . pathString
268+ }
269+
270+ static public func emitSummary( _ adopters: [ SwiftAdopter ] , to logDir: AbsolutePath ? ) throws {
271+ guard let logDir = logDir else { return }
272+ if !localFileSystem. exists ( logDir) {
273+ try localFileSystem. createDirectory ( logDir, recursive: true )
274+ }
275+ let data = try JSONEncoder ( ) . encode ( adopters)
276+ if let json = try ? JSONSerialization . jsonObject ( with: data, options: . mutableContainers) ,
277+ let jsonData = try ? JSONSerialization . data ( withJSONObject: json, options: . prettyPrinted) {
278+ try localFileSystem. writeFileContents ( logDir. appending ( component: " adopters.json " ) , bytes: ByteString ( jsonData) )
279+ }
280+ }
281+ }
282+
244283typealias PrebuiltModuleOutput = PrebuiltModuleInput
245284
246285public struct SDKPrebuiltModuleInputsCollector {
247286 let sdkPath : AbsolutePath
248287 let nonFrameworkDirs = [ RelativePath ( " usr/lib/swift " ) ,
249288 RelativePath ( " System/iOSSupport/usr/lib/swift " ) ]
250289 let frameworkDirs = [ RelativePath ( " System/Library/Frameworks " ) ,
251- RelativePath ( " System/iOSSupport/System/Library/Frameworks " ) ]
290+ RelativePath ( " System/Library/PrivateFrameworks " ) ,
291+ RelativePath ( " System/iOSSupport/System/Library/Frameworks " ) ,
292+ RelativePath ( " System/iOSSupport/System/Library/PrivateFrameworks " ) ]
252293 let sdkInfo : DarwinToolchain . DarwinSDKInfo
253294 let diagEngine : DiagnosticsEngine
254295 public init ( _ sdkPath: AbsolutePath , _ diagEngine: DiagnosticsEngine ) {
@@ -296,7 +337,8 @@ public struct SDKPrebuiltModuleInputsCollector {
296337 }
297338 }
298339
299- public func collectSwiftInterfaceMap( ) throws -> [ String : [ PrebuiltModuleInput ] ] {
340+ public func collectSwiftInterfaceMap( ) throws -> ( inputMap: [ String : [ PrebuiltModuleInput ] ] , adopters: [ SwiftAdopter ] ) {
341+ var allSwiftAdopters : [ SwiftAdopter ] = [ ]
300342 var results : [ String : [ PrebuiltModuleInput ] ] = [ : ]
301343
302344 func updateResults( _ dir: AbsolutePath ) throws {
@@ -307,7 +349,8 @@ public struct SDKPrebuiltModuleInputsCollector {
307349 if results [ moduleName] == nil {
308350 results [ moduleName] = [ ]
309351 }
310-
352+ var hasInterface : AbsolutePath ?
353+ var hasModule : AbsolutePath ?
311354 // Search inside a .swiftmodule directory for any .swiftinterface file, and
312355 // add the files into the dictionary.
313356 // Duplicate entries are discarded, otherwise llbuild will complain.
@@ -320,11 +363,14 @@ public struct SDKPrebuiltModuleInputsCollector {
320363 if !results[ moduleName] !. contains ( where: { $0. path. file. basenameWithoutExt == currentBaseName } ) {
321364 results [ moduleName] !. append ( PrebuiltModuleInput ( interfacePath) )
322365 }
366+ hasInterface = currentFile
323367 }
324368 if currentFile. extension == " swiftmodule " {
325369 diagEngine. emit ( warning: " found \( currentFile) " )
370+ hasModule = currentFile
326371 }
327372 }
373+ allSwiftAdopters. append ( SwiftAdopter ( moduleName, dir, hasInterface, hasModule) )
328374 }
329375 // Search inside framework dirs in an SDK to find .swiftmodule directories.
330376 for dir in frameworkDirs {
@@ -356,7 +402,7 @@ public struct SDKPrebuiltModuleInputsCollector {
356402 }
357403 }
358404 }
359- return sanitizeInterfaceMap ( results)
405+ return ( inputMap : sanitizeInterfaceMap ( results) , adopters : allSwiftAdopters )
360406 }
361407}
362408
@@ -448,10 +494,12 @@ extension Driver {
448494 _ dependencies: [ TypedVirtualPath ] , _ currentABIDir: AbsolutePath ? ,
449495 _ baselineABIDir: AbsolutePath ? ) throws -> [ Job ] {
450496 assert ( inputPath. path. file. basenameWithoutExt == outputPath. path. file. basenameWithoutExt)
497+ let sdkPath = sdkPath!
498+ let isInternal = sdkPath. basename. hasSuffix ( " .Internal.sdk " )
451499 var commandLine : [ Job . ArgTemplate ] = [ ]
452500 commandLine. appendFlag ( . compileModuleFromInterface)
453501 commandLine. appendFlag ( . sdk)
454- commandLine. append ( . path( sdkPath! ) )
502+ commandLine. append ( . path( sdkPath) )
455503 commandLine. appendFlag ( . prebuiltModuleCachePath)
456504 commandLine. appendPath ( prebuiltModuleDir)
457505 commandLine. appendFlag ( . moduleName)
@@ -467,6 +515,16 @@ extension Driver {
467515 if try isIosMacInterface ( inputPath. path. file) {
468516 commandLine. appendFlag ( . Fsystem)
469517 commandLine. append ( . path( iosMacFrameworksSearchPath) )
518+ if isInternal {
519+ commandLine. appendFlag ( . Fsystem)
520+ commandLine. append ( . path( iosMacPrivateFrameworksSearchPath) )
521+ }
522+ }
523+ if isInternal {
524+ commandLine. appendFlag ( . Fsystem)
525+ commandLine. append ( . path( sdkPath. appending ( component: " System " )
526+ . appending ( component: " Library " )
527+ . appending ( component: " PrivateFrameworks " ) ) )
470528 }
471529 // Use the specified module cache dir
472530 if let mcp = parsedOptions. getLastArgument ( . moduleCachePath) ? . asSingle {
0 commit comments