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