Skip to content

Commit dd2b278

Browse files
committed
fix: 请求的 glibc 版本与装好的 glibc 版本,是两种词汇
⚠️⚠️ 这条不是本 PR 引入的 —— `mcpp_ref=main` 的对照 run 报同一处错。 它是索引把 `xim:glibc` 在同一系列内移动之后,**任何**从源码构建 mcpp 的 全新 CI 机器都会中的一条,今天开始出现。修在这里,因为它卡住了本 PR 的门。 ## 机制 RuntimeBinding 带的是**声明的**身份;xlings 把载荷目录按请求**解析成**的版本命名。 索引把 `xim:glibc@2.44` 解析到 `2.44.2` 的那一刻,两者分开: error: selected RuntimeBinding glibc@2.44 requires payload '…/xim-x-glibc/2.44', but it is not installed $ ls …/xim-x-glibc/ → 2.44.2 ⭐ `runtime_binding.cppm` 早一个版本就记下了同一形状(「observed in CI as runtime=glibc@2.39 with libc.so.6 resolving to the managed 2.44 payload」) 并做了归一 —— 但只在 SubOS 视图存在之后。而这一处跑在**第一次**装工具链时, 那时还没有视图可读。 ## ⭐ 是「精化」不是「按目录顺序挑」,而这个区别是那条拒绝还站得住的全部理由 `2.44.2` 是请求 `2.44` 解析出来的东西:它的版本**分量**以请求的分量开头。 ⚠️ 逐**分量**比,不是逐字符:`2.4` 不是 `2.44` 回答的那个请求。按字符串前缀比 会说它是,然后把一个错的 C 库交给构建而什么也不说。 ⚠️ 若有两个载荷都精化了这个请求,这里**不做选择** —— 原样报拒绝。 「这个请求的解析结果」必须是**一个**载荷才谈得上是个答案。 ## 判据(5 条,四个方向) - 精确版本在场时优先(不会被精化抢走) - 唯一精化被采纳 - `2.4` 不匹配 `2.44`(逐分量) - 两个精化 → 仍然拒绝,且消息说明为什么 - 什么都没装 → 仍然拒绝
1 parent 9adc5ad commit dd2b278

2 files changed

Lines changed: 164 additions & 4 deletions

File tree

