24
24
from mesonbuild import mesonlib
25
25
from mesonbuild import mlog
26
26
from mesonbuild import mesonmain
27
- from mesonbuild .mesonlib import stringlistify
27
+ from mesonbuild .mesonlib import stringlistify , Popen_safe
28
28
import argparse
29
29
import xml .etree .ElementTree as ET
30
30
import time
@@ -93,26 +93,20 @@ def stop_handler(signal, frame):
93
93
backend_flags = None
94
94
compile_commands = None
95
95
test_commands = None
96
- install_commands = None
96
+ install_commands = []
97
+ clean_commands = []
97
98
98
99
def setup_commands (backend ):
99
- global backend_flags , compile_commands , test_commands , install_commands
100
+ global backend_flags , compile_commands , test_commands , install_commands , clean_commands
100
101
msbuild_exe = shutil .which ('msbuild' )
101
- if backend == 'vs2010' or (backend is None and msbuild_exe is not None ):
102
- backend_flags = ['--backend=vs2010' ]
102
+ if ( backend and backend . startswith ( 'vs' )) or (backend is None and msbuild_exe is not None ):
103
+ backend_flags = ['--backend=' + backend ]
103
104
compile_commands = ['msbuild' ]
104
105
test_commands = ['msbuild' , 'RUN_TESTS.vcxproj' ]
105
- install_commands = []
106
- elif backend == 'vs2015' :
107
- backend_flags = ['--backend=vs2015' ]
108
- compile_commands = ['msbuild' ]
109
- test_commands = ['msbuild' , 'RUN_TESTS.vcxproj' ]
110
- install_commands = []
111
106
elif backend == 'xcode' or (backend is None and mesonlib .is_osx ()):
112
107
backend_flags = ['--backend=xcode' ]
113
108
compile_commands = ['xcodebuild' ]
114
109
test_commands = ['xcodebuild' , '-target' , 'RUN_TESTS' ]
115
- install_commands = []
116
110
else :
117
111
backend_flags = []
118
112
ninja_command = environment .detect_ninja ()
@@ -125,6 +119,7 @@ def setup_commands(backend):
125
119
compile_commands += ['-w' , 'dupbuild=err' ]
126
120
test_commands = [ninja_command , 'test' , 'benchmark' ]
127
121
install_commands = [ninja_command , 'install' ]
122
+ clean_commands = [ninja_command , 'clean' ]
128
123
129
124
def get_relative_files_list_from_dir (fromdir ):
130
125
paths = []
@@ -233,17 +228,18 @@ def parse_test_args(testdir):
233
228
pass
234
229
return args
235
230
236
- def run_test (skipped , testdir , extra_args , flags , compile_commands , install_commands , should_fail ):
231
+ def run_test (skipped , testdir , extra_args , flags , compile_commands , should_fail ):
237
232
if skipped :
238
233
return None
239
234
with AutoDeletedDir (tempfile .mkdtemp (prefix = 'b ' , dir = '.' )) as build_dir :
240
235
with AutoDeletedDir (tempfile .mkdtemp (prefix = 'i ' , dir = os .getcwd ())) as install_dir :
241
236
try :
242
- return _run_test (testdir , build_dir , install_dir , extra_args , flags , compile_commands , install_commands , should_fail )
237
+ return _run_test (testdir , build_dir , install_dir , extra_args , flags , compile_commands , should_fail )
243
238
finally :
244
239
mlog .shutdown () # Close the log file because otherwise Windows wets itself.
245
240
246
- def _run_test (testdir , test_build_dir , install_dir , extra_args , flags , compile_commands , install_commands , should_fail ):
241
+ def _run_test (testdir , test_build_dir , install_dir , extra_args , flags , compile_commands , should_fail ):
242
+ global install_commands , clean_commands
247
243
test_args = parse_test_args (testdir )
248
244
gen_start = time .time ()
249
245
gen_command = [meson_command , '--prefix' , '/usr' , '--libdir' , 'lib' , testdir , test_build_dir ]\
@@ -268,12 +264,10 @@ def _run_test(testdir, test_build_dir, install_dir, extra_args, flags, compile_c
268
264
else :
269
265
comp = compile_commands
270
266
build_start = time .time ()
271
- pc = subprocess .Popen (comp , cwd = test_build_dir ,
272
- stdout = subprocess .PIPE , stderr = subprocess .PIPE )
273
- (o , e ) = pc .communicate ()
267
+ pc , o , e = Popen_safe (comp , cwd = test_build_dir )
274
268
build_time = time .time () - build_start
275
- stdo += o . decode ( sys . stdout . encoding )
276
- stde += e . decode ( sys . stdout . encoding )
269
+ stdo += o
270
+ stde += e
277
271
if should_fail == 'build' :
278
272
if pc .returncode != 0 :
279
273
return TestResult ('' , stdo , stde , mesonlog , gen_time )
@@ -294,19 +288,24 @@ def _run_test(testdir, test_build_dir, install_dir, extra_args, flags, compile_c
294
288
return TestResult ('Test that should have failed to run unit tests succeeded' , stdo , stde , mesonlog , gen_time )
295
289
if returncode != 0 :
296
290
return TestResult ('Running unit tests failed.' , stdo , stde , mesonlog , gen_time , build_time , test_time )
291
+ # Do installation
297
292
if len (install_commands ) == 0 :
298
293
return TestResult ('' , '' , '' , gen_time , build_time , test_time )
299
- else :
294
+ env = os .environ .copy ()
295
+ env ['DESTDIR' ] = install_dir
296
+ pi , o , e = Popen_safe (install_commands , cwd = test_build_dir , env = env )
297
+ stdo += o
298
+ stde += e
299
+ if pi .returncode != 0 :
300
+ return TestResult ('Running install failed.' , stdo , stde , mesonlog , gen_time , build_time , test_time )
301
+ if len (clean_commands ) != 0 :
300
302
env = os .environ .copy ()
301
- env ['DESTDIR' ] = install_dir
302
- pi = subprocess .Popen (install_commands , cwd = test_build_dir , env = env ,
303
- stdout = subprocess .PIPE , stderr = subprocess .PIPE )
304
- (o , e ) = pi .communicate ()
305
- stdo += o .decode (sys .stdout .encoding )
306
- stde += e .decode (sys .stdout .encoding )
303
+ pi , o , e = Popen_safe (clean_commands , cwd = test_build_dir , env = env )
304
+ stdo += o
305
+ stde += e
307
306
if pi .returncode != 0 :
308
- return TestResult ('Running install failed.' , stdo , stde , mesonlog , gen_time , build_time , test_time )
309
- return TestResult (validate_install (testdir , install_dir ), stdo , stde , mesonlog , gen_time , build_time , test_time )
307
+ return TestResult ('Running clean failed.' , stdo , stde , mesonlog , gen_time , build_time , test_time )
308
+ return TestResult (validate_install (testdir , install_dir ), stdo , stde , mesonlog , gen_time , build_time , test_time )
310
309
311
310
def gather_tests (testdir ):
312
311
tests = [t .replace ('\\ ' , '/' ).split ('/' , 2 )[2 ] for t in glob (os .path .join (testdir , '*' ))]
@@ -372,7 +371,7 @@ def detect_tests_to_run():
372
371
return all_tests
373
372
374
373
def run_tests (extra_args ):
375
- global passing_tests , failing_tests , stop , executor , futures
374
+ global install_commands , passing_tests , failing_tests , stop , executor , futures
376
375
all_tests = detect_tests_to_run ()
377
376
logfile = open ('meson-test-run.txt' , 'w' , encoding = "utf_8" )
378
377
junit_root = ET .Element ('testsuites' )
@@ -404,7 +403,7 @@ def run_tests(extra_args):
404
403
should_fail = False
405
404
if name .startswith ('failing' ):
406
405
should_fail = name .split ('failing-' )[1 ]
407
- result = executor .submit (run_test , skipped , t , extra_args , unity_flags + backend_flags , compile_commands , install_commands , should_fail )
406
+ result = executor .submit (run_test , skipped , t , extra_args , unity_flags + backend_flags , compile_commands , should_fail )
408
407
futures .append ((testname , t , result ))
409
408
for (testname , t , result ) in futures :
410
409
result = result .result ()
0 commit comments