Skip to content

Commit 6e57e45

Browse files
authored
Merge pull request #10034 from tamasvajk/kotlin-build-versions-2
Kotlin: Change handling of version variants in build script
2 parents f106e06 + ccef2f7 commit 6e57e45

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+40
-462
lines changed

java/kotlin-extractor/build.gradle

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,12 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
2727
sourceSets {
2828
main {
2929
kotlin {
30-
// change the excludes for building with other versions:
30+
// change the excludes for building with other versions.
31+
// Currently 1.7.0 is configured:
3132
excludes = [
3233
"utils/versions/v_1_4_32/*.kt",
33-
"utils/versions/v_1_5_0/*.kt",
34-
"utils/versions/v_1_5_10/*.kt",
35-
"utils/versions/v_1_5_21/*.kt",
36-
"utils/versions/v_1_5_31/*.kt",
37-
"utils/versions/v_1_6_10/*.kt",
38-
"utils/versions/v_1_6_20/*.kt",
39-
// "utils/versions/v_1_7_0/*.kt",
34+
"utils/versions/v_1_5_21/Descriptors.kt",
35+
"utils/versions/v_1_6_10/Descriptors.kt",
4036
]
4137
}
4238
}

java/kotlin-extractor/build.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import os.path
1212
import sys
1313
import shlex
14+
import distutils
15+
from distutils import dir_util
1416

1517

1618
def parse_args():
@@ -37,10 +39,11 @@ def is_windows():
3739
return True
3840
return False
3941

42+
4043
# kotlinc might be kotlinc.bat or kotlinc.cmd on Windows, so we use `which` to find out what it is
4144
kotlinc = shutil.which('kotlinc')
4245
if kotlinc is None:
43-
print("Cannot build the Kotlin extractor: no kotlinc found on your PATH", file = sys.stderr)
46+
print("Cannot build the Kotlin extractor: no kotlinc found on your PATH", file=sys.stderr)
4447
sys.exit(1)
4548

4649
javac = 'javac'
@@ -166,7 +169,7 @@ def transform_to_embeddable(srcs):
166169
f.write(content)
167170

168171

169-
def compile(jars, java_jars, dependency_folder, transform_to_embeddable, output, build_dir, version):
172+
def compile(jars, java_jars, dependency_folder, transform_to_embeddable, output, build_dir, current_version):
170173
classpath = patterns_to_classpath(dependency_folder, jars)
171174
java_classpath = patterns_to_classpath(dependency_folder, java_jars)
172175

@@ -176,9 +179,29 @@ def compile(jars, java_jars, dependency_folder, transform_to_embeddable, output,
176179
shutil.rmtree(tmp_src_dir)
177180
shutil.copytree('src', tmp_src_dir)
178181

179-
for v in kotlin_plugin_versions.many_versions:
180-
if v != version:
181-
d = tmp_src_dir + '/main/kotlin/utils/versions/v_' + v.replace('.', '_')
182+
include_version_folder = tmp_src_dir + '/main/kotlin/utils/versions/to_include'
183+
os.makedirs(include_version_folder)
184+
185+
parsed_current_version = kotlin_plugin_versions.version_string_to_tuple(
186+
current_version)
187+
188+
for version in kotlin_plugin_versions.many_versions:
189+
parsed_version = kotlin_plugin_versions.version_string_to_tuple(
190+
version)
191+
if parsed_version[0] < parsed_current_version[0] or \
192+
(parsed_version[0] == parsed_current_version[0] and parsed_version[1] < parsed_current_version[1]) or \
193+
(parsed_version[0] == parsed_current_version[0] and parsed_version[1] == parsed_current_version[1] and parsed_version[2] <= parsed_current_version[2]):
194+
d = tmp_src_dir + '/main/kotlin/utils/versions/v_' + \
195+
version.replace('.', '_')
196+
if os.path.exists(d):
197+
# copy and overwrite files from the version folder to the include folder
198+
distutils.dir_util.copy_tree(d, include_version_folder)
199+
200+
# remove all version folders:
201+
for version in kotlin_plugin_versions.many_versions:
202+
d = tmp_src_dir + '/main/kotlin/utils/versions/v_' + \
203+
version.replace('.', '_')
204+
if os.path.exists(d):
182205
shutil.rmtree(d)
183206

184207
srcs = find_sources(tmp_src_dir)
@@ -209,6 +232,7 @@ def compile_standalone(version):
209232
'build_standalone_' + version,
210233
version)
211234

235+
212236
if args.single_version:
213237
compile_standalone(args.single_version)
214238
elif args.many:

java/kotlin-extractor/kotlin_plugin_versions.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ def version_string_to_tuple(version):
2121
m = re.match(r'([0-9]+)\.([0-9]+)\.([0-9]+)(.*)', version)
2222
return tuple([int(m.group(i)) for i in range(1, 4)] + [m.group(4)])
2323

24+
# Version number used by CI. It needs to be one of the versions in many_versions.
25+
ci_version = '1.7.0'
26+
27+
# Version numbers in the list need to be in semantically increasing order
2428
many_versions = [ '1.4.32', '1.5.0', '1.5.10', '1.5.21', '1.5.31', '1.6.10', '1.6.20', '1.7.0' ]
2529

2630
many_versions_tuples = [version_string_to_tuple(v) for v in many_versions]
@@ -53,8 +57,9 @@ def get_single_version(fakeVersionOutput = None):
5357
raise Exception(f'No suitable kotlinc version found for {current_version} (got {versionOutput}; know about {str(many_versions)})')
5458

5559
def get_latest_url():
56-
version = many_versions[-1]
57-
url = 'https://github.com/JetBrains/kotlin/releases/download/v' + version + '/kotlin-compiler-' + version + '.zip'
60+
if ci_version not in many_versions:
61+
raise Exception('CI version must be one of many_versions')
62+
url = 'https://github.com/JetBrains/kotlin/releases/download/v' + ci_version + '/kotlin-compiler-' + ci_version + '.zip'
5863
return url
5964

6065
if __name__ == "__main__":

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_5_0/Descriptors.kt

Lines changed: 0 additions & 17 deletions
This file was deleted.

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_5_0/FileEntry.kt

Lines changed: 0 additions & 5 deletions
This file was deleted.

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_5_0/Functions.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_5_0/IsUnderscoreParameter.kt

Lines changed: 0 additions & 19 deletions
This file was deleted.

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_5_0/Psi2Ir.kt

Lines changed: 0 additions & 19 deletions
This file was deleted.

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_5_0/Types.kt

Lines changed: 0 additions & 7 deletions
This file was deleted.

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_5_0/withHasQuestionMark.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)