@@ -432,7 +432,10 @@ public struct ClangTaskPayload: ClangModuleVerifierPayloadType, DependencyInfoEd
432432
433433 public let fileNameMapPath : Path ?
434434
435- fileprivate init ( serializedDiagnosticsPath: Path ? , indexingPayload: ClangIndexingPayload ? , explicitModulesPayload: ClangExplicitModulesPayload ? = nil , outputObjectFilePath: Path ? = nil , fileNameMapPath: Path ? = nil , developerPathString: String ? = nil ) {
435+ public let moduleDependenciesContext : ModuleDependenciesContext ?
436+ public let traceFilePath : Path ?
437+
438+ fileprivate init ( serializedDiagnosticsPath: Path ? , indexingPayload: ClangIndexingPayload ? , explicitModulesPayload: ClangExplicitModulesPayload ? = nil , outputObjectFilePath: Path ? = nil , fileNameMapPath: Path ? = nil , developerPathString: String ? = nil , moduleDependenciesContext: ModuleDependenciesContext ? = nil , traceFilePath: Path ? = nil ) {
436439 if let developerPathString, explicitModulesPayload == nil {
437440 self . dependencyInfoEditPayload = . init( removablePaths: [ ] , removableBasenames: [ ] , developerPath: Path ( developerPathString) )
438441 } else {
@@ -443,27 +446,33 @@ public struct ClangTaskPayload: ClangModuleVerifierPayloadType, DependencyInfoEd
443446 self . explicitModulesPayload = explicitModulesPayload
444447 self . outputObjectFilePath = outputObjectFilePath
445448 self . fileNameMapPath = fileNameMapPath
449+ self . moduleDependenciesContext = moduleDependenciesContext
450+ self . traceFilePath = traceFilePath
446451 }
447452
448453 public func serialize< T: Serializer > ( to serializer: T ) {
449- serializer. serializeAggregate ( 6 ) {
454+ serializer. serializeAggregate ( 8 ) {
450455 serializer. serialize ( serializedDiagnosticsPath)
451456 serializer. serialize ( indexingPayload)
452457 serializer. serialize ( explicitModulesPayload)
453458 serializer. serialize ( outputObjectFilePath)
454459 serializer. serialize ( fileNameMapPath)
455460 serializer. serialize ( dependencyInfoEditPayload)
461+ serializer. serialize ( moduleDependenciesContext)
462+ serializer. serialize ( traceFilePath)
456463 }
457464 }
458465
459466 public init ( from deserializer: any Deserializer ) throws {
460- try deserializer. beginAggregate ( 6 )
467+ try deserializer. beginAggregate ( 8 )
461468 self . serializedDiagnosticsPath = try deserializer. deserialize ( )
462469 self . indexingPayload = try deserializer. deserialize ( )
463470 self . explicitModulesPayload = try deserializer. deserialize ( )
464471 self . outputObjectFilePath = try deserializer. deserialize ( )
465472 self . fileNameMapPath = try deserializer. deserialize ( )
466473 self . dependencyInfoEditPayload = try deserializer. deserialize ( )
474+ self . moduleDependenciesContext = try deserializer. deserialize ( )
475+ self . traceFilePath = try deserializer. deserialize ( )
467476 }
468477}
469478
@@ -1156,6 +1165,22 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
11561165 dependencyData = nil
11571166 }
11581167
1168+ let moduleDependenciesContext = cbc. producer. moduleDependenciesContext
1169+ let traceFilePath : Path ?
1170+ if clangInfo? . hasFeature ( " print-headers-direct-per-file " ) ?? false ,
1171+ ( moduleDependenciesContext? . validate ?? . defaultValue) != . no {
1172+ let file = Path ( outputNode. path. str + " .trace.json " )
1173+ commandLine += [
1174+ " -Xclang " , " -header-include-file " ,
1175+ " -Xclang " , file. str,
1176+ " -Xclang " , " -header-include-filtering=direct-per-file " ,
1177+ " -Xclang " , " -header-include-format=json "
1178+ ]
1179+ traceFilePath = file
1180+ } else {
1181+ traceFilePath = nil
1182+ }
1183+
11591184 // Add the diagnostics serialization flag. We currently place the diagnostics file right next to the output object file.
11601185 let diagFilePath : Path ?
11611186 if let serializedDiagnosticsOptions = self . serializedDiagnosticsOptions ( scope: cbc. scope, outputPath: outputNode. path) {
@@ -1266,7 +1291,9 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
12661291 explicitModulesPayload: explicitModulesPayload,
12671292 outputObjectFilePath: shouldGenerateRemarks ? outputNode. path : nil ,
12681293 fileNameMapPath: verifierPayload? . fileNameMapPath,
1269- developerPathString: recordSystemHeaderDepsOutsideSysroot ? cbc. scope. evaluate ( BuiltinMacros . DEVELOPER_DIR) . str : nil
1294+ developerPathString: recordSystemHeaderDepsOutsideSysroot ? cbc. scope. evaluate ( BuiltinMacros . DEVELOPER_DIR) . str : nil ,
1295+ moduleDependenciesContext: moduleDependenciesContext,
1296+ traceFilePath: traceFilePath
12701297 )
12711298
12721299 var inputNodes : [ any PlannedNode ] = inputDeps. map { delegate. createNode ( $0) }
@@ -1316,6 +1343,15 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
13161343 extraInputs = [ ]
13171344 }
13181345
1346+ if let moduleDependenciesContext {
1347+ guard let jsonData = try ? JSONEncoder ( outputFormatting: [ . prettyPrinted, . sortedKeys, . withoutEscapingSlashes] ) . encode ( moduleDependenciesContext) ,
1348+ let signature = String ( data: jsonData, encoding: . utf8) else {
1349+ delegate. error ( " failed to serialize 'MODULE_DEPENDENCIES' context information " )
1350+ return
1351+ }
1352+ additionalSignatureData += " | \( signature) "
1353+ }
1354+
13191355 // Finally, create the task.
13201356 delegate. createTask ( type: self , dependencyData: dependencyData, payload: payload, ruleInfo: ruleInfo, additionalSignatureData: additionalSignatureData, commandLine: commandLine, additionalOutput: additionalOutput, environment: environmentBindings, workingDirectory: compilerWorkingDirectory ( cbc) , inputs: inputNodes + extraInputs, outputs: [ outputNode] , action: action ?? delegate. taskActionCreationDelegate. createDeferredExecutionTaskActionIfRequested ( userPreferences: cbc. producer. userPreferences) , execDescription: resolveExecutionDescription ( cbc, delegate) , enableSandboxing: enableSandboxing, additionalTaskOrderingOptions: [ . compilationForIndexableSourceFile] , usesExecutionInputs: usesExecutionInputs, showEnvironment: true , priority: . preferred)
13211357
0 commit comments