Commit 025337a78d

Jacob G-W <jacoblevgw@gmail.com>
2022-01-28 23:53:40
autodoc: don't hardcode file name
1 parent 652e13e
Changed files (1)
src/Autodoc.zig
@@ -26,9 +26,16 @@ pub fn generateZirData(self: Autodoc) !void {
         std.debug.print("basename: {s}\n", .{loc.basename});
     }
 
-    // const root_file_path = self.module.main_pkg.root_src_path;
-    const root_file_path = "/home/kristoff/test/test.zig";
-    const zir = self.module.import_table.get(root_file_path).?.zir;
+    var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
+    const dir =
+        if (self.module.main_pkg.root_src_directory.path) |rp|
+        std.os.realpath(rp, &buf) catch unreachable
+    else
+        std.os.getcwd(&buf) catch unreachable;
+    const root_file_path = self.module.main_pkg.root_src_path;
+    const abs_root_path = try std.fs.path.join(gpa, &.{ dir, root_file_path });
+    defer gpa.free(abs_root_path);
+    const zir = self.module.import_table.get(abs_root_path).?.zir;
 
     var types = std.ArrayList(DocData.Type).init(gpa);
     var decls = std.ArrayList(DocData.Decl).init(gpa);