forked from spelunky-fyi/modlunky2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-exe.py
83 lines (63 loc) · 1.8 KB
/
build-exe.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# pylint: disable=invalid-name
import argparse
import subprocess
import os
from pathlib import Path
OPTIONAL_DATA = [
"dist/libogg.dll;.",
"dist/libvorbis.dll;.",
"dist/s99-client.exe;.",
]
DATA = [
"src/modlunky2/VERSION;.",
"src/modlunky2/static;static",
]
BASE_DIR = Path(__file__).parent.resolve()
DEBUG_DIR = Path("target/debug")
RELEASE_DIR = Path("target/release")
EXE_NAME = Path("modlunky2.exe")
def run_pyinstaller(debug):
pyinstaller_args = ["pyinstaller.exe", f"{BASE_DIR / 'pyinstaller-cli.py'}"]
for data in DATA:
pyinstaller_args.extend(["--add-data", data])
for data in OPTIONAL_DATA:
src, _, _ = data.partition(";")
if Path(src).exists():
pyinstaller_args.extend(["--add-data", data])
pyinstaller_args.extend(
[
"--name=modlunky2",
f"--icon={BASE_DIR / 'src/modlunky2/static/images/icon.ico'}",
"--clean",
"--onedir",
"--noconfirm",
]
)
if not debug:
pyinstaller_args.append("--noconsole")
subprocess.check_call(pyinstaller_args)
def build_launcher(debug):
args = [
"cargo",
"build",
"-p",
"launcher",
]
if not debug:
args.append("--release")
subprocess.check_call(args)
def main():
parser = argparse.ArgumentParser(description="Build modlunky2 exe")
parser.add_argument(
"--debug", action="store_true", help="Whether to build debug exe."
)
args = parser.parse_args()
run_pyinstaller(args.debug)
build_launcher(args.debug)
artifact_dir = RELEASE_DIR
if args.debug:
artifact_dir = DEBUG_DIR
print(f"exe successfully built at {artifact_dir / EXE_NAME}")
os.startfile(BASE_DIR / artifact_dir)
if __name__ == "__main__":
main()