22from collections .abc import Iterable
33from abc import ABCMeta , abstractmethod
44import os
5- import textwrap
65import re
6+ import json
7+ import shlex
78import jinja2
9+ import textwrap
10+ import warnings
811
912from .. import __version__
1013from .._toolchain import *
@@ -202,6 +205,12 @@ class TemplatedPlatform(Platform):
202205 if defined {{platform._toolchain_env_var}} call "%{{platform._toolchain_env_var}}%"
203206 {{emit_commands("bat")}}
204207 """ ,
208+ "build_{{name}}.json" : """
209+ {
210+ "comment": "{{autogenerated}}",
211+ "commands": {{emit_commands("json")}}
212+ }
213+ """ ,
205214 }
206215
207216 def iter_signal_clock_constraints (self ):
@@ -300,6 +309,8 @@ def emit_commands(syntax):
300309 template = \
301310 "if [!{env_var}!] equ [\" \" ] set {env_var}=\n " \
302311 "if [!{env_var}!] equ [] set {env_var}={name}"
312+ elif syntax == "json" :
313+ continue
303314 else :
304315 assert False
305316 commands .append (template .format (env_var = env_var , name = name ))
@@ -312,10 +323,15 @@ def emit_commands(syntax):
312323 commands .append (command )
313324 elif syntax == "bat" :
314325 commands .append (command + " || exit /b" )
326+ elif syntax == "json" :
327+ commands .append (command )
315328 else :
316329 assert False
317330
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 "
319335
320336 @jinja2 .pass_context
321337 def invoke_tool (context , name ):
@@ -324,6 +340,8 @@ def invoke_tool(context, name):
324340 return f"\" ${ env_var } \" "
325341 elif context .parent ["syntax" ] == "bat" :
326342 return f"\" %{ env_var } %\" "
343+ elif context .parent ["syntax" ] == "json" :
344+ return name
327345 else :
328346 assert False
329347
0 commit comments