36
36
def colored (str ,clr ,attrs = 0 ):
37
37
return str
38
38
39
+ def prepare_call (args ,variant_pin_sets ):
40
+ # prepare additional defines
41
+ defines = ""
42
+ if args .pins :
43
+ for pin_set in args .pins .split (',' ):
44
+ if not pin_set in variant_pin_sets :
45
+ print (colored ("pin set '" + pin_set + "' not defined in board variant" ,'red' ))
46
+ sys .exit (- 1 )
47
+ else :
48
+ if 'define' in variant_pin_sets [pin_set ]:
49
+ defines = defines + " -D " + variant_pin_sets [pin_set ]['define' ]
50
+ key_value = variant_pin_sets [pin_set ]['define' ].split ('=' )
51
+ if len (key_value ) == 2 :
52
+ os .environ [key_value [0 ]] = key_value [1 ]
53
+ elif len (key_value ) == 1 :
54
+ os .environ [key_value [0 ]] = 1
55
+ # adding command line defines
56
+ if args .defines :
57
+ for define in args .defines .split (',' ):
58
+ defines = defines + " -D " + define
59
+ # additional command line parameters
60
+ add_args = ""
61
+ if args .args :
62
+ for arg in args .args .split (',' ):
63
+ add_args = add_args + " --" + arg
64
+ return defines , add_args
65
+
39
66
def make (cmd_args ):
40
67
# command line
41
68
parser = argparse .ArgumentParser (description = 'silice-make is the Silice build tool' )
@@ -254,6 +281,9 @@ def make(cmd_args):
254
281
os .environ ["PATH" ] += os .pathsep + os .path .realpath (os .path .join (make_dir ,"../tools/fpga-binutils/mingw64/bin/" ))
255
282
os .environ ["PATH" ] += os .pathsep + os .path .realpath ("c:/intelFPGA_lite/19.1/quartus/bin64/" )
256
283
284
+ # top module name
285
+ os .environ ["SILICE_TOP" ] = args .top
286
+
257
287
if target_builder ['builder' ] == 'shell' :
258
288
259
289
# ==== building with a custom script
@@ -263,39 +293,13 @@ def make(cmd_args):
263
293
if not sysconfig .get_platform ().startswith ("mingw" ):
264
294
print (colored ("to build from scripts please run MinGW python from a shell" ,'red' ))
265
295
sys .exit (- 1 )
266
-
267
296
# script check
268
297
script = os .path .join (board_path ,target_builder ['command' ])
269
298
if not os .path .exists (script ):
270
299
print (colored ("script " + script + " not found" , 'red' ))
271
300
sys .exit ()
272
-
273
- # prepare additional defines
274
- defines = ""
275
- if args .pins :
276
- for pin_set in args .pins .split (',' ):
277
- if not pin_set in variant_pin_sets :
278
- print (colored ("pin set '" + pin_set + "' not defined in board variant" ,'red' ))
279
- sys .exit (- 1 )
280
- else :
281
- if 'define' in variant_pin_sets [pin_set ]:
282
- defines = defines + " -D " + variant_pin_sets [pin_set ]['define' ]
283
- key_value = variant_pin_sets [pin_set ]['define' ].split ('=' )
284
- if len (key_value ) == 2 :
285
- os .environ [key_value [0 ]] = key_value [1 ]
286
- elif len (key_value ) == 1 :
287
- os .environ [key_value [0 ]] = 1
288
- # adding command line defines
289
- if args .defines :
290
- for define in args .defines .split (',' ):
291
- defines = defines + " -D " + define
292
- # top module name
293
- os .environ ["SILICE_TOP" ] = args .top
294
- # additional command line parameters
295
- add_args = ""
296
- if args .args :
297
- for arg in args .args .split (',' ):
298
- add_args = add_args + " --" + arg
301
+ # prepare call
302
+ defines , add_args = prepare_call (args , variant_pin_sets )
299
303
# execute
300
304
command = script + " " + source_file
301
305
print ('launching command ' , colored (command ,'cyan' ))
@@ -307,15 +311,20 @@ def make(cmd_args):
307
311
308
312
elif target_builder ['builder' ] == 'yowasp' :
309
313
314
+ # ==== building with yowasp (custom python script)
315
+
310
316
# script check
311
317
script = os .path .join (board_path ,target_builder ['command' ])
312
318
if not os .path .exists (script ):
313
319
print (colored ("script " + script + " not found" , 'red' ))
314
320
sys .exit ()
321
+ # prepare call
322
+ defines , add_args = prepare_call (args , variant_pin_sets )
315
323
# execute
316
324
import importlib .util
317
325
spec = importlib .util .spec_from_file_location ("module_name" , script )
318
326
module = importlib .util .module_from_spec (spec )
327
+ module .silice_args = (source_file + " " + defines + " " + add_args + " --top " + args .top ).strip ()
319
328
sys .modules ["module_name" ] = module
320
329
spec .loader .exec_module (module )
321
330
0 commit comments