Skip to content

build.plat: add build_{{name}}.json output #1617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions amaranth/build/plat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
from collections.abc import Iterable
from abc import ABCMeta, abstractmethod
import os
import textwrap
import re
import json
import shlex
import jinja2
import textwrap
import warnings

from .. import __version__
Expand Down Expand Up @@ -217,6 +219,12 @@ class TemplatedPlatform(Platform):
if defined {{platform._toolchain_env_var}} call "%{{platform._toolchain_env_var}}%"
{{emit_commands("bat")}}
""",
"build_{{name}}.json": """
{
"comment": "{{autogenerated}}",
"commands": {{emit_commands("json")}}
}
""",
}

def iter_signal_clock_constraints(self):
Expand Down Expand Up @@ -315,6 +323,8 @@ def emit_commands(syntax):
template = \
"if [!{env_var}!] equ [\"\"] set {env_var}=\n" \
"if [!{env_var}!] equ [] set {env_var}={name}"
elif syntax == "json":
continue
else:
assert False
commands.append(template.format(env_var=env_var, name=name))
Expand All @@ -327,10 +337,15 @@ def emit_commands(syntax):
commands.append(command)
elif syntax == "bat":
commands.append(command + " || exit /b")
elif syntax == "json":
commands.append(command)
else:
assert False

return "\n".join(commands) + "\n"
if syntax == "json":
return json.dumps([shlex.split(command) for command in commands])
else:
return "\n".join(commands) + "\n"

@jinja2.pass_context
def invoke_tool(context, name):
Expand All @@ -339,6 +354,8 @@ def invoke_tool(context, name):
return f"\"${env_var}\""
elif context.parent["syntax"] == "bat":
return f"call %{env_var}%"
elif context.parent["syntax"] == "json":
return name
else:
assert False

Expand Down
19 changes: 19 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Documentation for past releases

Documentation for past releases of the Amaranth language and toolchain is available online:

* `Amaranth 0.5.7 <https://amaranth-lang.org/docs/amaranth/v0.5.7/>`_
* `Amaranth 0.5.6 <https://amaranth-lang.org/docs/amaranth/v0.5.6/>`_
* `Amaranth 0.5.5 <https://amaranth-lang.org/docs/amaranth/v0.5.5/>`_
* `Amaranth 0.5.4 <https://amaranth-lang.org/docs/amaranth/v0.5.4/>`_
* `Amaranth 0.5.3 <https://amaranth-lang.org/docs/amaranth/v0.5.3/>`_
Expand Down Expand Up @@ -92,6 +94,23 @@ Platform integration changes
* Changed: the Gowin platform now uses ``nextpnr-himbaechel`` rather than ``nextpnr-gowin``.


Version 0.5.7
=============

Platform integration changes
----------------------------

.. currentmodule:: amaranth.vendor

* Added: build commands are also serialized to ``build_{{name}}.json``.


Version 0.5.6
=============

Updated to address compatibility with PyPy 3.11.


Version 0.5.5
=============

Expand Down
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
r"^http://127\.0\.0\.1:8000$",
# Picked up automatically by ReST and doesn't have an index.
r"^https://amaranth-lang\.org/schema/$",
# Rejects requests from GHA infra.
r"^https://.+\.sourceforge\.net/"
]

linkcheck_anchors_ignore_for_url = [
Expand Down
Loading