Skip to content

Commit b0154f0

Browse files
committed
refactor(pm): extract DependencySpec into pm/dep_spec.cppm (PR-R1)
First step of the package-management subsystem refactor described in `.agents/docs/2026-05-08-pm-subsystem-architecture.md`. Strictly zero behavior change — the dependency data model just moves to its new home. * New module `mcpp.pm.dep_spec` (`src/pm/dep_spec.cppm`) owns the `DependencySpec` struct and the `kDefaultNamespace` constant. Pure value types only — no parsing, no IO. The `[dependencies]` / `[dev-dependencies]` parsing remains in `mcpp.manifest` for now and will move in a later refactor PR. * New empty placeholder module `mcpp.pm.index_spec` (`src/pm/index_spec.cppm`) so subsequent PRs can land their imports against a stable module path while the index-config implementation arrives. * `mcpp.manifest` keeps `mcpp::manifest::DependencySpec` and `mcpp::manifest::kDefaultNamespace` resolvable via aliases, so all existing call sites (cli.cppm, fetcher.cppm, ...) compile unchanged. These aliases will be removed once callers are migrated to the `mcpp::pm::` qualified names. Verification: * `mcpp build` compiles unchanged. * `mcpp test` — 9/9 unit binaries pass. * Local e2e subset (02 / 09 / 12 / 23 / 25 / 26 / 27) all pass; full suite expected to be unchanged given strict zero-behavior-change.
1 parent 25380b0 commit b0154f0

3 files changed

Lines changed: 76 additions & 23 deletions

File tree

src/manifest.cppm

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@ export module mcpp.manifest;
44

55
import std;
66
import mcpp.libs.toml;
7+
import mcpp.pm.dep_spec; // M5.x pm/ subsystem refactor: DependencySpec lives here
78

89
export namespace mcpp::manifest {
910

11+
// PR-R1 transitional: the dependency data model has moved into
12+
// `mcpp.pm.dep_spec`. The aliases below keep `mcpp::manifest::DependencySpec`
13+
// and `mcpp::manifest::kDefaultNamespace` available as before so existing
14+
// callers (`cli.cppm`, `fetcher.cppm`, ...) compile unchanged. A later
15+
// refactor PR will migrate call sites to reference `mcpp::pm::` directly
16+
// and these aliases can disappear.
17+
using DependencySpec = mcpp::pm::DependencySpec;
18+
inline constexpr auto kDefaultNamespace = mcpp::pm::kDefaultNamespace;
19+
1020
struct Package {
1121
std::string name;
1222
std::string version;
@@ -35,29 +45,9 @@ struct Target {
3545
std::string main; // for binary / test
3646
};
3747

38-
// One declared dependency. Path-based deps refer to a sibling mcpp package
39-
// on disk; version-based deps (M2 future) come from a registry.
40-
struct DependencySpec {
41-
// (M5.x) xpkg-style namespace. Defaults to "mcpp" for the root index.
42-
// Carried alongside the existing fully-qualified name (which the
43-
// dependencies map keys on) so callers that want the structured form
44-
// — registry lookup, lockfile entries, error messages — can pull it
45-
// out without re-splitting strings.
46-
std::string namespace_; // "mcpp" / "mcpplibs" / ...
47-
std::string shortName; // package name without namespace prefix
48-
std::string version; // "0.0.1" / "^1.2" / "" (req string)
49-
std::string path; // filesystem path, or empty
50-
std::string git; // "https://..." or empty
51-
std::string gitRev; // commit / tag / branch (any one)
52-
std::string gitRefKind; // "rev" / "tag" / "branch" (for clarity)
53-
bool isPath() const { return !path.empty(); }
54-
bool isGit() const { return !git.empty(); }
55-
bool isVersion() const { return !isPath() && !isGit() && !version.empty(); }
56-
};
57-
58-
// The default namespace for packages with no explicit namespace declaration.
59-
// Treated as the mcpp-index "root" — `gtest = "1.15.2"` ⇒ (mcpp, gtest).
60-
inline constexpr std::string_view kDefaultNamespace = "mcpp";
48+
// `DependencySpec` and `kDefaultNamespace` have moved to mcpp.pm.dep_spec.
49+
// Aliases at the top of this file keep `mcpp::manifest::DependencySpec`
50+
// resolvable for unchanged call sites.
6151

6252
// `[toolchain]` section per docs/21-toolchain-and-tools.md
6353
// linux = "gcc@15.1.0"

src/pm/dep_spec.cppm

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// mcpp.pm.dep_spec — package-management subsystem: dependency data model.
2+
//
3+
// Owns `DependencySpec` and the default-namespace constant. Pure value
4+
// types — no IO, no parsing here. Parsing currently lives in
5+
// `mcpp.manifest`; a follow-up PR-R5 will move the `[dependencies]` /
6+
// `[dev-dependencies]` parsing here, alongside the namespaced subtable
7+
// + flat + legacy-dotted forms already established in PR-A.
8+
//
9+
// See `.agents/docs/2026-05-08-pm-subsystem-architecture.md` for the
10+
// full pm/ subsystem layout.
11+
12+
export module mcpp.pm.dep_spec;
13+
14+
import std;
15+
16+
export namespace mcpp::pm {
17+
18+
// One declared dependency. Path-based deps refer to a sibling mcpp package
19+
// on disk; version-based deps come from a registry; git-based deps clone
20+
// a remote at a fixed ref.
21+
struct DependencySpec {
22+
// xpkg-style namespace. Defaults to `kDefaultNamespace` ("mcpp") for
23+
// the root index. Carried alongside the existing fully-qualified name
24+
// (which the dependencies map keys on) so callers that want the
25+
// structured form — registry lookup, lockfile entries, error
26+
// messages — can pull it out without re-splitting strings.
27+
std::string namespace_; // "mcpp" / "mcpplibs" / ...
28+
std::string shortName; // package name without namespace prefix
29+
std::string version; // "0.0.1" / "^1.2" / "" (req string)
30+
std::string path; // filesystem path, or empty
31+
std::string git; // "https://..." or empty
32+
std::string gitRev; // commit / tag / branch (any one)
33+
std::string gitRefKind; // "rev" / "tag" / "branch" (for clarity)
34+
35+
bool isPath() const { return !path.empty(); }
36+
bool isGit() const { return !git.empty(); }
37+
bool isVersion() const { return !isPath() && !isGit() && !version.empty(); }
38+
};
39+
40+
// Default namespace for packages declared without an explicit one — the
41+
// mcpp-index "root". Bare `gtest = "1.15.2"` becomes `(mcpp, gtest)`.
42+
inline constexpr std::string_view kDefaultNamespace = "mcpp";
43+
44+
} // namespace mcpp::pm

src/pm/index_spec.cppm

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// mcpp.pm.index_spec — package-index repository configuration.
2+
//
3+
// Reserved for the upcoming `[indices]` parsing & IndexSpec data type;
4+
// see `.agents/docs/2026-05-08-package-index-config.md` for the full
5+
// design. The module placeholder is created early so the rest of the
6+
// pm/ subsystem can land its imports against a stable module path
7+
// while the implementation arrives.
8+
9+
export module mcpp.pm.index_spec;
10+
11+
import std;
12+
13+
export namespace mcpp::pm {
14+
15+
// Placeholder. The full `IndexSpec` (url / rev / tag / branch / path)
16+
// + `[indices]` TOML parsing lands in a dedicated PR per the
17+
// package-index-config design doc.
18+
19+
} // namespace mcpp::pm

0 commit comments

Comments
 (0)