From 6fea2c20cfd95709adb05e9ba339f2cc1f993bdb Mon Sep 17 00:00:00 2001 From: yadavchiragg Date: Sat, 14 Nov 2026 20:11:19 +0530 Subject: [PATCH 1/2] fix(docker): add Dockerfile.cpp so C++ nodes can build in docker mode mkconcore selects Dockerfile.cpp for .cpp nodes, but the template did not exist, so every docker build of a C++ workflow exited with a misleading 'not correct path to concore' error. Add the template, emit the g++ compile step and CMD like the Verilog path does, and narrow the bare except so a missing template names the actual file. Adds tests. --- Dockerfile.cpp | 8 ++++++++ mkconcore.py | 7 +++++-- tests/test_docker_cpp.py | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 Dockerfile.cpp create mode 100644 tests/test_docker_cpp.py diff --git a/Dockerfile.cpp b/Dockerfile.cpp new file mode 100644 index 0000000..e211ec4 --- /dev/null +++ b/Dockerfile.cpp @@ -0,0 +1,8 @@ +FROM ubuntu:22.04 + +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + g++ && rm -rf /var/lib/apt/lists/* + +COPY . /src +WORKDIR /src + diff --git a/mkconcore.py b/mkconcore.py index a1f44ef..86f4127 100644 --- a/mkconcore.py +++ b/mkconcore.py @@ -842,8 +842,8 @@ def cleanup_script_files(): logging.info("assuming .m extension for Dockerfile") with open(src_path) as fsource: source_content = fsource.read() - except: - logging.error(f"{CONCOREPATH} is not correct path to concore") + except OSError as e: + logging.error(f"Cannot read Dockerfile template '{src_path}': {e}") sys.exit(1) dockerfile_parent = os.path.dirname(dockerfile_path) if dockerfile_parent: @@ -862,6 +862,9 @@ def cleanup_script_files(): if langext=="sh": fcopy.write('CMD ["./'+sourcecode+'" ,"/opt/mcr/v910"]') # 5/19/21 #["./run_pmmat.sh", "/opt/mcr/MATLAB/MATLAB_Runtime/v910"] + if langext=="cpp": + fcopy.write('RUN g++ ./'+sourcecode+'\n') + fcopy.write('CMD ["./a.out"]\n') if langext=="v": fcopy.write('RUN iverilog ./'+sourcecode+'\n') # 7/02/21 fcopy.write('CMD ["./a.out"]\n') # 7/02/21 diff --git a/tests/test_docker_cpp.py b/tests/test_docker_cpp.py new file mode 100644 index 0000000..a6f80e1 --- /dev/null +++ b/tests/test_docker_cpp.py @@ -0,0 +1,33 @@ +import subprocess +import sys +from pathlib import Path + +REPO = Path(__file__).resolve().parent.parent + + +def test_dockerfile_cpp_template_exists(): + assert (REPO / "Dockerfile.cpp").is_file() + + +def test_docker_build_for_cpp_node(tmp_path): + out = tmp_path / "study" + result = subprocess.run( + [ + sys.executable, + str(REPO / "mkconcore.py"), + str(REPO / "testsou" / "testSM1.graphml"), + str(REPO / "testsou"), + str(out), + "docker", + ], + capture_output=True, + text=True, + ) + assert result.returncode == 0, result.stdout + result.stderr + dockerfiles = sorted((out / "src").glob("Dockerfile.*")) + assert dockerfiles + for df in dockerfiles: + text = df.read_text() + assert "g++" in text + assert "RUN g++ ./" in text + assert 'CMD ["./a.out"]' in text From 94f2ac21b5d3d1f995fa1ff8e1ae5ca64fbbcd2c Mon Sep 17 00:00:00 2001 From: yadavchiragg Date: Sun, 15 Nov 2026 08:25:43 +0530 Subject: [PATCH 2/2] test(docker): check every Dockerfile template mkconcore selects exists Parses mkconcore.py for the Dockerfile. templates it can pick in docker mode and asserts each is present, and compiles sample C++ nodes the way the generated Dockerfile does. This would have caught the missing Dockerfile.cpp. --- tests/test_docker_templates.py | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/test_docker_templates.py diff --git a/tests/test_docker_templates.py b/tests/test_docker_templates.py new file mode 100644 index 0000000..6d72f82 --- /dev/null +++ b/tests/test_docker_templates.py @@ -0,0 +1,43 @@ +import re +import shutil +import subprocess +from pathlib import Path + +import pytest + +REPO = Path(__file__).resolve().parent.parent + + +def _templates_referenced_by_mkconcore(): + """Dockerfile. names that mkconcore.py can select in docker mode.""" + text = (REPO / "mkconcore.py").read_text() + return sorted(set(re.findall(r'CONCOREPATH\s*\+\s*"/(Dockerfile\.\w+)"', text))) + + +def test_mkconcore_references_templates(): + assert _templates_referenced_by_mkconcore() + + +@pytest.mark.parametrize("name", _templates_referenced_by_mkconcore()) +def test_referenced_dockerfile_template_exists(name): + assert (REPO / name).is_file(), ( + f"mkconcore.py selects {name} but it is not in the repo" + ) + + +@pytest.mark.skipif(shutil.which("g++") is None, reason="g++ not installed") +@pytest.mark.parametrize("source", ["pmpymat.cpp", "ccpymat.cpp"]) +def test_sample_cpp_node_compiles_like_docker_build(tmp_path, source): + # Mirrors the generated Dockerfile: the source plus the two headers + # that mkconcore copies into the build directory, compiled with plain g++. + for name in (source, "concore.hpp", "concore_base.hpp"): + shutil.copy( + REPO / "testsou" / name if name == source else REPO / name, tmp_path + ) + result = subprocess.run( + ["g++", f"./{source}", "-o", str(tmp_path / "a.out")], + cwd=tmp_path, + capture_output=True, + text=True, + ) + assert result.returncode == 0, result.stderr