‎src/toolchain/post_install.cppm‎

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,81 @@ select_glibc_payload_lib(const std::filesystem::path& glibcRoot,
413413
auto payload = glibcRoot / std::string(version);
414414
std::error_code ec;
415415
if (!std::filesystem::is_directory(payload, ec)) {
416-
return std::unexpected(std::format(
417-
"selected RuntimeBinding {} requires payload '{}', but it is not "
418-
"installed; mcpp will not fall back to another directory entry",
419-
runtimeId, payload.string()));
416+
// ⭐⭐ THE VERSION THAT WAS ASKED FOR AND THE VERSION THAT WAS
417+
// INSTALLED ARE TWO VOCABULARIES FOR ONE FACT.
418+
//
419+
// A RuntimeBinding carries the DECLARED identity — what the subos state
420+
// says the provider is. xlings names the payload directory after what
421+
// the request RESOLVED to, and the two differ the moment the index
422+
// moves a package within a series: `xim:glibc@2.44` resolving to
423+
// `2.44.2` puts the payload in `xim-x-glibc/2.44.2` while the
424+
// declaration still reads `glibc@2.44`.
425+
//
426+
// ⚠️ Measured 2026-08-27, on every CI machine with a cold cache, on
427+
// `main` as readily as on any branch:
428+
//
429+
// error: selected RuntimeBinding glibc@2.44 requires payload
430+
// '…/xim-x-glibc/2.44', but it is not installed
431+
//
432+
// $ ls …/xim-x-glibc/ → 2.44.2
433+
//
434+
// `runtime_binding.cppm` already names this exact shape one version
435+
// earlier ("observed in CI as runtime=glibc@2.39 with libc.so.6
436+
// resolving to the managed 2.44 payload") and canonicalizes it —
437+
// but only once the SubOS view exists. This runs during the FIRST
438+
// toolchain install, before there is a view to read.
439+
//
440+
// ⭐ A REFINEMENT, NOT A DIRECTORY-ORDER PICK — and that distinction is
441+
// the whole of why the refusal below still stands. `2.44.2` is what the
442+
// request `2.44` resolved to: its version components BEGIN with the
443+
// requested ones. `2.4` does not match `2.44`, because the comparison
444+
// is per component and not per character. And if two payloads both
445+
// refine the request, nothing here chooses between them: the refusal is
446+
// reported exactly as before, because "the resolution of this request"
447+
// has to be one payload to be an answer at all.
448+
auto components = [](std::string_view v) {
449+
std::vector<std::string> parts;
450+
std::size_t start = 0;
451+
while (start <= v.size()) {
452+
auto dot = v.find('.', start);
453+
if (dot == std::string_view::npos) {
454+
parts.emplace_back(v.substr(start));
455+
break;
456+
}
457+
parts.emplace_back(v.substr(start, dot - start));
458+
start = dot + 1;
459+
}
460+
return parts;
461+
};
462+
const auto wanted = components(version);
463+
464+
std::vector<std::filesystem::path> refinements;
465+
std::error_code dec;
466+
for (auto it = std::filesystem::directory_iterator(glibcRoot, dec);
467+
!dec && it != std::filesystem::directory_iterator{};
468+
it.increment(dec)) {
469+
if (!it->is_directory(dec)) continue;
470+
const auto have = components(it->path().filename().string());
471+
if (have.size() <= wanted.size()) continue;
472+
if (!std::equal(wanted.begin(), wanted.end(), have.begin())) continue;
473+
refinements.push_back(it->path());
474+
}
475+
476+
if (refinements.size() != 1) {
477+
return std::unexpected(std::format(
478+
"selected RuntimeBinding {} requires payload '{}', but it is not "
479+
"installed{}; mcpp will not fall back to another directory entry",
480+
runtimeId, payload.string(),
481+
refinements.empty()
482+
? std::string{}
483+
: std::format(" and {} installed payloads refine that "
484+
"version, so none of them is its resolution",
485+
refinements.size())));
486+
}
487+
payload = refinements.front();
488+
mcpp::log::verbose("toolchain", std::format(
489+
"RuntimeBinding {} resolved to installed payload '{}'",
490+
runtimeId, payload.filename().string()));
420491
}
421492
auto lib = payload_lib_dir_with_loader(payload);
422493
if (lib.empty()) {

‎tests/unit/test_post_install.cpp‎

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <gtest/gtest.h>
2+
#include <fstream>
23

34
import std;
45
import mcpp.toolchain.post_install;
@@ -190,3 +191,91 @@ TEST(PostInstallFixup, APackageWithNoFixupReportsNothingToReport) {
190191
<< "a toolchain with no fixup reported a degradation: "
191192
<< result->skippedReason;
192193
}
194+
195+
// ⭐⭐ THE VERSION THAT WAS ASKED FOR AND THE VERSION THAT WAS INSTALLED ARE
196+
// TWO VOCABULARIES FOR ONE FACT.
197+
//
198+
// A RuntimeBinding carries the DECLARED identity; xlings names the payload
199+
// directory after what the request RESOLVED to. The two come apart the moment
200+
// the index moves a package within a series — `xim:glibc@2.44` resolving to
201+
// `2.44.2`.
202+
//
203+
// Measured 2026-08-27 on every CI machine with a cold cache, on `main` as
204+
// readily as on any branch:
205+
//
206+
// error: selected RuntimeBinding glibc@2.44 requires payload
207+
// '…/xim-x-glibc/2.44', but it is not installed
208+
// $ ls …/xim-x-glibc/ → 2.44.2
209+
namespace {
210+
211+
// A payload is "installed" for this purpose when it has a lib dir with a
212+
// loader in it — that is what select_glibc_payload_lib returns.
213+
std::filesystem::path make_glibc_payload(const std::filesystem::path& root,
214+
std::string_view version) {
215+
auto lib = root / std::string(version) / "lib64";
216+
std::filesystem::create_directories(lib);
217+
std::ofstream(lib / "ld-linux-x86-64.so.2");
218+
return lib;
219+
}
220+
221+
struct GlibcRootFixture {
222+
std::filesystem::path root;
223+
explicit GlibcRootFixture(std::string_view name)
224+
: root(std::filesystem::temp_directory_path() / name) {
225+
std::error_code ec;
226+
std::filesystem::remove_all(root, ec);
227+
std::filesystem::create_directories(root);
228+
}
229+
~GlibcRootFixture() {
230+
std::error_code ec;
231+
std::filesystem::remove_all(root, ec);
232+
}
233+
};
234+
235+
} // namespace
236+
237+
TEST(GlibcPayload, TheExactVersionIsPreferred) {
238+
GlibcRootFixture fx{"mcpp_glibc_exact"};
239+
auto want = make_glibc_payload(fx.root, "2.44");
240+
make_glibc_payload(fx.root, "2.44.2");
241+
auto got = mcpp::toolchain::select_glibc_payload_lib(fx.root, "glibc@2.44");
242+
ASSERT_TRUE(got.has_value()) << got.error();
243+
EXPECT_EQ(*got, want);
244+
}
245+
246+
TEST(GlibcPayload, ARequestResolvesToItsOneRefinement) {
247+
GlibcRootFixture fx{"mcpp_glibc_refine"};
248+
auto only = make_glibc_payload(fx.root, "2.44.2");
249+
auto got = mcpp::toolchain::select_glibc_payload_lib(fx.root, "glibc@2.44");
250+
ASSERT_TRUE(got.has_value()) << got.error();
251+
EXPECT_EQ(*got, only);
252+
}
253+
254+
// ⚠️ PER COMPONENT, NOT PER CHARACTER. `2.4` is not a request that `2.44`
255+
// answers — a prefix match on the string would say it is, and would then hand
256+
// a build the wrong C library without saying anything.
257+
TEST(GlibcPayload, AStringPrefixIsNotARefinement) {
258+
GlibcRootFixture fx{"mcpp_glibc_strprefix"};
259+
make_glibc_payload(fx.root, "2.44");
260+
auto got = mcpp::toolchain::select_glibc_payload_lib(fx.root, "glibc@2.4");
261+
EXPECT_FALSE(got.has_value());
262+
}
263+
264+
// ⭐ AND THE REFUSAL STILL STANDS WHEN THERE IS NO ONE ANSWER. "The resolution
265+
// of this request" has to be a single payload to be an answer at all; two
266+
// refinements are not a menu to pick from.
267+
TEST(GlibcPayload, TwoRefinementsAreRefusedRatherThanChosenBetween) {
268+
GlibcRootFixture fx{"mcpp_glibc_ambiguous"};
269+
make_glibc_payload(fx.root, "2.44.1");
270+
make_glibc_payload(fx.root, "2.44.2");
271+
auto got = mcpp::toolchain::select_glibc_payload_lib(fx.root, "glibc@2.44");
272+
ASSERT_FALSE(got.has_value());
273+
EXPECT_NE(got.error().find("none of them is its resolution"), std::string::npos)
274+
<< got.error();
275+
}
276+
277+
TEST(GlibcPayload, NothingInstalledIsStillRefused) {
278+
GlibcRootFixture fx{"mcpp_glibc_empty"};
279+
auto got = mcpp::toolchain::select_glibc_payload_lib(fx.root, "glibc@2.44");
280+
EXPECT_FALSE(got.has_value());
281+
}

0 commit comments

Comments
 (0)