authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-19 23:52:44-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-19 23:52:44-04:00
logd9fc14975232c0aa09e6498763f60515100770b9
tree6f586389bf43fdb1031913dff02b42644cb124c4
parent3908b4fdee64c0ec6ef4d65e5b31210d4fea4423

relative path to cwd in compile errors


1 files changed, 14 insertions(+), 3 deletions(-)

src-self-hosted/compilation.zig+14-3
......@@ -40,6 +40,8 @@ pub const EventLoopLocal = struct {
4040
4141 native_libc: event.Future(LibCInstallation),
4242
43 cwd: []const u8,
44
4345 var lazy_init_targets = std.lazyInit(void);
4446
4547 fn init(loop: *event.Loop) !EventLoopLocal {
......@@ -51,16 +53,22 @@ pub const EventLoopLocal = struct {
5153 var seed_bytes: [@sizeOf(u64)]u8 = undefined;
5254 try std.os.getRandomBytes(seed_bytes[0..]);
5355 const seed = std.mem.readInt(seed_bytes, u64, builtin.Endian.Big);
56
57 const cwd = try os.getCwd(loop.allocator);
58 errdefer loop.allocator.free(cwd);
59
5460 return EventLoopLocal{
5561 .loop = loop,
5662 .llvm_handle_pool = std.atomic.Stack(llvm.ContextRef).init(),
5763 .prng = event.Locked(std.rand.DefaultPrng).init(loop, std.rand.DefaultPrng.init(seed)),
5864 .native_libc = event.Future(LibCInstallation).init(loop),
65 .cwd = cwd,
5966 };
6067 }
6168
6269 /// Must be called only after EventLoop.run completes.
6370 fn deinit(self: *EventLoopLocal) void {
71 self.loop.allocator.free(self.cwd);
6472 while (self.llvm_handle_pool.pop()) |node| {
6573 c.LLVMContextDispose(node.data);
6674 self.loop.allocator.destroy(node);
......@@ -867,13 +875,16 @@ pub const Compilation = struct {
867875 span: Span,
868876 text: []u8,
869877 ) !void {
870 const msg = try self.loop.allocator.create(errmsg.Msg{
871 .path = root.realpath,
878 const relpath = try os.path.relative(self.gpa(), self.event_loop_local.cwd, root.realpath);
879 errdefer self.gpa().free(relpath);
880
881 const msg = try self.gpa().create(errmsg.Msg{
882 .path = if (relpath.len < root.realpath.len) relpath else root.realpath,
872883 .text = text,
873884 .span = span,
874885 .tree = &root.tree,
875886 });
876 errdefer self.loop.allocator.destroy(msg);
887 errdefer self.gpa().destroy(msg);
877888
878889 const compile_errors = await (async self.compile_errors.acquire() catch unreachable);
879890 defer compile_errors.release();