mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Merge pull request #13286 from igfoo/igfoo/kotlin-1.9b
Kotlin: Support 1.9.0
This commit is contained in:
@@ -80,25 +80,37 @@ def run_process(cmd, capture_output=False):
|
||||
errors='replace'), file=sys.stderr)
|
||||
raise e
|
||||
|
||||
def write_arg_file(arg_file, args):
|
||||
with open(arg_file, 'w') as f:
|
||||
for arg in args:
|
||||
if "'" in arg:
|
||||
raise Exception('Single quote in argument: ' + arg)
|
||||
f.write("'" + arg.replace('\\', '/') + "'\n")
|
||||
|
||||
def compile_to_dir(srcs, classpath, java_classpath, output):
|
||||
def compile_to_dir(build_dir, srcs, classpath, java_classpath, output):
|
||||
# Use kotlinc to compile .kt files:
|
||||
kotlin_arg_file = build_dir + '/kotlin.args'
|
||||
kotlin_args = ['-Werror',
|
||||
'-opt-in=kotlin.RequiresOptIn',
|
||||
'-d', output,
|
||||
'-module-name', 'codeql-kotlin-extractor',
|
||||
'-no-reflect', '-no-stdlib',
|
||||
'-jvm-target', '1.8',
|
||||
'-classpath', classpath] + srcs
|
||||
write_arg_file(kotlin_arg_file, kotlin_args)
|
||||
run_process([kotlinc,
|
||||
# kotlinc can default to 256M, which isn't enough when we are extracting the build
|
||||
'-J-Xmx2G',
|
||||
'-Werror',
|
||||
'-opt-in=kotlin.RequiresOptIn',
|
||||
'-d', output,
|
||||
'-module-name', 'codeql-kotlin-extractor',
|
||||
'-no-reflect', '-no-stdlib',
|
||||
'-jvm-target', '1.8',
|
||||
'-classpath', classpath] + srcs)
|
||||
# kotlinc can default to 256M, which isn't enough when we are extracting the build
|
||||
'-J-Xmx2G',
|
||||
'@' + kotlin_arg_file])
|
||||
|
||||
# Use javac to compile .java files, referencing the Kotlin class files:
|
||||
run_process([javac,
|
||||
'-d', output,
|
||||
java_arg_file = build_dir + '/java.args'
|
||||
java_args = ['-d', output,
|
||||
'-source', '8', '-target', '8',
|
||||
'-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")]
|
||||
write_arg_file(java_arg_file, java_args)
|
||||
run_process([javac, '@' + java_arg_file])
|
||||
|
||||
|
||||
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
|
||||
shutil.rmtree(class_dir)
|
||||
os.makedirs(class_dir)
|
||||
|
||||
compile_to_dir(srcs, classpath, java_classpath, class_dir)
|
||||
compile_to_dir(build_dir, srcs, classpath, java_classpath, class_dir)
|
||||
|
||||
run_process(['jar', 'cf', output,
|
||||
'-C', class_dir, '.',
|
||||
|
||||
@@ -25,7 +25,7 @@ def version_string_to_tuple(version):
|
||||
ci_version = '1.8.10'
|
||||
|
||||
# Version numbers in the list need to be in semantically increasing order
|
||||
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' ]
|
||||
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' ]
|
||||
|
||||
many_versions_tuples = [version_string_to_tuple(v) for v in many_versions]
|
||||
|
||||
|
||||
@@ -366,7 +366,10 @@ open class KotlinFileExtractor(
|
||||
|
||||
val typeArgs = removeOuterClassTypeArgs(c, argsIncludingOuterClasses)
|
||||
if (typeArgs != null) {
|
||||
for ((idx, arg) in typeArgs.withIndex()) {
|
||||
// From 1.9, the list might change when we call erase,
|
||||
// so we make a copy that it is safe to iterate over.
|
||||
val typeArgsCopy = typeArgs.toList()
|
||||
for ((idx, arg) in typeArgsCopy.withIndex()) {
|
||||
val argId = getTypeArgumentLabel(arg).id
|
||||
tw.writeTypeArgs(argId, idx, id)
|
||||
}
|
||||
@@ -5531,7 +5534,7 @@ open class KotlinFileExtractor(
|
||||
return
|
||||
}
|
||||
|
||||
val typeOwner = e.typeOperandClassifier.owner
|
||||
val typeOwner = e.typeOperand.classifierOrFail.owner
|
||||
if (typeOwner !is IrClass) {
|
||||
logger.errorElement("Expected to find SAM conversion to IrClass. Found '${typeOwner.javaClass}' instead. Can't implement SAM interface.", e)
|
||||
return
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"markdownMessage": "The Kotlin version installed (`999.999.999`) is too recent for this version of CodeQL. Install a version lower than 1.8.30.",
|
||||
"markdownMessage": "The Kotlin version installed (`999.999.999`) is too recent for this version of CodeQL. Install a version lower than 1.9.10.",
|
||||
"severity": "error",
|
||||
"source": {
|
||||
"extractorName": "java",
|
||||
|
||||
4
java/ql/lib/change-notes/2023-05-24-kotlin-1.9.0.md
Normal file
4
java/ql/lib/change-notes/2023-05-24-kotlin-1.9.0.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: feature
|
||||
---
|
||||
* Kotlin versions up to 1.9.0 are now supported.
|
||||
Reference in New Issue
Block a user