Skip to content

Commit ed4cf64

Browse files
committed
fix(workspace): anchor inherited indices lexically
1 parent 0cc6a2a commit ed4cf64

3 files changed

Lines changed: 64 additions & 2 deletions

File tree

src/project.cppm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,13 @@ export void inherit_workspace_indices(mcpp::manifest::Manifest& member,
117117
member.indices = workspace.indices;
118118
for (auto& [_, idx] : member.indices) {
119119
if (idx.is_local() && idx.path.is_relative()) {
120-
idx.path = std::filesystem::weakly_canonical(wsRoot / idx.path);
120+
// This is an ownership/anchoring operation, not a request to
121+
// resolve filesystem aliases. weakly_canonical can rewrite a
122+
// Windows short/case-preserving workspace path into a different
123+
// spelling before the inherited index is opened. Keep the path
124+
// rooted exactly where the workspace manifest declared it; the
125+
// normal reader remains responsible for existence/readability.
126+
idx.path = (wsRoot / idx.path).lexically_normal();
121127
}
122128
}
123129
}

tests/e2e/12_add_command.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ grep -qE '^widget = "9\.9\.9"$' mcpp.toml || { cat mcpp.toml; echo "widget@9.9.9
212212
mkdir -p "$TMP/ws"
213213
cd "$TMP/ws"
214214
cp -r "$TMP/myapp/index" index
215+
[[ -f index/pkgs/a/acme.util.lua ]] || {
216+
echo "workspace index fixture copy is incomplete"
217+
exit 1
218+
}
215219
cat > mcpp.toml <<'EOF'
216220
[workspace]
217221
members = ["m1"]
@@ -221,7 +225,11 @@ acme = { path = "index" }
221225
EOF
222226
"$MCPP" new m1 > /dev/null
223227
cd m1
224-
"$MCPP" add acme.util@2.0.0 > /dev/null
228+
workspace_add=$("$MCPP" add acme.util@2.0.0 2>&1) || {
229+
echo "$workspace_add"
230+
echo "workspace member could not read its root-owned local index"
231+
exit 1
232+
}
225233
grep -qE '^util = "2\.0\.0"$' mcpp.toml || { cat mcpp.toml; echo "member should inherit workspace [indices]"; exit 1; }
226234
err=$("$MCPP" add acme.nope@1.0.0 2>&1) && { echo "expected error inside workspace member"; exit 1; }
227235
[[ "$err" == *"(acme, nope)"* ]] || { echo "wrong error: $err"; exit 1; }

tests/unit/test_pm_index_route.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,51 @@ TEST(PmIndexRoute, MissBehindAnUnreadableIndexIsNotConclusive) {
160160
EXPECT_FALSE(found.hit.has_value());
161161
EXPECT_FALSE(found.conclusive);
162162
}
163+
164+
TEST(PmIndexRoute, WorkspaceMemberReadsRootAnchoredRelativeIndex) {
165+
auto root = std::filesystem::temp_directory_path()
166+
/ "mcpp-index-route-workspace-relative";
167+
std::filesystem::remove_all(root);
168+
struct Cleanup {
169+
std::filesystem::path root;
170+
~Cleanup() {
171+
std::error_code ec;
172+
std::filesystem::remove_all(root, ec);
173+
}
174+
} cleanup{root};
175+
176+
std::filesystem::create_directories(root / "index" / "pkgs" / "a");
177+
std::filesystem::create_directories(root / "member");
178+
std::ofstream(root / "index" / "pkgs" / "a" / "acme.util.lua") << R"(
179+
package = {
180+
spec = "1",
181+
namespace = "acme",
182+
name = "util",
183+
type = "package",
184+
}
185+
)";
186+
std::ofstream(root / "mcpp.toml") << R"(
187+
[workspace]
188+
members = ["member"]
189+
190+
[indices]
191+
acme = { path = "index" }
192+
)";
193+
std::ofstream(root / "member" / "mcpp.toml") << R"(
194+
[package]
195+
name = "member"
196+
version = "0.1.0"
197+
)";
198+
199+
auto indices = mcpp::pm::effective_indices(root / "member");
200+
ASSERT_TRUE(indices.contains("acme"));
201+
EXPECT_EQ(indices.at("acme").path,
202+
(root / "index").lexically_normal());
203+
204+
mcpp::pm::IndexRoute route{ &indices, root / "member", nullptr };
205+
auto selector = mcpp::pm::resolve_dependency_selector("acme.util");
206+
auto found = mcpp::pm::lookup_descriptor(route, selector.candidates);
207+
ASSERT_TRUE(found.hit.has_value());
208+
EXPECT_EQ(found.hit->coord.namespace_, "acme");
209+
EXPECT_EQ(found.hit->coord.shortName, "util");
210+
}

0 commit comments

Comments
 (0)