-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.py
More file actions
180 lines (150 loc) · 5.55 KB
/
Copy pathbuild.py
File metadata and controls
180 lines (150 loc) · 5.55 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import os
import sys
import shutil
import shlex
os.chdir(os.path.dirname(os.path.abspath(__file__)))
systems = [{
"name": "Mac",
"code": "mac",
"compiler": "Xcode",
"executable": ".app"
},{
"name": "Win64",
"code": "win",
"compiler": "Visual Studio 17 2022",
"executable": ".exe"
},{
"name": "Linux",
"code": "linux",
"compiler": "Unix Makefiles",
"executable": ""
}]
if sys.platform == "darwin":
system = 0
import pty
elif sys.platform == "win32" or sys.platform == "cygwin":
system = 1
import subprocess
else:
system = 2
import pty
def fuzzy_match(term,data):
lower = str(term).replace(' ','').lower()
if lower != "":
for result in data:
if result.replace(' ','').lower().startswith(lower):
return result
def debug(string):
print('\033[1m'+string+'\033[0m')
def alert(string):
print('\033[1m\033[93m'+string+'\033[0m')
def error(string, exit_code=1):
print('\033[1m\033[91m'+string+'\033[0m')
#sys.exit(exit_code)
sys.exit(1)
def run_command(cmd,ignore_errors=False):
censored_command = cmd
#for secret in saved_data["secrets"].values(): TODO
# censored_command = censored_command.replace(secret,"***")
debug("RUNNING COMMAND: "+censored_command)
if systems[system]["code"] == "win":
os.environ['SYSTEMD_COLORS'] = '1'
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
while process.poll() == None:
print(process.stdout.readline().decode("UTF-8"),end='')
return_code = process.returncode
else:
return_code = pty.spawn(shlex.split(cmd), lambda fd: os.read(fd, 1024))
if return_code != 0:
if ignore_errors:
alert("Exited with return code "+str(return_code))
else:
error("Exited with return code "+str(return_code)+", exiting...",return_code)
def join(arr):
return '/'.join(arr)
def copy(path, output):
debug("COPYING PATH "+path+" TO "+output)
if not os.path.exists(path):
error("Invalid path: "+path)
if output.endswith('/'):
if not os.path.isdir(os.path.abspath(output+"..")):
error("Invalid path: "+output)
elif not os.path.isdir(os.path.dirname(output)):
error("Invalid path: "+output)
if os.path.isdir(path):
if os.path.exists(output):
shutil.rmtree(output)
shutil.copytree(path,output)
else:
shutil.copy2(path, output)
def create_dir(path):
debug("CREATING DIRECTORY "+path)
if os.path.isdir(path):
alert("Directory "+path+" already exists.")
return
os.makedirs(path)
def prepare():
debug("PREPARING DEPENDENCIES")
if systems[system]["code"] == "linux":
run_command("sudo apt-get update",True)
run_command("sudo apt install build-essential libgl1-mesa-dev libfontconfig1-dev libfreetype-dev libgtk-3-dev libx11-dev libx11-xcb-dev libxcb-cursor-dev libxcb-glx0-dev libxcb-icccm4-dev libxcb-image0-dev libxcb-keysyms1-dev libxcb-randr0-dev libxcb-render-util0-dev libxcb-shape0-dev libxcb-shm0-dev libxcb-sync-dev libxcb-util-dev libxcb-xfixes0-dev libxcb-xkb-dev libxcb1-dev libxext-dev libxfixes-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev libxrender-dev libatspi2.0-dev libvulkan-dev qt6-image-formats-plugins qt6-base-dev",True)
def configure():
debug("CONFIGURING")
cmd = "cmake -B \"build_"+systems[system]["code"]+"\" -G "
if systems[system]["code"] == "win":
run_command(cmd+"\""+systems[system]["compiler"]+"\" -T host=x64 -A x64")
else:
run_command(cmd+"\""+systems[system]["compiler"]+"\"")
def build(config):
debug("BUILDING "+config.upper()+" VERSION")
run_command("cmake --build \"build_"+systems[system]["code"]+"\" --config "+config+" --target borderless",systems[system]["code"]=="mac")
create_dir("artifact")
if systems[system]["code"] == "mac":
copy(join(["build_"+systems[system]["code"],"Release","borderless"+systems[system]["executable"]]),join(["artifact","borderless"+systems[system]["executable"]]))
run_command("macdeployqt "+join(["artifact","borderless"+systems[system]["executable"]])+" -dmg");
# TODO codesign
elif systems[system]["code"] == "win":
copy(join(["build_"+systems[system]["code"],"Release","borderless"+systems[system]["executable"]]),join(["artifact","borderless"+systems[system]["executable"]]))
run_command("windeployqt "+join(["artifact","borderless"+systems[system]["executable"]])+" --release");
else:
copy(join(["build_"+systems[system]["code"],"borderless"+systems[system]["executable"]]),join(["artifact","borderless"+systems[system]["executable"]]))
def execute():
artefact = join(["artifact","borderless"+systems[system]["executable"]])
if systems[system]["code"] == "mac":
run_command("open -W \""+artefact+"\"")
elif systems[system]["code"] == "win":
run_command("\""+artefact+"\"")
else:
run_command("gdb -ex run \""+artefact+"\"")
def build_installer():
debug("BUILDING INSTALLER")
if systems[system]["code"] == "win":
run_command("iscc \"innosetup.iss\"")
def run_program(string):
if string.strip() == "":
error("You must specify arguments!")
args = shlex.split(string)
if "prepare".startswith(args[0]) and ',' not in string and len(args) <= 1:
prepare()
return
if "configure".startswith(args[0]) and ',' not in string and len(args) <= 1:
configure()
return
if "installer".startswith(args[0]) and ',' not in string and len(args) <= 1:
build_installer()
return
config = "release"
if len(args) >= 1:
config = fuzzy_match(args[0],["release","Debug"])
if config == None:
error("Unknown config: "+args[0])
run = "yes"
if len(args) >= 2:
run = fuzzy_match(args[1],["yes","no"])
if run == None:
error("Unknown run: "+args[1])
build(config)
if run == "yes":
execute()
if __name__ == "__main__":
run_program(' '.join(shlex.quote(s) for s in (sys.argv[1:])))