Skip to content

feat(cargo): support test target artifacts#149

Open
ZR233 wants to merge 1 commit into
mainfrom
codex/cargo-test-artifacts
Open

feat(cargo): support test target artifacts#149
ZR233 wants to merge 1 commit into
mainfrom
codex/cargo-test-artifacts

Conversation

@ZR233

@ZR233 ZR233 commented Jul 1, 2026

Copy link
Copy Markdown
Member

问题

TGOSKits 的内核/QEMU 测试需要通过 Cargo [[test]] 目标构建 harness = false 的可执行测试产物,但 ostool 当前只能选择 Cargo bin artifact,无法用 --test <target> 指定 test target。

修改

  • system.Cargo 和命令行 selector 增加 test 目标选择,和 bin 保持互斥。
  • Cargo 构建命令在配置 test target 时使用 --test <name>,并从 JSON message 中同时接受 bin/test executable artifact。
  • artifact selector 支持显式 test target 选择,并补充对应错误提示和单元测试。
  • 更新 README/README.en 文档,说明 --testsystem.Cargo.test 用法。
  • BuildSystem::Cargo 装箱,避免新增字段后触发 large enum variant clippy。

验证

  • cargo test -p ostool
  • cargo clippy -p ostool -- -D warnings
  • 在 TGOSKits 本地通过 path patch 验证:
    • cargo test -p axbuild ktest -- --nocapture
    • cargo xtask clippy --package axbuild
    • cargo xtask ktest qemu -p starry-kernel --test axtest_kernel --arch x86_64 --coverage
    • cargo xtask ktest qemu -p axvisor --test axtest --arch x86_64

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

审查总结

本次 PR 为 Cargo 构建系统新增了 test 目标选择功能,支持通过 [[test]] 构建 harness = false 的可执行测试产物。

变更概览

  • Cargo 配置结构体中新增 test 字段,与 bin 互斥
  • CLI 层面通过 clap conflicts_with 属性保证互斥,运行时在 build_cargo_plan 中再次校验
  • --test 传递给 Cargo 构建命令,artifact selector 支持 test 目标选择
  • JSON message 解析器通过 is_executable_target_kind 同时接受 BinTest 类型
  • BuildSystem::Cargo 装箱以避免 clippy 大枚举变体警告
  • README/README.en 文档已同步更新
  • 新增了完整的单元测试覆盖

代码质量

整体质量很好,实现方式与现有 bin 的模式保持一致,互斥逻辑在三个层面(CLI clap、运行时 bail、selector 覆盖)都有保障。测试覆盖全面,包括正常路径和错误路径。

小建议(非阻塞)

artifact_selector.rs 中当存在多个可执行 artifact 且未指定选择器时,错误信息仅提示 pass system.Cargo.bin or --bin,但此时如果同时存在 bin 和 test 目标,建议也提及 --test / system.Cargo.test 选项。这不影响功能,只是一个体验改进点。

验证结果

  • cargo clippy -p ostool -- -D warnings ✅ 通过
  • cargo test -p ostool ✅ 204 通过,5 个失败均为环境中缺少 llvm-tools 组件导致,与本次 PR 无关

结论:批准合并。

Powered by mimo-v2.5-pro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant