Skip to content

Commit dbd2ab9

Browse files
fix: a Luban system's root is declared and its /xlings upstream is its store (2026.10.22.1)
In a Luban system the compiler's sysroot / is the system itself (os-release ID=luban, /usr/lib/xlings-abi), and [xlings] upstream = ["/xlings"] reads the home its root record (/etc/xlings/usr) names when /xlings is not there: a system made on a host keeps its home at the path of the home that made it. Verified in a Luban KVM machine: mcpp self doctor without the sysroot or upstream warning, a first mcpp run of a new project in 4 s. Co-authored-by: speak-agent <248744407+speak-agent@users.noreply.github.com>
1 parent 0e79128 commit dbd2ab9

7 files changed

Lines changed: 154 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44
> Each `## [<version>]` section is that release's notes. Entries are written in English
55
> from 2026.9.28.3 on; earlier entries remain as written.
66

7+
## [2026.10.22.1] - 2026-10-22
8+
9+
### Fixed
10+
11+
- In a Luban system, the compiler's sysroot `/` is the system's own declared
12+
root (`ID=luban` in `/etc/os-release` and `/usr/lib/xlings-abi`): `mcpp self
13+
doctor` no longer reports it as belonging to neither the mcpp home nor the
14+
project.
15+
- In a Luban system, `[xlings] upstream = ["/xlings"]` reads the store the
16+
system's root record names (`/etc/xlings/usr`) when `/xlings` is not there --
17+
a system made on a host keeps its home at the path of the home that made it.
18+
Its gcc and glibc are reused rather than reported unreachable.
19+
720
## [2026.10.21.1] - 2026-10-21
821

922
### Fixed

‎mcpp.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mcpp"
3-
version = "2026.10.21.1"
3+
version = "2026.10.22.1"
44
description = "Modern C++ build & package management tool"
55
license = "Apache-2.0"
66
authors = ["mcpp-community"]

‎modules/versioning/src/version.cppm‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ import std;
3131

3232
export namespace mcpp {
3333

34-
inline constexpr std::string_view MCPP_VERSION = "2026.10.21.1";
34+
inline constexpr std::string_view MCPP_VERSION = "2026.10.22.1";
3535

3636
} // namespace mcpp

‎src/config.cppm‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import mcpp.provider.select;
3131
import mcpp.platform;
3232
import mcpp.log;
3333
import mcpp.diag;
34+
import mcpp.luban;
3435
import mcpp.fallback.xlings_binary;
3536
import mcpp.fallback.config_migration;
3637

