Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,9 @@ fn generateLangRef(b: *std.Build) std.Build.LazyPath {
const docgen_cmd = b.addRunArtifact(docgen_exe);
docgen_cmd.addArgs(&.{"--code-dir"});
docgen_cmd.addDirectoryArg(wf.getDirectory());
var buf: [std.fs.max_path_bytes]u8 = undefined;
const os_cwd = std.process.getCwd(&buf) catch unreachable;
docgen_cmd.addArgs(&.{"--base-dir", os_cwd });

docgen_cmd.addFileArg(b.path("doc/langref.html.in"));
return docgen_cmd.addOutputFileArg("langref.html");
Expand Down
18 changes: 16 additions & 2 deletions tools/docgen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub fn main() !void {
if (!args_it.skip()) @panic("expected self arg");

var opt_code_dir: ?[]const u8 = null;
var opt_base_dir: ?[]const u8 = null;
var opt_input: ?[]const u8 = null;
var opt_output: ?[]const u8 = null;

Expand All @@ -51,6 +52,12 @@ pub fn main() !void {
} else {
fatal("expected parameter after --code-dir", .{});
}
} else if (mem.eql(u8, arg, "--base-dir")) {
if (args_it.next()) |param| {
opt_base_dir = param;
} else {
fatal("expected parameter after --base-dir", .{});
}
} else {
fatal("unrecognized option: '{s}'", .{arg});
}
Expand Down Expand Up @@ -83,7 +90,7 @@ pub fn main() !void {
var tokenizer = Tokenizer.init(input_path, input_file_bytes);
var toc = try genToc(arena, &tokenizer);

try genHtml(arena, &tokenizer, &toc, code_dir, &out_file_writer.interface);
try genHtml(arena, &tokenizer, &toc, code_dir, opt_base_dir, &out_file_writer.interface);
try out_file_writer.end();
}

Expand Down Expand Up @@ -985,6 +992,7 @@ fn genHtml(
tokenizer: *Tokenizer,
toc: *Toc,
code_dir: std.fs.Dir,
opt_base_dir: ?[]const u8,
out: *Writer,
) !void {
for (toc.nodes) |node| {
Expand Down Expand Up @@ -1045,7 +1053,13 @@ fn genHtml(
};
defer allocator.free(contents);

try out.writeAll(contents);
if (opt_base_dir) |base_dir| {
const rep_contents = try mem.replaceOwned(u8, allocator, contents, base_dir, "");
defer allocator.free(rep_contents);
try out.writeAll(rep_contents);
} else {
try out.writeAll(contents);
}
},
}
}
Expand Down
Loading