本地打包每次都要等很久,其中编译这一段有两处纯粹的重复劳动。 Visual Studio 生成器把 ZERO_CHECK 接进了每个目标,CMakeLists.txt 变化时 构建会自己重新生成,所以已有 CMake 缓存时前置的 cmake --preset 不改变任何 结果,只是每个构建目录白等约 10 秒,三个目录就是 30 秒。改成缓存存在就跳过, 需要强制重跑(改了 preset、换了工具链)时传 -Reconfigure。 构建目标也从 ALL_BUILD 收窄到 MetasequoiaImeServer / MetasequoiaImeTsf。 原先会一并构建 MetasequoiaImeServerTests、test_webview_contract、 test_windows_ipc_contract,而 Prepare-PackageFiles.ps1 随后又把它们从包里 删掉。server 目标的依赖闭包已经覆盖 Watchdog、三个面板、Settings、 DictionaryReplay 和 OpenCC 词典,产物一个不少。要连测试一起构建(比如为了 跑 ctest)传 -Target ALL_BUILD,server/AGENTS.md 里的 ctest 段落已注明。 顺带给 cmake --build 加上 --parallel,真正有代码改动时也能并行。 无改动时的增量编译:TSF 18.0s -> 3.7s,Server 21.9s -> 10.9s。 CI 不受影响,它直接调 cmake,不经过这些脚本。
26 lines
1.4 KiB
PowerShell
26 lines
1.4 KiB
PowerShell
# Build the TSF DLL without depending on the caller's working directory.
|
|
[CmdletBinding()]
|
|
param(
|
|
[ValidateSet('32', '64')][string]$Architecture = '64',
|
|
# ALL_BUILD also builds test_windows_ipc_contract and the tests/ subdirectory, neither of which
|
|
# is packaged. Naming the DLL target keeps a local packaging run from paying for them; the test
|
|
# jobs still build ALL_BUILD by passing -Target ALL_BUILD.
|
|
[string]$Target = 'MetasequoiaImeTsf',
|
|
# The Visual Studio generator wires ZERO_CHECK into every target, so a build regenerates itself
|
|
# whenever CMakeLists.txt changes. Re-running configure up front only costs ~10s per build
|
|
# directory without changing the result, so do it once and let ZERO_CHECK handle the rest.
|
|
[switch]$Reconfigure
|
|
)
|
|
$ErrorActionPreference = 'Stop'
|
|
$projectRoot = Split-Path -Parent $PSScriptRoot
|
|
$buildDirectory = Join-Path $projectRoot "build$Architecture-release"
|
|
Push-Location $projectRoot
|
|
try {
|
|
if ($Reconfigure -or -not (Test-Path -LiteralPath (Join-Path $buildDirectory 'CMakeCache.txt'))) {
|
|
cmake "--preset=for$Architecture-release"
|
|
if ($LASTEXITCODE -ne 0) { throw "TSF $Architecture configure failed ($LASTEXITCODE)" }
|
|
}
|
|
cmake --build $buildDirectory --config Release --target $Target --parallel
|
|
if ($LASTEXITCODE -ne 0) { throw "TSF $Architecture build failed ($LASTEXITCODE)" }
|
|
} finally { Pop-Location }
|