Skip to content

fix(xvm): let a package's own target own its ungrouped headers - #391

Merged
Sunrisepeak merged 1 commit into
release/0.4.70from
fix/xvm-header-group-owner
Jul 26, 2026
Merged

Sunrisepeak merged 1 commit into
release/0.4.70from
fix/xvm-header-group-owner

Conversation

@Sunrisepeak

Copy link
Copy Markdown
Member

P0.2 of the 0.4.70 release train — 修复 #384 引入的第二个回归。

Problem

normalize_xpkg_registration_plan 构造 header 时从不设 .group:

plan.batch.headers.push_back({ .sourceDir = operation.includedir });

而 apply_registration_batch 对无 group 的 header 要求 groups.size() == 1,否则 HeaderAmbiguous 硬失败。

由于每个无 binding 的节点都会各自成为一个单例 group,任何注册了多个独立 target 再声明 headers 的 recipe 都会直接装不上 —— program + lib 是最常见的形态:

xvm.add("openssl")
xvm.add("libssl", { type = "lib", filename = "libssl.so" })
xvm.headers(...)          -- ← 2 个候选 group → HeaderAmbiguous → 装不上

这在 origin/main 上是能装的。

Change

用包自身的 target 打破平局:包 p 发布的头文件属于 p。recipe 惯例上都会注册一个与包同名的 target,所以这解决了常规情形而不需要猜。

RegistrationBatch 增加 primaryTarget,由 normalizer 填 node.name。

保持歧义(有意为之) 的两种情况:

  • 该 target 不在批次里 → 无从推断归属
  • 该 target 被绑进了多个 group → 指名它也定位不到唯一 owner

这两种情况下随便挑一个 group,正是"头文件挂到不发布它的组上"的成因。错误信息现在会说明尝试过的 hint 以及怎么解决(在 header 上显式指定 group)。

Tests

测试 覆盖
UngroupedHeaderFallsBackToThePrimaryTarget 解决常规情形
UngroupedHeaderStaysAmbiguousWhenPrimaryTargetIsNotRegistered target 缺席仍拒绝
UngroupedHeaderStaysAmbiguousWhenPrimaryTargetSpansGroups target 跨组仍拒绝
UngroupedHeaderRoutesToThePackagesOwnTarget 适配器层,走 normalizer,形状同真实 recipe(program + lib + headers)

最后一条同时钉住了接线(批次确实携带包名)—— 这正是 P0.1 里我无法覆盖的那类缺口,这次补上了。

构造第三条测试时发现:同一 target 注册两个版本且都无 binding,会在更早的 GroupConflict 就被拒(两者的 label 都是 target 名,root 不同)。所以能真正走到"跨组"分支的是两个不同 root 的绑定,测试已按此构造。

两条既有的 HeaderAmbiguous 测试保持通过 —— 它们都没有注册与包同名的 target,因此本来就无 owner 可推断。

Verification

mcpp build   →  Finished release [optimized] in 43.99s
mcpp test    →  test result ok. 11 passed; 0 failed
*UngroupedHeader* / *PrimaryTarget*  →  8 passed

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

The normalizer never sets a group on a header, and registration rejected
an ungrouped header whenever there was more than one candidate group.
Every node without a binding becomes its own singleton group, so any
recipe that registers several independent targets -- a program plus a
library is the common shape -- and then declares headers failed to
install outright with HeaderAmbiguous.

Break the tie with the package's own target: headers shipped by package
p belong with p. Recipes conventionally register a target under the
package name, so this resolves the ordinary case without guessing.

It stays ambiguous, deliberately, when that target is absent from the
batch or is bound into more than one group -- naming it then identifies
no single owner, and picking a group arbitrarily is how headers end up
attached to something that does not ship them. The error now names the
hint it tried and says to put an explicit group on the header.

Tests: the resolving case, both ambiguous cases, and an adapter-level
case shaped like a real recipe (program + lib + headers) that goes
through the normalizer, so it also pins the wiring -- that the batch
carries the package's own name. The two pre-existing tests asserting
HeaderAmbiguous still hold: neither registers a target under the
package name, so neither has an owner to infer.
@Sunrisepeak
Sunrisepeak merged commit 8dfc69f 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