From 9ad9664ea86897891696b35cc3f45affb06944f1 Mon Sep 17 00:00:00 2001 From: Jacob G-W Date: Sat, 29 Jan 2022 13:24:51 -0500 Subject: [PATCH] autdoc: install artifacts --- src/Autodoc.zig | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/Autodoc.zig b/src/Autodoc.zig index 7b897f2e05..c4f5026db5 100644 --- a/src/Autodoc.zig +++ b/src/Autodoc.zig @@ -5,9 +5,9 @@ const Module = @import("Module.zig"); const Zir = @import("Zir.zig"); module: *Module, -doc_location: ?Compilation.EmitLoc, +doc_location: Compilation.EmitLoc, -pub fn init(m: *Module, dl: ?Compilation.EmitLoc) Autodoc { +pub fn init(m: *Module, dl: Compilation.EmitLoc) Autodoc { return .{ .doc_location = dl, .module = m, @@ -17,14 +17,12 @@ pub fn init(m: *Module, dl: ?Compilation.EmitLoc) Autodoc { pub fn generateZirData(self: Autodoc) !void { const gpa = self.module.gpa; std.debug.print("yay, you called me!\n", .{}); - if (self.doc_location) |loc| { - if (loc.directory) |dir| { - if (dir.path) |path| { - std.debug.print("path: {s}\n", .{path}); - } + if (self.doc_location.directory) |dir| { + if (dir.path) |path| { + std.debug.print("path: {s}\n", .{path}); } - std.debug.print("basename: {s}\n", .{loc.basename}); } + std.debug.print("basename: {s}\n", .{self.doc_location.basename}); var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; const dir = @@ -74,7 +72,23 @@ pub fn generateZirData(self: Autodoc) !void { data.packages[0].main = main_type_index.type; - const out = std.io.getStdOut().writer(); + if (self.doc_location.directory) |d| + (d.handle.makeDir(self.doc_location.basename) catch |e| switch (e) { + error.PathAlreadyExists => {}, + else => unreachable, + }) + else + (self.module.zig_cache_artifact_directory.handle.makeDir(self.doc_location.basename) catch |e| switch (e) { + error.PathAlreadyExists => {}, + else => unreachable, + }); + const output_dir = if (self.doc_location.directory) |d| + (d.handle.openDir(self.doc_location.basename, .{}) catch unreachable) + else + (self.module.zig_cache_artifact_directory.handle.openDir(self.doc_location.basename, .{}) catch unreachable); + const data_js_f = output_dir.createFile("data.js", .{}) catch unreachable; + defer data_js_f.close(); + const out = data_js_f.writer(); out.print("zigAnalysis=", .{}) catch unreachable; std.json.stringify( data, @@ -85,6 +99,12 @@ pub fn generateZirData(self: Autodoc) !void { out, ) catch unreachable; out.print(";", .{}) catch unreachable; + // copy main.js, index.html + const special = try self.module.comp.zig_lib_directory.join(gpa, &.{ "std", "special", "docs", std.fs.path.sep_str }); + var special_dir = std.fs.openDirAbsolute(special, .{}) catch unreachable; + defer special_dir.close(); + special_dir.copyFile("main.js", output_dir, "main.js", .{}) catch unreachable; + special_dir.copyFile("index.html", output_dir, "index.html", .{}) catch unreachable; } const Scope = struct {