This repository has been archived by the owner on Jul 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.py
147 lines (101 loc) · 4.6 KB
/
build.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import sys
import os
import subprocess
import shutil
import fnmatch
from pathlib import Path
curDir = Path(__file__).parent.absolute()
pythonExecutable = Path(sys.executable).absolute()
def main():
# type: () -> None
os.chdir(curDir.as_posix())
if sys.argv[-1] in operators.keys():
operators[sys.argv[-1]]()
else:
print("X Invalid command:", sys.argv[-1])
print("Available commands:", ", ".join([i for i in operators.keys()]))
def build(target):
# type: (str) -> None
toolchain = "i686-pc-windows-gnu" if target == "windows" else "i686-unknown-linux-gnu"
ext = ".exe" if target == "windows" else ""
launcherSourcePath = (curDir / "source/launcher").absolute()
sourceExe = (curDir / "source/launcher/target/{toolchain}/release/bgarmor{ext}".format(toolchain=toolchain, ext=ext)).absolute()
targetExe = (curDir / ("release/launcher/Launcher" + ext)).absolute()
print("> Started build for target:", toolchain)
if targetExe.exists():
print("> Deleted existing executable:", targetExe.as_posix())
targetExe.unlink()
os.chdir(launcherSourcePath.as_posix())
args = ["cargo", "build", "--target=" + toolchain, "--release"]
print("> Running cargo build:", " ".join(args))
subprocess.call(args)
os.chdir(curDir.as_posix())
print("> Copying executable to:", targetExe.as_posix())
shutil.copy2(sourceExe.as_posix(), targetExe.as_posix())
if target != "windows":
args = ["upx", "-5", targetExe.as_posix()]
print("> Running upx on executable:", " ".join(args))
subprocess.call(args)
print("> Done!")
def minify():
# type: () -> None
script = curDir / "source/scripts/minify_launcher.py"
subprocess.call([pythonExecutable.as_posix(), script.as_posix()])
def clean():
# type: () -> None
directory = curDir / "source/launcher/target"
if directory.exists():
print("> Deleting directory:", directory.as_posix())
shutil.rmtree(directory.as_posix())
def export(_target):
# type: (str) -> None
minify()
projectFile = (curDir / "project.godot").absolute()
exportPath = (curDir / "bin").absolute()
if not exportPath.exists():
exportPath.mkdir()
(exportPath / ".gdignore").touch()
targets = {
"Windows32": "Windows Desktop 32",
"Windows64": "Windows Desktop 64",
"Linux32": "Linux 32",
"Linux64": "Linux 64",
}
for target in targets.keys():
if _target == "All" or target.startswith(_target):
name = targets[target]
targetPath = (exportPath / target).absolute()
if targetPath.exists():
shutil.rmtree(targetPath.as_posix())
targetPath.mkdir()
print("> Exporting for target:", name)
args = ["godot", "--export-debug", name, "--no-window", projectFile.as_posix()]
print(" > Running Godot export:", " ".join(args))
subprocess.call(args)
print(" > Copying release files to:", targetPath.as_posix())
shutil.copytree((curDir / "release").as_posix(), (targetPath / "release").as_posix())
print(" > Deleting ignored files from:", targetPath.as_posix())
ignoredPatterns = [".gitignore", "__pycache__"]
for pattern in ignoredPatterns:
for folder, subfolders, files in os.walk(targetPath.as_posix()):
items = subfolders + files
for item in items:
curItem = (Path(folder) / item).absolute()
if fnmatch.fnmatch(curItem.name, pattern):
if curItem.is_file():
print(" > Deleted file:", curItem.as_posix())
curItem.unlink()
elif curItem.is_dir():
print(" > Deleted directory:", curItem.as_posix())
shutil.rmtree(curItem.as_posix())
print("> Done!")
operators = {
"clean": lambda: clean(),
"export": lambda: export("All"),
"export_windows": lambda: export("Windows"),
"export_linux": lambda: export("Linux"),
"launcher_windows": lambda: build("windows"),
"launcher_linux": lambda: build("linux"),
"minify": lambda: minify(),
} # type: dict[str, object]
main()