Skip to content

Commit e5ae491

Browse files
committed
build.plat: add build_{{name}}.json output.
This is useful for custom build runners that don't run a shell; more specifically, WebAssembly based tooling.
1 parent bc5d1a4 commit e5ae491

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

amaranth/build/plat.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
from collections.abc import Iterable
33
from abc import ABCMeta, abstractmethod
44
import os
5-
import textwrap
65
import re
6+
import json
7+
import shlex
78
import jinja2
9+
import textwrap
810
import warnings
911

1012
from .. import __version__
@@ -217,6 +219,12 @@ class TemplatedPlatform(Platform):
217219
if defined {{platform._toolchain_env_var}} call "%{{platform._toolchain_env_var}}%"
218220
{{emit_commands("bat")}}
219221
""",
222+
"build_{{name}}.json": """
223+
{
224+
"comment": "{{autogenerated}}",
225+
"commands": {{emit_commands("json")}}
226+
}
227+
""",
220228
}
221229

222230
def iter_signal_clock_constraints(self):
@@ -315,6 +323,8 @@ def emit_commands(syntax):
315323
template = \
316324
"if [!{env_var}!] equ [\"\"] set {env_var}=\n" \
317325
"if [!{env_var}!] equ [] set {env_var}={name}"
326+
elif syntax == "json":
327+
continue
318328
else:
319329
assert False
320330
commands.append(template.format(env_var=env_var, name=name))
@@ -327,10 +337,15 @@ def emit_commands(syntax):
327337
commands.append(command)
328338
elif syntax == "bat":
329339
commands.append(command + " || exit /b")
340+
elif syntax == "json":
341+
commands.append(command)
330342
else:
331343
assert False
332344

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"
334349

335350
@jinja2.pass_context
336351
def invoke_tool(context, name):
@@ -339,6 +354,8 @@ def invoke_tool(context, name):
339354
return f"\"${env_var}\""
340355
elif context.parent["syntax"] == "bat":
341356
return f"call %{env_var}%"
357+
elif context.parent["syntax"] == "json":
358+
return name
342359
else:
343360
assert False
344361

0 commit comments

Comments
 (0)