From 1bfa714244dd59224a8880bc3ddd371a0e0048df Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Wed, 4 Sep 2024 13:23:07 +0200 Subject: [PATCH] On failure `generate_references.py` save error message. --- test/usecases/generate_references.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/test/usecases/generate_references.py b/test/usecases/generate_references.py index c401b50dc..dbfc244c3 100755 --- a/test/usecases/generate_references.py +++ b/test/usecases/generate_references.py @@ -13,16 +13,31 @@ def substitute_line(lines, starts_with, replacement): break +def ensure_directory_exists(filename=None, dirname=None): + if dirname is None: + dirname = os.path.dirname(filename) + + if dirname and not os.path.exists(dirname): + os.makedirs(dirname) + + def generate_references(nmodl, usecase_dir, output_dir, nmodl_flags): mod_files = glob.glob(os.path.join(usecase_dir, "*.mod")) for mod_file in mod_files: try: subprocess.run( - ["nmodl", mod_file, *nmodl_flags, "-o", output_dir], check=True + [nmodl, mod_file, *nmodl_flags, "-o", output_dir], + capture_output=True, + check=True, ) except subprocess.CalledProcessError as e: - print(e.output) - raise e + if e.output: + cxx_file = os.path.join( + output_dir, os.path.basename(mod_file[:-4] + ".cpp") + ) + ensure_directory_exists(filename=cxx_file) + with open(cxx_file, "w") as cxx: + cxx.write(e.output.decode("utf-8")) cxx_files = glob.glob(os.path.join(output_dir, "*.cpp"))