authorgravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2022-01-29 13:24:51-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-19 19:10:10-07:00
log9ad9664ea86897891696b35cc3f45affb06944f1
treebd9474370403e97e752c1c8a856e20a90357b877
parent2dcaed743f27a7c53f1fa742fdc42ddd77fe15f4

autdoc: install artifacts


1 files changed, 29 insertions(+), 9 deletions(-)

src/Autodoc.zig+29-9
......@@ -5,9 +5,9 @@ const Module = @import("Module.zig");
55const Zir = @import("Zir.zig");
66
77module: *Module,
8doc_location: ?Compilation.EmitLoc,
8doc_location: Compilation.EmitLoc,
99
10pub fn init(m: *Module, dl: ?Compilation.EmitLoc) Autodoc {
10pub fn init(m: *Module, dl: Compilation.EmitLoc) Autodoc {
1111 return .{
1212 .doc_location = dl,
1313 .module = m,
......@@ -17,14 +17,12 @@ pub fn init(m: *Module, dl: ?Compilation.EmitLoc) Autodoc {
1717pub fn generateZirData(self: Autodoc) !void {
1818 const gpa = self.module.gpa;
1919 std.debug.print("yay, you called me!\n", .{});
20 if (self.doc_location) |loc| {
21 if (loc.directory) |dir| {
22 if (dir.path) |path| {
23 std.debug.print("path: {s}\n", .{path});
24 }
20 if (self.doc_location.directory) |dir| {
21 if (dir.path) |path| {
22 std.debug.print("path: {s}\n", .{path});
2523 }
26 std.debug.print("basename: {s}\n", .{loc.basename});
2724 }
25 std.debug.print("basename: {s}\n", .{self.doc_location.basename});
2826
2927 var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
3028 const dir =
......@@ -74,7 +72,23 @@ pub fn generateZirData(self: Autodoc) !void {
7472
7573 data.packages[0].main = main_type_index.type;
7674
77 const out = std.io.getStdOut().writer();
75 if (self.doc_location.directory) |d|
76 (d.handle.makeDir(self.doc_location.basename) catch |e| switch (e) {
77 error.PathAlreadyExists => {},
78 else => unreachable,
79 })
80 else
81 (self.module.zig_cache_artifact_directory.handle.makeDir(self.doc_location.basename) catch |e| switch (e) {
82 error.PathAlreadyExists => {},
83 else => unreachable,
84 });
85 const output_dir = if (self.doc_location.directory) |d|
86 (d.handle.openDir(self.doc_location.basename, .{}) catch unreachable)
87 else
88 (self.module.zig_cache_artifact_directory.handle.openDir(self.doc_location.basename, .{}) catch unreachable);
89 const data_js_f = output_dir.createFile("data.js", .{}) catch unreachable;
90 defer data_js_f.close();
91 const out = data_js_f.writer();
7892 out.print("zigAnalysis=", .{}) catch unreachable;
7993 std.json.stringify(
8094 data,
......@@ -85,6 +99,12 @@ pub fn generateZirData(self: Autodoc) !void {
8599 out,
86100 ) catch unreachable;
87101 out.print(";", .{}) catch unreachable;
102 // copy main.js, index.html
103 const special = try self.module.comp.zig_lib_directory.join(gpa, &.{ "std", "special", "docs", std.fs.path.sep_str });
104 var special_dir = std.fs.openDirAbsolute(special, .{}) catch unreachable;
105 defer special_dir.close();
106 special_dir.copyFile("main.js", output_dir, "main.js", .{}) catch unreachable;
107 special_dir.copyFile("index.html", output_dir, "index.html", .{}) catch unreachable;
88108}
89109
90110const Scope = struct {