Files
msime-windows/installer/Invoke-LocalTest.ps1
T
fanlusky d30d2946e4 feat(installer): 打包时生成并安装词格语言模型 sc.lm
sc.lm 此前只能手工投放,重装即失效,发布包里也没有它。这里把它变成一个被钉住、
可复现、自动参与打包的产品输入。

它不走词库那条路:词库 release 由本仓库之外的构建器产出,资产集合和摘要在产品锁
里逐一钉死,加一项要对方先发新版。改为独立钉住上游语料,与 libime 自己的做法一致。

- language-model/lock.json 钉住上游 URL、语料摘要、转换参数和产物摘要。转换是
  确定性的(已在 MSVC 14.44 与 14.50 两套工具链上验证产物摘要一致),所以产物
  摘要可以像下载摘要一样钉死。
- scripts/build-language-model.ps1 下载、校验、转换、再校验,写临时文件后改名,
  中途失败不会留下摘要对不上的 sc.lm。幂等,摘要对得上直接返回。
- 它只 configure engine/ngram 一个目录,不拉 vcpkg 和 SQLite:转换工具只依赖
  kenlm 自己,而打包机上未必装得起引擎的全部依赖。
- Invoke-LocalTest.ps1 打完整包前自动调用它,轻量包本就不带数据文件,不调。
- 打包脚本只断言文件存在,摘要由构建脚本负责,与词库交给 product_lock.py 校验
  的分工一致。缺模型让打包失败而不是跳过:引擎对缺模型是静默降级的,运行期不会
  暴露,打包是唯一拦得住的地方,package-files.ps1 为此加了反向用例。

模型是 LGPL-2.1-or-later 的第三方数据,声明随之安装为 libime-lm-NOTICE.md。
安装脚本无需改动,它已按通配收集资源目录。产物与语料不进仓库,只进锁与声明。
2026-09-19 10:08:39 +08:00

76 lines
4.0 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 本地测试安装流程的共用实现:编译本仓组件 → 收集安装文件 → 本机自签名 →
# Inno Setup 打包 → 签安装包 → 启动安装程序。
#
# 三个入口都是这个脚本的薄包装:
# test.ps1 完整包(含词库),不含 PDB
# test-light.ps1 轻量包(不含词库),不含 PDB
# test-symbols.ps1 带 PDB,默认轻量,加 -Full 走完整包
#
# 编译是增量的:build-release / build{32,64}-release 已有 CMake 缓存时不再重跑 configure
# (Visual Studio 生成器的 ZERO_CHECK 会在 CMakeLists.txt 变化时自己重新生成),并且只构建
# 打包用的目标,不构建那些打完包又被删掉的测试可执行文件。-Reconfigure 可强制重跑 configure。
[CmdletBinding()]
param(
# 轻量包:跳过词库、辅助码、拼音表和出厂配置,只刷新 TSF、Server、HTML。
# 适用:只改了 TSF、Server 或 HTML,本机已有完整安装(词库已在
# %LOCALAPPDATA%\metasequoiaime)。不要用轻量包做首次安装。
[switch]$Light,
# 把 PDB 打进安装包。PDB 有 ~140 MB,而真正的二进制只有 ~20 MB,Inno Setup 还要对它们做
# 固实 LZMA2 压缩,所以默认不打包;只有需要在装好的机器上直接做崩溃分析时才加这个开关。
[switch]$IncludeSymbols,
# 强制重跑 CMake configure(改了 preset、换了工具链或怀疑缓存不对时用)。
[switch]$Reconfigure
)
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
# Every build step below uses its own Push-Location and absolute paths ($repoRoot / $PSScriptRoot),
# so the script never relies on the process cwd. Push/pop it here too, inside try/finally, so the
# caller's shell is left where it started instead of stranded in installer\ when the script exits.
Push-Location $PSScriptRoot
try {
$repoRoot = Split-Path -Parent $PSScriptRoot
$tsfCompile = Join-Path $repoRoot 'windows\scripts\lcompile-release-both.ps1'
$serverCompile = Join-Path $repoRoot 'server\scripts\lcompile-release.ps1'
$settingsDir = Join-Path $repoRoot 'ui-html\webview2\settings\ime-settings'
# All three are directories of this repository now, so a missing one is a broken checkout rather
# than a neighbour nobody cloned. Skipping the build and packaging whatever binaries happen to be
# lying around would produce an installer you then run on your own machine.
foreach ($required in @($tsfCompile, $serverCompile, (Join-Path $settingsDir 'package.json'))) {
if (-not (Test-Path -LiteralPath $required -PathType Leaf)) {
throw "缺少组件构建入口:$required"
}
}
Push-Location (Join-Path $repoRoot 'windows')
try { & $tsfCompile -Reconfigure:$Reconfigure } finally { Pop-Location }
Push-Location (Join-Path $repoRoot 'server')
try { & $serverCompile -Reconfigure:$Reconfigure } finally { Pop-Location }
Push-Location $settingsDir
try {
pnpm run build
if ($LASTEXITCODE -ne 0) { throw "Settings page build failed ($LASTEXITCODE)" }
} finally { Pop-Location }
# 轻量包不带任何数据文件,所以只有完整包需要语言模型。脚本是幂等的:摘要对得上时
# 直接返回,不重下也不重转,因此这里无条件调用不会让日常 test.ps1 变慢。首次运行
# 要下 ~75 MB 并转换一次,之后都是秒回。
if (-not $Light) {
& (Join-Path $repoRoot 'scripts\build-language-model.ps1')
}
& (Join-Path $PSScriptRoot 'Prepare-PackageFiles.ps1') -Light:$Light -IncludeSymbols:$IncludeSymbols `
-RepoRoot $repoRoot -TsfDirectory windows -ServerDirectory server -UiHtmlDirectory ui-html -NoticesDirectory .
& (Join-Path $PSScriptRoot 'Sign-PackageBinaries-Local.ps1')
& (Join-Path $PSScriptRoot 'Compile-Installer.ps1') -Light:$Light
& (Join-Path $PSScriptRoot 'Sign-Installer-Local.ps1') -Light:$Light
& (Join-Path $PSScriptRoot 'Install.ps1') -Light:$Light
} finally {
Pop-Location
}