Skip to content

Commit a2659ee

Browse files
authored
Merge pull request github#14018 from igfoo/igfoo/extractor_information_kotlin1
Kotlin: Write usesK2 ("uses Kotlin 2") information to the database
2 parents 77369a0 + bbf441f commit a2659ee

File tree

14 files changed

+70
-1
lines changed

14 files changed

+70
-1
lines changed

java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import java.nio.file.Files
2020
import java.nio.file.Paths
2121
import java.util.zip.GZIPInputStream
2222
import java.util.zip.GZIPOutputStream
23+
import com.github.codeql.utils.versions.usesK2
2324
import com.semmle.util.files.FileUtil
2425
import kotlin.system.exitProcess
2526

@@ -97,6 +98,7 @@ class KotlinExtractorExtension(
9798

9899
private fun runExtractor(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) {
99100
val startTimeMs = System.currentTimeMillis()
101+
val usesK2 = usesK2(pluginContext)
100102
// This default should be kept in sync with com.semmle.extractor.java.interceptors.KotlinInterceptor.initializeExtractionContext
101103
val trapDir = File(System.getenv("CODEQL_EXTRACTOR_JAVA_TRAP_DIR").takeUnless { it.isNullOrEmpty() } ?: "kotlin-extractor/trap")
102104
val compression_env_var = "CODEQL_EXTRACTOR_JAVA_OPTION_TRAP_COMPRESSION"
@@ -134,6 +136,7 @@ class KotlinExtractorExtension(
134136
tw.writeCompilation_info(compilation, "Kotlin Compiler Version", KotlinCompilerVersion.getVersion() ?: "<unknown>")
135137
val extractor_name = this::class.java.getResource("extractor.name")?.readText() ?: "<unknown>"
136138
tw.writeCompilation_info(compilation, "Kotlin Extractor Name", extractor_name)
139+
tw.writeCompilation_info(compilation, "Uses Kotlin 2", usesK2.toString())
137140
if (compilationStartTime != null) {
138141
tw.writeCompilation_compiler_times(compilation, -1.0, (System.currentTimeMillis()-compilationStartTime)/1000.0)
139142
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.github.codeql.utils.versions
2+
3+
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
4+
5+
fun usesK2(@Suppress("UNUSED_PARAMETER") pluginContext: IrPluginContext): Boolean {
6+
return false
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.github.codeql.utils.versions
2+
3+
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
4+
5+
fun usesK2(pluginContext: IrPluginContext): Boolean {
6+
return pluginContext.languageVersionSettings.languageVersion.usesK2
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
| Number of files with extension jar | 1 |
2+
| Number of files with extension kt | 1 |
3+
| Number of lines of code | 2 |
4+
| Number of lines of code with extension kt | 2 |
5+
| Total number of lines | 3 |
6+
| Total number of lines with extension kt | 3 |
7+
| Uses Kotlin 2: false | 1 |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/java-queries
4+
extensible: extractorInformationSkipKey
5+
data:
6+
# These will have unstable values, as they are dependent on the
7+
# JDK that the test is run with, so filter them out:
8+
- ["Number of files"]
9+
- ["Number of files with extension class"]
10+
# These depend on the Kotlin version you have installed
11+
- ["Kotlin Compiler Version: %"]
12+
- ["Kotlin Extractor Name: %"]
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Telemetry/ExtractorInformation.ql
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class SomeClass {
2+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from create_database_utils import *
2+
3+
run_codeql_database_create(["kotlinc SomeClass.kt"], lang="java")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| Number of files with extension jar | 1 |
2+
| Number of files with extension kt | 1 |
3+
| Uses Kotlin 2: true | 1 |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/java-queries
4+
extensible: extractorInformationSkipKey
5+
data:
6+
# These will have unstable values, as they are dependent on the
7+
# JDK that the test is run with, so filter them out:
8+
- ["Number of files"]
9+
- ["Number of files with extension class"]
10+
# These depend on the Kotlin version you have installed
11+
- ["Kotlin Compiler Version: %"]
12+
- ["Kotlin Extractor Name: %"]
13+
# Currently we get some diagnostics as Kotlin 2 support isn't complete.
14+
# Ignore these, as the number probably isn't stable.
15+
- ["Number of diagnostics from CodeQL Kotlin extractor with severity %"]
16+
- ["Total number of diagnostics from CodeQL Kotlin extractor"]
17+

0 commit comments

Comments
 (0)