FIX: build_windows.ps1 parse error PS5.1 — ASCII-only + UTF-8 BOM (unicode em-dash lam hong string terminator)

This commit is contained in:
2026-08-08 14:01:40 +00:00
parent eaca051191
commit 8b0551b18f
2 changed files with 18 additions and 7 deletions
+9 -7
View File
@@ -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 # 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" $ErrorActionPreference = "Stop"
Set-Location $PSScriptRoot 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) ==" Write-Host "== [3/6] Build daw_engine.exe (PyInstaller) =="
pyinstaller engine.spec --clean --noconfirm pyinstaller engine.spec --clean --noconfirm
Write-Host "== [3.5/6] Verify bundle contents (app/static, app/templates phi có) ==" Write-Host "== [3.5/6] Verify bundle contents (app/static, app/templates phai co) =="
# Bt li bundle NGAY ti build (đã gp 2 ln: chy pyinstaller t nơi khác # Bat loi bundle NGAY tai build (da gap 2 lan: chay pyinstaller tu noi khac
# -> static/templates thiếu -> exe crash 'Directory ...\app\static does not exist'). # -> static/templates thieu -> exe crash 'Directory ...\app\static does not exist').
$missing = @() $missing = @()
if (-not (Test-Path "build\engine\Analysis-00.toc")) { if (-not (Test-Path "build\engine\Analysis-00.toc")) {
# PyInstaller 6.x: đọc TOC trc tiếp t Analysis # PyInstaller 6.x: doc TOC truc tiep tu Analysis
$tocFiles = Get-ChildItem "build\engine" -Filter "*.toc" -ErrorAction SilentlyContinue $tocFiles = Get-ChildItem "build\engine" -Filter "*.toc" -ErrorAction SilentlyContinue
if ($tocFiles) { if ($tocFiles) {
$tocContent = Get-Content $tocFiles[0].FullName -Raw $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 ($tocContent -notmatch "app/templates") { $missing += "app/templates" }
} }
if ($missing.Count -gt 0) { if ($missing.Count -gt 0) {
Write-Host "ERROR: Bundle thiếu: $($missing -join ', '). Dng build kim tra engine.spec datas!" -ForegroundColor Red Write-Host "ERROR: Bundle thieu: $($missing -join ', '). Dung build - kiem tra engine.spec datas!" -ForegroundColor Red
exit 1 exit 1
} else { } 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) ==" Write-Host "== [4/6] Sidecar binary -> src-tauri/binaries (tauri triple naming) =="
+9
View File
@@ -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 ### [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ủ: - **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. 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.