blob: 3bcf9b773d125ebfeaf62595f6da40a3cd1a6168 [file] [log] [blame]
Ian Zernydcb172e2022-02-22 15:36:45 +01001#!/usr/bin/env python3
Morten Krogh-Jespersenc69a5542021-09-23 08:10:23 +02002# Copyright (c) 2021, the R8 project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5
Morten Krogh-Jespersen5b557362022-02-16 11:41:48 +01006import utils
7if utils.is_python3():
8 from html.parser import HTMLParser
9 import urllib.request
10 url_request = urllib.request
11else:
12 from HTMLParser import HTMLParser
13 import urllib
Morten Krogh-Jespersen3204fc02022-02-16 11:46:08 +010014 url_request = urllib
Morten Krogh-Jespersenc69a5542021-09-23 08:10:23 +020015import os
16import sys
Morten Krogh-Jespersenc69a5542021-09-23 08:10:23 +020017
18JETBRAINS_KOTLIN_MAVEN_URL = "https://maven.pkg.jetbrains.space/kotlin/p/" \
19 "kotlin/bootstrap/org/jetbrains/kotlin/"
20KOTLIN_RELEASE_URL = JETBRAINS_KOTLIN_MAVEN_URL + "kotlin-compiler/"
21
22def download_newest():
Morten Krogh-Jespersen5b557362022-02-16 11:41:48 +010023 response = url_request.urlopen(KOTLIN_RELEASE_URL)
Morten Krogh-Jespersenc69a5542021-09-23 08:10:23 +020024 if response.getcode() != 200:
25 raise Exception('Url: %s \n returned %s'
26 % (KOTLIN_RELEASE_URL, response.getcode()))
Morten Krogh-Jespersenbb396912022-02-15 15:14:05 +010027 content = str(response.read())
Morten Krogh-Jespersenc69a5542021-09-23 08:10:23 +020028 release_candidates = []
29
30 class HTMLContentParser(HTMLParser):
31 def handle_data(self, data):
32 if ('-dev-' in data):
33 release_candidates.append(data)
34
35 parser = HTMLContentParser()
36 parser.feed(content)
37
38 top_most_version = (0, 0, 0, 0)
39 top_most_version_and_build = None
40
41 for version in release_candidates:
42 # The compiler version is on the form <major>.<minor>.<revision>-dev-<build>/
43 version = version.replace('/', '')
44 version_build_args = version.split('-')
45 version_components = version_build_args[0].split('.')
46 version_components.append(version_build_args[2])
47 current_version = tuple(map(int, version_components))
48 if (current_version > top_most_version):
49 top_most_version = current_version
50 top_most_version_and_build = version
51
52 if (top_most_version_and_build is None):
53 raise Exception('Url: %s \n returned %s'
54 % (KOTLIN_RELEASE_URL, response.getcode()))
55
56 # We can now download all files related to the kotlin compiler version.
57 print("Downloading version: " + top_most_version_and_build)
58
59 kotlinc_lib = os.path.join(
60 utils.THIRD_PARTY, "kotlin", "kotlin-compiler-dev", "kotlinc", "lib")
61
62 utils.DownloadFromGoogleCloudStorage(
63 os.path.join(
64 utils.THIRD_PARTY, "kotlin", "kotlin-compiler-dev.tar.gz.sha1"))
65
66 download_and_save(
67 JETBRAINS_KOTLIN_MAVEN_URL + "kotlin-compiler/{0}/kotlin-compiler-{0}.jar"
68 .format(top_most_version_and_build), kotlinc_lib, "kotlin-compiler.jar")
69 download_and_save(
70 JETBRAINS_KOTLIN_MAVEN_URL + "kotlin-stdlib/{0}/kotlin-stdlib-{0}.jar"
71 .format(top_most_version_and_build), kotlinc_lib, "kotlin-stdlib.jar")
72 download_and_save(
73 JETBRAINS_KOTLIN_MAVEN_URL + "kotlin-reflect/{0}/kotlin-reflect-{0}.jar"
74 .format(top_most_version_and_build), kotlinc_lib, "kotlin-reflect.jar")
Morten Krogh-Jespersen07ac4e72022-10-19 14:38:37 +020075 download_and_save(
76 JETBRAINS_KOTLIN_MAVEN_URL + "kotlin-script-runtime/{0}/kotlin-script-runtime-{0}.jar"
77 .format(top_most_version_and_build), kotlinc_lib, "kotlin-script-runtime.jar")
Morten Krogh-Jespersenc69a5542021-09-23 08:10:23 +020078
79
80def download_and_save(url, path, name):
81 print('Downloading: ' + url)
Morten Krogh-Jespersen5b557362022-02-16 11:41:48 +010082 url_request.urlretrieve(url, os.path.join(path, name))
Morten Krogh-Jespersenc69a5542021-09-23 08:10:23 +020083
84
85if __name__ == '__main__':
86 sys.exit(download_newest())
87