-
Notifications
You must be signed in to change notification settings - Fork 133
Add new clang build setting EMIT_SARIF_DIAGNOSTICS_FILE #938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add new clang build setting EMIT_SARIF_DIAGNOSTICS_FILE #938
Conversation
passes -fdiagnostic-add-output=sarif:file=<path>. The flag emits a SARIF log during the compilation which contains diagnostic information. The path is currently fixed to <object_file_path>.source-metadata.json
| let dataCache = cbc.producer.getSpecDataCache(self, cacheType: DataCache.self) | ||
| let constantFlags = dataCache.getStandardFlags(self, producer: cbc.producer, scope: cbc.scope, optionContext: clangInfo, delegate: delegate, inputFileType: resolvedInputFileType) | ||
| let cbcWithOutput = cbc.outputs.isEmpty ? cbc.appendingOutputs([outputNode.path]) : cbc | ||
| let constantFlags = dataCache.getStandardFlags(self, cbc: cbcWithOutput, optionContext: clangInfo, delegate: delegate, inputFileType: resolvedInputFileType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These flags are cached and reused across translation units, so I think this is going to incorrectly inject per-TU flags
dbartol
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly a bunch of naming suggestions.
| public static let EMBEDDED_CONTENT_CONTAINS_SWIFT = BuiltinMacros.declareBooleanMacro("EMBEDDED_CONTENT_CONTAINS_SWIFT") | ||
| public static let EMBEDDED_PROFILE_NAME = BuiltinMacros.declareStringMacro("EMBEDDED_PROFILE_NAME") | ||
| public static let EMBED_PACKAGE_RESOURCE_BUNDLE_NAMES = BuiltinMacros.declareStringListMacro("EMBED_PACKAGE_RESOURCE_BUNDLE_NAMES") | ||
| public static let EMIT_COMPILER_SOURCE_METADATA = BuiltinMacros.declareBooleanMacro("EMIT_COMPILER_SOURCE_METADATA") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested name: CLANG_EMIT_SARIF_DIAGNOSTICS_FILE. Unless this macro is reused by the Swift compiler, in which case you should probably drop the CLANG_ prefix.
| } | ||
| } | ||
|
|
||
| commandLine += addCompilerMetadataFlags(cbc, outputFileDir.join(outputNode.path.str + ".source-metadata.json"), delegate, &extraOutputs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| commandLine += addCompilerMetadataFlags(cbc, outputFileDir.join(outputNode.path.str + ".source-metadata.json"), delegate, &extraOutputs) | |
| commandLine += addCompilerSarifFlags(cbc, outputFileDir.join(outputNode.path.str + ".compiled.sarif"), delegate, &extraOutputs) |
| let ftb = FileToBuild(absolutePath: securityMetadataNode.path, fileType: metadatatype) | ||
| taskOutputs.append(securityMetadataNode) | ||
| delegate.declareOutput(ftb) | ||
| return ["-fdiagnostics-add-output=sarif:file=" + securityMetadataNode.path.str] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to add quoting and/or escaping here, since the path has to be part of the same option? Or does the fact the result is an array mean that the build system will property quote each array element?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latter.
| UTI = "public.protobuf-source"; | ||
| }, | ||
| { | ||
| Identifier = text.json.compiler-metadata.source; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Identifier = text.json.compiler-metadata.source; | |
| Identifier = text.sarif; |
Unless the hierarchy means something, in which case text.json.sarif is fine.
| { | ||
| Identifier = text.json.compiler-metadata.source; | ||
| Type = FileType; | ||
| Name = "Source metadata emitted from compiler"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Name = "Source metadata emitted from compiler"; | |
| Name = "Diagnostics log in SARIF format."; |
| Identifier = text.json.compiler-metadata.source; | ||
| Type = FileType; | ||
| Name = "Source metadata emitted from compiler"; | ||
| UTI = "com.apple.compiler-metadata.source"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| UTI = "com.apple.compiler-metadata.source"; | |
| UTI = "com.apple.sarif"; |
|
@swift-ci test |
deb9f17 to
8d321a5
Compare
|
@swift-ci test |
|
@swift-ci test windows |
Add new clang build setting EMIT_SARIF_DIAGNOSTICS_FILE that passes
-fdiagnostic-add-output=sarif:file=. The flag emits a SARIF log during the compilation which contains diagnostic information. The path is currently fixed to <object_file_path>.compiled.sarif