Skip to content

Commit 20f5ceb

Browse files
committed
fix(build): attribute a source to its most specific package root
Package roots can nest — a workspace member lives under the workspace root — and taking the first matching root filed the member's sources under the outer package, i.e. into the wrong cache key. Index payloads live in the xpkgs store and cannot be shadowed this way, so no cached entry is affected today; resolving by specificity rather than by iteration order is what keeps that true if roots ever move.
1 parent a5bb4f0 commit 20f5ceb

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/build/prepare.cppm

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3885,15 +3885,28 @@ prepare_build(bool print_fingerprint,
38853885
// Sources belonging to each package, package-root-relative and sorted.
38863886
std::vector<std::vector<std::string>> pkgSources(packages.size());
38873887
for (auto& cu : ctx.plan.compileUnits) {
3888+
// Longest matching root wins. Package roots can nest — a workspace
3889+
// member lives under the workspace root — and taking the first match
3890+
// would file the member's sources under the outer package, putting
3891+
// them in the wrong key. (Index payloads live in the xpkgs store and
3892+
// cannot be shadowed this way, so no cached entry is affected today;
3893+
// resolving it by specificity rather than by iteration order is what
3894+
// keeps that true if roots ever move.)
3895+
std::size_t best = packages.size();
3896+
std::size_t bestLen = 0;
3897+
std::string bestRel;
38883898
for (std::size_t p = 0; p < packages.size(); ++p) {
38893899
std::error_code ec;
38903900
auto rel = std::filesystem::relative(cu.source, packages[p].root, ec);
38913901
if (ec || rel.empty()) continue;
38923902
auto rels = rel.generic_string();
38933903
if (rels.starts_with("..")) continue;
3894-
pkgSources[p].push_back(rels);
3895-
break;
3904+
auto len = packages[p].root.generic_string().size();
3905+
if (best == packages.size() || len > bestLen) {
3906+
best = p; bestLen = len; bestRel = std::move(rels);
3907+
}
38963908
}
3909+
if (best != packages.size()) pkgSources[best].push_back(std::move(bestRel));
38973910
}
38983911
for (auto& v : pkgSources) std::ranges::sort(v);
38993912

0 commit comments

Comments
 (0)