|
|
楼主 |
发表于 2026-9-6 20:47:17
|
显示全部楼层
def run_uv4(uv4, proj_path, target, rebuild=False, timeout=900):
fd, logfile = tempfile.mkstemp(prefix='keil_build_', suffix='.log')
os.close(fd)
cmd = [uv4, '-r' if rebuild else '-b', proj_path, '-t', target, '-j0', '-o', logfile]
try:
subprocess.run(cmd, timeout=timeout, creationflags=subprocess.CREATE_NO_WINDOW)
except subprocess.TimeoutExpired:
subprocess.run(['taskkill', '/F', '/IM', 'UV4.exe'],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
creationflags=subprocess.CREATE_NO_WINDOW)
text = (_read_log(logfile) or '') + '\n[编译超时, 已强制结束 UV4]'
try: os.remove(logfile)
except Exception: pass
return False, text, 1, 0
except Exception as ex:
try: os.remove(logfile)
except Exception: pass
return False, f'[启动 UV4 失败: {ex}]', 1, 0
text = _read_log(logfile) or ''
try: os.remove(logfile)
except Exception: pass
e, w = count_errors(text)
return (e == 0), text, e, w |
|