2
2
from collections .abc import Iterable
3
3
from abc import ABCMeta , abstractmethod
4
4
import os
5
- import textwrap
6
5
import re
6
+ import json
7
+ import shlex
7
8
import jinja2
9
+ import textwrap
10
+ import warnings
8
11
9
12
from .. import __version__
10
13
from .._toolchain import *
@@ -202,6 +205,12 @@ class TemplatedPlatform(Platform):
202
205
if defined {{platform._toolchain_env_var}} call "%{{platform._toolchain_env_var}}%"
203
206
{{emit_commands("bat")}}
204
207
""" ,
208
+ "build_{{name}}.json" : """
209
+ {
210
+ "comment": "{{autogenerated}}",
211
+ "commands": {{emit_commands("json")}}
212
+ }
213
+ """ ,
205
214
}
206
215
207
216
def iter_signal_clock_constraints (self ):
@@ -300,6 +309,8 @@ def emit_commands(syntax):
300
309
template = \
301
310
"if [!{env_var}!] equ [\" \" ] set {env_var}=\n " \
302
311
"if [!{env_var}!] equ [] set {env_var}={name}"
312
+ elif syntax == "json" :
313
+ continue
303
314
else :
304
315
assert False
305
316
commands .append (template .format (env_var = env_var , name = name ))
@@ -312,10 +323,15 @@ def emit_commands(syntax):
312
323
commands .append (command )
313
324
elif syntax == "bat" :
314
325
commands .append (command + " || exit /b" )
326
+ elif syntax == "json" :
327
+ commands .append (command )
315
328
else :
316
329
assert False
317
330
318
- return "\n " .join (commands ) + "\n "
331
+ if syntax == "json" :
332
+ return json .dumps ([shlex .split (command ) for command in commands ])
333
+ else :
334
+ return "\n " .join (commands ) + "\n "
319
335
320
336
@jinja2 .pass_context
321
337
def invoke_tool (context , name ):
@@ -324,6 +340,8 @@ def invoke_tool(context, name):
324
340
return f"\" ${ env_var } \" "
325
341
elif context .parent ["syntax" ] == "bat" :
326
342
return f"\" %{ env_var } %\" "
343
+ elif context .parent ["syntax" ] == "json" :
344
+ return name
327
345
else :
328
346
assert False
329
347
0 commit comments