@@ -432,7 +432,10 @@ public struct ClangTaskPayload: ClangModuleVerifierPayloadType, DependencyInfoEd
432
432
433
433
public let fileNameMapPath : Path ?
434
434
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 ) {
436
439
if let developerPathString, explicitModulesPayload == nil {
437
440
self . dependencyInfoEditPayload = . init( removablePaths: [ ] , removableBasenames: [ ] , developerPath: Path ( developerPathString) )
438
441
} else {
@@ -443,27 +446,33 @@ public struct ClangTaskPayload: ClangModuleVerifierPayloadType, DependencyInfoEd
443
446
self . explicitModulesPayload = explicitModulesPayload
444
447
self . outputObjectFilePath = outputObjectFilePath
445
448
self . fileNameMapPath = fileNameMapPath
449
+ self . moduleDependenciesContext = moduleDependenciesContext
450
+ self . traceFilePath = traceFilePath
446
451
}
447
452
448
453
public func serialize< T: Serializer > ( to serializer: T ) {
449
- serializer. serializeAggregate ( 6 ) {
454
+ serializer. serializeAggregate ( 8 ) {
450
455
serializer. serialize ( serializedDiagnosticsPath)
451
456
serializer. serialize ( indexingPayload)
452
457
serializer. serialize ( explicitModulesPayload)
453
458
serializer. serialize ( outputObjectFilePath)
454
459
serializer. serialize ( fileNameMapPath)
455
460
serializer. serialize ( dependencyInfoEditPayload)
461
+ serializer. serialize ( moduleDependenciesContext)
462
+ serializer. serialize ( traceFilePath)
456
463
}
457
464
}
458
465
459
466
public init ( from deserializer: any Deserializer ) throws {
460
- try deserializer. beginAggregate ( 6 )
467
+ try deserializer. beginAggregate ( 8 )
461
468
self . serializedDiagnosticsPath = try deserializer. deserialize ( )
462
469
self . indexingPayload = try deserializer. deserialize ( )
463
470
self . explicitModulesPayload = try deserializer. deserialize ( )
464
471
self . outputObjectFilePath = try deserializer. deserialize ( )
465
472
self . fileNameMapPath = try deserializer. deserialize ( )
466
473
self . dependencyInfoEditPayload = try deserializer. deserialize ( )
474
+ self . moduleDependenciesContext = try deserializer. deserialize ( )
475
+ self . traceFilePath = try deserializer. deserialize ( )
467
476
}
468
477
}
469
478
@@ -1156,6 +1165,22 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
1156
1165
dependencyData = nil
1157
1166
}
1158
1167
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
+
1159
1184
// Add the diagnostics serialization flag. We currently place the diagnostics file right next to the output object file.
1160
1185
let diagFilePath : Path ?
1161
1186
if let serializedDiagnosticsOptions = self . serializedDiagnosticsOptions ( scope: cbc. scope, outputPath: outputNode. path) {
@@ -1266,7 +1291,9 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
1266
1291
explicitModulesPayload: explicitModulesPayload,
1267
1292
outputObjectFilePath: shouldGenerateRemarks ? outputNode. path : nil ,
1268
1293
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
1270
1297
)
1271
1298
1272
1299
var inputNodes : [ any PlannedNode ] = inputDeps. map { delegate. createNode ( $0) }
@@ -1316,6 +1343,15 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
1316
1343
extraInputs = [ ]
1317
1344
}
1318
1345
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
+
1319
1355
// Finally, create the task.
1320
1356
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)
1321
1357
0 commit comments