mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Kotlin: Add comments saying what generated TRAP files
This commit is contained in:
@@ -9,7 +9,7 @@ import java.util.ArrayList
|
||||
import java.util.HashSet
|
||||
import java.util.zip.GZIPOutputStream
|
||||
|
||||
class ExternalClassExtractor(val logger: FileLogger, val sourceFilePath: String, val primitiveTypeMapping: PrimitiveTypeMapping, val pluginContext: IrPluginContext) {
|
||||
class ExternalClassExtractor(val logger: FileLogger, val invocationTrapFile: String, val sourceFilePath: String, val primitiveTypeMapping: PrimitiveTypeMapping, val pluginContext: IrPluginContext) {
|
||||
|
||||
val externalClassesDone = HashSet<IrClass>()
|
||||
val externalClassWorkList = ArrayList<IrClass>()
|
||||
@@ -33,10 +33,17 @@ class ExternalClassExtractor(val logger: FileLogger, val sourceFilePath: String,
|
||||
logger.info("Skipping extracting class ${irClass.name}")
|
||||
} else {
|
||||
GZIPOutputStream(manager.getFile().outputStream()).bufferedWriter().use { trapFileBW ->
|
||||
// We want our comments to be the first thing in the file,
|
||||
// so start off with a mere TrapWriter
|
||||
val tw = TrapWriter(TrapLabelManager(), trapFileBW)
|
||||
tw.writeComment("Generated by the CodeQL Kotlin extractor for external dependencies")
|
||||
tw.writeComment("Part of invocation $invocationTrapFile")
|
||||
// Now elevate to a SourceFileTrapWriter, and populate the
|
||||
// file information
|
||||
val binaryPath = getIrClassBinaryPath(irClass)
|
||||
val tw =
|
||||
FileTrapWriter(TrapLabelManager(), trapFileBW, binaryPath, true)
|
||||
val fileExtractor = KotlinFileExtractor(logger, tw, manager, this, primitiveTypeMapping, pluginContext)
|
||||
val ftw = tw.makeFileTrapWriter(binaryPath, true)
|
||||
|
||||
val fileExtractor = KotlinFileExtractor(logger, ftw, manager, this, primitiveTypeMapping, pluginContext)
|
||||
fileExtractor.extractClassSource(irClass)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,11 +112,17 @@ fun doFile(invocationTrapFile: String,
|
||||
if (checkTrapIdentical || !trapFile.exists()) {
|
||||
val trapTmpFile = File.createTempFile("$filePath.", ".trap.tmp", trapFileDir)
|
||||
trapTmpFile.bufferedWriter().use { trapFileBW ->
|
||||
val tw = SourceFileTrapWriter(TrapLabelManager(), trapFileBW, file, true)
|
||||
tw.writeComment("Generated by invocation $invocationTrapFile")
|
||||
val externalClassExtractor = ExternalClassExtractor(logger, file.path, primitiveTypeMapping, pluginContext)
|
||||
val fileExtractor = KotlinSourceFileExtractor(logger, tw, file, externalClassExtractor, primitiveTypeMapping, pluginContext)
|
||||
fileExtractor.extractFileContents(tw.fileId)
|
||||
// We want our comments to be the first thing in the file,
|
||||
// so start off with a mere TrapWriter
|
||||
val tw = TrapWriter(TrapLabelManager(), trapFileBW)
|
||||
tw.writeComment("Generated by the CodeQL Kotlin extractor for kotlin source code")
|
||||
tw.writeComment("Part of invocation $invocationTrapFile")
|
||||
// Now elevate to a SourceFileTrapWriter, and populate the
|
||||
// file information
|
||||
val sftw = tw.makeSourceFileTrapWriter(file, true)
|
||||
val externalClassExtractor = ExternalClassExtractor(logger, invocationTrapFile, file.path, primitiveTypeMapping, pluginContext)
|
||||
val fileExtractor = KotlinSourceFileExtractor(logger, sftw, file, externalClassExtractor, primitiveTypeMapping, pluginContext)
|
||||
fileExtractor.extractFileContents(sftw.fileId)
|
||||
externalClassExtractor.extractExternalClasses()
|
||||
}
|
||||
if (checkTrapIdentical && trapFile.exists()) {
|
||||
|
||||
@@ -73,7 +73,7 @@ open class KotlinUsesExtractor(
|
||||
val clsFile = cls.fileOrNull
|
||||
|
||||
if (isExternalDeclaration(cls) || clsFile == null) {
|
||||
val newTrapWriter = tw.makeFileTrapWriter(getIrClassBinaryPath(cls))
|
||||
val newTrapWriter = tw.makeFileTrapWriter(getIrClassBinaryPath(cls), false)
|
||||
val newLogger = FileLogger(logger.logCounter, newTrapWriter)
|
||||
return KotlinFileExtractor(newLogger, newTrapWriter, dependencyCollector, externalClassExtractor, primitiveTypeMapping, pluginContext)
|
||||
}
|
||||
|
||||
@@ -159,8 +159,8 @@ open class TrapWriter (protected val lm: TrapLabelManager, private val bw: Buffe
|
||||
* Gets a FileTrapWriter like this one (using the same label manager,
|
||||
* writer etc), but using the given `filePath` for locations.
|
||||
*/
|
||||
fun makeFileTrapWriter(filePath: String) =
|
||||
FileTrapWriter(lm, bw, filePath, false)
|
||||
fun makeFileTrapWriter(filePath: String, populateFileTables: Boolean) =
|
||||
FileTrapWriter(lm, bw, filePath, populateFileTables)
|
||||
|
||||
/**
|
||||
* Gets a FileTrapWriter like this one (using the same label manager,
|
||||
|
||||
Reference in New Issue
Block a user