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