authorgravatar for ian@ianjohnson.devIan Johnson <ian@ianjohnson.dev> 2024-04-12 21:18:18-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-04-12 23:43:57-07:00
log4fac5bd601da12140586115dc9ddc6a92577ff6d
tree8746445aaaf7b1895b650d0698c98892961f17e2
parentf1c0f42cddd344d6ac56569decb42eab2dfc07e5

Autodoc: fix root module name in sources.tar

This was overlooked in #19458. Using the fully qualified name of each module usually makes sense, but there is one module where it does not, namely, the root module, since its name is `root`. The original Autodoc tar creation logic used `comp.root_name` for the root module back when it was the only module included in `sources.tar`, and that made sense. Now, we get the best of both worlds, using the proper root name for the root module while using the module name for the rest.

1 files changed, 7 insertions(+), 7 deletions(-)

src/Compilation.zig+7-7
......@@ -3731,24 +3731,24 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void {
37313731 };
37323732 defer tar_file.close();
37333733
3734 var seen_table: std.AutoArrayHashMapUnmanaged(*Package.Module, void) = .{};
3734 var seen_table: std.AutoArrayHashMapUnmanaged(*Package.Module, []const u8) = .{};
37353735 defer seen_table.deinit(comp.gpa);
37363736
3737 try seen_table.put(comp.gpa, zcu.main_mod, {});
3738 try seen_table.put(comp.gpa, zcu.std_mod, {});
3737 try seen_table.put(comp.gpa, zcu.main_mod, comp.root_name);
3738 try seen_table.put(comp.gpa, zcu.std_mod, zcu.std_mod.fully_qualified_name);
37393739
37403740 var i: usize = 0;
37413741 while (i < seen_table.count()) : (i += 1) {
37423742 const mod = seen_table.keys()[i];
3743 try comp.docsCopyModule(mod, tar_file);
3743 try comp.docsCopyModule(mod, seen_table.values()[i], tar_file);
37443744
37453745 const deps = mod.deps.values();
37463746 try seen_table.ensureUnusedCapacity(comp.gpa, deps.len);
3747 for (deps) |dep| seen_table.putAssumeCapacity(dep, {});
3747 for (deps) |dep| seen_table.putAssumeCapacity(dep, dep.fully_qualified_name);
37483748 }
37493749}
37503750
3751fn docsCopyModule(comp: *Compilation, module: *Package.Module, tar_file: std.fs.File) !void {
3751fn docsCopyModule(comp: *Compilation, module: *Package.Module, name: []const u8, tar_file: std.fs.File) !void {
37523752 const root = module.root;
37533753 const sub_path = if (root.sub_path.len == 0) "." else root.sub_path;
37543754 var mod_dir = root.root_dir.handle.openDir(sub_path, .{ .iterate = true }) catch |err| {
......@@ -3788,7 +3788,7 @@ fn docsCopyModule(comp: *Compilation, module: *Package.Module, tar_file: std.fs.
37883788
37893789 var file_header = std.tar.output.Header.init();
37903790 file_header.typeflag = .regular;
3791 try file_header.setPath(module.fully_qualified_name, entry.path);
3791 try file_header.setPath(name, entry.path);
37923792 try file_header.setSize(stat.size);
37933793 try file_header.updateChecksum();
37943794