11
11
//===----------------------------------------------------------------------===//
12
12
import TSCBasic
13
13
import SwiftOptions
14
+ import Foundation
14
15
15
16
@_spi ( Testing) public func isIosMacInterface( _ path: VirtualPath ) throws -> Bool {
16
17
let data = try localFileSystem. readFileContents ( path) . cString
@@ -241,14 +242,54 @@ public struct PrebuiltModuleInput {
241
242
}
242
243
}
243
244
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
+
244
283
typealias PrebuiltModuleOutput = PrebuiltModuleInput
245
284
246
285
public struct SDKPrebuiltModuleInputsCollector {
247
286
let sdkPath : AbsolutePath
248
287
let nonFrameworkDirs = [ RelativePath ( " usr/lib/swift " ) ,
249
288
RelativePath ( " System/iOSSupport/usr/lib/swift " ) ]
250
289
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 " ) ]
252
293
let sdkInfo : DarwinToolchain . DarwinSDKInfo
253
294
let diagEngine : DiagnosticsEngine
254
295
public init ( _ sdkPath: AbsolutePath , _ diagEngine: DiagnosticsEngine ) {
@@ -296,7 +337,8 @@ public struct SDKPrebuiltModuleInputsCollector {
296
337
}
297
338
}
298
339
299
- public func collectSwiftInterfaceMap( ) throws -> [ String : [ PrebuiltModuleInput ] ] {
340
+ public func collectSwiftInterfaceMap( ) throws -> ( inputMap: [ String : [ PrebuiltModuleInput ] ] , adopters: [ SwiftAdopter ] ) {
341
+ var allSwiftAdopters : [ SwiftAdopter ] = [ ]
300
342
var results : [ String : [ PrebuiltModuleInput ] ] = [ : ]
301
343
302
344
func updateResults( _ dir: AbsolutePath ) throws {
@@ -307,7 +349,8 @@ public struct SDKPrebuiltModuleInputsCollector {
307
349
if results [ moduleName] == nil {
308
350
results [ moduleName] = [ ]
309
351
}
310
-
352
+ var hasInterface : AbsolutePath ?
353
+ var hasModule : AbsolutePath ?
311
354
// Search inside a .swiftmodule directory for any .swiftinterface file, and
312
355
// add the files into the dictionary.
313
356
// Duplicate entries are discarded, otherwise llbuild will complain.
@@ -320,11 +363,14 @@ public struct SDKPrebuiltModuleInputsCollector {
320
363
if !results[ moduleName] !. contains ( where: { $0. path. file. basenameWithoutExt == currentBaseName } ) {
321
364
results [ moduleName] !. append ( PrebuiltModuleInput ( interfacePath) )
322
365
}
366
+ hasInterface = currentFile
323
367
}
324
368
if currentFile. extension == " swiftmodule " {
325
369
diagEngine. emit ( warning: " found \( currentFile) " )
370
+ hasModule = currentFile
326
371
}
327
372
}
373
+ allSwiftAdopters. append ( SwiftAdopter ( moduleName, dir, hasInterface, hasModule) )
328
374
}
329
375
// Search inside framework dirs in an SDK to find .swiftmodule directories.
330
376
for dir in frameworkDirs {
@@ -356,7 +402,7 @@ public struct SDKPrebuiltModuleInputsCollector {
356
402
}
357
403
}
358
404
}
359
- return sanitizeInterfaceMap ( results)
405
+ return ( inputMap : sanitizeInterfaceMap ( results) , adopters : allSwiftAdopters )
360
406
}
361
407
}
362
408
@@ -448,10 +494,12 @@ extension Driver {
448
494
_ dependencies: [ TypedVirtualPath ] , _ currentABIDir: AbsolutePath ? ,
449
495
_ baselineABIDir: AbsolutePath ? ) throws -> [ Job ] {
450
496
assert ( inputPath. path. file. basenameWithoutExt == outputPath. path. file. basenameWithoutExt)
497
+ let sdkPath = sdkPath!
498
+ let isInternal = sdkPath. basename. hasSuffix ( " .Internal.sdk " )
451
499
var commandLine : [ Job . ArgTemplate ] = [ ]
452
500
commandLine. appendFlag ( . compileModuleFromInterface)
453
501
commandLine. appendFlag ( . sdk)
454
- commandLine. append ( . path( sdkPath! ) )
502
+ commandLine. append ( . path( sdkPath) )
455
503
commandLine. appendFlag ( . prebuiltModuleCachePath)
456
504
commandLine. appendPath ( prebuiltModuleDir)
457
505
commandLine. appendFlag ( . moduleName)
@@ -467,6 +515,16 @@ extension Driver {
467
515
if try isIosMacInterface ( inputPath. path. file) {
468
516
commandLine. appendFlag ( . Fsystem)
469
517
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 " ) ) )
470
528
}
471
529
// Use the specified module cache dir
472
530
if let mcp = parsedOptions. getLastArgument ( . moduleCachePath) ? . asSingle {
0 commit comments