From 4fc295dc02dd0b311a22b3b8b962015138dde4c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20=C3=85stholm?= Date: Tue, 22 Oct 2024 23:27:16 +0200 Subject: [PATCH] Take eagerness into account when deduplicating dependencies If the same dependency is first found as lazy and then later as eager, the existing entry needs to be updated to eager in order for `b.dependency()` to work. --- src/Package/Fetch.zig | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Package/Fetch.zig b/src/Package/Fetch.zig index 6e7469425b..6017a234e4 100644 --- a/src/Package/Fetch.zig +++ b/src/Package/Fetch.zig @@ -662,6 +662,9 @@ fn queueJobsForDeps(f: *Fetch) RunError!void { // * path-based location is used without a hash. // - Hash is added to the table based on the path alone before // calling run(); no need to add it again. + // + // If we add a dep as lazy and then later try to add the same dep as eager, + // eagerness takes precedence and the existing entry is updated. for (dep_names, deps) |dep_name, dep| { const new_fetch = &new_fetches[new_fetch_index]; @@ -673,7 +676,12 @@ fn queueJobsForDeps(f: *Fetch) RunError!void { const digest_len = @typeInfo(Manifest.MultiHashHexDigest).array.len; const multihash_digest = h[0..digest_len].*; const gop = f.job_queue.table.getOrPutAssumeCapacity(multihash_digest); - if (gop.found_existing) continue; + if (gop.found_existing) { + if (!dep.lazy) { + gop.value_ptr.*.lazy_status = .eager; + } + continue; + } gop.value_ptr.* = new_fetch; break :h multihash_digest; }, @@ -684,7 +692,12 @@ fn queueJobsForDeps(f: *Fetch) RunError!void { const new_root = try f.package_root.resolvePosix(parent_arena, rel_path); const multihash_digest = relativePathDigest(new_root, cache_root); const gop = f.job_queue.table.getOrPutAssumeCapacity(multihash_digest); - if (gop.found_existing) continue; + if (gop.found_existing) { + if (!dep.lazy) { + gop.value_ptr.*.lazy_status = .eager; + } + continue; + } gop.value_ptr.* = new_fetch; break :l .{ .relative_path = new_root }; },