Skip to content

Commit 513a39f

Browse files
committed
Kotlin: Specify language versino when compiling for old compilers
Otherwise builds with Kotlin 2 won't work with older compilers.
1 parent f3c5c01 commit 513a39f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

java/kotlin-extractor/build.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,16 @@ def write_arg_file(arg_file, args):
8787
raise Exception('Single quote in argument: ' + arg)
8888
f.write("'" + arg.replace('\\', '/') + "'\n")
8989

90-
def compile_to_dir(build_dir, srcs, classpath, java_classpath, output):
90+
def compile_to_dir(build_dir, srcs, language_version, classpath, java_classpath, output):
9191
# Use kotlinc to compile .kt files:
9292
kotlin_arg_file = build_dir + '/kotlin.args'
9393
kotlin_args = ['-Werror',
9494
'-opt-in=kotlin.RequiresOptIn',
9595
'-opt-in=org.jetbrains.kotlin.ir.symbols.IrSymbolInternals',
9696
'-d', output,
9797
'-module-name', 'codeql-kotlin-extractor',
98+
'-Xsuppress-version-warnings',
99+
'-language-version', language_version,
98100
'-no-reflect', '-no-stdlib',
99101
'-jvm-target', '1.8',
100102
'-classpath', classpath] + srcs
@@ -114,14 +116,14 @@ def compile_to_dir(build_dir, srcs, classpath, java_classpath, output):
114116
run_process([javac, '@' + java_arg_file])
115117

116118

117-
def compile_to_jar(build_dir, tmp_src_dir, srcs, classpath, java_classpath, output):
119+
def compile_to_jar(build_dir, tmp_src_dir, srcs, language_version, classpath, java_classpath, output):
118120
class_dir = build_dir + '/classes'
119121

120122
if os.path.exists(class_dir):
121123
shutil.rmtree(class_dir)
122124
os.makedirs(class_dir)
123125

124-
compile_to_dir(build_dir, srcs, classpath, java_classpath, class_dir)
126+
compile_to_dir(build_dir, srcs, language_version, classpath, java_classpath, class_dir)
125127

126128
run_process(['jar', 'cf', output,
127129
'-C', class_dir, '.',
@@ -192,14 +194,16 @@ def compile(jars, java_jars, dependency_folder, transform_to_embeddable, output,
192194
# copy and overwrite files from the version folder to the include folder
193195
shutil.copytree(d, include_version_folder, dirs_exist_ok=True)
194196

197+
language_version = str(parsed_current_version[0]) + '.' + str(parsed_current_version[1])
198+
195199
# remove all version folders:
196200
shutil.rmtree(tmp_src_dir + '/main/kotlin/utils/versions')
197201

198202
srcs = find_sources(tmp_src_dir)
199203

200204
transform_to_embeddable(srcs)
201205

202-
compile_to_jar(build_dir, tmp_src_dir, srcs, classpath, java_classpath, output)
206+
compile_to_jar(build_dir, tmp_src_dir, srcs, language_version, classpath, java_classpath, output)
203207

204208
shutil.rmtree(tmp_src_dir)
205209

0 commit comments

Comments
 (0)