Skip to content

Commit c28af76

Browse files
authored
Merge pull request github#13286 from igfoo/igfoo/kotlin-1.9b
Kotlin: Support 1.9.0
2 parents 10bab71 + 82578af commit c28af76

File tree

6 files changed

+39
-20
lines changed

6 files changed

+39
-20
lines changed

docs/codeql/reusables/supported-versions-compilers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Java,"Java 7 to 20 [4]_","javac (OpenJDK and Oracle JDK),
2121

2222
Eclipse compiler for Java (ECJ) [5]_",``.java``
23-
Kotlin [6]_,"Kotlin 1.5.0 to 1.8.20","kotlinc",``.kt``
23+
Kotlin [6]_,"Kotlin 1.5.0 to 1.9.0","kotlinc",``.kt``
2424
JavaScript,ECMAScript 2022 or lower,Not applicable,"``.js``, ``.jsx``, ``.mjs``, ``.es``, ``.es6``, ``.htm``, ``.html``, ``.xhtm``, ``.xhtml``, ``.vue``, ``.hbs``, ``.ejs``, ``.njk``, ``.json``, ``.yaml``, ``.yml``, ``.raml``, ``.xml`` [7]_"
2525
Python [8]_,"2.7, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11",Not applicable,``.py``
2626
Ruby [9]_,"up to 3.2",Not applicable,"``.rb``, ``.erb``, ``.gemspec``, ``Gemfile``"

java/kotlin-extractor/build.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,37 @@ def run_process(cmd, capture_output=False):
8080
errors='replace'), file=sys.stderr)
8181
raise e
8282

83-
84-
def compile_to_dir(srcs, classpath, java_classpath, output):
83+
def write_arg_file(arg_file, args):
84+
with open(arg_file, 'w') as f:
85+
for arg in args:
86+
if "'" in arg:
87+
raise Exception('Single quote in argument: ' + arg)
88+
f.write("'" + arg.replace('\\', '/') + "'\n")
89+
90+
def compile_to_dir(build_dir, srcs, classpath, java_classpath, output):
8591
# Use kotlinc to compile .kt files:
92+
kotlin_arg_file = build_dir + '/kotlin.args'
93+
kotlin_args = ['-Werror',
94+
'-opt-in=kotlin.RequiresOptIn',
95+
'-d', output,
96+
'-module-name', 'codeql-kotlin-extractor',
97+
'-no-reflect', '-no-stdlib',
98+
'-jvm-target', '1.8',
99+
'-classpath', classpath] + srcs
100+
write_arg_file(kotlin_arg_file, kotlin_args)
86101
run_process([kotlinc,
87-
# kotlinc can default to 256M, which isn't enough when we are extracting the build
88-
'-J-Xmx2G',
89-
'-Werror',
90-
'-opt-in=kotlin.RequiresOptIn',
91-
'-d', output,
92-
'-module-name', 'codeql-kotlin-extractor',
93-
'-no-reflect', '-no-stdlib',
94-
'-jvm-target', '1.8',
95-
'-classpath', classpath] + srcs)
102+
# kotlinc can default to 256M, which isn't enough when we are extracting the build
103+
'-J-Xmx2G',
104+
'@' + kotlin_arg_file])
96105

97106
# Use javac to compile .java files, referencing the Kotlin class files:
98-
run_process([javac,
99-
'-d', output,
107+
java_arg_file = build_dir + '/java.args'
108+
java_args = ['-d', output,
100109
'-source', '8', '-target', '8',
101-
'-classpath', os.path.pathsep.join([output, classpath, java_classpath])] + [s for s in srcs if s.endswith(".java")])
110+
'-classpath', os.path.pathsep.join([output, classpath, java_classpath])] \
111+
+ [s for s in srcs if s.endswith(".java")]
112+
write_arg_file(java_arg_file, java_args)
113+
run_process([javac, '@' + java_arg_file])
102114

103115

104116
def compile_to_jar(build_dir, tmp_src_dir, srcs, classpath, java_classpath, output):
@@ -108,7 +120,7 @@ def compile_to_jar(build_dir, tmp_src_dir, srcs, classpath, java_classpath, outp
108120
shutil.rmtree(class_dir)
109121
os.makedirs(class_dir)
110122

111-
compile_to_dir(srcs, classpath, java_classpath, class_dir)
123+
compile_to_dir(build_dir, srcs, classpath, java_classpath, class_dir)
112124

113125
run_process(['jar', 'cf', output,
114126
'-C', class_dir, '.',

java/kotlin-extractor/kotlin_plugin_versions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def version_string_to_tuple(version):
2525
ci_version = '1.8.10'
2626

2727
# Version numbers in the list need to be in semantically increasing order
28-
many_versions = [ '1.4.32', '1.5.0', '1.5.10', '1.5.20', '1.5.30', '1.6.0', '1.6.20', '1.7.0', '1.7.20', '1.8.0' ]
28+
many_versions = [ '1.4.32', '1.5.0', '1.5.10', '1.5.20', '1.5.30', '1.6.0', '1.6.20', '1.7.0', '1.7.20', '1.8.0', '1.9.0-Beta' ]
2929

3030
many_versions_tuples = [version_string_to_tuple(v) for v in many_versions]
3131

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,10 @@ open class KotlinFileExtractor(
366366

367367
val typeArgs = removeOuterClassTypeArgs(c, argsIncludingOuterClasses)
368368
if (typeArgs != null) {
369-
for ((idx, arg) in typeArgs.withIndex()) {
369+
// From 1.9, the list might change when we call erase,
370+
// so we make a copy that it is safe to iterate over.
371+
val typeArgsCopy = typeArgs.toList()
372+
for ((idx, arg) in typeArgsCopy.withIndex()) {
370373
val argId = getTypeArgumentLabel(arg).id
371374
tw.writeTypeArgs(argId, idx, id)
372375
}
@@ -5531,7 +5534,7 @@ open class KotlinFileExtractor(
55315534
return
55325535
}
55335536

5534-
val typeOwner = e.typeOperandClassifier.owner
5537+
val typeOwner = e.typeOperand.classifierOrFail.owner
55355538
if (typeOwner !is IrClass) {
55365539
logger.errorElement("Expected to find SAM conversion to IrClass. Found '${typeOwner.javaClass}' instead. Can't implement SAM interface.", e)
55375540
return

java/ql/integration-tests/all-platforms/kotlin/diagnostics/kotlin-version-too-new/diagnostics.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"markdownMessage": "The Kotlin version installed (`999.999.999`) is too recent for this version of CodeQL. Install a version lower than 1.8.30.",
2+
"markdownMessage": "The Kotlin version installed (`999.999.999`) is too recent for this version of CodeQL. Install a version lower than 1.9.10.",
33
"severity": "error",
44
"source": {
55
"extractorName": "java",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: feature
3+
---
4+
* Kotlin versions up to 1.9.0 are now supported.

0 commit comments

Comments
 (0)