authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-10-14 14:12:00-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-10-14 17:42:15-07:00
log5b4e91bc391b7c0f537e3eaeda3beb60b8813ad9
tree0afe07eac56224399358bc26b90d0404ba2a6e0d
parent35c2541cf9924cdcccf666afb173320fd610e9ef

Maker: --print-tree supports paths and forks


2 files changed, 46 insertions(+), 12 deletions(-)

lib/compiler/Maker.zig+43-9
...@@ -1385,7 +1385,7 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {...@@ -1385,7 +1385,7 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
1385 printPkgTree(.{1385 printPkgTree(.{
1386 .writer = initStdoutWriter(io),1386 .writer = initStdoutWriter(io),
1387 .mode = try .detect(io, .stdout(), NO_COLOR, CLICOLOR_FORCE),1387 .mode = try .detect(io, .stdout(), NO_COLOR, CLICOLOR_FORCE),
1388 }, arena, &job_queue, &fetch) catch |err| switch (err) {1388 }, arena, graph.global_cache_root, &job_queue, &fetch, &fork_set) catch |err| switch (err) {
1389 error.WriteFailed => return stdout_writer_allocation.err.?,1389 error.WriteFailed => return stdout_writer_allocation.err.?,
1390 else => |e| return e,1390 else => |e| return e,
1391 };1391 };
...@@ -1469,7 +1469,7 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {...@@ -1469,7 +1469,7 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
1469 const man = &f.manifest;1469 const man = &f.manifest;
1470 const dep_names = man.dependencies.keys();1470 const dep_names = man.dependencies.keys();
1471 try mod.deps.ensureUnusedCapacity(arena, @intCast(dep_names.len));1471 try mod.deps.ensureUnusedCapacity(arena, @intCast(dep_names.len));
1472 for (dep_names, man.dependencies.values()) |name, dep| {1472 for (dep_names, man.dependencies.values()) |name, *dep| {
1473 const dep_digest = Package.Fetch.depDigest(1473 const dep_digest = Package.Fetch.depDigest(
1474 f.package_root,1474 f.package_root,
1475 graph.global_cache_root,1475 graph.global_cache_root,
...@@ -1804,8 +1804,10 @@ fn validateFingerprints(...@@ -1804,8 +1804,10 @@ fn validateFingerprints(
1804fn printPkgTree(1804fn printPkgTree(
1805 terminal: Io.Terminal,1805 terminal: Io.Terminal,
1806 arena: Allocator,1806 arena: Allocator,
1807 global_cache_root: Cache.Directory,
1807 job_queue: *const Fetch.JobQueue,1808 job_queue: *const Fetch.JobQueue,
1808 root_fetch: *const Fetch,1809 root_fetch: *const Fetch,
1810 fork_set: *const Package.Fetch.JobQueue.ForkSet,
1809) !void {1811) !void {
1810 if (!root_fetch.have_manifest) return;1812 if (!root_fetch.have_manifest) return;
1811 const names = root_fetch.manifest.dependencies.keys();1813 const names = root_fetch.manifest.dependencies.keys();
...@@ -1814,37 +1816,49 @@ fn printPkgTree(...@@ -1814,37 +1816,49 @@ fn printPkgTree(
1814 .parent = null,1816 .parent = null,
1815 .last = i == names.len - 1,1817 .last = i == names.len - 1,
1816 };1818 };
1817 try printPkgTreeChild(terminal, arena, job_queue, &print_node, name, dep.hash);1819 switch (dep.location) {
1820 .url => {
1821 const child_hash = if (dep.hash) |h| Package.Hash.fromSlice(h) else null;
1822 try printPkgTreeChild(terminal, arena, global_cache_root, job_queue, &print_node, name, child_hash, fork_set);
1823 },
1824 .path => {
1825 const child_hash = Package.Fetch.depDigest(root_fetch.package_root, global_cache_root, dep);
1826 try printPkgTreeChild(terminal, arena, global_cache_root, job_queue, &print_node, name, child_hash, fork_set);
1827 },
1828 }
1818 }1829 }
1819}1830}
18201831
1821fn printPkgTreeChild(1832fn printPkgTreeChild(
1822 terminal: Io.Terminal,1833 terminal: Io.Terminal,
1823 arena: Allocator,1834 arena: Allocator,
1835 global_cache_root: Cache.Directory,
1824 job_queue: *const Fetch.JobQueue,1836 job_queue: *const Fetch.JobQueue,
1825 parent_print_node: *const PrintNode,1837 parent_print_node: *const PrintNode,
1826 dep_name: []const u8,1838 dep_name: []const u8,
1827 opt_hash: ?[]const u8,1839 opt_pkg_hash: ?Package.Hash,
1840 fork_set: *const Package.Fetch.JobQueue.ForkSet,
1828) !void {1841) !void {
1829 const w = terminal.writer;1842 const w = terminal.writer;
1830 try parent_print_node.printPrefixedChild(w, terminal.mode);1843 try parent_print_node.printPrefixedChild(w, terminal.mode);
1831 try w.writeAll(dep_name);1844 try w.writeAll(dep_name);
18321845
1833 const hash = opt_hash orelse {1846 const pkg_hash = opt_pkg_hash orelse {
1834 try terminal.setColor(.red);1847 try terminal.setColor(.red);
1835 try w.writeAll(" (missing hash)\n");1848 try w.writeAll(" (missing hash)\n");
1836 try terminal.setColor(.reset);1849 try terminal.setColor(.reset);
1837 return;1850 return;
1838 };1851 };
1839 try terminal.setColor(.dim);1852 try terminal.setColor(.dim);
1840 try w.print(" {s}", .{hash});1853 try w.print(" {s}", .{pkg_hash.toSlice()});
1841 try terminal.setColor(.reset);1854 try terminal.setColor(.reset);
1842 const child_fetch = job_queue.table.get(.fromSlice(hash)) orelse {1855 const child_fetch = job_queue.table.get(pkg_hash) orelse {
1843 try terminal.setColor(.red);1856 try terminal.setColor(.red);
1844 try w.writeAll(" (fetch failed)\n");1857 try w.writeAll(" (fetch failed)\n");
1845 try terminal.setColor(.reset);1858 try terminal.setColor(.reset);
1846 return;1859 return;
1847 };1860 };
1861
1848 switch (child_fetch.lazy_status) {1862 switch (child_fetch.lazy_status) {
1849 .eager, .available => {},1863 .eager, .available => {},
1850 .unavailable => {1864 .unavailable => {
...@@ -1854,8 +1868,19 @@ fn printPkgTreeChild(...@@ -1854,8 +1868,19 @@ fn printPkgTreeChild(
1854 return;1868 return;
1855 },1869 },
1856 }1870 }
1871 if (!child_fetch.have_manifest) {
1872 try w.writeByte('\n');
1873 return;
1874 }
1875
1876 const project_id: Package.ProjectId = .init(child_fetch.manifest.name, child_fetch.manifest.id);
1877 if (fork_set.getKeyPtrAdapted(project_id, @as(Fetch.JobQueue.Fork.Adapter, .{}))) |fork| {
1878 try terminal.setColor(.yellow);
1879 try w.print(" (fork: {f})", .{fork.path});
1880 try terminal.setColor(.reset);
1881 }
1882
1857 try w.writeByte('\n');1883 try w.writeByte('\n');
1858 if (!child_fetch.have_manifest) return;
18591884
1860 const names = child_fetch.manifest.dependencies.keys();1885 const names = child_fetch.manifest.dependencies.keys();
1861 for (names, child_fetch.manifest.dependencies.values(), 0..) |name, *dep, i| {1886 for (names, child_fetch.manifest.dependencies.values(), 0..) |name, *dep, i| {
...@@ -1863,7 +1888,16 @@ fn printPkgTreeChild(...@@ -1863,7 +1888,16 @@ fn printPkgTreeChild(
1863 .parent = parent_print_node,1888 .parent = parent_print_node,
1864 .last = i == names.len - 1,1889 .last = i == names.len - 1,
1865 };1890 };
1866 try printPkgTreeChild(terminal, arena, job_queue, &print_node, name, dep.hash);1891 switch (dep.location) {
1892 .url => {
1893 const child_hash = if (dep.hash) |h| Package.Hash.fromSlice(h) else null;
1894 try printPkgTreeChild(terminal, arena, global_cache_root, job_queue, &print_node, name, child_hash, fork_set);
1895 },
1896 .path => {
1897 const child_hash = Package.Fetch.depDigest(child_fetch.package_root, global_cache_root, dep);
1898 try printPkgTreeChild(terminal, arena, global_cache_root, job_queue, &print_node, name, child_hash, fork_set);
1899 },
1900 }
1867 }1901 }
1868}1902}
18691903
lib/compiler/Maker/Fetch.zig+3-3
...@@ -302,7 +302,7 @@ pub const JobQueue = struct {...@@ -302,7 +302,7 @@ pub const JobQueue = struct {
302 \\ pub const deps: []const struct { []const u8, []const u8 } = &.{302 \\ pub const deps: []const struct { []const u8, []const u8 } = &.{
303 \\303 \\
304 );304 );
305 for (manifest.dependencies.keys(), manifest.dependencies.values()) |name, dep| {305 for (manifest.dependencies.keys(), manifest.dependencies.values()) |name, *dep| {
306 const h = depDigest(fetch.package_root, jq.global_cache, dep) orelse continue;306 const h = depDigest(fetch.package_root, jq.global_cache, dep) orelse continue;
307 try w.print(307 try w.print(
308 " .{{ \"{f}\", \"{f}\" }},\n",308 " .{{ \"{f}\", \"{f}\" }},\n",
...@@ -335,7 +335,7 @@ pub const JobQueue = struct {...@@ -335,7 +335,7 @@ pub const JobQueue = struct {
335 assert(root_fetch.have_manifest);335 assert(root_fetch.have_manifest);
336 const root_manifest = &root_fetch.manifest;336 const root_manifest = &root_fetch.manifest;
337337
338 for (root_manifest.dependencies.keys(), root_manifest.dependencies.values()) |name, dep| {338 for (root_manifest.dependencies.keys(), root_manifest.dependencies.values()) |name, *dep| {
339 const h = depDigest(root_fetch.package_root, jq.global_cache, dep) orelse continue;339 const h = depDigest(root_fetch.package_root, jq.global_cache, dep) orelse continue;
340 try w.print(340 try w.print(
341 " .{{ \"{f}\", \"{f}\" }},\n",341 " .{{ \"{f}\", \"{f}\" }},\n",
...@@ -2033,7 +2033,7 @@ const Filter = struct {...@@ -2033,7 +2033,7 @@ const Filter = struct {
2033 }2033 }
2034};2034};
20352035
2036pub fn depDigest(pkg_root: Path, cache_root: Directory, dep: Manifest.Dependency) ?Package.Hash {2036pub fn depDigest(pkg_root: Path, cache_root: Directory, dep: *const Manifest.Dependency) ?Package.Hash {
2037 if (dep.hash) |h| return .fromSlice(h);2037 if (dep.hash) |h| return .fromSlice(h);
20382038
2039 switch (dep.location) {2039 switch (dep.location) {