mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Add 1.6.20 support
This commit is contained in:
@@ -27,9 +27,11 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
|
||||
sourceSets {
|
||||
main {
|
||||
kotlin {
|
||||
excludes = ["utils/versions/v_1_4/*.kt", "utils/versions/v_1_6/*.kt"]
|
||||
// change the above line to the below for building with kotlinVersion=1.4.32:
|
||||
//excludes = ["utils/versions/default/*.kt", "utils/versions/v_1_6/*.kt"]
|
||||
// change the excludes for building with other versions:
|
||||
excludes = [
|
||||
"utils/versions/v_1_4_32/*.kt",
|
||||
"utils/versions/v_1_5_31/*.kt",
|
||||
"utils/versions/v_1_6_10/*.kt"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,15 +12,21 @@ import os.path
|
||||
import sys
|
||||
import shlex
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--dependencies', default='../../../resources/kotlin-dependencies', help='Folder containing the dependencies')
|
||||
parser.add_argument('--many', action='store_true', help='Build for all versions/kinds')
|
||||
parser.add_argument('--single', action='store_false', dest='many', help='Build for a single version/kind')
|
||||
parser.add_argument('--dependencies', default='../../../resources/kotlin-dependencies',
|
||||
help='Folder containing the dependencies')
|
||||
parser.add_argument('--many', action='store_true',
|
||||
help='Build for all versions/kinds')
|
||||
parser.add_argument('--single', action='store_false',
|
||||
dest='many', help='Build for a single version/kind')
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
args = parse_args()
|
||||
|
||||
|
||||
def is_windows():
|
||||
'''Whether we appear to be running on Windows'''
|
||||
if platform.system() == 'Windows':
|
||||
@@ -29,10 +35,12 @@ def is_windows():
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
kotlinc = 'kotlinc.bat' if is_windows() else 'kotlinc'
|
||||
javac = 'javac'
|
||||
kotlin_dependency_folder = args.dependencies
|
||||
|
||||
|
||||
def quote_for_batch(arg):
|
||||
if ';' in arg or '=' in arg:
|
||||
if '"' in arg:
|
||||
@@ -41,6 +49,7 @@ def quote_for_batch(arg):
|
||||
else:
|
||||
return arg
|
||||
|
||||
|
||||
def run_process(cmd, capture_output=False):
|
||||
print("Running command: " + shlex.join(cmd))
|
||||
if is_windows():
|
||||
@@ -156,15 +165,10 @@ def compile(jars, java_jars, dependency_folder, transform_to_embeddable, output,
|
||||
shutil.rmtree(tmp_dir)
|
||||
shutil.copytree('src', tmp_dir)
|
||||
|
||||
if version.startswith('1.4'):
|
||||
shutil.rmtree(tmp_dir + '/main/kotlin/utils/versions/default')
|
||||
shutil.rmtree(tmp_dir + '/main/kotlin/utils/versions/v_1_6')
|
||||
elif version.startswith('1.6'):
|
||||
shutil.rmtree(tmp_dir + '/main/kotlin/utils/versions/v_1_4')
|
||||
shutil.rmtree(tmp_dir + '/main/kotlin/utils/versions/default')
|
||||
else:
|
||||
shutil.rmtree(tmp_dir + '/main/kotlin/utils/versions/v_1_4')
|
||||
shutil.rmtree(tmp_dir + '/main/kotlin/utils/versions/v_1_6')
|
||||
for v in kotlin_plugin_versions.many_versions:
|
||||
if v != version:
|
||||
shutil.rmtree(
|
||||
tmp_dir + '/main/kotlin/utils/versions/v_' + v.replace('.', '_'))
|
||||
|
||||
srcs = find_sources(tmp_dir)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
kotlin.code.style=official
|
||||
kotlinVersion=1.5.21
|
||||
kotlinVersion=1.6.20
|
||||
|
||||
GROUP=com.github.codeql
|
||||
VERSION_NAME=0.0.1
|
||||
|
||||
@@ -10,16 +10,28 @@ def is_windows():
|
||||
return True
|
||||
return False
|
||||
|
||||
many_versions = [ '1.4.32', '1.5.31', '1.6.10' ]
|
||||
many_versions = [ '1.4.32', '1.5.31', '1.6.10', '1.6.20' ]
|
||||
|
||||
def get_single_version():
|
||||
# TODO: `shell=True` is a workaround to get CI working on Windows. It breaks the build on Linux.
|
||||
versionOutput = subprocess.run(['kotlinc', '-version'], capture_output=True, text=True, shell=is_windows())
|
||||
m = re.match(r'.* kotlinc-jvm ([0-9]+\.[0-9]+\.)[0-9]+ .*', versionOutput.stderr)
|
||||
m = re.match(r'.* kotlinc-jvm ([0-9]+)\.([0-9]+\.)([0-9]+) .*', versionOutput.stderr)
|
||||
if m is None:
|
||||
raise Exception('Cannot detect version of kotlinc (got ' + str(versionOutput) + ')')
|
||||
prefix = m.group(1)
|
||||
for version in many_versions:
|
||||
if version.startswith(prefix):
|
||||
major = m.group(1)
|
||||
minor = m.group(2)
|
||||
patch = m.group(3)
|
||||
current_version = f'{major}.{minor}.{patch}'
|
||||
matching_minor_versions = [ version for version in many_versions if version.startswith(f'{major}.{minor}') ]
|
||||
if len(matching_minor_versions) == 0:
|
||||
raise Exception(f'Cannot find a matching minor version for kotlinc version {current_version} (got {versionOutput}; know about {str(many_versions)})')
|
||||
|
||||
matching_minor_versions.sort()
|
||||
|
||||
for version in matching_minor_versions:
|
||||
if current_version >= version:
|
||||
return version
|
||||
raise Exception('No suitable kotlinc version found for ' + prefix + ' (got ' + str(versionOutput) + '; know about ' + str(many_versions) + ')')
|
||||
|
||||
return matching_minor_versions[-1]
|
||||
|
||||
raise Exception(f'No suitable kotlinc version found for {current_version} (got {versionOutput}; know about {str(many_versions)})')
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.github.codeql
|
||||
|
||||
import com.github.codeql.utils.*
|
||||
import com.github.codeql.utils.versions.isRawType
|
||||
import com.semmle.extractor.java.OdasaOutput
|
||||
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
|
||||
import org.jetbrains.kotlin.backend.common.lower.parentsWithSelf
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.isRawType
|
||||
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
@@ -601,7 +601,6 @@ open class KotlinUsesExtractor(
|
||||
s.classifier.owner is IrClass -> {
|
||||
val classifier: IrClassifierSymbol = s.classifier
|
||||
val cls: IrClass = classifier.owner as IrClass
|
||||
|
||||
val args = if (s.isRawType()) null else s.arguments
|
||||
|
||||
return useSimpleTypeClass(cls, args, s.hasQuestionMark)
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.isRawType
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
|
||||
|
||||
fun IrSimpleType.isRawType() = this.isRawType()
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.isRawType
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
|
||||
|
||||
fun IrSimpleType.isRawType() = this.isRawType()
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.isRawType
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
|
||||
|
||||
fun IrSimpleType.isRawType() = this.isRawType()
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import com.github.codeql.KotlinUsesExtractor
|
||||
import com.github.codeql.Severity
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.psi2ir.generators.DeclarationStubGeneratorImpl
|
||||
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
fun <TIrStub> KotlinUsesExtractor.getIrStubFromDescriptor(generateStub: (DeclarationStubGenerator) -> TIrStub) : TIrStub? =
|
||||
(pluginContext.symbolTable as? SymbolTable) ?.let {
|
||||
val stubGenerator = DeclarationStubGeneratorImpl(pluginContext.moduleDescriptor, it, pluginContext.irBuiltIns)
|
||||
generateStub(stubGenerator)
|
||||
} ?: run {
|
||||
logger.error("Plugin context has no symbol table, couldn't get IR stub")
|
||||
null
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import org.jetbrains.kotlin.ir.IrFileEntry
|
||||
|
||||
typealias FileEntry = IrFileEntry
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
|
||||
|
||||
fun functionN(pluginContext: IrPluginContext) = pluginContext.irBuiltIns::functionN
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.backend.common.psi.PsiSourceManager
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.getKtFile
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
class Psi2Ir: Psi2IrFacade {
|
||||
override fun getKtFile(irFile: IrFile): KtFile? {
|
||||
return irFile.getKtFile()
|
||||
}
|
||||
|
||||
override fun findPsiElement(irElement: IrElement, irFile: IrFile): PsiElement? {
|
||||
return PsiSourceManager.findPsiElement(irElement, irFile)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.isRawType
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
|
||||
|
||||
fun IrSimpleType.isRawType() = this.isRawType()
|
||||
Reference in New Issue
Block a user