@@ -239,6 +239,57 @@ public struct SDKPrebuiltModuleInputsCollector {
239239 }
240240}
241241
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+
242293extension Driver {
243294
244295 private mutating func generateSingleModuleBuildingJob( _ moduleName: String , _ prebuiltModuleDir: AbsolutePath ,
@@ -285,12 +336,16 @@ extension Driver {
285336
286337 public mutating func generatePrebuitModuleGenerationJobs( with inputMap: [ String : [ PrebuiltModuleInput ] ] ,
287338 into prebuiltModuleDir: AbsolutePath ,
288- exhaustive: Bool ) throws -> ( [ Job ] , [ Job ] ) {
339+ exhaustive: Bool ,
340+ dotGraphPath: AbsolutePath ? = nil ) throws -> ( [ Job ] , [ Job ] ) {
289341 assert ( sdkPath != nil )
290342 // Run the dependency scanner and update the dependency oracle with the results
291343 // We only need Swift dependencies here, so we don't need to invoke gatherModuleDependencies,
292344 // which also resolves versioned clang modules.
293345 let dependencyGraph = try performDependencyScan ( )
346+ if let dotGraphPath = dotGraphPath {
347+ try dependencyGraph. dumpDotGraph ( dotGraphPath, false )
348+ }
294349 var jobs : [ Job ] = [ ]
295350 var danglingJobs : [ Job ] = [ ]
296351 var inputCount = 0
0 commit comments