import shutil import os import sys import subprocess import threading clean = '--noclean' not in sys.argv kernel_only = '--kernel-only' in sys.argv cmd = r'D:\Python312\python.exe ../Projectrans.py --project VKernel/project.json' if clean: cmd += ' --clean' cmd += ' --clear-cache' os.system(cmd) shutil.copy("VKernel/output/kernel.bin", "./disk/sys/kernel/x86_64/kernel.bin") if kernel_only: # 仅重编译VKernel,跳过其他应用和库 print("[build] --kernel-only: 跳过其他应用和库的编译") so_path = os.path.abspath("Libs/SerialLogger/output/slog.so") vpui_path = os.path.abspath("Libs/VPUI64/output/vpui64.so") # 确保disk.img中的apps和libs存在(使用之前的缓存) if not os.path.exists("./disk/apps/hello.elf"): print("[build] 警告: hello.elf 不存在,请先不带 --kernel-only 完整构建一次") else: so_cmd = r'D:\Python312\python.exe ../Projectrans.py --project Libs/SerialLogger/project.json' if clean: so_cmd += ' --clean' os.system(so_cmd) vpui_cmd = r'D:\Python312\python.exe ../Projectrans.py --project Libs/VPUI64/project.json' if clean: vpui_cmd += ' --clean' os.system(vpui_cmd) app_cmd = r'D:\Python312\python.exe ../Projectrans.py --project Apps/HelloWorld/project.json' if clean: app_cmd += ' --clean' os.system(app_cmd) os.makedirs("./disk/apps", exist_ok=True) shutil.copy("Apps/HelloWorld/output/helloworld.elf", "./disk/apps/hello.elf") term_cmd = r'D:\Python312\python.exe ../Projectrans.py --project Apps/Terminal/project.json' if clean: term_cmd += ' --clean' os.system(term_cmd) shutil.copy("Apps/Terminal/output/terminal.elf", "./disk/apps/terminal.elf") garg_cmd = r'D:\Python312\python.exe ../Projectrans.py --project Apps/Gargantua/project.json' if clean: garg_cmd += ' --clean' os.system(garg_cmd) shutil.copy("Apps/Gargantua/output/gargantua.elf", "./disk/apps/gargantua.elf") scene3d_cmd = r'D:\Python312\python.exe ../Projectrans.py --project Apps/Scene3D/project.json' if clean: scene3d_cmd += ' --clean' os.system(scene3d_cmd) shutil.copy("Apps/Scene3D/output/scene3d.elf", "./disk/apps/scene3d.elf") os.makedirs("./disk/libs", exist_ok=True) so_path = os.path.abspath("Libs/SerialLogger/output/slog.so") vpui_path = os.path.abspath("Libs/VPUI64/output/vpui64.so") if os.path.exists(so_path): shutil.copy(so_path, "./disk/libs/slog.so") if os.path.exists(vpui_path): shutil.copy(vpui_path, "./disk/libs/vpui64.so") os.system('powershell -ExecutionPolicy Bypass -File ./Scripts/disk.ps1') #if "--noqemu" not in sys.argv: 不准使用 --noqemu!!! serial_log = os.path.abspath("serial.log") if os.path.exists(serial_log): os.remove(serial_log) print(f"[build] CWD: {os.getcwd()}") print(f"[build] serial_log: {serial_log}") qemu_cmd = [ 'qemu-system-x86_64', '-pflash', r'D:\msys64\mingw64\share\qemu\edk2-x86_64-code.fd', '-drive', 'file=disk.img,format=raw,if=ide', '-m', '256m', '-vga', 'std', '-usb', '-device', 'usb-kbd', '-device', 'usb-mouse', '-accel', 'tcg,tb-size=128', '-serial', f'file:{serial_log}', '-no-reboot' ] print(f"[build] QEMU cmd: {' '.join(qemu_cmd)}") proc = subprocess.Popen(qemu_cmd) proc.wait() print(f"[build] serial_log path: {serial_log}") print(f"[build] file exists: {os.path.exists(serial_log)}") if os.path.exists(serial_log): with open(serial_log, "r", encoding="utf-8", errors="replace") as f: content = f.read() print(f"[build] serial_log size: {len(content)} bytes") print(content) try: pass # Keep serial.log for inspection except: pass else: print("[build] serial.log not found!")