Skip to content

Commit 6652c27

Browse files
authored
Merge pull request #9236 from igfoo/igfoo/kotlinc
Kotlin: Use 'which' to find kotlinc
2 parents 7375970 + 3fd6158 commit 6652c27

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

java/kotlin-extractor/build.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ def is_windows():
3535
return True
3636
return False
3737

38+
# kotlinc might be kotlinc.bat or kotlinc.cmd on Windows, so we use `which` to find out what it is
39+
kotlinc = shutil.which('kotlinc')
40+
if kotlinc is None:
41+
print("Cannot build the Kotlin extractor: no kotlinc found on your PATH", file = sys.stderr)
42+
sys.exit(1)
3843

39-
kotlinc = 'kotlinc.bat' if is_windows() else 'kotlinc'
4044
javac = 'javac'
4145
kotlin_dependency_folder = args.dependencies
4246

@@ -201,10 +205,6 @@ def compile_standalone(version):
201205
'build/temp_src',
202206
version)
203207

204-
if shutil.which(kotlinc) == None:
205-
print("Cannot build the Kotlin extractor: no '%s' found on your PATH" % kotlinc, file = sys.stderr)
206-
sys.exit(1)
207-
208208
if args.many:
209209
for version in kotlin_plugin_versions.many_versions:
210210
compile_standalone(version)

java/kotlin-extractor/kotlin_plugin_versions.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import platform
22
import re
3+
import shutil
34
import subprocess
45
import sys
56

@@ -26,11 +27,11 @@ class KotlincNotFoundException(Exception):
2627
pass
2728

2829
def get_single_version(fakeVersionOutput = None):
29-
# TODO: `shell=True` is a workaround to get CI working on Windows. It breaks the build on Linux.
30-
try:
31-
versionOutput = subprocess.run(['kotlinc', '-version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=is_windows()).stderr if fakeVersionOutput is None else fakeVersionOutput
32-
except FileNotFoundError as e:
33-
raise KotlincNotFoundException(e)
30+
# kotlinc might be kotlinc.bat or kotlinc.cmd on Windows, so we use `which` to find out what it is
31+
kotlinc = shutil.which('kotlinc')
32+
if kotlinc is None:
33+
raise KotlincNotFoundException()
34+
versionOutput = subprocess.run([kotlinc, '-version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).stderr if fakeVersionOutput is None else fakeVersionOutput
3435
m = re.match(r'.* kotlinc-jvm ([0-9]+\.[0-9]+\.[0-9]+) .*', versionOutput)
3536
if m is None:
3637
raise Exception('Cannot detect version of kotlinc (got ' + str(versionOutput) + ')')

0 commit comments

Comments
 (0)