Skip to content

Commit 0134a8b

Browse files
committed
feat: namespace-aware read_xpkg_lua + bump to 0.0.8
read_xpkg_lua now tries multiple filename patterns when looking up a package's .lua descriptor in index repos: 1. <full-qualified-name>.lua (old: mcpplibs.cmdline.lua) 2. <short-name>.lua (new: cmdline.lua) 3. compat.<name>.lua (new: compat.gtest.lua) This completes namespace migration support: both install_path (0.0.7) and read_xpkg_lua (0.0.8) handle old and new index layouts. Locally verified: mcpp self-build + tinyhttps + llmapi + cmdline all pass against the migrated mcpp-index (namespace fields + short names + renamed files).
1 parent 9675ea9 commit 0134a8b

3 files changed

Lines changed: 37 additions & 11 deletions

File tree

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 = "0.0.7"
3+
version = "0.0.8"
44
description = "Modern C++ build & package management tool"
55
license = "Apache-2.0"
66
authors = ["mcpp-community"]

src/pm/package_fetcher.cppm

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -593,22 +593,48 @@ std::optional<std::string>
593593
Fetcher::read_xpkg_lua(std::string_view package_name) const
594594
{
595595
if (package_name.empty()) return std::nullopt;
596-
char first = static_cast<char>(std::tolower(static_cast<unsigned char>(package_name.front())));
597-
std::string letter(1, first);
598596

599597
auto data = cfg_.xlingsHome() / "data";
600598
if (!std::filesystem::exists(data)) return std::nullopt;
601599

600+
// Build candidate file names. For "mcpplibs.cmdline" we try:
601+
// 1. mcpplibs.cmdline.lua (old: full qualified name)
602+
// 2. cmdline.lua (new: short name, namespace in file)
603+
// 3. capi.lua.lua (new: sub-ns prefix for mcpplibs.capi.lua)
604+
// Each candidate is tried under pkgs/<first-letter-of-filename>/.
605+
std::vector<std::string> filenames;
606+
filenames.push_back(std::string(package_name) + ".lua");
607+
608+
// Split on first dot → (ns, short)
609+
auto dot = package_name.find('.');
610+
if (dot != std::string_view::npos) {
611+
auto shortName = package_name.substr(dot + 1);
612+
filenames.push_back(std::string(shortName) + ".lua");
613+
// For "mcpplibs.capi.lua" → shortName = "capi.lua" → already covered.
614+
// Also try compat.<name>.lua pattern:
615+
filenames.push_back("compat." + std::string(package_name) + ".lua");
616+
if (!shortName.empty()) {
617+
filenames.push_back("compat." + std::string(shortName) + ".lua");
618+
}
619+
} else {
620+
// Bare name like "gtest" → also try compat.gtest.lua
621+
filenames.push_back("compat." + std::string(package_name) + ".lua");
622+
}
623+
602624
std::error_code ec;
603-
// Iterate over each cloned index dir and search for the .lua file.
604625
for (auto& entry : std::filesystem::directory_iterator(data, ec)) {
605626
if (!entry.is_directory()) continue;
606-
auto candidate = entry.path() / "pkgs" / letter
607-
/ (std::string(package_name) + ".lua");
608-
if (std::filesystem::exists(candidate)) {
609-
std::ifstream is(candidate);
610-
std::stringstream ss; ss << is.rdbuf();
611-
return ss.str();
627+
auto pkgsDir = entry.path() / "pkgs";
628+
if (!std::filesystem::exists(pkgsDir)) continue;
629+
for (auto& fname : filenames) {
630+
char first = static_cast<char>(std::tolower(
631+
static_cast<unsigned char>(fname.front())));
632+
auto candidate = pkgsDir / std::string(1, first) / fname;
633+
if (std::filesystem::exists(candidate)) {
634+
std::ifstream is(candidate);
635+
std::stringstream ss; ss << is.rdbuf();
636+
return ss.str();
637+
}
612638
}
613639
}
614640
return std::nullopt;

src/toolchain/fingerprint.cppm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import mcpp.toolchain.detect;
1818

1919
export namespace mcpp::toolchain {
2020

21-
inline constexpr std::string_view MCPP_VERSION = "0.0.7";
21+
inline constexpr std::string_view MCPP_VERSION = "0.0.8";
2222

2323
struct FingerprintInputs {
2424
Toolchain toolchain;

0 commit comments

Comments
 (0)