Skip to content

Commit 38fcd9e

Browse files
committed
fix: install_dir_candidates use namespace prefix (match xlings layout)
xlings creates package directories as <ns>-x-<ns>.<shortName>, e.g. mcpplibs-x-mcpplibs.tinyhttps. The previous code used indexName (mcpp-index) as the prefix which was wrong. Canonical candidate is now <ns>-x-<ns>.<shortName>. Old <index>-x-<fqname> form kept as fallback for existing installs.
1 parent f04cfc3 commit 38fcd9e

1 file changed

Lines changed: 18 additions & 33 deletions

File tree

src/pm/compat.cppm

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,18 @@ inline std::string qualified_name(std::string_view ns,
8787
// Maps (indexName, namespace, shortName) → the xpkgs subdirectory name
8888
// that xlings places the extracted tarball under.
8989
//
90-
// Current layout (compat):
91-
// <xpkgs>/<index>-x-<ns>.<short>/<version>/
92-
// e.g. mcpp-index-x-mcpplibs.cmdline/0.0.2/
93-
//
94-
// The function encapsulates this so a future layout change (e.g.
95-
// <xpkgs>/<index>-x-<short>/<version>/ with ns in metadata)
96-
// only touches one place.
90+
// xlings layout: <ns>-x-<ns>.<short>/<version>/
91+
// e.g. mcpplibs-x-mcpplibs.cmdline/0.0.2/
92+
// compat-x-compat.mbedtls/3.6.1/
9793

9894
inline std::string xpkg_dir_name(std::string_view indexName,
9995
std::string_view ns,
10096
std::string_view shortName)
10197
{
102-
auto qname = qualified_name(ns, shortName);
103-
return std::format("{}-x-{}", indexName, qname);
98+
auto fqname = ns.empty() ? std::string(shortName)
99+
: std::format("{}.{}", ns, shortName);
100+
if (!ns.empty()) return std::format("{}-x-{}", ns, fqname);
101+
return std::format("{}-x-{}", indexName, fqname);
104102
}
105103

106104
// ─── xpkg .lua filename candidates (namespace-aware) ────────────────
@@ -169,44 +167,31 @@ inline std::vector<std::string> xpkg_lua_candidates(std::string_view ns,
169167
// Given a structured (namespace, shortName) and index name, return the
170168
// list of candidate directory names under <xpkgs>/ to search for.
171169
//
172-
// DEPRECATION SCHEDULE (fallback candidates):
173-
// Fallback candidates are slated for removal in mcpp 1.0.0.
174-
// By then xlings should use a consistent directory layout.
170+
// xlings directory layout: <ns>-x-<ns>.<shortName>/<version>/
171+
// e.g. mcpplibs-x-mcpplibs.tinyhttps/0.2.2/
172+
// compat-x-compat.mbedtls/3.6.1/
175173

176174
inline std::vector<std::string> install_dir_candidates(std::string_view ns,
177175
std::string_view shortName,
178176
std::string_view indexName)
179177
{
180178
std::vector<std::string> candidates;
181-
auto qname = qualified_name(ns, shortName);
182179
auto fqname = ns.empty() ? std::string(shortName)
183180
: std::format("{}.{}", ns, shortName);
184181

185-
// Canonical: <index>-x-<ns>.<shortName> (e.g. "mcpp-index-x-compat.mbedtls")
186-
// For default namespace: <index>-x-<shortName> (e.g. "mcpp-index-x-cmdline")
187-
candidates.push_back(std::format("{}-x-{}", indexName, qname));
188-
189-
// Fallback: xlings always installs with the full qualified name
190-
// (ns.shortName), even for the default namespace. So we also try
191-
// <index>-x-<ns>.<shortName> when qname != fqname.
192-
if (qname != fqname) {
193-
candidates.push_back(std::format("{}-x-{}", indexName, fqname));
182+
// Canonical: <ns>-x-<ns>.<shortName> (xlings current layout)
183+
if (!ns.empty()) {
184+
candidates.push_back(std::format("{}-x-{}", ns, fqname));
194185
}
195186

196187
// ── Fallback candidates (COMPAT, remove in 1.0.0) ──────────────
197188

198-
// Namespace-prefixed dir (xlings uses namespace as prefix, not index name)
199-
// e.g. "compat-x-mbedtls", "mcpplibs-x-mcpplibs.tinyhttps"
200-
if (!ns.empty()) {
201-
candidates.push_back(std::format("{}-x-{}", ns, fqname));
202-
if (std::string(shortName) != fqname) {
203-
candidates.push_back(std::format("{}-x-{}", ns, shortName));
204-
}
205-
}
189+
// Old index-prefixed layout: <index>-x-<ns>.<shortName>
190+
candidates.push_back(std::format("{}-x-{}", indexName, fqname));
206191

207-
// Index-prefixed with bare short name
208-
// e.g. "mcpp-index-x-mbedtls" (old pre-namespace layout)
209-
if (!ns.empty() && ns != mcpp::pm::kDefaultNamespace) {
192+
// Bare short name variants
193+
if (!ns.empty()) {
194+
candidates.push_back(std::format("{}-x-{}", ns, shortName));
210195
candidates.push_back(std::format("{}-x-{}", indexName, shortName));
211196
}
212197

0 commit comments

Comments
 (0)