Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 27ab487

Browse files
committed
Kotlin: simplify kotlinc wrapper
1 parent aee3c0d commit 27ab487

2 files changed

Lines changed: 8 additions & 16 deletions

File tree

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1+
/.kotlinc_version
12
/.kotlinc_installed
2-
/.kotlinc_installed_version
3-
/.kotlinc_selected_version

java/kotlin-extractor/deps/dev/kotlinc

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ def options():
4040

4141
url_template = 'https://github.com/JetBrains/kotlin/releases/download/v{version}/kotlin-compiler-{version}.zip'
4242
this_dir = pathlib.Path(__file__).resolve().parent
43-
version_file = this_dir / ".kotlinc_selected_version"
44-
installed_version_file = this_dir / ".kotlinc_installed_version"
43+
version_file = this_dir / ".kotlinc_version"
4544
install_dir = this_dir / ".kotlinc_installed"
4645
windows_ripunzip = this_dir.parents[4] / "resources" / "lib" / "windows" / "ripunzip" / "ripunzip.exe"
4746

@@ -73,9 +72,9 @@ def check_version(version: str):
7372
raise
7473

7574

76-
def get_version(file: pathlib.Path) -> str:
75+
def get_version():
7776
try:
78-
return file.read_text()
77+
return version_file.read_text()
7978
except FileNotFoundError:
8079
return None
8180

@@ -121,9 +120,6 @@ def clear():
121120
if install_dir.exists():
122121
print(f"removing {install_dir}", file=sys.stderr)
123122
shutil.rmtree(install_dir)
124-
if installed_version_file.exists():
125-
print(f"removing {installed_version_file}", file=sys.stderr)
126-
installed_version_file.unlink()
127123
if version_file.exists():
128124
print(f"removing {version_file}", file=sys.stderr)
129125
version_file.unlink()
@@ -133,18 +129,15 @@ def main(opts, forwarded_opts):
133129
if opts.clear:
134130
clear()
135131
return
132+
current_version = get_version()
136133
if opts.select:
137134
check_version(opts.select)
138-
version_file.write_text(opts.select)
139135
selected_version = opts.select
140136
else:
141-
selected_version = get_version(version_file)
142-
if not selected_version:
143-
selected_version = DEFAULT_VERSION
144-
version_file.write_text(selected_version)
145-
if get_version(installed_version_file) != selected_version:
137+
selected_version = current_version or DEFAULT_VERSION
138+
if selected_version != current_version:
146139
install(selected_version)
147-
installed_version_file.write_text(selected_version)
140+
version_file.write_text(selected_version)
148141
if opts.version or (opts.select and not forwarded_opts):
149142
print(f"info: kotlinc-jvm {selected_version} (codeql dev wrapper)", file=sys.stderr)
150143
return

0 commit comments

Comments
 (0)