Kotlin: Put extractor name in a resource rather than generating code

This commit is contained in:
Ian Lynagh
2022-11-11 13:00:07 +00:00
parent e00f87045e
commit 7d54b542b5
2 changed files with 8 additions and 6 deletions

View File

@@ -103,7 +103,7 @@ def compile_to_dir(srcs, classpath, java_classpath, output):
'-classpath', os.path.pathsep.join([output, classpath, java_classpath])] + [s for s in srcs if s.endswith(".java")]) '-classpath', os.path.pathsep.join([output, classpath, java_classpath])] + [s for s in srcs if s.endswith(".java")])
def compile_to_jar(build_dir, srcs, classpath, java_classpath, output): def compile_to_jar(build_dir, tmp_src_dir, srcs, classpath, java_classpath, output):
class_dir = build_dir + '/classes' class_dir = build_dir + '/classes'
if os.path.exists(class_dir): if os.path.exists(class_dir):
@@ -114,7 +114,7 @@ def compile_to_jar(build_dir, srcs, classpath, java_classpath, output):
run_process(['jar', 'cf', output, run_process(['jar', 'cf', output,
'-C', class_dir, '.', '-C', class_dir, '.',
'-C', 'src/main/resources', 'META-INF']) '-C', tmp_src_dir + '/main/resources', '.'])
shutil.rmtree(class_dir) shutil.rmtree(class_dir)
@@ -185,9 +185,10 @@ def compile(jars, java_jars, dependency_folder, transform_to_embeddable, output,
include_version_folder = tmp_src_dir + '/main/kotlin/utils/versions/to_include' include_version_folder = tmp_src_dir + '/main/kotlin/utils/versions/to_include'
os.makedirs(include_version_folder) os.makedirs(include_version_folder)
with open(tmp_src_dir + '/main/kotlin/utils/ExtractorName.kt', 'w') as f: resource_dir = tmp_src_dir + '/main/resources/com/github/codeql'
f.write('package com.github.codeql\n') os.makedirs(resource_dir)
f.write('val extractor_name: String = "' + output + '"\n') with open(resource_dir + '/extractor.name', 'w') as f:
f.write(output)
parsed_current_version = kotlin_plugin_versions.version_string_to_tuple( parsed_current_version = kotlin_plugin_versions.version_string_to_tuple(
current_version) current_version)
@@ -215,7 +216,7 @@ def compile(jars, java_jars, dependency_folder, transform_to_embeddable, output,
transform_to_embeddable(srcs) transform_to_embeddable(srcs)
compile_to_jar(build_dir, srcs, classpath, java_classpath, output) compile_to_jar(build_dir, tmp_src_dir, srcs, classpath, java_classpath, output)
shutil.rmtree(tmp_src_dir) shutil.rmtree(tmp_src_dir)

View File

@@ -132,6 +132,7 @@ class KotlinExtractorExtension(
val compilation: Label<DbCompilation> = StringLabel("compilation") val compilation: Label<DbCompilation> = StringLabel("compilation")
tw.writeCompilation_started(compilation) tw.writeCompilation_started(compilation)
tw.writeCompilation_info(compilation, "Kotlin Compiler Version", KotlinCompilerVersion.getVersion() ?: "<unknown>") tw.writeCompilation_info(compilation, "Kotlin Compiler Version", KotlinCompilerVersion.getVersion() ?: "<unknown>")
val extractor_name = this::class.java.getResource("extractor.name")?.readText() ?: "<unknown>"
tw.writeCompilation_info(compilation, "Kotlin Extractor Name", extractor_name) tw.writeCompilation_info(compilation, "Kotlin Extractor Name", extractor_name)
if (compilationStartTime != null) { if (compilationStartTime != null) {
tw.writeCompilation_compiler_times(compilation, -1.0, (System.currentTimeMillis()-compilationStartTime)/1000.0) tw.writeCompilation_compiler_times(compilation, -1.0, (System.currentTimeMillis()-compilationStartTime)/1000.0)