Skip to content

Commit 4635956

Browse files
tbitcsoz-agent
andcommitted
feat: mount host dotnet + CANopenEditor into container for EDSSharp OD generation
Adds _edssharp_volumes() to bind-mount $HOME/.dotnet and $HOME/.local/tools/canopeneditor (read-only) into the build container. Adds _container_prep_cmd() to pip-install canopennode deps and write /root/.local/bin/EDSSharp wrapper, allowing CMake find_program(EDSSharp) to succeed so CANopenNode can generate OD.c/OD.h from XDD/EDS at build time. Re-adds PYTHONPATH=/work/modules/west-env so the west-env extension is importable inside the container. Mounts are skipped silently when host paths do not exist. Co-Authored-By: Oz <oz-agent@warp.dev>
1 parent 1ead262 commit 4635956

1 file changed

Lines changed: 45 additions & 2 deletions

File tree

west_env/container.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,47 @@ def _container_workdir(workspace, host_cwd):
2222
return CONTAINER_WORKDIR
2323

2424

25+
def _edssharp_volumes(host_home: Path) -> list:
26+
"""Volume-mount args to expose host dotnet + CANopenEditor into container.
27+
28+
Mounted read-only under /root/ so the EDSSharp wrapper written by
29+
_container_prep_cmd() can invoke dotnet on the mounted DLL.
30+
Mounts are skipped silently when the paths don't exist on the host.
31+
"""
32+
mounts = []
33+
dotnet_dir = host_home / ".dotnet"
34+
coed_dir = host_home / ".local" / "tools" / "canopeneditor"
35+
if dotnet_dir.is_dir():
36+
mounts += ["-v", f"{dotnet_dir}:/root/.dotnet:ro"]
37+
if coed_dir.is_dir():
38+
mounts += ["-v", f"{coed_dir}:/root/.local/tools/canopeneditor:ro"]
39+
return mounts
40+
41+
42+
def _container_prep_cmd() -> str:
43+
"""Shell commands run before the main build command inside the container.
44+
45+
1. Installs project-specific Python deps (canopennode requirements).
46+
2. Writes /root/.local/bin/EDSSharp wrapper using the dotnet runtime and
47+
CANopenEditor DLL bind-mounted from the host by _edssharp_volumes().
48+
This lets CMake find_program(EDSSharp) succeed for OD.c/OD.h generation.
49+
"""
50+
pip_cmd = (
51+
"pip install --quiet --disable-pip-version-check "
52+
"-r /work/external/zephyr/modules/canopennode/zephyr/requirements.txt "
53+
"2>/dev/null || true"
54+
)
55+
edssharp_cmd = (
56+
"mkdir -p /root/.local/bin && "
57+
"_dll=$(find /root/.local/tools/canopeneditor -name 'EDSSharp.dll' 2>/dev/null | head -1) && "
58+
"[ -n \"$_dll\" ] && "
59+
"printf '#!/bin/sh\\nexport DOTNET_ROOT=/root/.dotnet\\nexport PATH=/root/.dotnet:/root/.local/bin:$PATH\\nexec dotnet \"%s\" \"$@\"\\n' \"$_dll\" "
60+
"> /root/.local/bin/EDSSharp && "
61+
"chmod +x /root/.local/bin/EDSSharp || true"
62+
)
63+
return f"{pip_cmd} && {edssharp_cmd}"
64+
65+
2566
def _container_args(
2667
cfg, command, interactive=False, workspace=None, host_cwd=None
2768
):
@@ -47,7 +88,9 @@ def _container_args(
4788
f"{workspace}:{CONTAINER_WORKDIR}",
4889
"-w",
4990
container_wd,
50-
]
91+
"-e",
92+
"PYTHONPATH=/work/modules/west-env",
93+
] + _edssharp_volumes(Path.home())
5194

5295
if interactive:
5396
args.extend(["-i", "-t"])
@@ -70,7 +113,7 @@ def _container_args(
70113
args.extend([
71114
"sh",
72115
"-c",
73-
f"{git_prep} && exec {full_cmd}",
116+
f"{git_prep} && {_container_prep_cmd()} && exec {full_cmd}",
74117
])
75118
return engine, warned, args
76119

0 commit comments

Comments
 (0)