Skip to content

Commit 4aa0a8e

Browse files
committed
Kotlin: make wrapper more robust for windows
1 parent c014cd8 commit 4aa0a8e

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

java/kotlin-extractor/current_kotlin_version.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
kotlinc = shutil.which('kotlinc')
66
if kotlinc is None:
77
raise Exception("kotlinc not found")
8-
output = subprocess.run([kotlinc, "-version"], text=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE,
9-
check=True).stderr
10-
m = re.match(r'.* kotlinc-jvm ([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z][a-zA-Z0-9]*)?) .*', output)
8+
res = subprocess.run([kotlinc, "-version"], text=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
9+
if res.returncode != 0:
10+
raise Exception(f"kotlinc -version failed: {res.stderr}")
11+
m = re.match(r'.* kotlinc-jvm ([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z][a-zA-Z0-9]*)?) .*', res.stderr)
1112
if m is None:
12-
raise Exception(f'Cannot detect version of kotlinc (got {output})')
13+
raise Exception(f'Cannot detect version of kotlinc (got {res.stderr})')
1314
print(m[1])

java/kotlin-extractor/deps/dev/kotlinc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import io
2828
import os
2929

3030
DEFAULT_VERSION = "1.9.0"
31-
DEVNULL = open(os.devnull, "w")
3231

3332
def options():
3433
parser = argparse.ArgumentParser(add_help=False)
@@ -80,7 +79,12 @@ def get_version():
8079

8180

8281
def install(version: str, quiet: bool):
83-
info_out = DEVNULL if quiet else sys.stderr
82+
if quiet:
83+
info_out = subprocess.DEVNULL
84+
info = lambda *args: None
85+
else:
86+
info_out = sys.stderr
87+
info = lambda *args: print(*args, file=sys.stderr)
8488
url = url_template.format(version=version)
8589
if install_dir.exists():
8690
shutil.rmtree(install_dir)
@@ -89,20 +93,20 @@ def install(version: str, quiet: bool):
8993
if ripunzip is None and platform.system() == "Windows" and windows_ripunzip.exists():
9094
ripunzip = windows_ripunzip
9195
if ripunzip:
92-
print(f"downloading and extracting {url} using ripunzip", file=info_out)
96+
info(f"downloading and extracting {url} using ripunzip")
9397
subprocess.run([ripunzip, "unzip-uri", url], stdout=info_out, stderr=info_out, cwd=install_dir,
9498
check=True)
9599
return
96100
with io.BytesIO() as buffer:
97-
print(f"downloading {url}", file=info_out)
101+
info(f"downloading {url}")
98102
with urllib.request.urlopen(url) as response:
99103
while True:
100104
bytes = response.read()
101105
if not bytes:
102106
break
103107
buffer.write(bytes)
104108
buffer.seek(0)
105-
print(f"extracting kotlin-compiler-{version}.zip", file=info_out)
109+
info(f"extracting kotlin-compiler-{version}.zip")
106110
with ZipFilePreservingPermissions(buffer) as archive:
107111
archive.extractall(install_dir)
108112

0 commit comments

Comments
 (0)