24
24
25
25
class DictAction (argparse .Action ):
26
26
def __call__ (self , parser , namespace , values , option_string = None ):
27
- assert isinstance (getattr (namespace , self .dest ), dict ), "Use ArgumentParser.set_defaults() to initialize {} to dict()" .format (self .dest )
27
+ assert isinstance (getattr (namespace , self .dest ),
28
+ dict ), "Use ArgumentParser.set_defaults() to initialize {} to dict()" .format (self .dest )
28
29
name = option_string .lstrip (parser .prefix_chars ).replace ("-" , "_" )
29
30
getattr (namespace , self .dest )[name ] = values
30
31
31
- parser = argparse .ArgumentParser (prog = "sby" ,
32
- usage = "%(prog)s [options] [<jobname>.sby [tasknames] | <dirname>]" )
32
+ parser = argparse .ArgumentParser (prog = "sby" , usage = "%(prog)s [options] [<jobname>.sby [tasknames] | <dirname>]" )
33
33
parser .set_defaults (exe_paths = dict ())
34
34
35
35
parser .add_argument ("-d" , metavar = "<dirname>" , dest = "workdir" ,
36
- help = "set workdir name. default: <jobname> or <jobname>_<taskname>" )
37
- parser .add_argument ("-f" , action = "store_true" , dest = "force" ,
38
- help = "remove workdir if it already exists" )
39
- parser .add_argument ("-b" , action = "store_true" , dest = "backup" ,
40
- help = "backup workdir if it already exists" )
41
- parser .add_argument ("-t" , action = "store_true" , dest = "tmpdir" ,
42
- help = "run in a temporary workdir (remove when finished)" )
36
+ help = "set workdir name. default: <jobname> or <jobname>_<taskname>" )
37
+ parser .add_argument ("-f" , action = "store_true" , dest = "force" , help = "remove workdir if it already exists" )
38
+ parser .add_argument ("-b" , action = "store_true" , dest = "backup" , help = "backup workdir if it already exists" )
39
+ parser .add_argument ("-t" , action = "store_true" , dest = "tmpdir" , help = "run in a temporary workdir (remove when finished)" )
43
40
parser .add_argument ("-T" , metavar = "<taskname>" , action = "append" , dest = "tasknames" , default = list (),
44
- help = "add taskname (useful when sby file is read from stdin)" )
41
+ help = "add taskname (useful when sby file is read from stdin)" )
45
42
parser .add_argument ("-E" , action = "store_true" , dest = "throw_err" ,
46
- help = "throw an exception (incl stack trace) for most errors" )
47
-
48
- parser .add_argument ("--yosys" , metavar = "<path_to_executable>" ,
49
- action = DictAction , dest = "exe_paths" )
50
- parser .add_argument ("--abc" , metavar = "<path_to_executable>" ,
51
- action = DictAction , dest = "exe_paths" )
52
- parser .add_argument ("--smtbmc" , metavar = "<path_to_executable>" ,
53
- action = DictAction , dest = "exe_paths" )
54
- parser .add_argument ("--suprove" , metavar = "<path_to_executable>" ,
55
- action = DictAction , dest = "exe_paths" )
56
- parser .add_argument ("--aigbmc" , metavar = "<path_to_executable>" ,
57
- action = DictAction , dest = "exe_paths" )
58
- parser .add_argument ("--avy" , metavar = "<path_to_executable>" ,
59
- action = DictAction , dest = "exe_paths" )
60
- parser .add_argument ("--btormc" , metavar = "<path_to_executable>" ,
61
- action = DictAction , dest = "exe_paths" )
62
- parser .add_argument ("--pono" , metavar = "<path_to_executable>" ,
63
- action = DictAction , dest = "exe_paths" ,
64
- help = "configure which executable to use for the respective tool" )
43
+ help = "throw an exception (incl stack trace) for most errors" )
44
+
45
+ parser .add_argument ("--yosys" , metavar = "<path_to_executable>" , action = DictAction , dest = "exe_paths" )
46
+ parser .add_argument ("--abc" , metavar = "<path_to_executable>" , action = DictAction , dest = "exe_paths" )
47
+ parser .add_argument ("--smtbmc" , metavar = "<path_to_executable>" , action = DictAction , dest = "exe_paths" )
48
+ parser .add_argument ("--suprove" , metavar = "<path_to_executable>" , action = DictAction , dest = "exe_paths" )
49
+ parser .add_argument ("--aigbmc" , metavar = "<path_to_executable>" , action = DictAction , dest = "exe_paths" )
50
+ parser .add_argument ("--avy" , metavar = "<path_to_executable>" , action = DictAction , dest = "exe_paths" )
51
+ parser .add_argument ("--btormc" , metavar = "<path_to_executable>" , action = DictAction , dest = "exe_paths" )
52
+ parser .add_argument ("--pono" , metavar = "<path_to_executable>" , action = DictAction , dest = "exe_paths" ,
53
+ help = "configure which executable to use for the respective tool" )
65
54
parser .add_argument ("--dumpcfg" , action = "store_true" , dest = "dump_cfg" ,
66
- help = "print the pre-processed configuration file" )
67
- parser .add_argument ("--dumptasks" , action = "store_true" , dest = "dump_tasks" ,
68
- help = "print the list of tasks" )
69
- parser .add_argument ("--dumpfiles" , action = "store_true" , dest = "dump_files" ,
70
- help = "print the list of source files" )
71
- parser .add_argument ("--setup" , action = "store_true" , dest = "setupmode" ,
72
- help = "set up the working directory and exit" )
73
-
74
- parser .add_argument ("--init-config-file" , dest = "init_config_file" ,
75
- help = "create a default .sby config file" )
55
+ help = "print the pre-processed configuration file" )
56
+ parser .add_argument ("--dumptasks" , action = "store_true" , dest = "dump_tasks" , help = "print the list of tasks" )
57
+ parser .add_argument ("--dumpfiles" , action = "store_true" , dest = "dump_files" , help = "print the list of source files" )
58
+ parser .add_argument ("--setup" , action = "store_true" , dest = "setupmode" , help = "set up the working directory and exit" )
59
+
60
+ parser .add_argument ("--init-config-file" , dest = "init_config_file" , help = "create a default .sby config file" )
76
61
parser .add_argument ("sbyfile" , metavar = "<jobname>.sby | <dirname>" , nargs = "?" ,
77
- help = ".sby file OR directory containing config.sby file" )
62
+ help = ".sby file OR directory containing config.sby file" )
78
63
parser .add_argument ("arg_tasknames" , metavar = "tasknames" , nargs = "*" ,
79
- help = "tasks to run (only valid when <jobname>.sby is used)" )
64
+ help = "tasks to run (only valid when <jobname>.sby is used)" )
80
65
81
66
args = parser .parse_args ()
82
67
@@ -198,11 +183,11 @@ def handle_line(line):
198
183
task_skip_line = False
199
184
200
185
for t in task_tags_all :
201
- if line .startswith (t + ":" ):
202
- line = line [len (t )+ 1 :].lstrip ()
186
+ if line .startswith (t + ":" ):
187
+ line = line [len (t ) + 1 :].lstrip ()
203
188
match = t in task_tags_active
204
- elif line .startswith ("~" + t + ":" ):
205
- line = line [len (t )+ 2 :].lstrip ()
189
+ elif line .startswith ("~" + t + ":" ):
190
+ line = line [len (t ) + 2 :].lstrip ()
206
191
match = t not in task_tags_active
207
192
else :
208
193
continue
@@ -268,7 +253,6 @@ def handle_line(line):
268
253
269
254
return cfgdata , tasklist
270
255
271
-
272
256
sbydata = list ()
273
257
with (open (sbyfile , "r" ) if sbyfile is not None else sys .stdin ) as f :
274
258
for line in f :
@@ -295,7 +279,7 @@ def find_files(taskname):
295
279
if start_index == - 1 :
296
280
return
297
281
298
- for line in sbyconfig [start_index + 1 :]:
282
+ for line in sbyconfig [start_index + 1 :]:
299
283
line = line .strip ()
300
284
if line .startswith ("[" ):
301
285
break
@@ -341,7 +325,9 @@ def run_job(taskname):
341
325
backup_idx = 0
342
326
while os .path .exists ("{}.bak{:03d}" .format (my_workdir , backup_idx )):
343
327
backup_idx += 1
344
- early_log (my_workdir , "Moving directory '{}' to '{}'." .format (my_workdir , "{}.bak{:03d}" .format (my_workdir , backup_idx )))
328
+ early_log (
329
+ my_workdir , "Moving directory '{}' to '{}'." .format (my_workdir ,
330
+ "{}.bak{:03d}" .format (my_workdir , backup_idx )))
345
331
shutil .move (my_workdir , "{}.bak{:03d}" .format (my_workdir , backup_idx ))
346
332
347
333
if opt_force and not reusedir :
@@ -361,7 +347,8 @@ def run_job(taskname):
361
347
my_opt_tmpdir = True
362
348
my_workdir = tempfile .mkdtemp ()
363
349
364
- junit_ts_name = os .path .basename (sbyfile [:- 4 ]) if sbyfile is not None else workdir if workdir is not None else "stdin"
350
+ junit_ts_name = os .path .basename (
351
+ sbyfile [:- 4 ]) if sbyfile is not None else workdir if workdir is not None else "stdin"
365
352
junit_tc_name = taskname if taskname is not None else "default"
366
353
367
354
if reusedir :
@@ -404,33 +391,41 @@ def run_job(taskname):
404
391
junit_errors = 1 if job .retcode == 16 else 0
405
392
junit_failures = 1 if job .retcode != 0 and junit_errors == 0 else 0
406
393
print ('<?xml version="1.0" encoding="UTF-8"?>' , file = f )
407
- print ('<testsuites disabled="0" errors="{}" failures="{}" tests="1" time="{}">' .format (junit_errors , junit_failures , job .total_time ), file = f )
408
- print ('<testsuite disabled="0" errors="{}" failures="{}" name="{}" skipped="0" tests="1" time="{}">' .format (junit_errors , junit_failures , junit_ts_name , job .total_time ), file = f )
394
+ print (
395
+ '<testsuites disabled="0" errors="{}" failures="{}" tests="1" time="{}">' .format (
396
+ junit_errors , junit_failures , job .total_time ), file = f )
397
+ print (
398
+ '<testsuite disabled="0" errors="{}" failures="{}" name="{}" skipped="0" tests="1" time="{}">' .format (
399
+ junit_errors , junit_failures , junit_ts_name , job .total_time ), file = f )
409
400
print ('<properties>' , file = f )
410
401
print ('<property name="os" value="{}"/>' .format (os .name ), file = f )
411
402
print ('</properties>' , file = f )
412
- print ('<testcase classname="{}" name="{}" status="{}" time="{}">' .format (junit_ts_name , junit_tc_name , job .status , job .total_time ), file = f )
403
+ print (
404
+ '<testcase classname="{}" name="{}" status="{}" time="{}">' .format (junit_ts_name , junit_tc_name ,
405
+ job .status , job .total_time ), file = f )
413
406
if junit_errors :
414
407
print ('<error message="{}" type="{}"/>' .format (job .status , job .status ), file = f )
415
408
if junit_failures :
416
409
print ('<failure message="{}" type="{}"/>' .format (job .status , job .status ), file = f )
417
410
print ('<system-out>' , end = "" , file = f )
418
411
with open ("{}/logfile.txt" .format (job .workdir ), "r" ) as logf :
419
412
for line in logf :
420
- print (line .replace ("&" , "&" ).replace ("<" , "<" ).replace (">" , ">" ).replace ("\" " , """ ), end = "" , file = f )
413
+ print (
414
+ line .replace ("&" , "&" ).replace ("<" , "<" ).replace (">" , ">" ).replace ("\" " , """ ),
415
+ end = "" , file = f )
421
416
print ('</system-out></testcase></testsuite></testsuites>' , file = f )
422
417
with open ("{}/status" .format (job .workdir ), "w" ) as f :
423
418
print ("{} {} {}" .format (job .status , job .retcode , job .total_time ), file = f )
424
419
425
420
return job .retcode
426
421
427
-
428
422
retcode = 0
429
423
for t in tasknames :
430
424
retcode |= run_job (t )
431
425
432
426
if retcode and (len (tasknames ) > 1 or tasknames [0 ] is not None ):
433
427
tm = localtime ()
434
- print ("SBY {:2d}:{:02d}:{:02d} One or more tasks produced a non-zero return code." .format (tm .tm_hour , tm .tm_min , tm .tm_sec ))
428
+ print ("SBY {:2d}:{:02d}:{:02d} One or more tasks produced a non-zero return code." .format (
429
+ tm .tm_hour , tm .tm_min , tm .tm_sec ))
435
430
436
431
sys .exit (retcode )
0 commit comments