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,6 +242,41 @@ public struct PrebuiltModuleInput {
241
242
}
242
243
}
243
244
245
+ public class SwiftAdopter : Codable {
246
+ let name : String
247
+ let moduleDir : String
248
+ let hasInterface : Bool
249
+ let hasModule : Bool
250
+ let isFramework : Bool
251
+ let isPrivateFramework : 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 . isPrivateFramework = 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
+ let data = try JSONEncoder ( ) . encode ( adopters)
273
+ if let json = try ? JSONSerialization . jsonObject ( with: data, options: . mutableContainers) ,
274
+ let jsonData = try ? JSONSerialization . data ( withJSONObject: json, options: . prettyPrinted) {
275
+ try localFileSystem. writeFileContents ( logDir. appending ( component: " adopters.json " ) , bytes: ByteString ( jsonData) )
276
+ }
277
+ }
278
+ }
279
+
244
280
typealias PrebuiltModuleOutput = PrebuiltModuleInput
245
281
246
282
public struct SDKPrebuiltModuleInputsCollector {
@@ -298,7 +334,8 @@ public struct SDKPrebuiltModuleInputsCollector {
298
334
}
299
335
}
300
336
301
- public func collectSwiftInterfaceMap( ) throws -> [ String : [ PrebuiltModuleInput ] ] {
337
+ public func collectSwiftInterfaceMap( ) throws -> ( inputMap: [ String : [ PrebuiltModuleInput ] ] , adopters: [ SwiftAdopter ] ) {
338
+ var allSwiftAdopters : [ SwiftAdopter ] = [ ]
302
339
var results : [ String : [ PrebuiltModuleInput ] ] = [ : ]
303
340
304
341
func updateResults( _ dir: AbsolutePath ) throws {
@@ -309,7 +346,8 @@ public struct SDKPrebuiltModuleInputsCollector {
309
346
if results [ moduleName] == nil {
310
347
results [ moduleName] = [ ]
311
348
}
312
-
349
+ var hasInterface : AbsolutePath ?
350
+ var hasModule : AbsolutePath ?
313
351
// Search inside a .swiftmodule directory for any .swiftinterface file, and
314
352
// add the files into the dictionary.
315
353
// Duplicate entries are discarded, otherwise llbuild will complain.
@@ -322,11 +360,14 @@ public struct SDKPrebuiltModuleInputsCollector {
322
360
if !results[ moduleName] !. contains ( where: { $0. path. file. basenameWithoutExt == currentBaseName } ) {
323
361
results [ moduleName] !. append ( PrebuiltModuleInput ( interfacePath) )
324
362
}
363
+ hasInterface = currentFile
325
364
}
326
365
if currentFile. extension == " swiftmodule " {
327
366
diagEngine. emit ( warning: " found \( currentFile) " )
367
+ hasModule = currentFile
328
368
}
329
369
}
370
+ allSwiftAdopters. append ( SwiftAdopter ( moduleName, dir, hasInterface, hasModule) )
330
371
}
331
372
// Search inside framework dirs in an SDK to find .swiftmodule directories.
332
373
for dir in frameworkDirs {
@@ -358,7 +399,7 @@ public struct SDKPrebuiltModuleInputsCollector {
358
399
}
359
400
}
360
401
}
361
- return sanitizeInterfaceMap ( results)
402
+ return ( inputMap : sanitizeInterfaceMap ( results) , adopters : allSwiftAdopters )
362
403
}
363
404
}
364
405
0 commit comments