diff --git a/build_windows.ps1 b/build_windows.ps1 index 5e7398c..3eb2716 100644 --- a/build_windows.ps1 +++ b/build_windows.ps1 @@ -1,5 +1,7 @@ -# build_windows.ps1 — ONE-COMMAND build: daw_engine.exe (PyInstaller) + Tauri v2 (NSIS + MSI) +# build_windows.ps1 - ONE-COMMAND build: daw_engine.exe (PyInstaller) + Tauri v2 (NSIS + MSI) # Chay tren Windows: powershell -ExecutionPolicy Bypass -File build_windows.ps1 +# LUU Y: file nay chi dung ky tu ASCII (khong dau, khong em-dash) - PowerShell 5.1 +# doc .ps1 khong BOM theo ANSI, ky tu Unicode bi hong -> "String is missing terminator". $ErrorActionPreference = "Stop" Set-Location $PSScriptRoot @@ -14,12 +16,12 @@ node build.mjs # @babel/standalone; thay cho 'npm run build' (Babel 8 ESM-only Write-Host "== [3/6] Build daw_engine.exe (PyInstaller) ==" pyinstaller engine.spec --clean --noconfirm -Write-Host "== [3.5/6] Verify bundle contents (app/static, app/templates phải có) ==" -# Bắt lỗi bundle NGAY tại build (đã gặp 2 lần: chạy pyinstaller từ nơi khác -# -> static/templates thiếu -> exe crash 'Directory ...\app\static does not exist'). +Write-Host "== [3.5/6] Verify bundle contents (app/static, app/templates phai co) ==" +# Bat loi bundle NGAY tai build (da gap 2 lan: chay pyinstaller tu noi khac +# -> static/templates thieu -> exe crash 'Directory ...\app\static does not exist'). $missing = @() if (-not (Test-Path "build\engine\Analysis-00.toc")) { - # PyInstaller 6.x: đọc TOC trực tiếp từ Analysis + # PyInstaller 6.x: doc TOC truc tiep tu Analysis $tocFiles = Get-ChildItem "build\engine" -Filter "*.toc" -ErrorAction SilentlyContinue if ($tocFiles) { $tocContent = Get-Content $tocFiles[0].FullName -Raw @@ -32,10 +34,10 @@ if (-not (Test-Path "build\engine\Analysis-00.toc")) { if ($tocContent -notmatch "app/templates") { $missing += "app/templates" } } if ($missing.Count -gt 0) { - Write-Host "ERROR: Bundle thiếu: $($missing -join ', '). Dừng build — kiểm tra engine.spec datas!" -ForegroundColor Red + Write-Host "ERROR: Bundle thieu: $($missing -join ', '). Dung build - kiem tra engine.spec datas!" -ForegroundColor Red exit 1 } else { - Write-Host "OK: app/static + app/templates có trong bundle." -ForegroundColor Green + Write-Host "OK: app/static + app/templates co trong bundle." -ForegroundColor Green } Write-Host "== [4/6] Sidecar binary -> src-tauri/binaries (tauri triple naming) ==" diff --git a/wiki.md b/wiki.md index 99de8ab..b3ebc11 100644 --- a/wiki.md +++ b/wiki.md @@ -1,3 +1,12 @@ +### [2026-08-08] FIX: build_windows.ps1 lỗi parse PowerShell — "String is missing terminator" (file chứa ký tự Unicode, PS 5.1 đọc theo ANSI) +- **Tóm tắt thay đổi:** User chạy build_windows.ps1 trên Windows nhận ParserError "String is missing terminator" ở dòng 57 + "Missing closing '}'" ở dòng 34. Root cause: bản mình thêm bước verify [3.5/6] có chứa ký tự Unicode (em-dash `—` trong comment + chuỗi tiếng Việt có dấu "thiếu/Dừng/kiểm tra"). PowerShell 5.1 đọc file .ps1 KHÔNG có BOM theo ANSI/Windows-1252 → byte UTF-8 của `—` (E2 80 94) giải mã thành `â€"` — dấu ngoặc kép giả chui vào giữa chuỗi → chuỗi "mất terminator" + block `{}` lệch. Fix: + 1. Viết lại toàn bộ build_windows.ps1 **chỉ ASCII** (bỏ dấu tiếng Việt, bỏ em-dash, dùng `->`). + 2. Thêm **UTF-8 BOM** (EF BB BF) vào đầu file — PowerShell đọc đúng encoding bất kể. + 3. Giữ nguyên bước verify [3.5/6] (TOC check app/static + app/templates). +- **Các file ảnh hưởng:** `build_windows.ps1` (ASCII-only + BOM) +- **Ghi chú/Test (nếu có):** File giờ 0 ký tự non-ASCII, có BOM; brace depth = 0 (cân bằng), không có dòng Write-Host quote lẻ. Lưu ý chung: MỌI .ps1/.bat trong dự án phải ASCII-only + BOM (PS 5.1 ANSI bug) — tránh tiếng Việt có dấu/em-dash trong file script Windows. + +--- ### [2026-08-08] FIX (LẦN 2): Windows exe vẫn crash 'app\static does not exist' + stuck 'Đang khởi động Engine' — bundle qua collect_data_files + fallback + verify build - **Tóm tắt thay đổi:** User build bản Windows vẫn gặp RuntimeError `Directory '..._MEIxxxx\app\static' does not exist` (lần 2 — fix trước dùng datas ABSOLUTE theo SPECPATH nhưng trên máy user vẫn thiếu static trong bundle) + UI stuck "Đang khởi động SonicForge Engine". 3 lớp phòng thủ: 1. **engine.spec — bundle qua IMPORT SYSTEM**: bỏ datas đường dẫn tĩnh, thay bằng `collect_data_files('app', excludes=['**/storage/**','**/__pycache__/**','**/*.pyc'])` — PyInstaller tự tìm assets (static/templates/models) qua package import, KHÔNG phụ thuộc CWD/SPECPATH lúc chạy lệnh (nguyên nhân gốc: chạy pyinstaller từ thư mục khác → relative path không resolve → bỏ qua âm thầm). Loại luôn `app/storage` (57MB soundfonts — vô ích trong onefile, config.py đã redirect %APPDATA%). Giữ `md/` (ngoài package) + librosa .pyi.