Skip to content

Commit 0f9c782

Browse files
committed
fix(index): index list and the router read the same effective indices on a workspace root
`mcpp index list` lists what resolution searches: a member's own [indices], [workspace.indices], and a root's own table by position. effective_indices recognises a workspace root by its own [workspace] table (e2e 44).
1 parent 01e3e2a commit 0f9c782

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

‎src/pm/index_management.cppm‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import mcpp.lockfile;
1616
import mcpp.manifest;
1717
import mcpp.platform;
1818
import mcpp.project;
19+
import mcpp.pm.index_route;
1920
import mcpp.ui;
2021
import mcpp.xlings;
2122

@@ -95,15 +96,15 @@ export int index_list() {
9596
// Show project-level custom indices from mcpp.toml [indices].
9697
auto root = mcpp::project::find_manifest_root(std::filesystem::current_path());
9798
if (root) {
98-
// The effective manifest: a member inherits the workspace's
99-
// `[indices]` (#690, W4).
100-
std::optional<mcpp::manifest::Manifest> m;
101-
if (auto effective = mcpp::project::load_effective_manifest(*root))
102-
m = std::move(effective->manifest);
103-
if (m && !m->indices.empty()) {
99+
// The effective `[indices]`: a member's own, `[workspace.indices]`, and
100+
// a workspace root's own read by position (#690; SPEC-004 §9.12, §9.13).
101+
// One function with the index router, so the list names what
102+
// resolution searches.
103+
const auto indices = mcpp::pm::effective_indices(*root);
104+
if (!indices.empty()) {
104105
std::println("");
105106
std::println("Project indices (mcpp.toml):");
106-
for (auto& [name, spec] : m->indices) {
107+
for (auto& [name, spec] : indices) {
107108
if (spec.is_local()) {
108109
std::println(" {:<15} {} (local path)", name, spec.path.string());
109110
} else {

‎src/pm/index_route.cppm‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,11 @@ IndexMap effective_indices(const std::filesystem::path& root) {
256256
// by name; the root's own [indices] by position when it has none of the
257257
// former), whose relative `path` is anchored at the ROOT (#224).
258258
auto wsRoot = mcpp::project::find_workspace_root(root);
259-
if (wsRoot.empty()) return m->indices;
260259
// The workspace root itself: its own [indices], and what it gives every
261260
// member, its root package included.
262261
std::error_code ec;
263-
if (std::filesystem::equivalent(wsRoot, root, ec)) {
262+
if (m->workspace.present || (!wsRoot.empty() && std::filesystem::equivalent(wsRoot, root, ec))) {
263+
if (m->workspace.present) wsRoot = root;
264264
if (m->layer)
265265
for (auto const& [name, idx] : m->layer->indices) {
266266
auto [it, inserted] = m->indices.try_emplace(name, idx);
@@ -269,6 +269,7 @@ IndexMap effective_indices(const std::filesystem::path& root) {
269269
}
270270
return m->indices;
271271
}
272+
if (wsRoot.empty()) return m->indices;
272273
auto ws = mcpp::manifest::load(wsRoot / "mcpp.toml");
273274
if (!ws || !ws->workspace.present) return m->indices;
274275
mcpp::project::inherit_workspace_indices(*m, *ws, wsRoot);

0 commit comments

Comments
 (0)