@@ -109,6 +109,8 @@ package final class ClangModuleDependencyGraph {
109109 /// for example, when using `-save-temps`.
110110 package let commands : [ CompileCommand ]
111111
112+ package let scanningCommandLine : [ String ]
113+
112114 package let transitiveIncludeTreeIDs : OrderedSet < String >
113115 package let transitiveCompileCommandCacheKeys : OrderedSet < String >
114116
@@ -121,6 +123,7 @@ package final class ClangModuleDependencyGraph {
121123 moduleDependencies: OrderedSet < Path > ,
122124 workingDirectory: Path ,
123125 commands: [ CompileCommand ] ,
126+ scanningCommandLine: [ String ] ,
124127 transitiveIncludeTreeIDs: OrderedSet < String > ,
125128 transitiveCompileCommandCacheKeys: OrderedSet < String > ,
126129 usesSerializedDiagnostics: Bool
@@ -131,6 +134,7 @@ package final class ClangModuleDependencyGraph {
131134 self . modules = moduleDependencies
132135 self . workingDirectory = workingDirectory
133136 self . commands = commands
137+ self . scanningCommandLine = scanningCommandLine
134138 self . transitiveIncludeTreeIDs = transitiveIncludeTreeIDs
135139 self . transitiveCompileCommandCacheKeys = transitiveCompileCommandCacheKeys
136140 self . usesSerializedDiagnostics = usesSerializedDiagnostics
@@ -143,6 +147,7 @@ package final class ClangModuleDependencyGraph {
143147 moduleDependencies: OrderedSet < Path > ,
144148 workingDirectory: Path ,
145149 command: CompileCommand ,
150+ scanningCommandLine: [ String ] ,
146151 transitiveIncludeTreeIDs: OrderedSet < String > ,
147152 transitiveCompileCommandCacheKeys: OrderedSet < String > ,
148153 usesSerializedDiagnostics: Bool
@@ -153,33 +158,36 @@ package final class ClangModuleDependencyGraph {
153158 self . modules = moduleDependencies
154159 self . workingDirectory = workingDirectory
155160 self . commands = [ command]
161+ self . scanningCommandLine = scanningCommandLine
156162 self . transitiveIncludeTreeIDs = transitiveIncludeTreeIDs
157163 self . transitiveCompileCommandCacheKeys = transitiveCompileCommandCacheKeys
158164 self . usesSerializedDiagnostics = usesSerializedDiagnostics
159165 }
160166
161167 package func serialize< T> ( to serializer: T ) where T : Serializer {
162- serializer. serializeAggregate ( 9 ) {
168+ serializer. serializeAggregate ( 10 ) {
163169 serializer. serialize ( kind)
164170 serializer. serialize ( files)
165171 serializer. serialize ( includeTreeID)
166172 serializer. serialize ( modules)
167173 serializer. serialize ( workingDirectory)
168174 serializer. serialize ( commands)
175+ serializer. serialize ( scanningCommandLine)
169176 serializer. serialize ( transitiveIncludeTreeIDs)
170177 serializer. serialize ( transitiveCompileCommandCacheKeys)
171178 serializer. serialize ( usesSerializedDiagnostics)
172179 }
173180 }
174181
175182 package init ( from deserializer: any Deserializer ) throws {
176- try deserializer. beginAggregate ( 9 )
183+ try deserializer. beginAggregate ( 10 )
177184 self . kind = try deserializer. deserialize ( )
178185 self . files = try deserializer. deserialize ( )
179186 self . includeTreeID = try deserializer. deserialize ( )
180187 self . modules = try deserializer. deserialize ( )
181188 self . workingDirectory = try deserializer. deserialize ( )
182189 self . commands = try deserializer. deserialize ( )
190+ self . scanningCommandLine = try deserializer. deserialize ( )
183191 self . transitiveIncludeTreeIDs = try deserializer. deserialize ( )
184192 self . transitiveCompileCommandCacheKeys = try deserializer. deserialize ( )
185193 self . usesSerializedDiagnostics = try deserializer. deserialize ( )
@@ -334,12 +342,13 @@ package final class ClangModuleDependencyGraph {
334342 var moduleTransitiveCacheKeys : [ String : OrderedSet < String > ] = [ : ]
335343
336344 let fileDeps : DependencyScanner . FileDependencies
345+ let scanningCommandLine = [ compiler] + originalFileArgs
337346 let modulesCallbackErrors = LockedValue < [ any Error ] > ( [ ] )
338347 let dependencyPaths = LockedValue < Set < Path > > ( [ ] )
339348 let requiredTargetDependencies = LockedValue < Set < ScanResult . RequiredDependency > > ( [ ] )
340349 do {
341350 fileDeps = try clangWithScanner. scanner. scanDependencies (
342- commandLine: [ compiler ] + originalFileArgs ,
351+ commandLine: scanningCommandLine ,
343352 workingDirectory: workingDirectory. str,
344353 lookupOutput: { name, contextHash, kind in
345354 let moduleOutputPath = outputPathForModule ( name, contextHash)
@@ -432,6 +441,7 @@ package final class ClangModuleDependencyGraph {
432441 // Cached builds do not rely on the process working directory, and different scanner working directories should not inhibit task deduplication. The same is true if the scanner reports the working directory can be ignored.
433442 workingDirectory: module. cache_key != nil || module. is_cwd_ignored ? Path . root : workingDirectory,
434443 command: DependencyInfo . CompileCommand ( cacheKey: module. cache_key, arguments: commandLine) ,
444+ scanningCommandLine: scanningCommandLine,
435445 transitiveIncludeTreeIDs: transitiveIncludeTreeIDs,
436446 transitiveCompileCommandCacheKeys: transitiveCommandCacheKeys,
437447 usesSerializedDiagnostics: usesSerializedDiagnostics)
@@ -513,6 +523,7 @@ package final class ClangModuleDependencyGraph {
513523 // Cached builds do not rely on the process working directory, and different scanner working directories should not inhibit task deduplication
514524 workingDirectory: fileDeps. commands. allSatisfy { $0. cache_key != nil } ? Path . root : workingDirectory,
515525 commands: commands,
526+ scanningCommandLine: scanningCommandLine,
516527 transitiveIncludeTreeIDs: transitiveIncludeTreeIDs,
517528 transitiveCompileCommandCacheKeys: transitiveCommandCacheKeys,
518529 usesSerializedDiagnostics: usesSerializedDiagnostics)
@@ -549,6 +560,21 @@ package final class ClangModuleDependencyGraph {
549560 return clangWithScanner. casDBs
550561 }
551562
563+ package func generateReproducer( forFailedDependency dependency: DependencyInfo ,
564+ libclangPath: Path , casOptions: CASOptions ? ) throws -> String ? {
565+ let clangWithScanner = try libclangWithScanner (
566+ forPath: libclangPath,
567+ casOptions: casOptions,
568+ cacheFallbackIfNotAvailable: false ,
569+ core: core
570+ )
571+ guard clangWithScanner. libclang. supportsReproducerGeneration else {
572+ return nil
573+ }
574+ return try clangWithScanner. scanner. generateReproducer (
575+ commandLine: dependency. scanningCommandLine, workingDirectory: dependency. workingDirectory. str)
576+ }
577+
552578 package var isEmpty : Bool {
553579 recordedDependencyInfoRegistry. isEmpty
554580 }
0 commit comments