Skip to content

Commit 2fa4169

Browse files
committed
refactor(pm): isolate legacy compat helpers
1 parent 2349882 commit 2fa4169

5 files changed

Lines changed: 82 additions & 68 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
> 本文件追踪 `mcpp-community/mcpp` 公开仓的版本演进。
44
> 格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)
55
6+
## [0.0.33] — 2026-05-30
7+
8+
### 改进
9+
10+
- 将 legacy dotted dependency key 兼容解析移入 `mcpp.pm.compat.legacy`
11+
模块,保留 `mcpp.pm.compat` 作为 facade,并明确标注该兼容路径将在
12+
mcpp 1.0.0 移除。
13+
614
## [0.0.32] — 2026-05-30
715

816
### 修复

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

src/pm/compat.cppm

Lines changed: 5 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// mcpp.pm.compat — backward-compatibility shims for evolving package
2-
// conventions. Centralises all migration logic so it can be retired
3-
// cleanly in a future major version.
1+
// mcpp.pm.compat - compatibility facade for evolving package conventions.
2+
// Legacy-only behavior lives under src/pm/compat/legacy.cppm so it has an
3+
// explicit retirement boundary.
44
//
55
// DEPRECATION SCHEDULE:
66
// The shims in this module are slated for removal in mcpp 1.0.0.
@@ -20,6 +20,8 @@
2020

2121
export module mcpp.pm.compat;
2222

23+
export import mcpp.pm.compat.legacy;
24+
2325
import std;
2426
import mcpp.pm.dep_spec;
2527

@@ -82,69 +84,6 @@ inline std::string qualified_name(std::string_view ns,
8284
return std::format("{}.{}", ns, shortName);
8385
}
8486

85-
// ─── Legacy dependency key parsing ─────────────────────────────────
86-
//
87-
// COMPAT: legacy flat dependency keys used quoted dotted names under a
88-
// dependency table:
89-
//
90-
// [dependencies]
91-
// "mcpplibs.cmdline" = "0.0.2"
92-
//
93-
// Canonical projects should use namespaced TOML tables instead:
94-
//
95-
// [dependencies.mcpplibs]
96-
// cmdline = "0.0.2"
97-
//
98-
// Nested default-namespace packages can also be written without quotes:
99-
//
100-
// [dependencies]
101-
// capi.lua = "0.0.3"
102-
//
103-
// This compatibility parser is slated for removal in mcpp 1.0.0.
104-
105-
struct LegacyDependencyKey {
106-
std::string namespace_;
107-
std::string shortName;
108-
bool legacyDottedKey = false;
109-
};
110-
111-
inline LegacyDependencyKey split_legacy_dependency_key(std::string_view key)
112-
{
113-
auto dot = key.find('.');
114-
if (dot == std::string_view::npos) {
115-
return LegacyDependencyKey {
116-
.namespace_ = std::string(mcpp::pm::kDefaultNamespace),
117-
.shortName = std::string(key),
118-
.legacyDottedKey = false,
119-
};
120-
}
121-
122-
return LegacyDependencyKey {
123-
.namespace_ = std::string(key.substr(0, dot)),
124-
.shortName = std::string(key.substr(dot + 1)),
125-
.legacyDottedKey = true,
126-
};
127-
}
128-
129-
// Normalize legacy nested names after the first-dot split:
130-
// ns="mcpplibs", shortName="capi.lua" → ns="mcpplibs.capi", shortName="lua".
131-
//
132-
// This preserves the fully qualified name while making dependency de-dup use
133-
// the same structured key as canonical [dependencies.mcpplibs] capi.lua.
134-
inline void normalize_nested_namespace(std::string& ns,
135-
std::string& shortName,
136-
bool legacyDottedKey)
137-
{
138-
if (!legacyDottedKey) return;
139-
if (ns.empty()) return;
140-
auto dot = shortName.rfind('.');
141-
if (dot == std::string::npos || dot + 1 >= shortName.size()) return;
142-
143-
ns += ".";
144-
ns += shortName.substr(0, dot);
145-
shortName = shortName.substr(dot + 1);
146-
}
147-
14887
// ─── Index directory naming ──────────────────────────────────────────
14988
//
15089
// Maps (indexName, namespace, shortName) → the xpkgs subdirectory name

src/pm/compat/legacy.cppm

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// mcpp.pm.compat.legacy - legacy dependency-key compatibility.
2+
//
3+
// COMPAT: This module exists only to keep pre-namespace dependency syntax
4+
// working during migration. It is slated for removal in mcpp 1.0.0.
5+
// TODO(mcpp 1.0.0): remove this module and the legacy dotted-key parser.
6+
//
7+
// Deprecated:
8+
//
9+
// [dependencies]
10+
// "mcpplibs.cmdline" = "0.0.2"
11+
//
12+
// Canonical:
13+
//
14+
// [dependencies.mcpplibs]
15+
// cmdline = "0.0.2"
16+
17+
export module mcpp.pm.compat.legacy;
18+
19+
import std;
20+
import mcpp.pm.dep_spec;
21+
22+
export namespace mcpp::pm::compat {
23+
24+
struct LegacyDependencyKey {
25+
std::string namespace_;
26+
std::string shortName;
27+
bool legacyDottedKey = false;
28+
};
29+
30+
inline LegacyDependencyKey split_legacy_dependency_key(std::string_view key)
31+
{
32+
auto dot = key.find('.');
33+
if (dot == std::string_view::npos) {
34+
return LegacyDependencyKey {
35+
.namespace_ = std::string(mcpp::pm::kDefaultNamespace),
36+
.shortName = std::string(key),
37+
.legacyDottedKey = false,
38+
};
39+
}
40+
41+
return LegacyDependencyKey {
42+
.namespace_ = std::string(key.substr(0, dot)),
43+
.shortName = std::string(key.substr(dot + 1)),
44+
.legacyDottedKey = true,
45+
};
46+
}
47+
48+
// Normalize legacy nested names after the first-dot split:
49+
// ns="mcpplibs", shortName="capi.lua" -> ns="mcpplibs.capi", shortName="lua".
50+
//
51+
// This preserves the fully qualified name while making dependency de-dup use
52+
// the same structured key as canonical [dependencies.mcpplibs] capi.lua.
53+
inline void normalize_nested_namespace(std::string& ns,
54+
std::string& shortName,
55+
bool legacyDottedKey)
56+
{
57+
if (!legacyDottedKey) return;
58+
if (ns.empty()) return;
59+
auto dot = shortName.rfind('.');
60+
if (dot == std::string::npos || dot + 1 >= shortName.size()) return;
61+
62+
ns += ".";
63+
ns += shortName.substr(0, dot);
64+
shortName = shortName.substr(dot + 1);
65+
}
66+
67+
} // namespace mcpp::pm::compat

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.32";
21+
inline constexpr std::string_view MCPP_VERSION = "0.0.33";
2222

2323
struct FingerprintInputs {
2424
Toolchain toolchain;

0 commit comments

Comments
 (0)