Skip to content

Commit 5ee3796

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 eb8645f commit 5ee3796

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

amaranth/build/plat.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
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
10+
import warnings
811

912
from .. import __version__
1013
from .._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

Comments
 (0)