"""Сборка и запуск исходного регистратора с подменой GPIO/IRQ на Windows. Нужны GCC либо Clang и lld-link в PATH. TEMPLATES_ROOT задаёт библиотеку. Проверяется алгоритм, но не ABI и тайминги TI. DLL создаётся во временной папке; исходные .out/.hex прошивки не затрагиваются. """ import ctypes import os from pathlib import Path import subprocess import shutil import tempfile root = Path(__file__).resolve().parents[2] templates = Path(os.environ.get('TEMPLATES_ROOT', root.parent / 'newProject/SETGUI/third_party/templates')) protocol = templates / 'c/set-protocol' compiler = os.environ.get('CC') or shutil.which('clang') or shutil.which('gcc') if not compiler: raise SystemExit('Clang or GCC is required in PATH') link_flags = [] if 'gcc' in Path(compiler).name else ['-nostdlib', '-fuse-ld=lld', '-Wl,/noentry,/nodefaultlib'] with tempfile.TemporaryDirectory(prefix='ump-recorder-') as directory: library = Path(directory) / 'recorder_test.dll' subprocess.run([ compiler, '-shared', *link_flags, '-Wno-unknown-pragmas', '-Wno-int-to-pointer-cast', '-Itests/ump_logger/stubs', '-ISource/Internal/Include', '-I' + str(protocol), '-I' + str(protocol / 'ports/tms320f28335'), 'tests/ump_logger/recorder_test.c', 'Source/Internal/shared_ump.c', '-o', str(library), ], cwd=root, check=True) # Отдельный процесс освобождает DLL до удаления временной папки Windows. subprocess.run([ os.sys.executable, '-c', 'import ctypes,sys; r=ctypes.CDLL(sys.argv[1]).run_tests(); ' 'print("PASS" if r==0 else f"FAIL: C line {r}"); sys.exit(bool(r))', str(library), ], check=True)