refactor(build): unify SDK configuration and release tooling
Gitea CI / Check code and tests (pull_request) Failing after 8m56s
Gitea CI / Build Android APK (pull_request) Skipped
Gitea CI / Build Windows x64 app (pull_request) Skipped
Gitea CI / Audit and package Windows x64 (pull_request) Skipped
Gitea CI / Assemble and validate CI artifacts (pull_request) Skipped
Gitea CI / Gitea CI passed (pull_request) Failing after 4s

Pin Flutter with FVM and share local environment loading across IDE, Python, and Dart entrypoints. Keep CI on the verified preinstalled SDK and skip local overrides.

Extract common build presets, process execution, and file hashing. Propagate project roots through SDK selection and release commands, and migrate macOS release, signing, and DMG orchestration to Python.

Reuse local check suites in CI, support Android source overrides, and update documentation and regression tests.
This commit is contained in:
lingjhf committed 2026-10-06 22:24:32 +08:00
1 parent ca2efdaf18
commit 152c051a29
57 files changed
+1858 -375

No files matched your search

+55 -12
View File
@@ -1,6 +1,6 @@
# 仓库工具
使用 Python 3.11 或更新版本,在 cutdex 仓库根目录运行下列入口。通用检查为 `python3 tool/check.py`;可用 `FLUTTER` 指定 Flutter 可执行文件。它检查 Python/Shell 语法、Python 业务/CLI 单测及 macOS Swift 辅助工具回归和 `lib test integration_test test_driver tool` 的 Dart 静态分析,只会在临时目录编译 Swift 测试辅助程序并生成测试密钥,不执行应用打包、签名、上传或真实模型推理。Windows 没有 bash 时会明确跳过 Shell 语法检查。
使用 Python 3.11 或更新版本,先在 cutdex 仓库根目录运行 `fvm use`。通用检查为 `python3 tool/check.py`,与 CI 共用 `analyze`、`flutter`、`tools` 三个检查套件:严格静态分析、应用及内部包 Flutter 测试、源码卫生与 Python/Shell/CLI 工具检查。可通过 `--suite analyze|flutter|tools` 单独重试;macOS Swift 回归仅在宿主能力可用时运行。检查不执行应用打包、上传或真实模型推理。Windows 没有 bash 时会明确跳过 Shell 语法检查。
## 源码检查
@@ -8,32 +8,74 @@
## 稳定客户端入口
`dart run tool/mcp_stdio.dart` 由外部 MCP 客户端启动,通过 `CUTDEX_MCP_PORT` 和 `CUTDEX_MCP_TOKEN` 连接正在运行的 Cutdex。客户端配置见 [MCP 连接指南](../docs/mcp-connection.md),可用工具与参数由客户端连接后发现。
先在仓库根目录运行 `fvm use`,按 `.fvmrc` 准备项目 SDK。本地 Flutter 启动与构建
使用 `fvm dart tool/flutter_local.dart <Flutter 参数>`,或 VS Code
的 Debug/Profile/Release 启动项。入口将 `.env.local` 注入 Flutter 子进程,并保留
标准输入输出、全部参数和退出码;CI 不读取该文件。配置与优先级见
[开发指南](../docs/development.md#运行应用)。`tool/flutter-local.bat` 和
`tool/flutter-local.sh` 是 IDE 使用的薄启动入口;两者均通过 `.fvm/flutter_sdk`
使用项目的 Dart/Flutter,不读取 `FLUTTER` 环境变量或回退到全局 SDK。
Python 构建工具通过 `project_tools.py` → `project_tools.dart` 共用同一个 Dart
环境加载器。本地始终使用项目 SDK;CI 使用已通过 `.fvmrc` 校验的预装 SDK,
且跳过 `.env.local`。SDK 的 bin 放在子进程 PATH 首位,跨语言测试也使用相同版本。
`python3 tool/project_tools.py dart <参数>` 可运行 Dart 工具,保留当前工作目录。
macOS 打包在整个流水线开始前加载配置,签名、公证和更新配置均可从文件读取。
## 工具结构
```text
tool/
build.py / check.py 应用编译与检查入口
project_tools.py SDK 与环境加载的 Python 适配
common/ 构建预设、公共进程调用、退出码和文件哈希
macos/ macOS 发布、签名、DMG 与平台验证
windows/ Windows 打包、更新与 Sandbox 验证
gitea/ CI 与 Release 产物管理
```
平台 CLI 只解析参数并调用实现。macOS 的共享发布实现位于 `macos/release.py`,
调用 `common/build.py` 的同一构建预设;`build.py` 只负责命令行解析,签名和更新
验证也复用平台实现。公共构建 API 的 `root` 决定 SDK、环境加载器与默认工作目录,
独立验证工程可通过 `cwd` 单独指定构建目录。`common/process.py`
统一子进程失败退出码与诊断,不输出完整命令参数或环境。公共调用默认不增加超时,
真实 smoke 检查可自行限定时长。`common/files.py` 在各平台按流计算文件 SHA256。
HTTP 传输和平台格式验证保留在所属模块中。
应用构建统一使用 `python3 tool/build.py android|windows|macos`。默认是
production/release;可选 `--flavor development`、`--mode debug|profile|release`,
Android 可选 `--split-per-abi`,附加 Flutter 参数放在 `--` 后。Android 固定支持
ARM64/x86_64,macOS 默认输出分离符号。CI 与本地发布共用这些预设;真实更新
验证仍保留独立工程、测试入口和专用版本号。
`fvm dart run tool/mcp_stdio.dart` 由外部 MCP 客户端启动,通过 `CUTDEX_MCP_PORT` 和 `CUTDEX_MCP_TOKEN` 连接正在运行的 Cutdex。客户端配置见 [MCP 连接指南](../docs/mcp-connection.md),可用工具与参数由客户端连接后发现。
## macOS
| 脚本 | 责任 |
| --- | --- |
| macos/build_macos_release.sh | 检查 processing 包、构建 production、签名、审计、生成 ZIP/DMG;可按配置公证 |
| macos/build_macos_release.py | 检查 processing 包、构建 production、签名、审计、生成 ZIP/DMG;可按配置公证 |
| macos/check_macos_build_target.sh | 拒绝覆盖正在运行的目标 App;Xcode 构建阶段直接调用 |
| macos/check_macos_release.py | 检查 arm64、macOS 14 最低版本约束、动态依赖、签名与 worker |
| macos/sign_macos_app.sh | 处理引擎搜索路径并统一签名嵌套二进制与 App |
| macos/create_macos_dmg.sh | 从现有 App 生成安装磁盘映像 |
| macos/sign_macos_app.py | 处理引擎搜索路径并统一签名嵌套二进制与 App |
| macos/create_macos_dmg.py | 从现有 App 生成安装磁盘映像 |
| macos/release.py | 构建、签名、DMG、公证的共享实现,供平台 CLI 和验证工具调用 |
| macos/set_macos_file_icon.swift | DMG 脚本调用的文件图标辅助程序 |
| macos/macos_updates.py | 配置更新源并生成应用更新产物 |
| macos/test_macos_release.py | 构建独立 smoke App,搬迁后验证无模型及有模型启动 |
| macos/test_check_macos_release.py | 需要真实 processing 包的发布审计故障注入测试 |
| macos/test_macos_updates_unit.py | 更新配置、版本与发布规则的纯 Python 单测 |
| macos/test_release_unit.py | 使用模拟系统命令验证发布顺序、签名策略与失败清理,无需 macOS |
| macos/test_macos_updates.py | 本地更新模拟与测试服务器,需 App/Sparkle 工具 |
| macos/sparkle_test_key.swift | 更新模拟专用临时密钥工具,不写系统钥匙串 |
正常应用打包入口:
```sh
bash tool/macos/build_macos_release.sh /absolute/path/to/processing-runtime
python3 tool/macos/build_macos_release.py /absolute/path/to/processing-runtime
```
默认输出到 `dist/macos/`,第二个参数可指定输出目录。`FLUTTER`、`PYTHON` 可指定工具;最终签名使用 `CUTDEX_CODESIGN_IDENTITY`,公证使用 `CUTDEX_NOTARY_PROFILE`。开发签名配置见 [开发指南](../docs/development.md)。
默认输出到 `dist/macos/`,第二个参数可指定输出目录。Flutter 使用项目 FVM SDK,子工具复用当前 Python 解释器;最终签名使用 `CUTDEX_CODESIGN_IDENTITY`,公证使用 `CUTDEX_NOTARY_PROFILE`。这些构建配置可放在 `.env.local`。开发签名配置见 [开发指南](../docs/development.md)。
发布验证使用 `check_macos_release.py` 和 `test_macos_release.py`,参数见 `--help`。后者构建独立测试入口,完成后重新打包正常应用;搬迁启动不能代替干净 Mac 上的安装验证。
@@ -53,7 +95,7 @@ bash tool/macos/build_macos_release.sh /absolute/path/to/processing-runtime
正常发行包组装入口,构建机还需安装 `pefile`:
```powershell
flutter build windows --release --flavor production
python tool/build.py windows
python tool/windows/package_windows_release.py `
--app build/windows/x64/production/runner/Release `
--processing D:\packages\processing `
@@ -80,7 +122,7 @@ deskup 0.3.0 的开发更新源由 Dart 参数配置。Windows 的编译期配
## 诊断与共享测试入口
- `diagnostics/frame_budget.py`:读取 `CUTDEX_FRAME_TIMINGS` JSONL,可带阶段标记文件;报告帧耗时。
- `diagnostics/benchmark_diagnostic_store.dart`:无输入数据,比较逐条刷盘与默认批写策略的合成日志突发;`--samples=7` 设置测量轮数,JSON 输出包含同步记录耗时、排空耗时、定时器间隔与持久化追加次数。可先 `dart compile exe tool/diagnostics/benchmark_diagnostic_store.dart -o /tmp/cutdex-diagnostic-benchmark` 再运行可执行文件,排除 JIT 预热影响;不测量实际剪辑帧率。合成突发使用 320 项队列容量,其中 40 项预留给错误。
- `diagnostics/benchmark_diagnostic_store.dart`:无输入数据,比较逐条刷盘与默认批写策略的合成日志突发;`--samples=7` 设置测量轮数,JSON 输出包含同步记录耗时、排空耗时、定时器间隔与持久化追加次数。可先 `fvm dart compile exe tool/diagnostics/benchmark_diagnostic_store.dart -o /tmp/cutdex-diagnostic-benchmark` 再运行可执行文件,排除 JIT 预热影响;不测量实际剪辑帧率。合成突发使用 320 项队列容量,其中 40 项预留给错误。
- `diagnostics/benchmark_agent_context.dart`:读取第一个参数指定的 AgentMessage JSON 数组,比较完整历史和 Harness 投影的估算 token/字节量。
- `testing/release_smoke.dart`:macOS/Windows 发布测试共用的 Flutter 入口,验证导出、翻译和资源配置。测试 App 不得分发;结束后使用 `lib/main.dart` 重建正式 App。
@@ -88,8 +130,9 @@ deskup 0.3.0 的开发更新源由 Dart 参数配置。Windows 的编译期配
## 语言与入口约定
- Shell 负责系统命令编排与临时资源清理;JSON、XML、依赖和发布规则集中在 Python。签名脚本中的文件筛选与命令排序属于签名流程,保持单一实现。
- Swift 处理原生能力;PowerShell 处理 Windows 桌面与进程环境;Dart 入口用于应用连接与 Flutter 测试。
- Python 负责构建和发布编排、临时资源清理及格式/依赖验证;参数、环境和进程调用使用公共层。签名筛选和顺序只有一份 macOS 实现。
- Shell/BAT 保留 IDE 启动入口及 Xcode/原生平台检查,PowerShell 保留 Windows 环境准备和 Sandbox;Flutter 自动生成的脚本由 Flutter 管理。
- Swift 处理原生能力;Dart 入口用于应用连接、本地环境加载、Flutter 启动与测试。
- 普通 Python、Shell、Swift 和 Dart 诊断入口支持 `--help`(Shell/Swift/Dart 也支持 `-h`),帮助不启动构建、服务器或发布操作。PowerShell 使用 `Get-Help <脚本> -Full`。
- 普通 CLI:成功/帮助为 0,参数格式或数量错误为 2,工具主动判定的运行失败为 1。外部子命令失败保留其非零状态,不承诺所有第三方退出码均为 1;调用方按非零失败处理。
- 人类诊断写 stderr;JSON、报告路径等结果写 stdout 或显式报告文件;密钥和凭据不得出现在输出中。
@@ -100,4 +143,4 @@ deskup 0.3.0 的开发更新源由 Dart 参数配置。Windows 的编译期配
桌面原生标题栏回归工具由 [cutdex_native](../packages/cutdex_native/README.md#原生回归) 维护。
Flutter 侧使用 `flutter test test/editor_window_chrome_test.dart test/adaptive_workspace_test.dart test/localization_resources_test.dart`。Windows 构建和 Flutter 测试请顺序运行,避免测试进程占用构建需要替换的 SQLite DLL。
Flutter 侧使用 `fvm dart tool/flutter_local.dart test test/editor_window_chrome_test.dart test/adaptive_workspace_test.dart test/localization_resources_test.dart`。Windows 构建和 Flutter 测试请顺序运行,避免测试进程占用构建需要替换的 SQLite DLL。