@@ -239,6 +239,57 @@ public struct SDKPrebuiltModuleInputsCollector {
239
239
}
240
240
}
241
241
242
+ extension InterModuleDependencyGraph {
243
+ func dumpDotGraph( _ path: AbsolutePath , _ includingPCM: Bool ) throws {
244
+ func isPCM( _ dep: ModuleDependencyId ) -> Bool {
245
+ switch dep {
246
+ case . clang:
247
+ return true
248
+ default :
249
+ return false
250
+ }
251
+ }
252
+ func dumpModuleName( _ stream: WritableByteStream , _ dep: ModuleDependencyId ) {
253
+ switch dep {
254
+ case . swift( let name) :
255
+ stream <<< " \" \( name) .swiftmodule \" "
256
+ case . clang( let name) :
257
+ stream <<< " \" \( name) .pcm \" "
258
+ default :
259
+ break
260
+ }
261
+ }
262
+ try localFileSystem. writeFileContents ( path) { Stream in
263
+ Stream <<< " digraph { \n "
264
+ for key in modules. keys {
265
+ switch key {
266
+ case . swift( let name) :
267
+ if name == mainModuleName {
268
+ break
269
+ }
270
+ fallthrough
271
+ case . clang:
272
+ if !includingPCM && isPCM ( key) {
273
+ break
274
+ }
275
+ modules [ key] !. directDependencies? . forEach { dep in
276
+ if !includingPCM && isPCM ( dep) {
277
+ return
278
+ }
279
+ dumpModuleName ( Stream, key)
280
+ Stream <<< " -> "
281
+ dumpModuleName ( Stream, dep)
282
+ Stream <<< " ; \n "
283
+ }
284
+ default :
285
+ break
286
+ }
287
+ }
288
+ Stream <<< " } \n "
289
+ }
290
+ }
291
+ }
292
+
242
293
extension Driver {
243
294
244
295
private mutating func generateSingleModuleBuildingJob( _ moduleName: String , _ prebuiltModuleDir: AbsolutePath ,
@@ -285,12 +336,16 @@ extension Driver {
285
336
286
337
public mutating func generatePrebuitModuleGenerationJobs( with inputMap: [ String : [ PrebuiltModuleInput ] ] ,
287
338
into prebuiltModuleDir: AbsolutePath ,
288
- exhaustive: Bool ) throws -> ( [ Job ] , [ Job ] ) {
339
+ exhaustive: Bool ,
340
+ dotGraphPath: AbsolutePath ? = nil ) throws -> ( [ Job ] , [ Job ] ) {
289
341
assert ( sdkPath != nil )
290
342
// Run the dependency scanner and update the dependency oracle with the results
291
343
// We only need Swift dependencies here, so we don't need to invoke gatherModuleDependencies,
292
344
// which also resolves versioned clang modules.
293
345
let dependencyGraph = try performDependencyScan ( )
346
+ if let dotGraphPath = dotGraphPath {
347
+ try dependencyGraph. dumpDotGraph ( dotGraphPath, false )
348
+ }
294
349
var jobs : [ Job ] = [ ]
295
350
var danglingJobs : [ Job ] = [ ]
296
351
var inputCount = 0
0 commit comments