diff options
| author | Ian Johnson <ian@ianjohnson.dev> | 2024-03-23 23:46:17 -0400 |
|---|---|---|
| committer | Ian Johnson <ian@ianjohnson.dev> | 2024-03-28 00:30:29 -0400 |
| commit | 424dd17b6cc3db868c837f6b7a8fa36dac2166c1 (patch) | |
| tree | 91d247d8250024fd7e6161c9ca11a4553f5854ea /src | |
| parent | 9dac8db2df2332d6dd4aa52a0b524e5c88a9349b (diff) | |
| download | zig-424dd17b6cc3db868c837f6b7a8fa36dac2166c1.tar.gz zig-424dd17b6cc3db868c837f6b7a8fa36dac2166c1.zip | |
Autodoc: add all modules to sources.tar
Closes #19403
This commit adds all modules in the compilation to the generated
`sources.tar` when using `-femit-docs` (including `std` and `builtin`).
Additionally, it considers the main module when doing so, rather than
the root module, so the behavior when running `zig test -femit-docs
test.zig` is now correct.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Compilation.zig | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 5bbca51ede..460a1e5d9e 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -3693,6 +3693,9 @@ fn workerDocsCopy(comp: *Compilation, wg: *WaitGroup) void { } fn docsCopyFallible(comp: *Compilation) anyerror!void { + const zcu = comp.module orelse + return comp.lockAndSetMiscFailure(.docs_copy, "no Zig code to document", .{}); + const emit = comp.docs_emit.?; var out_dir = emit.directory.handle.makeOpenPath(emit.sub_path, .{}) catch |err| { return comp.lockAndSetMiscFailure( @@ -3723,7 +3726,25 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void { }; defer tar_file.close(); - const root = comp.root_mod.root; + var seen_table: std.AutoArrayHashMapUnmanaged(*Package.Module, void) = .{}; + defer seen_table.deinit(comp.gpa); + + try seen_table.put(comp.gpa, zcu.main_mod, {}); + try seen_table.put(comp.gpa, zcu.std_mod, {}); + + var i: usize = 0; + while (i < seen_table.count()) : (i += 1) { + const mod = seen_table.keys()[i]; + try comp.docsCopyModule(mod, tar_file); + + const deps = mod.deps.values(); + try seen_table.ensureUnusedCapacity(comp.gpa, deps.len); + for (deps) |dep| seen_table.putAssumeCapacity(dep, {}); + } +} + +fn docsCopyModule(comp: *Compilation, module: *Package.Module, tar_file: std.fs.File) !void { + const root = module.root; const sub_path = if (root.sub_path.len == 0) "." else root.sub_path; var mod_dir = root.root_dir.handle.openDir(sub_path, .{ .iterate = true }) catch |err| { return comp.lockAndSetMiscFailure(.docs_copy, "unable to open directory '{}': {s}", .{ @@ -3762,7 +3783,7 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void { var file_header = std.tar.output.Header.init(); file_header.typeflag = .regular; - try file_header.setPath(comp.root_name, entry.path); + try file_header.setPath(module.fully_qualified_name, entry.path); try file_header.setSize(stat.size); try file_header.updateChecksum(); |
