build.run: add BuildPlan.execute_docker()

One usecase for this is using amaranth with vivado on macOs.
This commit is contained in:
Jaro Habiger 2024-01-03 11:40:54 +01:00 committed by Catherine
parent 3200a3961d
commit b823a8ee9d
2 changed files with 23 additions and 0 deletions

View file

@ -115,6 +115,28 @@ class BuildPlan:
return LocalBuildProducts(build_dir)
def execute_local_docker(self, image, *, root="build", docker_args=[]):
"""
Execute build plan inside a Docker container. Files from the build plan are placed in the
build root directory ``root`` on the local filesystem. This directory is bind mounted to
``/build`` in a container and the script ``{script}.sh`` is executed inside it.
``docker_args`` is a list containing additional arguments to docker.
Returns :class:`LocalBuildProducts`.
"""
build_dir = self.extract(root)
subprocess.check_call([
"docker", "run", *docker_args,
"--rm", # remove the container after running
"--mount", f"type=bind,source={build_dir},target=/build",
"--workdir", "/build",
image,
"sh", f"{self.script}.sh",
])
return LocalBuildProducts(build_dir)
def execute_remote_ssh(self, *, connect_to={}, root, run_script=True):
"""
Execute build plan using the remote SSH strategy. Files from the build

View file

@ -35,6 +35,7 @@ Platform integration changes
.. currentmodule:: amaranth.vendor
* Added: :meth:`BuildPlan.execute_local_docker`.
* Added: :meth:`BuildPlan.extract`.
* Added: ``build.sh`` begins with ``#!/bin/sh``.
* Removed: (deprecated in 0.4) :mod:`vendor.intel`, :mod:`vendor.lattice_ecp5`, :mod:`vendor.lattice_ice40`, :mod:`vendor.lattice_machxo2_3l`, :mod:`vendor.quicklogic`, :mod:`vendor.xilinx`. (`RFC 18`_)