mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Bazel/Kotlin: use a wrapper to get the current kotlin version
This commit is contained in:
13
java/kotlin-extractor/current_kotlin_version.py
Normal file
13
java/kotlin-extractor/current_kotlin_version.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import subprocess
|
||||
import re
|
||||
import shutil
|
||||
|
||||
kotlinc = shutil.which('kotlinc')
|
||||
if kotlinc is None:
|
||||
raise Exception("kotlinc not found")
|
||||
output = subprocess.run([kotlinc, "-version"], text=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE,
|
||||
check=True).stderr
|
||||
m = re.match(r'.* kotlinc-jvm ([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z][a-zA-Z0-9]*)?) .*', output)
|
||||
if m is None:
|
||||
raise Exception(f'Cannot detect version of kotlinc (got {output})')
|
||||
print(m[1])
|
||||
@@ -75,16 +75,12 @@ def _get_default_version(repository_ctx):
|
||||
return default_version
|
||||
if not repository_ctx.which("kotlinc"):
|
||||
return DEFAULT_VERSION
|
||||
res = repository_ctx.execute(["kotlinc", "-version"])
|
||||
if not res:
|
||||
fail("kotlinc -version failed: %s" % res.stderr)
|
||||
out = (res.stdout or res.stderr).split(" ")
|
||||
if "kotlinc-jvm" not in out:
|
||||
fail("kotlinc -version output does not contain 'kotlinc-jvm': %s" % out)
|
||||
kotlinc_jvm_index = out.index("kotlinc-jvm")
|
||||
if kotlinc_jvm_index + 1 >= len(out):
|
||||
fail("kotlinc -version output does not contain a version after 'kotlinc-jvm': %s" % out)
|
||||
return out[kotlinc_jvm_index + 1]
|
||||
kotlin_plugin_versions = repository_ctx.path(Label("//java/kotlin-extractor:current_kotlin_version.py"))
|
||||
python = repository_ctx.which("python3") or repository_ctx.which("python")
|
||||
res = repository_ctx.execute([python, kotlin_plugin_versions])
|
||||
if res.return_code != 0:
|
||||
fail(res.stderr)
|
||||
return res.stdout.strip()
|
||||
|
||||
def _get_available_version(version):
|
||||
for available_version in reversed(VERSIONS):
|
||||
|
||||
Reference in New Issue
Block a user