-
Notifications
You must be signed in to change notification settings - Fork 20
/
kex.py
executable file
·66 lines (57 loc) · 1.66 KB
/
kex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/python3
import os.path
import re
import subprocess
import sys
KEX_VERSION = "0.0.11"
HEAP_MEMORY_SIZE = "8g"
STACK_MEMORY_SIZE = "1g"
kex_home = os.path.dirname(os.path.realpath(__file__))
MODULES_FILE = os.path.join(kex_home, "runtime-deps", "modules.info")
def get_jvm_version() -> int:
pattern = '\"(1.)?(\d+).*\"'
runner = subprocess.Popen(
["java", "-version"],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
stdout, stderr = runner.communicate()
version = re.search(pattern, stdout.decode()).groups()[1]
return int(version)
def get_jvm_args() -> list [str]:
version = get_jvm_version()
if version < 8:
print("Only Java version 8+ is supported", file=sys.stderr)
quit()
elif version == 8:
return []
else:
modules = open(MODULES_FILE).read()
args = []
for line in modules.splitlines():
args.append("--add-opens")
args.append(line)
args.append("--illegal-access=warn")
return args
def run_kex(args: list [str]):
kex_env = os.environ.copy()
kex_env["KEX_HOME"] = kex_home
command = ["java",
"-Xmx{}".format(HEAP_MEMORY_SIZE),
"-Djava.security.manager",
"-Djava.security.policy=={}".format(os.path.join(kex_home, "kex.policy")),
"-Dlogback.statusListenerClass=ch.qos.logback.core.status.NopStatusListener"
]
command.extend(get_jvm_args())
command.extend([
"-jar", os.path.join(kex_home, "kex-runner", "target", "kex-runner-{}-jar-with-dependencies.jar".format(KEX_VERSION))
])
command.extend(args)
kexProcess = subprocess.Popen(command, env=kex_env)
kexProcess.wait()
return kexProcess.returncode
def main() -> int:
return run_kex(sys.argv[1:])
if __name__ == "__main__":
returnCode = main()
sys.exit(returnCode)