-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.py
executable file
·179 lines (140 loc) · 3.31 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
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
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import os
import sys
import subprocess
import inspect
import multiprocessing
import shutil
import getpass
config = {
'display_name': 'audiobook',
'logToFile': False,
'path': {
'cwd': os.path.abspath(os.getcwd()),
'bin': os.path.abspath('./build/src/audiobook'),
'build': os.path.abspath('./build/'),
'binary': os.path.abspath('audiobook'),
},
}
def main():
menu = {}
menu['1'] = ['Build release', 'build_release']
menu['2'] = ['Build debug', 'build_debug']
menu['3'] = ['Run desktop', 'run_desktop']
menu['4'] = ['Run mobile', 'run_mobile']
menu['5'] = ['Debug (GDB)', 'debug']
menu['p'] = ['pkgbuild', 'pkgbuild']
menu['i'] = ['install', 'install']
menu['0'] = ['Requirements', 'requirements']
print('\n********************')
print (' {}'.format(config['display_name']))
print('********************')
for item in menu:
print (' ' + item + '. ' + menu[item][0])
selection = input('> ')
# check if in menu
if selection in menu:
eval(menu[selection][1] + '()')
# exec function
if '()' in selection:
eval(selection)
main()
return
def install():
run('''
mkdir -p build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr
make
sudo make install
''')
return
def pkgbuild():
log('create .srcinfo')
run('makepkg --printsrcinfo > .SRCINFO')
log('install')
run('makepkg -f')
return
def run_desktop():
try:
run('''
cd build/src
./audiobook
''')
except KeyboardInterrupt:
log('exit')
return
def run_mobile():
try:
run('''
cd build/src
QT_QUICK_CONTROLS_MOBILE=true QT_QUICK_CONTROLS_STYLE=Plasma ./audiobook
''')
except KeyboardInterrupt:
log('exit')
return
def debug():
run('''
cd build/src
gdb audiobook
''')
return
def build_debug():
run('''
mkdir -p build
cd build
cmake .. -DDEFINE_DEBUG=ON -DCMAKE_BUILD_TYPE=Debug
make
cd ..
''')
return
def build_release():
run('''
mkdir -p build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release
make
sudo make install
''')
return
def requirements():
run('''
yay -S --noconfirm --needed cmake extra-cmake-modules gdb
''')
return
def log(str=''):
print(str)
if not config['logToFile']:
return
with open("log.txt", "a") as f:
f.write(str + '\n')
return
# run commands
# params:
# cwd
# show cmd
def run(command, params = {}):
# clean command
cmd = inspect.cleandoc(command)
# show output
show_cmd = False
if 'show_cmd' in params:
show_cmd = params['show_cmd']
if show_cmd:
print(cmd + '\n')
working_dir = os.getcwd()
if 'cwd' in params:
working_dir = params['cwd']
# exec
subprocess.run(cmd, shell=True, cwd=working_dir)
return
def run_sudo(command, params = {}):
cmd = inspect.cleandoc(command)
password = getpass.getpass('[sudo] password: ')
cmd = 'echo {}|sudo -S {}'.format(password, cmd)
run(cmd, params)
return
if __name__ == '__main__':
os.system('cls||clear')
main()