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");...@@ -5,9 +5,9 @@ const Module = @import("Module.zig");
5const Zir = @import("Zir.zig");5const Zir = @import("Zir.zig");
66
7module: *Module,7module: *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 {
11 return .{11 return .{
12 .doc_location = dl,12 .doc_location = dl,
13 .module = m,13 .module = m,
...@@ -17,14 +17,12 @@ pub fn init(m: *Module, dl: ?Compilation.EmitLoc) Autodoc {...@@ -17,14 +17,12 @@ pub fn init(m: *Module, dl: ?Compilation.EmitLoc) Autodoc {
17pub fn generateZirData(self: Autodoc) !void {17pub fn generateZirData(self: Autodoc) !void {
18 const gpa = self.module.gpa;18 const gpa = self.module.gpa;
19 std.debug.print("yay, you called me!\n", .{});19 std.debug.print("yay, you called me!\n", .{});
20 if (self.doc_location) |loc| {20 if (self.doc_location.directory) |dir| {
21 if (loc.directory) |dir| {21 if (dir.path) |path| {
22 if (dir.path) |path| {22 std.debug.print("path: {s}\n", .{path});
23 std.debug.print("path: {s}\n", .{path});
24 }
25 }23 }
26 std.debug.print("basename: {s}\n", .{loc.basename});
27 }24 }
25 std.debug.print("basename: {s}\n", .{self.doc_location.basename});
2826
29 var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;27 var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
30 const dir =28 const dir =
...@@ -74,7 +72,23 @@ pub fn generateZirData(self: Autodoc) !void {...@@ -74,7 +72,23 @@ pub fn generateZirData(self: Autodoc) !void {
7472
75 data.packages[0].main = main_type_index.type;73 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();
78 out.print("zigAnalysis=", .{}) catch unreachable;92 out.print("zigAnalysis=", .{}) catch unreachable;
79 std.json.stringify(93 std.json.stringify(
80 data,94 data,
...@@ -85,6 +99,12 @@ pub fn generateZirData(self: Autodoc) !void {...@@ -85,6 +99,12 @@ pub fn generateZirData(self: Autodoc) !void {
85 out,99 out,
86 ) catch unreachable;100 ) catch unreachable;
87 out.print(";", .{}) catch unreachable;101 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;
88}108}
89109
90const Scope = struct {110const Scope = struct {