mirror of
https://github.com/github/codeql.git
synced 2025-12-24 20:56:33 +01:00
Kotlin: Put extractor name in a resource rather than generating code
This commit is contained in:
@@ -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")])
|
||||
|
||||
|
||||
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'
|
||||
|
||||
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,
|
||||
'-C', class_dir, '.',
|
||||
'-C', 'src/main/resources', 'META-INF'])
|
||||
'-C', tmp_src_dir + '/main/resources', '.'])
|
||||
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'
|
||||
os.makedirs(include_version_folder)
|
||||
|
||||
with open(tmp_src_dir + '/main/kotlin/utils/ExtractorName.kt', 'w') as f:
|
||||
f.write('package com.github.codeql\n')
|
||||
f.write('val extractor_name: String = "' + output + '"\n')
|
||||
resource_dir = tmp_src_dir + '/main/resources/com/github/codeql'
|
||||
os.makedirs(resource_dir)
|
||||
with open(resource_dir + '/extractor.name', 'w') as f:
|
||||
f.write(output)
|
||||
|
||||
parsed_current_version = kotlin_plugin_versions.version_string_to_tuple(
|
||||
current_version)
|
||||
@@ -215,7 +216,7 @@ def compile(jars, java_jars, dependency_folder, transform_to_embeddable, output,
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@@ -132,6 +132,7 @@ class KotlinExtractorExtension(
|
||||
val compilation: Label<DbCompilation> = StringLabel("compilation")
|
||||
tw.writeCompilation_started(compilation)
|
||||
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)
|
||||
if (compilationStartTime != null) {
|
||||
tw.writeCompilation_compiler_times(compilation, -1.0, (System.currentTimeMillis()-compilationStartTime)/1000.0)
|
||||
|
||||
Reference in New Issue
Block a user