fetch: ensure that forks are actually used

This commit is contained in:
Andrew Kelley
2026-02-06 14:29:45 -08:00
parent 9d02562717
commit 9f3b60b23a
2 changed files with 25 additions and 0 deletions
+3
View File
@@ -162,6 +162,7 @@ pub const JobQueue = struct {
path: Cache.Path,
manifest_ast: std.zig.Ast,
manifest: Package.Manifest,
uses: usize,
pub const Context = struct {
pub fn hash(_: @This(), a: Fork) u32 {
@@ -575,6 +576,8 @@ pub fn run(f: *Fetch) RunError!void {
if (remote.hash) |expected_hash| {
const expected_project_id: Package.ProjectId = expected_hash.projectId();
if (job_queue.fork_set.getKeyPtrAdapted(expected_project_id, @as(JobQueue.Fork.Adapter, .{}))) |fork| {
log.debug("using fork {f} for {s}", .{ fork.path, fork.manifest.name });
fork.uses += 1;
f.package_root = fork.path;
f.manifest_ast = fork.manifest_ast;
f.manifest = fork.manifest;
+22
View File
@@ -5213,6 +5213,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,
.path = fork.path,
.manifest_ast = fork.manifest_ast,
.manifest = fork.manifest,
.uses = 0,
}, {});
}
}
@@ -5279,6 +5280,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,
.recursive = true,
.debug_hash = false,
.unlazy_set = unlazy_set,
.fork_set = fork_set,
.mode = fetch_mode,
.prog_node = fetch_prog_node,
};
@@ -5344,6 +5346,26 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,
job_queue.group.async(io, Package.Fetch.workerRun, .{ &fetch, "root" });
try job_queue.group.await(io);
{
// Ensure that forks were actually used. This is done
// before printing manifest errors because using a fork can
// prevent them.
var any_unused = false;
for (fork_set.keys()) |*fork| {
if (fork.uses == 0) {
std.log.err("fork {f} matched no {s} packages", .{
fork.path, fork.manifest.name,
});
any_unused = true;
} else {
std.log.info("fork {f} matched {d} {s} packages", .{
fork.path, fork.uses, fork.manifest.name,
});
}
}
if (any_unused) process.exit(1);
}
try job_queue.consolidateErrors();
if (fetch.error_bundle.root_list.items.len > 0) {