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