Skip to content

fix(xvm): switch the whole release on xlings use, or none of it - #397

Merged
Sunrisepeak merged 1 commit into
release/0.4.70from
fix/xvm-lossless-unparsed-records
Jul 26, 2026
Merged

Sunrisepeak merged 1 commit into
release/0.4.70from
fix/xvm-lossless-unparsed-records

Conversation

@Sunrisepeak

Copy link
Copy Markdown
Member

P3.3 of the 0.4.70 release train — 本轮的 headline 修复。

Problem

cmd_use 把决策和执行混在一起:先换入口 target 的头文件和库,再手工遍历 binding 边去找其它成员。这个顺序带来两个问题。

1. 遍历不安全。 以 target(而非 (target, version))为 visited key,且从不检查抵达的东西是否存在。一条残缺边把它带到一个没有 payload 的版本,它照样写进 active workspace —— shim 在 exec 时才失败,离肇事命令已经很远。

2. 顺序错误。 交换在遍历之前、且只对入口 target 执行。中途失败就留下 sysroot 是一个 release、workspace 声称另一个。

换了 gcc 却把上个 release 的 libstdc++ 头文件留在 sysroot 里,正是"gcc --version 报得对、编译照样炸"的成因。

Change

把决策和执行拆开。

plan_use_switch(纯函数)通过 resolve_binding_selection 解析整个 release、预检每个成员的 payload,返回需要做的文件系统改动 —— 或者返回错误,且什么都没碰。cmd_use 只负责执行这个 plan。

plan 覆盖的一切现在都是逐成员而非逐入口:

  • 头文件和库为整个 release 移动
  • 已经就位的成员不产生改动
  • 从 gcc、g++ 或 libstdc++ 进入,得到同一个 plan

这个拆分也是可测性的来源

cmd_use 需要 Config 单例和真实文件系统,它内部的逻辑此前没有一行能被单测触及。现在 7 条用例跑在纯函数上:

测试 覆盖
PlansEveryMemberNotJustTheEntryPoint 整组进入 plan
SwapsHeadersAndLibsForEveryMovingMember 逐成员换 include/lib
MembersAlreadyInPlaceProduceNoChange 不重复交换
EveryEntryPointYieldsTheSamePlan 多入口一致(A5)
AMissingMemberIsAnErrorNotAPartialSwitch 预检拦住半切换
AnUnresolvableGroupIsRefusedBeforeAnyChange fail-closed + 有 hint
AnUngroupedTargetSwitchesOnItsOwn legacy 单包不受影响

场景验收进度

这解决了评审 §5.1 的目标输出:

$ xlings use gcc 15.1.0
✓ gcc / g++ / gcc-ar / libstdc++ / headers  → 15.1.0

或者什么都不发生 + 具名原因 + hint。

对应 A1(切换程序)、A2/A3(切换头文件/库)、A4(失败零改动)、A5(多入口一致)。端到端证明仍在 P4.2。

Verification

mcpp build   →  Finished release [optimized] in 19.35s
mcpp test    →  test result ok. 11 passed; 0 failed
XvmSwitchPlan → 7 passed

CI 状态为已知上游拉取签名(见 #386),依计划 §3.1.1 合入集成分支。

cmd_use decided and acted at the same time. It swapped the entry
target's headers and libraries first, then walked the binding edges by
hand to find everything else. Two problems followed from that order.

The walk was keyed by target rather than by (target, version) and never
checked that what it reached existed, so a stale edge led to a version
with no payload, which it wrote into the active workspace anyway. The
shim then failed at exec time, far from the command that caused it.

And because the swap ran before the walk, and only for the entry target,
a failure part-way through left the sysroot holding one release while
the workspace claimed another. Switching gcc while leaving the previous
release's libstdc++ headers in place is how gcc (XPKG: xlings install fromsource:gcc) 15.1.0
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. reports the
right thing and the compile fails anyway.

Split the decision from the work. plan_use_switch resolves the release
through resolve_binding_selection, preflights every member's payload,
and returns the filesystem changes -- or an error, having touched
nothing. cmd_use carries the plan out.

Everything the plan covers is now per member rather than per entry
point: headers and libraries move for the whole release, members already
in place emit no change, and entering from gcc, g++ or libstdc++ yields
the same plan.

The split is also what makes any of this testable. cmd_use needs a
Config singleton and a real filesystem, so none of its logic could be
reached from a unit test; the seven cases here run against the pure
function.
@Sunrisepeak
Sunrisepeak merged commit 7261205 into release/0.4.70 Jul 26, 2026
0 of 6 checks passed
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