@@ -838,6 +839,10 @@ std::expected<GlobalConfig, ConfigError> load_or_init(
838839
dir = std::filesystem::path(h) / (entry.size() > 2 ? entry.substr(2) : std::string{});
839840
dir = dir.lexically_normal();
840841
std::error_code ec;
842+
// A Luban system's /xlings is its store, wherever its xlings put it
843+
// (the home that made it, for a system made on a host).
844+
if (dir == "/xlings" && !std::filesystem::is_directory(dir, ec))
845+
if (auto store = mcpp::luban::system_store()) dir = *store;
841846
if (!dir.is_absolute() || !std::filesystem::is_directory(dir, ec)) {
842847
// Fewer packages reused than asked for: said, not hidden.
843848
mcpp::diag::degraded("xlings/upstream", std::format("[xlings] upstream {} is not a directory", entry),

‎src/fallback/probe_sysroot.cppm‎

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

1920
export namespace mcpp::fallback {
2021

@@ -99,10 +100,15 @@ bool sysroot_is_owned(std::string_view reportedPath,
99100
//
100101
// Both anchors are required. Registry alone would flag every legitimate
101102
// project-local tree; project alone would flag every payload sysroot.
103+
// In a Luban system (`systemRoot`, "/" but for a test) the sysroot `/` is the
104+
// system's own declared root (xlings design 2026-10-21 §3.7).
102105
bool sysroot_is_foreign(const std::filesystem::path& sysroot,
103106
const std::filesystem::path& registryRoot,
104-
const std::filesystem::path& projectRoot) {
107+
const std::filesystem::path& projectRoot,
108+
const std::filesystem::path& systemRoot = "/") {
105109
if (sysroot.empty()) return false;
110+
// 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;
106112
return !path_is_under(sysroot, registryRoot)
107113
&& !path_is_under(sysroot, projectRoot);
108114
}

‎src/luban.cppm‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// mcpp.luban — what a Luban system says about itself (xlings design
2+
// 2026-10-21 §3.7, J5): its root is the system's declared root, and its store
3+
// is where its xlings put it.
4+
//
5+
// A Luban system's /etc/os-release says ID=luban and its /usr/lib/xlings-abi
6+
// is the runtime xlings bound there; its compiler's sysroot is `/`, which is
7+
// then the system itself, not a tree nothing declared. Its packages live in
8+
// the home its root record names (/etc/xlings/usr: <home>/subos/<name>/root/usr),
9+
// which is /xlings for a system installed on a machine and the path of the
10+
// home that made it for one made on a host -- the edition's [xlings] upstream
11+
// says /xlings for both.
12+
//
13+
// `root` is "/" but for a test.
14+
15+
export module mcpp.luban;
16+
17+
import std;
18+
19+
export namespace mcpp::luban {
20+
21+
bool is_luban_root(const std::filesystem::path& root = "/");
22+
23+
// The home whose store the system reads, from its root record; nullopt when
24+
// `root` is not a Luban system or says nothing readable.
25+
std::optional<std::filesystem::path> system_store(const std::filesystem::path& root = "/");
26+
27+
} // namespace mcpp::luban
28+
29+
namespace mcpp::luban {
30+
31+
bool is_luban_root(const std::filesystem::path& root) {
32+
std::error_code ec;
33+
if (!std::filesystem::exists(root / "usr/lib/xlings-abi", ec)) return false;
34+
std::ifstream in(root / "etc/os-release");
35+
for (std::string line; std::getline(in, line);) {
36+
if (!line.starts_with("ID=")) continue;
37+
auto id = line.substr(3);
38+
if (id.size() >= 2 && (id.front() == '"' || id.front() == '\'')) id = id.substr(1, id.size() - 2);
39+
return id == "luban";
40+
}
41+
return false;
42+
}
43+
44+
std::optional<std::filesystem::path> system_store(const std::filesystem::path& root) {
45+
if (!is_luban_root(root)) return std::nullopt;
46+
std::ifstream in(root / "etc/xlings/usr");
47+
std::string line;
48+
if (!std::getline(in, line)) return std::nullopt;
49+
while (!line.empty() && (line.back() == '\r' || line.back() == ' ')) line.pop_back();
50+
const std::filesystem::path usr = std::filesystem::path(line).lexically_normal();
51+
// <home>/subos/<name>/root/usr
52+
const auto rootDir = usr.parent_path(), instance = rootDir.parent_path(), subos = instance.parent_path();
53+
if (!usr.is_absolute() || usr.filename() != "usr" || rootDir.filename() != "root" || subos.filename() != "subos")
54+
return std::nullopt;
55+
const auto home = subos.parent_path();
56+
std::error_code ec;
57+
if (!std::filesystem::is_directory(home, ec)) return std::nullopt;
58+
return home;
59+
}
60+
61+
} // namespace mcpp::luban

‎tests/unit/test_luban_root.cpp‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// A Luban system says what it is (xlings design 2026-10-21 §3.7, J5): its
2+
// root is declared (os-release ID=luban and /usr/lib/xlings-abi), so its
3+
// compiler's sysroot `/` is not foreign there; and its store is the home its
4+
// root record names, which `[xlings] upstream = ["/xlings"]` means for a
5+
// system made on a host (whose home is not at /xlings).
6+
7+
#include <gtest/gtest.h>
8+
9+
import std;
10+
import mcpp.luban;
11+
import mcpp.fallback.probe_sysroot;
12+
13+
namespace fs = std::filesystem;
14+
15+
namespace {
16+
17+
struct Tree {
18+
fs::path dir;
19+
Tree() {
20+
dir = fs::temp_directory_path() / std::format("mcpp-luban-root-{}-{}", ::testing::UnitTest::GetInstance()->random_seed(),
21+
std::chrono::steady_clock::now().time_since_epoch().count());
22+
fs::create_directories(dir);
23+
}
24+
~Tree() { std::error_code ec; fs::remove_all(dir, ec); }
25+
void write(const fs::path& rel, std::string_view text) const {
26+
fs::create_directories((dir / rel).parent_path());
27+
std::ofstream(dir / rel) << text;
28+
}
29+
};
30+
31+
} // namespace
32+
33+
TEST(LubanRoot, ALubanSystemsRootIsDeclared) {
34+
Tree t;
35+
EXPECT_FALSE(mcpp::luban::is_luban_root(t.dir));
36+
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+
t.write("usr/lib/xlings-abi/README", "");
39+
EXPECT_TRUE(mcpp::luban::is_luban_root(t.dir));
40+
t.write("etc/os-release", "ID=\"debian\"\n");
41+
EXPECT_FALSE(mcpp::luban::is_luban_root(t.dir));
42+
}
43+
44+
TEST(LubanRoot, ItsSysrootSlashIsNotForeign) {
45+
Tree t;
46+
const fs::path registry = "/home/u/.mcpp/registry", project = "/home/u/work/demo";
47+
EXPECT_TRUE(mcpp::fallback::sysroot_is_foreign("/", registry, project, t.dir)) << "anywhere else, / is nothing declared";
48+
t.write("etc/os-release", "ID=luban\n");
49+
t.write("usr/lib/xlings-abi/README", "");
50+
EXPECT_FALSE(mcpp::fallback::sysroot_is_foreign("/", registry, project, t.dir));
51+
EXPECT_TRUE(mcpp::fallback::sysroot_is_foreign("/opt/other/sysroot", registry, project, t.dir)) << "only its own root";
52+
}
53+
54+
TEST(LubanRoot, ItsStoreIsTheHomeItsRootRecordNames) {
55+
Tree t;
56+
t.write("etc/os-release", "ID=luban\n");
57+
t.write("usr/lib/xlings-abi/README", "");
58+
EXPECT_FALSE(mcpp::luban::system_store(t.dir).has_value()) << "no record";
59+
const auto home = t.dir / "host-home";
60+
fs::create_directories(home / "subos" / "box" / "root" / "usr");
61+
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());
64+
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";
66+
}

0 commit comments

Comments
 (0)