Skip to content

Commit 3afd895

Browse files
authored
Merge pull request github#11217 from igfoo/igfoo/kotlin_version_rec
Java/Kotlin: Write Kotlin version information to the database
2 parents 83b3312 + b5c7d6b commit 3afd895

File tree

12 files changed

+9312
-3890
lines changed

12 files changed

+9312
-3890
lines changed

java/downgrades/44d61b266bebf261cb027872646262e645efa059/old.dbscheme

Lines changed: 1246 additions & 0 deletions
Large diffs are not rendered by default.

java/downgrades/44d61b266bebf261cb027872646262e645efa059/semmlecode.dbscheme

Lines changed: 1240 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
description: Remove compilation_info
2+
compatibility: full
3+
compilation_info.rel: delete

java/kotlin-extractor/build.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def compile_to_dir(srcs, classpath, java_classpath, output):
103103
'-classpath', os.path.pathsep.join([output, classpath, java_classpath])] + [s for s in srcs if s.endswith(".java")])
104104

105105

106-
def compile_to_jar(build_dir, srcs, classpath, java_classpath, output):
106+
def compile_to_jar(build_dir, tmp_src_dir, srcs, classpath, java_classpath, output):
107107
class_dir = build_dir + '/classes'
108108

109109
if os.path.exists(class_dir):
@@ -114,7 +114,8 @@ def compile_to_jar(build_dir, srcs, classpath, java_classpath, output):
114114

115115
run_process(['jar', 'cf', output,
116116
'-C', class_dir, '.',
117-
'-C', 'src/main/resources', 'META-INF'])
117+
'-C', tmp_src_dir + '/main/resources', 'META-INF',
118+
'-C', tmp_src_dir + '/main/resources', 'com/github/codeql/extractor.name'])
118119
shutil.rmtree(class_dir)
119120

120121

@@ -185,6 +186,11 @@ def compile(jars, java_jars, dependency_folder, transform_to_embeddable, output,
185186
include_version_folder = tmp_src_dir + '/main/kotlin/utils/versions/to_include'
186187
os.makedirs(include_version_folder)
187188

189+
resource_dir = tmp_src_dir + '/main/resources/com/github/codeql'
190+
os.makedirs(resource_dir)
191+
with open(resource_dir + '/extractor.name', 'w') as f:
192+
f.write(output)
193+
188194
parsed_current_version = kotlin_plugin_versions.version_string_to_tuple(
189195
current_version)
190196

@@ -211,7 +217,7 @@ def compile(jars, java_jars, dependency_folder, transform_to_embeddable, output,
211217

212218
transform_to_embeddable(srcs)
213219

214-
compile_to_jar(build_dir, srcs, classpath, java_classpath, output)
220+
compile_to_jar(build_dir, tmp_src_dir, srcs, classpath, java_classpath, output)
215221

216222
shutil.rmtree(tmp_src_dir)
217223

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ class KotlinExtractorExtension(
131131
// The interceptor has already defined #compilation = *
132132
val compilation: Label<DbCompilation> = StringLabel("compilation")
133133
tw.writeCompilation_started(compilation)
134+
tw.writeCompilation_info(compilation, "Kotlin Compiler Version", KotlinCompilerVersion.getVersion() ?: "<unknown>")
135+
val extractor_name = this::class.java.getResource("extractor.name")?.readText() ?: "<unknown>"
136+
tw.writeCompilation_info(compilation, "Kotlin Extractor Name", extractor_name)
134137
if (compilationStartTime != null) {
135138
tw.writeCompilation_compiler_times(compilation, -1.0, (System.currentTimeMillis()-compilationStartTime)/1000.0)
136139
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: feature
3+
---
4+
* The new `string Compilation.getInfo(string)` provides access to some information about compilations.

java/ql/lib/config/semmlecode.dbscheme

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ compilation_started(
3131
int id : @compilation ref
3232
)
3333

34+
compilation_info(
35+
int id : @compilation ref,
36+
string info_key: string ref,
37+
string info_value: string ref
38+
)
39+
3440
/**
3541
* The arguments that were passed to the extractor for a compiler
3642
* invocation. If `id` is for the compiler invocation

0 commit comments

Comments
 (0)