Skip to content

Commit 7d54b54

Browse files
committed
Kotlin: Put extractor name in a resource rather than generating code
1 parent e00f870 commit 7d54b54

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

java/kotlin-extractor/build.py

Lines changed: 7 additions & 6 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,7 @@ 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', '.'])
118118
shutil.rmtree(class_dir)
119119

120120

@@ -185,9 +185,10 @@ def compile(jars, java_jars, dependency_folder, transform_to_embeddable, output,
185185
include_version_folder = tmp_src_dir + '/main/kotlin/utils/versions/to_include'
186186
os.makedirs(include_version_folder)
187187

188-
with open(tmp_src_dir + '/main/kotlin/utils/ExtractorName.kt', 'w') as f:
189-
f.write('package com.github.codeql\n')
190-
f.write('val extractor_name: String = "' + output + '"\n')
188+
resource_dir = tmp_src_dir + '/main/resources/com/github/codeql'
189+
os.makedirs(resource_dir)
190+
with open(resource_dir + '/extractor.name', 'w') as f:
191+
f.write(output)
191192

192193
parsed_current_version = kotlin_plugin_versions.version_string_to_tuple(
193194
current_version)
@@ -215,7 +216,7 @@ def compile(jars, java_jars, dependency_folder, transform_to_embeddable, output,
215216

216217
transform_to_embeddable(srcs)
217218

218-
compile_to_jar(build_dir, srcs, classpath, java_classpath, output)
219+
compile_to_jar(build_dir, tmp_src_dir, srcs, classpath, java_classpath, output)
219220

220221
shutil.rmtree(tmp_src_dir)
221222

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class KotlinExtractorExtension(
132132
val compilation: Label<DbCompilation> = StringLabel("compilation")
133133
tw.writeCompilation_started(compilation)
134134
tw.writeCompilation_info(compilation, "Kotlin Compiler Version", KotlinCompilerVersion.getVersion() ?: "<unknown>")
135+
val extractor_name = this::class.java.getResource("extractor.name")?.readText() ?: "<unknown>"
135136
tw.writeCompilation_info(compilation, "Kotlin Extractor Name", extractor_name)
136137
if (compilationStartTime != null) {
137138
tw.writeCompilation_compiler_times(compilation, -1.0, (System.currentTimeMillis()-compilationStartTime)/1000.0)

0 commit comments

Comments
 (0)