-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_projects.py
More file actions
executable file
·254 lines (220 loc) · 8.2 KB
/
test_projects.py
File metadata and controls
executable file
·254 lines (220 loc) · 8.2 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import glob
import os
import platform
import shutil
import subprocess
import sys
if sys.version_info >= (3, 11):
from contextlib import chdir
else:
class chdir:
"""Context manager for changing the current working directory"""
def __init__(self, newPath):
self.newPath = os.path.expanduser(newPath)
def __enter__(self):
self.savedPath = os.getcwd()
os.chdir(self.newPath)
def __exit__(self, etype, value, traceback):
os.chdir(self.savedPath)
def usage():
print('test_project (premake4|premake5) project-root action [args]')
sys.exit(-1)
def append_path_in_env(env, key, value):
if key in env:
env[key] += ':' + value
else:
env[key] = value
print(key, env[key], flush=True)
def get_fixed_env_os():
if platform.system() == 'Windows':
return None
elif platform.system() == 'Linux':
env = os.environ.copy()
append_path_in_env(env, 'LD_LIBRARY_PATH', './bin/Release')
#append_path_in_env(env, 'QT_DEBUG_PLUGINS', 1)
return env
elif platform.system() == 'Darwin': # Mac
env = os.environ.copy()
append_path_in_env(env, 'DYLD_LIBRARY_PATH', './bin/Release')
return env
else:
print('platform', platform.system(), flush=True)
return None
# execute binary
def exec_os():
try:
return subprocess.run(['./bin/Release/app'], env=get_fixed_env_os()).returncode
except FileNotFoundError:
print('Error, file not found')
return -1
else:
print('Unknow issue')
return -1
#
# build executable from different generator.
def run_cmake():
ret = subprocess.run(['cmake', '-DCMAKE_BUILD_TYPE=Release', '.'])
if ret.returncode != 0:
print('CMake first stage fails', flush=True)
return ret.returncode
return subprocess.run(['cmake', '--build', '.', '--target', 'app', '--config', 'Release']).returncode
def run_codeblocks():
# require X11/graphical terminal :-/
# xvfb might simulate one.
return subprocess.run(['codeblocks', '--no-splash-screen', '--target=Release', '--build', 'Project.workspace']).returncode
# Project.workspace
# app.cbp
def run_codelite():
return subprocess.run(['codelite-make', '--settings=../../../../codelite/build_settings.xml', '--workspace=Project.workspace', '--project=app', '--config=Release', '--command=build', '--verbose', '--execute']).returncode
def run_ninja():
ret = subprocess.run(['ninja', 'app_Release'])
if os.path.isfile('../../has_permanent_out_of_date_step'): # pre/post build is unconditionally run
return ret.returncode
ret = subprocess.run(['ninja', 'app_Release'], capture_output=True)
if b'ninja: no work to do.' not in ret.stdout:
print('--- Next build should have nothing to do ---')
print()
print(ret.stdout.decode())
print('----------', flush=True)
return 1
return 0
def run_make():
return subprocess.run(['make', 'app', 'config=release']).returncode
def run_qmake():
subprocess.run(['qmake', '-makefile', 'Project.pro'])
#print('------- Makefile --------', flush=True)
#ret = subprocess.run(['cat', 'Makefile'], capture_output=True)
#print(ret.stdout.decode())
#print('---------------', flush=True)
return subprocess.run(['make', 'sub-app-all']).returncode
def run_vs():
if os.path.isfile('packages.config'): # visual studio calls nuget, but not msbuild
nuget_cmd = ['nuget', 'install', 'packages.config', '-OutputDirectory', 'packages']
print(nuget_cmd)
ret = subprocess.run(nuget_cmd)
if ret.returncode != 0:
print(ret.stdout.decode())
print(ret.stderr.decode(), flush=True)
return 1
return subprocess.run(['msbuild.exe', '/property:Configuration=Release', 'Project.sln']).returncode
def run_xcode4():
#xcodebuild -list -project app.xcodeproj
return subprocess.run(['xcodebuild', '-project', 'app.xcodeproj', '-configuration', 'Release', '-scheme', 'app', 'build']).returncode
def select_action_runner(action):
if action == 'cmake':
return run_cmake
elif action == 'codeblocks':
return run_codeblocks
elif action == 'codelite':
return run_codelite
elif action in ['gmake']:
return run_make
elif action in ['premake-ninja', 'ninja']:
return run_ninja
elif action == 'qmake':
return run_qmake
elif action in ['vs2005', 'vs2008', 'vs2010', 'vs2012', 'vs2013', 'vs2015', 'vs2017', 'vs2019', 'vs2022']:
return run_vs
elif action == 'xcode4':
return run_xcode4
return None
# main
if __name__ == "__main__":
if len(sys.argv) < 4:
print('invalid argument')
usage()
premake = sys.argv[1]
project_root = sys.argv[2]
action = sys.argv[3]
options = sys.argv[4:]
print('premake:', premake)
print('project_root:', project_root)
print('action', action)
print('options:', options)
options_without_scripts = [option for option in options if not option.startswith('--scripts=')]
if premake != 'premake4' and premake != 'premake5':
print('Invalid argument, should be premake4 or premake5')
usage()
if not os.path.isdir(project_root):
print('Invalid project_root argument')
usage()
run_action = select_action_runner(action)
if not run_action:
print('Unknown action')
usage()
skipped_projects=[]
ko_projects=[]
for project in sorted(os.listdir(project_root)):
project_dir = os.path.join(project_root, project)
if not os.path.isdir(project_dir):
continue;
print('***********************************', project, '************************************', flush=True)
premake_lua = os.path.join(project_dir, premake + '.lua')
if (not os.path.isfile(premake_lua)
or os.path.isfile(os.path.join(project_dir, 'unsupported_by_' + action))
or os.path.isfile(os.path.join(project_dir, 'unsupported_by_' + action + '_' + platform.system().lower()))
or os.path.isfile(os.path.join(project_dir, 'unsupported_by_' + action + ''.join(options_without_scripts)))
or os.path.isfile(os.path.join(project_dir, 'unsupported_by' + ''.join(options_without_scripts)))
or os.path.isfile(os.path.join(project_dir, 'unsupported_by_' + premake + '_' + action))
):
print(project, "skipped", flush=True)
skipped_projects.append(project)
continue
# Clean possibly previous solution directories
for sol_dir in glob.glob(os.path.join(project_dir, '*solution')):
print('rmtree', sol_dir, flush=True)
shutil.rmtree(sol_dir)
pre_premake_lua = os.path.join(project_dir, 'pre-' + premake + '.lua')
if os.path.isfile(pre_premake_lua):
print('run:', [premake, '--file=' + pre_premake_lua, action] + options, flush=True)
ret = subprocess.run([premake, '--file=' + pre_premake_lua, action] + options)
if ret.returncode != 0:
print(project, 'KO (prephase)', flush=True)
ko_projects.append(project + ' (prephase)')
continue
with chdir(os.path.join(project_dir, 'external_solution', action)):
ret = run_action()
if ret != 0:
print(project, 'KO', ret, flush=True)
ko_projects.append(project + ' Generation (prephase)')
continue
print('run:', [premake, '--file=' + premake_lua, action] + options, flush=True)
ret = subprocess.run([premake, '--file=' + premake_lua, action] + options)
if ret.returncode != 0:
print(project, 'KO', flush=True)
ko_projects.append(project + ' (premake)')
continue
failed_build_expected = os.path.isfile(os.path.join(project_dir, 'failed_build_expected'))
with chdir(os.path.join(project_dir, 'solution', action)):
ret = run_action()
if failed_build_expected:
if ret == 0 and (os.path.isfile('./bin/Release/app') or os.path.isfile('./bin/Release/app.exe')):
print(project, '(not failed) KO', ret, flush=True)
ko_projects.append(project + ' Execution')
else:
print(project, '(failed) OK', flush=True)
elif ret == 0:
print('execute app')
ret = exec_os()
if ret == 0:
print(project, 'OK', flush=True)
else:
print(project, 'KO', ret, flush=True)
ko_projects.append(project + ' Execution')
else:
print(project, 'KO', ret, flush=True)
ko_projects.append(project + ' Generation')
print ('*********************************** Summary ***********************************', flush=True)
if len (skipped_projects) != 0:
print ('Skipped:', flush=True)
for project in skipped_projects:
print('', project)
if len (ko_projects) != 0:
print ('KO:', flush=True)
for project in ko_projects:
print('', project)
ret = subprocess.run(['git', 'status', '-s'], capture_output=True)
if len(ret.stdout) != 0:
print('Extra files:', flush=True)
print(ret.stdout.decode())
sys.exit(len (ko_projects) != 0)