Kotlin/Bazel: fix wrapper on Windows

This commit is contained in:
Paolo Tranquilli
2024-04-15 13:13:31 +02:00
parent b07fa70133
commit e53ef4acd2
2 changed files with 11 additions and 4 deletions

View File

@@ -15,7 +15,6 @@ is available in `resources/lib/windows/ripunzip` then).
"""
import pathlib
import os
import urllib
import urllib.request
import urllib.error
@@ -29,6 +28,7 @@ import io
DEFAULT_VERSION = "1.9.0"
def options():
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument("--select")
@@ -71,6 +71,7 @@ def check_version(version: str):
raise Error(f"Version {version} not found in github.com/JetBrains/kotlin/releases") from e
raise
def get_version(file: pathlib.Path) -> str:
try:
return file.read_text()
@@ -108,9 +109,12 @@ def forward(forwarded_opts):
kotlinc = install_dir / "kotlinc" / "bin" / "kotlinc"
if platform.system() == "Windows":
kotlinc = kotlinc.with_suffix(".bat")
args = [sys.argv[0]]
assert kotlinc.exists(), f"{kotlinc} not found"
args = [kotlinc]
args.extend(forwarded_opts)
os.execv(kotlinc, args)
ret = subprocess.run(args).returncode
sys.exit(ret)
def clear():
if install_dir.exists():
@@ -123,6 +127,7 @@ def clear():
print(f"removing {version_file}", file=sys.stderr)
version_file.unlink()
def main(opts, forwarded_opts):
if opts.clear:
clear()

View File

@@ -1,2 +1,4 @@
@echo off
python3 %~dp0/kotlinc
python "%~dp0/kotlinc" %*
exit /b %ERRORLEVEL%