Skip to content

Commit 2a5e79a

Browse files
refactor: what a Luban system says of itself is the provider's layout (declared_system_root, system_home) -- mcpp names none of xlings' paths
Co-authored-by: speak-agent <248744407+speak-agent@users.noreply.github.com>
1 parent dbd2ab9 commit 2a5e79a

6 files changed

Lines changed: 48 additions & 74 deletions

File tree

‎src/config.cppm‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import mcpp.provider.select;
3131
import mcpp.platform;
3232
import mcpp.log;
3333
import mcpp.diag;
34-
import mcpp.luban;
3534
import mcpp.fallback.xlings_binary;
3635
import mcpp.fallback.config_migration;
3736

@@ -842,7 +841,7 @@ std::expected<GlobalConfig, ConfigError> load_or_init(
842841
// A Luban system's /xlings is its store, wherever its xlings put it
843842
// (the home that made it, for a system made on a host).
844843
if (dir == "/xlings" && !std::filesystem::is_directory(dir, ec))
845-
if (auto store = mcpp::luban::system_store()) dir = *store;
844+
if (auto store = mcpp::provider::layout().system_home("/"); !store.empty()) dir = store;
846845
if (!dir.is_absolute() || !std::filesystem::is_directory(dir, ec)) {
847846
// Fewer packages reused than asked for: said, not hidden.
848847
mcpp::diag::degraded("xlings/upstream", std::format("[xlings] upstream {} is not a directory", entry),

‎src/fallback/probe_sysroot.cppm‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import mcpp.provider;
1515
import mcpp.provider.select;
1616
import mcpp.platform;
1717
import mcpp.log;
18-
import mcpp.luban;
1918

2019
export namespace mcpp::fallback {
2120

@@ -108,7 +107,7 @@ bool sysroot_is_foreign(const std::filesystem::path& sysroot,
108107
const std::filesystem::path& systemRoot = "/") {
109108
if (sysroot.empty()) return false;
110109
// A Luban system's own root: its compiler's `/` is the system it is.
111-
if (sysroot.lexically_normal() == "/" && mcpp::luban::is_luban_root(systemRoot)) return false;
110+
if (sysroot.lexically_normal() == "/" && mcpp::provider::layout().declared_system_root(systemRoot)) return false;
112111
return !path_is_under(sysroot, registryRoot)
113112
&& !path_is_under(sysroot, projectRoot);
114113
}

‎src/luban.cppm‎

Lines changed: 0 additions & 61 deletions
This file was deleted.

‎src/provider/provider.cppm‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,13 @@ public:
377377
// Whether `name` is one of the provider's own indexes (its default and
378378
// the ones it adds itself), which stay where the provider keeps them.
379379
virtual bool is_provider_index(std::string_view name) const = 0;
380+
// A system the provider made, as `root` (/, but for a test) says of
381+
// itself (xlings design 2026-10-21 §3.7): its compiler's sysroot `/` is
382+
// then the system's own declared root, not a tree nothing declared.
383+
virtual bool declared_system_root(const std::filesystem::path& root) const = 0;
384+
// The home such a system reads its packages from, by its root record;
385+
// empty: not one, or its record says nothing usable.
386+
virtual std::filesystem::path system_home(const std::filesystem::path& root) const = 0;
380387
};
381388

382389
// What a provider says of a package's payload without installing anything

‎src/provider/xlings/provider.cppm‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,36 @@ public:
196196
return {{dir, {}, {"xim"}}};
197197
return {};
198198
}
199+
// A Luban system (xlings design 2026-10-21 §3.7): its os-release says
200+
// ID=luban and /usr/lib/xlings-abi is the runtime xlings bound; its root
201+
// record (/etc/xlings/usr) names its generation, <home>/subos/<name>/root/usr
202+
// -- /xlings for one installed on a machine, the path of the home that
203+
// made it for one made on a host.
204+
bool declared_system_root(const std::filesystem::path& root) const override {
205+
std::error_code ec;
206+
if (!std::filesystem::exists(root / "usr/lib/xlings-abi", ec)) return false;
207+
std::ifstream in(root / "etc/os-release");
208+
for (std::string line; std::getline(in, line);) {
209+
if (!line.starts_with("ID=")) continue;
210+
auto id = line.substr(3);
211+
if (id.size() >= 2 && (id.front() == '"' || id.front() == '\'')) id = id.substr(1, id.size() - 2);
212+
return id == "luban";
213+
}
214+
return false;
215+
}
216+
std::filesystem::path system_home(const std::filesystem::path& root) const override {
217+
if (!declared_system_root(root)) return {};
218+
std::ifstream in(root / "etc/xlings/usr");
219+
std::string line;
220+
if (!std::getline(in, line)) return {};
221+
while (!line.empty() && (line.back() == '\r' || line.back() == ' ')) line.pop_back();
222+
const std::filesystem::path usr = std::filesystem::path(line).lexically_normal();
223+
const auto rootDir = usr.parent_path(), instance = rootDir.parent_path(), subos = instance.parent_path();
224+
if (!usr.is_absolute() || usr.filename() != "usr" || rootDir.filename() != "root" || subos.filename() != "subos") return {};
225+
std::error_code ec;
226+
const auto home = subos.parent_path();
227+
return std::filesystem::is_directory(home, ec) ? home : std::filesystem::path{};
228+
}
199229
bool is_provider_index(std::string_view name) const override {
200230
// xlings' default index and the ones it adds beside it.
201231
return name == "xim" || name == "awesome" || name == "scode" || name == "d2x";

‎tests/unit/test_luban_root.cpp‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#include <gtest/gtest.h>
88

99
import std;
10-
import mcpp.luban;
10+
import mcpp.provider;
11+
import mcpp.provider.select;
1112
import mcpp.fallback.probe_sysroot;
1213

1314
namespace fs = std::filesystem;
@@ -32,13 +33,13 @@ struct Tree {
3233

3334
TEST(LubanRoot, ALubanSystemsRootIsDeclared) {
3435
Tree t;
35-
EXPECT_FALSE(mcpp::luban::is_luban_root(t.dir));
36+
EXPECT_FALSE(mcpp::provider::layout().declared_system_root(t.dir));
3637
t.write("etc/os-release", "NAME=\"Luban\"\nID=luban\nVERSION_ID=2026.10.22.1\n");
37-
EXPECT_FALSE(mcpp::luban::is_luban_root(t.dir)) << "its os-release alone is not enough";
38+
EXPECT_FALSE(mcpp::provider::layout().declared_system_root(t.dir)) << "its os-release alone is not enough";
3839
t.write("usr/lib/xlings-abi/README", "");
39-
EXPECT_TRUE(mcpp::luban::is_luban_root(t.dir));
40+
EXPECT_TRUE(mcpp::provider::layout().declared_system_root(t.dir));
4041
t.write("etc/os-release", "ID=\"debian\"\n");
41-
EXPECT_FALSE(mcpp::luban::is_luban_root(t.dir));
42+
EXPECT_FALSE(mcpp::provider::layout().declared_system_root(t.dir));
4243
}
4344

4445
TEST(LubanRoot, ItsSysrootSlashIsNotForeign) {
@@ -55,12 +56,11 @@ TEST(LubanRoot, ItsStoreIsTheHomeItsRootRecordNames) {
5556
Tree t;
5657
t.write("etc/os-release", "ID=luban\n");
5758
t.write("usr/lib/xlings-abi/README", "");
58-
EXPECT_FALSE(mcpp::luban::system_store(t.dir).has_value()) << "no record";
59+
EXPECT_TRUE(mcpp::provider::layout().system_home(t.dir).empty()) << "no record";
5960
const auto home = t.dir / "host-home";
6061
fs::create_directories(home / "subos" / "box" / "root" / "usr");
6162
t.write("etc/xlings/usr", (home / "subos" / "box" / "root" / "usr").string() + "\n");
62-
ASSERT_TRUE(mcpp::luban::system_store(t.dir).has_value());
63-
EXPECT_EQ(*mcpp::luban::system_store(t.dir), home.lexically_normal());
63+
EXPECT_EQ(mcpp::provider::layout().system_home(t.dir), home.lexically_normal());
6464
t.write("etc/xlings/usr", "/somewhere/else/usr\n");
65-
EXPECT_FALSE(mcpp::luban::system_store(t.dir).has_value()) << "a record of another shape";
65+
EXPECT_TRUE(mcpp::provider::layout().system_home(t.dir).empty()) << "a record of another shape";
6666
}

0 commit comments

Comments
 (0)