@@ -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 traceFile : Path ?
437+
438+ fileprivate init ( serializedDiagnosticsPath: Path ? , indexingPayload: ClangIndexingPayload ? , explicitModulesPayload: ClangExplicitModulesPayload ? = nil , outputObjectFilePath: Path ? = nil , fileNameMapPath: Path ? = nil , developerPathString: String ? = nil , moduleDependenciesContext: ModuleDependenciesContext ? = nil , traceFile: 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 . traceFile = traceFile
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 ( traceFile)
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 . traceFile = 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 traceFile : 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+ traceFile = file
1180+ } else {
1181+ traceFile = 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+ traceFile: traceFile
12701297 )
12711298
12721299 var inputNodes : [ any PlannedNode ] = inputDeps. map { delegate. createNode ( $0) }
@@ -1316,8 +1343,12 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
13161343 extraInputs = [ ]
13171344 }
13181345
1346+ if let moduleDependenciesContext {
1347+ additionalSignatureData += moduleDependenciesContext. signatureData ( )
1348+ }
1349+
13191350 // Finally, create the task.
1320- 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)
1351+ 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. createClangNonModularCompileTaskAction ( ) , execDescription: resolveExecutionDescription ( cbc, delegate) , enableSandboxing: enableSandboxing, additionalTaskOrderingOptions: [ . compilationForIndexableSourceFile] , usesExecutionInputs: usesExecutionInputs, showEnvironment: true , priority: . preferred)
13211352
13221353 // If the object file verifier is enabled and we are building with explicit modules, also create a job to produce adjacent objects using implicit modules, then compare the results.
13231354 if cbc. scope. evaluate ( BuiltinMacros . CLANG_ENABLE_EXPLICIT_MODULES_OBJECT_FILE_VERIFIER) && action != nil {
0 commit comments