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
8
10
import warnings
9
11
10
12
from .. import __version__
@@ -217,6 +219,12 @@ class TemplatedPlatform(Platform):
217
219
if defined {{platform._toolchain_env_var}} call "%{{platform._toolchain_env_var}}%"
218
220
{{emit_commands("bat")}}
219
221
""" ,
222
+ "build_{{name}}.json" : """
223
+ {
224
+ "comment": "{{autogenerated}}",
225
+ "commands": {{emit_commands("json")}}
226
+ }
227
+ """ ,
220
228
}
221
229
222
230
def iter_signal_clock_constraints (self ):
@@ -315,6 +323,8 @@ def emit_commands(syntax):
315
323
template = \
316
324
"if [!{env_var}!] equ [\" \" ] set {env_var}=\n " \
317
325
"if [!{env_var}!] equ [] set {env_var}={name}"
326
+ elif syntax == "json" :
327
+ continue
318
328
else :
319
329
assert False
320
330
commands .append (template .format (env_var = env_var , name = name ))
@@ -327,10 +337,15 @@ def emit_commands(syntax):
327
337
commands .append (command )
328
338
elif syntax == "bat" :
329
339
commands .append (command + " || exit /b" )
340
+ elif syntax == "json" :
341
+ commands .append (command )
330
342
else :
331
343
assert False
332
344
333
- return "\n " .join (commands ) + "\n "
345
+ if syntax == "json" :
346
+ return json .dumps ([shlex .split (command ) for command in commands ])
347
+ else :
348
+ return "\n " .join (commands ) + "\n "
334
349
335
350
@jinja2 .pass_context
336
351
def invoke_tool (context , name ):
@@ -339,6 +354,8 @@ def invoke_tool(context, name):
339
354
return f"\" ${ env_var } \" "
340
355
elif context .parent ["syntax" ] == "bat" :
341
356
return f"call %{ env_var } %"
357
+ elif context .parent ["syntax" ] == "json" :
358
+ return name
342
359
else :
343
360
assert False
344
361
0 commit comments