authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-10-15 12:24:46-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-10-15 12:24:46-07:00
log27f5843b753b7d16e4ef73cf6ef3fe2136aeabfd
treec2fa9afce7dc7e013c4fad3a26aa2aa569a7f9ab
parentab4f45bf9a9fc0c028dd87eecefe4073c40ae24a

Revert "Merge pull request '`--fork` fixes' (#37241) from fix-fork into master"

This reverts commit ab4f45bf9a9fc0c028dd87eecefe4073c40ae24a. Not ready to be cherry-picked yet.

2 files changed, 22 insertions(+), 94 deletions(-)

lib/compiler/Maker.zig+15-77
......@@ -1385,7 +1385,7 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
13851385 printPkgTree(.{
13861386 .writer = initStdoutWriter(io),
13871387 .mode = try .detect(io, .stdout(), NO_COLOR, CLICOLOR_FORCE),
1388 }, arena, graph.global_cache_root, &job_queue, &fetch, &fork_set) catch |err| switch (err) {
1388 }, arena, &job_queue, &fetch) catch |err| switch (err) {
13891389 error.WriteFailed => return stdout_writer_allocation.err.?,
13901390 else => |e| return e,
13911391 };
......@@ -1398,7 +1398,7 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
13981398 process.exit(0);
13991399 }
14001400
1401 try validateFingerprints(gpa, &job_queue, &fork_set);
1401 try validateFingerprints(gpa, &job_queue);
14021402
14031403 // Create the dependencies.zig file for configurer to
14041404 // obtain via `@import("@dependencies")`.
......@@ -1444,29 +1444,10 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
14441444 // The first one is a dummy package for the current project.
14451445 continue;
14461446 }
1447 if (!f.has_build_zig) continue;
1448
1449 if (f.have_manifest) {
1450 const project_id: Package.ProjectId = .init(f.manifest.name, f.manifest.id);
1451 if (fork_set.getKeyPtrAdapted(project_id, @as(Fetch.JobQueue.Fork.Adapter, .{}))) |fork| {
1452 const path = try fork.path.toString(arena);
1453 const gop = deps_mod.deps.getOrPutAssumeCapacity(path);
1454 if (gop.found_existing) {
1455 assert(fork.uses > 1);
1456 f.cli_module = gop.value_ptr.*;
1457 } else {
1458 const m = try arena.create(CliModule);
1459 m.* = .{
1460 .root_path = try f.package_root.toString(arena),
1461 .name = path,
1462 };
1463 gop.value_ptr.* = m;
1464 f.cli_module = m;
1465 }
1466 continue;
1467 }
1468 }
1447 if (!f.has_build_zig)
1448 continue;
14691449 const hash_slice = try arena.dupe(u8, hash.toSlice());
1450
14701451 const m = try arena.create(CliModule);
14711452 m.* = .{
14721453 .root_path = try f.package_root.toString(arena),
......@@ -1488,7 +1469,7 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
14881469 const man = &f.manifest;
14891470 const dep_names = man.dependencies.keys();
14901471 try mod.deps.ensureUnusedCapacity(arena, @intCast(dep_names.len));
1491 for (dep_names, man.dependencies.values()) |name, *dep| {
1472 for (dep_names, man.dependencies.values()) |name, dep| {
14921473 const dep_digest = Package.Fetch.depDigest(
14931474 f.package_root,
14941475 graph.global_cache_root,
......@@ -1768,11 +1749,7 @@ const ValidFingerprintTable = std.array_hash_map.Custom(
17681749
17691750/// Ensure that the dependency tree did not have any fingerprint matches with the same semantic version but
17701751/// differing package hashes.
1771fn validateFingerprints(
1772 gpa: Allocator,
1773 job_queue: *const Fetch.JobQueue,
1774 fork_set: *const Package.Fetch.JobQueue.ForkSet,
1775) !void {
1752fn validateFingerprints(gpa: Allocator, job_queue: *const Fetch.JobQueue) !void {
17761753 var any_errors = false;
17771754
17781755 var table: ValidFingerprintTable = .empty;
......@@ -1780,13 +1757,8 @@ fn validateFingerprints(
17801757
17811758 for (job_queue.table.keys(), job_queue.table.values()) |pkg_hash, fetch| {
17821759 if (!fetch.have_manifest) continue;
1783
1784 // Forked packages are exempt since they overide multiple package hashes to have the forked contents.
1785 const project_id: Package.ProjectId = .init(fetch.manifest.name, fetch.manifest.id);
1786 if (fork_set.containsAdapted(project_id, @as(Fetch.JobQueue.Fork.Adapter, .{}))) continue;
1787
17881760 const gop = try table.getOrPut(gpa, .{
1789 .project_id = project_id,
1761 .project_id = .init(fetch.manifest.name, fetch.manifest.id),
17901762 .version = fetch.manifest.version,
17911763 });
17921764 if (gop.found_existing) {
......@@ -1823,10 +1795,8 @@ fn validateFingerprints(
18231795fn printPkgTree(
18241796 terminal: Io.Terminal,
18251797 arena: Allocator,
1826 global_cache_root: Cache.Directory,
18271798 job_queue: *const Fetch.JobQueue,
18281799 root_fetch: *const Fetch,
1829 fork_set: *const Package.Fetch.JobQueue.ForkSet,
18301800) !void {
18311801 if (!root_fetch.have_manifest) return;
18321802 const names = root_fetch.manifest.dependencies.keys();
......@@ -1835,49 +1805,37 @@ fn printPkgTree(
18351805 .parent = null,
18361806 .last = i == names.len - 1,
18371807 };
1838 switch (dep.location) {
1839 .url => {
1840 const child_hash = if (dep.hash) |h| Package.Hash.fromSlice(h) else null;
1841 try printPkgTreeChild(terminal, arena, global_cache_root, job_queue, &print_node, name, child_hash, fork_set);
1842 },
1843 .path => {
1844 const child_hash = Package.Fetch.depDigest(root_fetch.package_root, global_cache_root, dep);
1845 try printPkgTreeChild(terminal, arena, global_cache_root, job_queue, &print_node, name, child_hash, fork_set);
1846 },
1847 }
1808 try printPkgTreeChild(terminal, arena, job_queue, &print_node, name, dep.hash);
18481809 }
18491810}
18501811
18511812fn printPkgTreeChild(
18521813 terminal: Io.Terminal,
18531814 arena: Allocator,
1854 global_cache_root: Cache.Directory,
18551815 job_queue: *const Fetch.JobQueue,
18561816 parent_print_node: *const PrintNode,
18571817 dep_name: []const u8,
1858 opt_pkg_hash: ?Package.Hash,
1859 fork_set: *const Package.Fetch.JobQueue.ForkSet,
1818 opt_hash: ?[]const u8,
18601819) !void {
18611820 const w = terminal.writer;
18621821 try parent_print_node.printPrefixedChild(w, terminal.mode);
18631822 try w.writeAll(dep_name);
18641823
1865 const pkg_hash = opt_pkg_hash orelse {
1824 const hash = opt_hash orelse {
18661825 try terminal.setColor(.red);
18671826 try w.writeAll(" (missing hash)\n");
18681827 try terminal.setColor(.reset);
18691828 return;
18701829 };
18711830 try terminal.setColor(.dim);
1872 try w.print(" {s}", .{pkg_hash.toSlice()});
1831 try w.print(" {s}", .{hash});
18731832 try terminal.setColor(.reset);
1874 const child_fetch = job_queue.table.get(pkg_hash) orelse {
1833 const child_fetch = job_queue.table.get(.fromSlice(hash)) orelse {
18751834 try terminal.setColor(.red);
18761835 try w.writeAll(" (fetch failed)\n");
18771836 try terminal.setColor(.reset);
18781837 return;
18791838 };
1880
18811839 switch (child_fetch.lazy_status) {
18821840 .eager, .available => {},
18831841 .unavailable => {
......@@ -1887,19 +1845,8 @@ fn printPkgTreeChild(
18871845 return;
18881846 },
18891847 }
1890 if (!child_fetch.have_manifest) {
1891 try w.writeByte('\n');
1892 return;
1893 }
1894
1895 const project_id: Package.ProjectId = .init(child_fetch.manifest.name, child_fetch.manifest.id);
1896 if (fork_set.getKeyPtrAdapted(project_id, @as(Fetch.JobQueue.Fork.Adapter, .{}))) |fork| {
1897 try terminal.setColor(.yellow);
1898 try w.print(" (fork: {f})", .{fork.path});
1899 try terminal.setColor(.reset);
1900 }
1901
19021848 try w.writeByte('\n');
1849 if (!child_fetch.have_manifest) return;
19031850
19041851 const names = child_fetch.manifest.dependencies.keys();
19051852 for (names, child_fetch.manifest.dependencies.values(), 0..) |name, *dep, i| {
......@@ -1907,16 +1854,7 @@ fn printPkgTreeChild(
19071854 .parent = parent_print_node,
19081855 .last = i == names.len - 1,
19091856 };
1910 switch (dep.location) {
1911 .url => {
1912 const child_hash = if (dep.hash) |h| Package.Hash.fromSlice(h) else null;
1913 try printPkgTreeChild(terminal, arena, global_cache_root, job_queue, &print_node, name, child_hash, fork_set);
1914 },
1915 .path => {
1916 const child_hash = Package.Fetch.depDigest(child_fetch.package_root, global_cache_root, dep);
1917 try printPkgTreeChild(terminal, arena, global_cache_root, job_queue, &print_node, name, child_hash, fork_set);
1918 },
1919 }
1857 try printPkgTreeChild(terminal, arena, job_queue, &print_node, name, dep.hash);
19201858 }
19211859}
19221860
lib/compiler/Maker/Fetch.zig+7-17
......@@ -289,21 +289,11 @@ pub const JobQueue = struct {
289289 \\
290290 , .{std.fmt.alt(fetch.package_root, .formatEscapeString)});
291291
292 if (fetch.has_build_zig) b: {
293 if (fetch.have_manifest) {
294 const project_id: Package.ProjectId = .init(fetch.manifest.name, fetch.manifest.id);
295 if (jq.fork_set.getKeyPtrAdapted(project_id, @as(JobQueue.Fork.Adapter, .{}))) |fork| {
296 try w.print(
297 \\ pub const build_zig = @import({qf});
298 \\
299 , .{fork.path});
300 }
301 break :b;
302 }
292 if (fetch.has_build_zig) {
303293 try w.print(
304 \\ pub const build_zig = @import({q});
294 \\ pub const build_zig = @import("{f}");
305295 \\
306 , .{hash_slice});
296 , .{std.zig.fmtString(hash_slice)});
307297 }
308298
309299 if (fetch.have_manifest) {
......@@ -312,7 +302,7 @@ pub const JobQueue = struct {
312302 \\ pub const deps: []const struct { []const u8, []const u8 } = &.{
313303 \\
314304 );
315 for (manifest.dependencies.keys(), manifest.dependencies.values()) |name, *dep| {
305 for (manifest.dependencies.keys(), manifest.dependencies.values()) |name, dep| {
316306 const h = depDigest(fetch.package_root, jq.global_cache, dep) orelse continue;
317307 try w.print(
318308 " .{{ \"{f}\", \"{f}\" }},\n",
......@@ -345,7 +335,7 @@ pub const JobQueue = struct {
345335 assert(root_fetch.have_manifest);
346336 const root_manifest = &root_fetch.manifest;
347337
348 for (root_manifest.dependencies.keys(), root_manifest.dependencies.values()) |name, *dep| {
338 for (root_manifest.dependencies.keys(), root_manifest.dependencies.values()) |name, dep| {
349339 const h = depDigest(root_fetch.package_root, jq.global_cache, dep) orelse continue;
350340 try w.print(
351341 " .{{ \"{f}\", \"{f}\" }},\n",
......@@ -605,7 +595,7 @@ pub fn run(f: *Fetch) RunError!void {
605595 if (remote.hash) |expected_hash| {
606596 const expected_project_id: Package.ProjectId = expected_hash.projectId();
607597 if (job_queue.fork_set.getKeyPtrAdapted(expected_project_id, @as(JobQueue.Fork.Adapter, .{}))) |fork| {
608 log.debug("using fork {f} for {s}", .{ fork.path, expected_hash.toSlice() });
598 log.debug("using fork {f} for {s}", .{ fork.path, fork.manifest.name });
609599 fork.uses += 1;
610600 f.package_root = fork.path;
611601 f.remote_package_root = f.package_root;
......@@ -2043,7 +2033,7 @@ const Filter = struct {
20432033 }
20442034};
20452035
2046pub fn depDigest(pkg_root: Path, cache_root: Directory, dep: *const Manifest.Dependency) ?Package.Hash {
2036pub fn depDigest(pkg_root: Path, cache_root: Directory, dep: Manifest.Dependency) ?Package.Hash {
20472037 if (dep.hash) |h| return .fromSlice(h);
20482038
20492039 switch (dep.location) {