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