@@ -836,6 +836,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
836836 " -fmessage-length= " ,
837837 " -fmacro-backtrace-limit= " ,
838838 " -fbuild-session-timestamp= " ,
839+ " -fdiagnostics-add-output= "
839840 ] )
840841
841842 static let outputAgnosticCompilerArgumentsWithValues = Set < ByteString > ( [
@@ -1220,7 +1221,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
12201221 dependencyData = nil
12211222 }
12221223
1223- let extraOutputs : [ any PlannedNode ]
1224+ var extraOutputs : [ any PlannedNode ]
12241225 let moduleDependenciesContext = cbc. producer. moduleDependenciesContext
12251226 let headerDependenciesContext = cbc. producer. headerDependenciesContext
12261227 let dependencyValidationOutputPath : Path ?
@@ -1337,6 +1338,8 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
13371338 }
13381339 }
13391340
1341+ commandLine += addCompilerMetadataFlags ( cbc, outputFileDir. join ( outputNode. path. str + " .source-metadata.json " ) , delegate, & extraOutputs)
1342+
13401343 // Handle explicit modules build.
13411344 let scanningOutput = delegate. createNode ( outputNode. path. dirname. join ( outputNode. path. basename + " .scan " ) )
13421345 let ( action, usesExecutionInputs, explicitModulesPayload, explicitModulesSignatureData) = createExplicitModulesActionAndPayload ( cbc, delegate, launcher, input, resolvedInputFileType. languageDialect, commandLine: commandLine, scanningOutputPath: scanningOutput. path, isForPCHTask: false , clangInfo: clangInfo)
@@ -1649,6 +1652,22 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
16491652 }
16501653 }
16511654
1655+ func addCompilerMetadataFlags( _ cbc: CommandBuildContext , _ outputPath: Path , _ delegate: any TaskGenerationDelegate , _ taskOutputs: inout [ any PlannedNode ] ) -> [ String ] {
1656+ guard cbc. scope. evaluate ( BuiltinMacros . EMIT_COMPILER_SOURCE_METADATA) else {
1657+ return [ ]
1658+ }
1659+
1660+ guard let metadatatype = cbc. producer. lookupFileType ( identifier: " text.json.compiler-metadata.source " ) else {
1661+ return [ ]
1662+ }
1663+
1664+ let securityMetadataNode = delegate. createNode ( outputPath)
1665+ let ftb = FileToBuild ( absolutePath: securityMetadataNode. path, fileType: metadatatype)
1666+ taskOutputs. append ( securityMetadataNode)
1667+ delegate. declareOutput ( ftb)
1668+ return [ " -fdiagnostics-add-output=sarif:file= " + securityMetadataNode. path. str]
1669+ }
1670+
16521671 /// Specialized function that creates a task for precompiling a particular header.
16531672 private func precompile( _ cbc: CommandBuildContext , _ delegate: any TaskGenerationDelegate , headerPath: Path , language: GCCCompatibleLanguageDialect , inputFileType: FileTypeSpec , extraArgs: [ String ] , precompPath: Path , clangInfo: DiscoveredClangToolSpecInfo ? ) -> ClangPrefixInfo . PCHInfo {
16541673
0 commit comments