2022-05-24 14:40:16 +03:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2022-03-15 15:21:25 +03:00
|
|
|
import platform
|
2021-12-01 16:00:19 +03:00
|
|
|
import re
|
2022-05-20 14:44:55 +03:00
|
|
|
import shutil
|
2021-12-01 16:00:19 +03:00
|
|
|
import subprocess
|
2022-04-08 15:58:28 +03:00
|
|
|
import sys
|
2021-12-01 16:00:19 +03:00
|
|
|
|
2022-03-15 15:21:25 +03:00
|
|
|
def is_windows():
|
|
|
|
'''Whether we appear to be running on Windows'''
|
|
|
|
if platform.system() == 'Windows':
|
|
|
|
return True
|
|
|
|
if platform.system().startswith('CYGWIN'):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2022-04-13 00:25:51 +03:00
|
|
|
def version_tuple_to_string(version):
|
2022-06-16 15:25:59 +03:00
|
|
|
return f'{version[0]}.{version[1]}.{version[2]}{version[3]}'
|
2022-04-13 00:25:51 +03:00
|
|
|
|
|
|
|
def version_string_to_tuple(version):
|
2022-06-16 15:25:59 +03:00
|
|
|
m = re.match(r'([0-9]+)\.([0-9]+)\.([0-9]+)(.*)', version)
|
|
|
|
return tuple([int(m.group(i)) for i in range(1, 4)] + [m.group(4)])
|
2022-04-13 00:25:51 +03:00
|
|
|
|
2023-02-03 19:19:29 +03:00
|
|
|
# Version number used by CI.
|
|
|
|
ci_version = '1.8.10'
|
2022-08-12 15:27:06 +03:00
|
|
|
|
2023-05-24 15:32:52 +03:00
|
|
|
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' ]
|
2021-12-01 16:00:19 +03:00
|
|
|
|
2022-04-13 00:25:51 +03:00
|
|
|
many_versions_tuples = [version_string_to_tuple(v) for v in many_versions]
|
|
|
|
|
2022-05-19 23:54:18 +03:00
|
|
|
class KotlincNotFoundException(Exception):
|
|
|
|
pass
|
|
|
|
|
2022-04-13 00:25:51 +03:00
|
|
|
def get_single_version(fakeVersionOutput = None):
|
2022-05-20 14:44:55 +03:00
|
|
|
# kotlinc might be kotlinc.bat or kotlinc.cmd on Windows, so we use `which` to find out what it is
|
|
|
|
kotlinc = shutil.which('kotlinc')
|
|
|
|
if kotlinc is None:
|
|
|
|
raise KotlincNotFoundException()
|
2022-05-20 14:59:04 +03:00
|
|
|
versionOutput = subprocess.run([kotlinc, '-version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).stderr if fakeVersionOutput is None else fakeVersionOutput
|
2022-09-22 12:23:29 +03:00
|
|
|
m = re.match(r'.* kotlinc-jvm ([0-9]+\.[0-9]+\.[0-9]+-?[a-zA-Z]*) .*', versionOutput)
|
2021-12-01 16:00:19 +03:00
|
|
|
if m is None:
|
2022-03-15 15:21:25 +03:00
|
|
|
raise Exception('Cannot detect version of kotlinc (got ' + str(versionOutput) + ')')
|
2022-04-13 00:25:51 +03:00
|
|
|
current_version = version_string_to_tuple(m.group(1))
|
2022-04-07 17:20:47 +03:00
|
|
|
|
2023-06-06 16:09:55 +03:00
|
|
|
many_versions_tuples.sort(reverse = True)
|
2022-04-07 17:20:47 +03:00
|
|
|
|
2023-06-06 16:09:55 +03:00
|
|
|
for version in many_versions_tuples:
|
2022-10-25 20:50:08 +03:00
|
|
|
if version[0:3] <= current_version[0:3]:
|
2022-04-13 00:25:51 +03:00
|
|
|
return version_tuple_to_string(version)
|
2022-04-07 17:20:47 +03:00
|
|
|
|
|
|
|
raise Exception(f'No suitable kotlinc version found for {current_version} (got {versionOutput}; know about {str(many_versions)})')
|
2022-04-08 15:58:28 +03:00
|
|
|
|
|
|
|
def get_latest_url():
|
2022-08-12 15:27:06 +03:00
|
|
|
url = 'https://github.com/JetBrains/kotlin/releases/download/v' + ci_version + '/kotlin-compiler-' + ci_version + '.zip'
|
2022-04-08 15:58:28 +03:00
|
|
|
return url
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
args = sys.argv
|
2022-04-13 00:25:51 +03:00
|
|
|
if len(args) < 2:
|
2022-04-08 15:58:28 +03:00
|
|
|
raise Exception("Bad arguments")
|
|
|
|
command = args[1]
|
|
|
|
if command == 'latest-url':
|
|
|
|
print(get_latest_url())
|
2022-04-13 00:25:51 +03:00
|
|
|
elif command == 'single-version':
|
|
|
|
print(get_single_version(*args[2:]))
|
2022-04-08 15:58:28 +03:00
|
|
|
else:
|
|
|
|
raise Exception("Unknown command: " + command)
|
|
|
|
|