authorgravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2020-01-11 19:21:54-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-01-11 19:21:54-05:00
loga6f6d8d2f7eedbeca56115c7297ba4a2748cf394
tree7a2b1010481ed3e1f891a5de5ca9b752d5dd7052
parent860d88037a0ede87bc192786a8b5f5cce715a529
parentfc20a589931ab9aac6f51e7685d724cbec52dd9e
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #4139 from mikdusan/stage1-relative-path-errors

strip cwd from compile error paths

1 files changed, 23 insertions(+), 2 deletions(-)

src/errmsg.cpp+23-2
......@@ -21,11 +21,32 @@ static void print_err_msg_type(ErrorMsg *err, ErrColor color, ErrType err_type)
2121
2222 // Show the error location, if available
2323 if (err->path != nullptr) {
24 const char *path = buf_ptr(err->path);
25 Slice<const char> pathslice{path, strlen(path)};
26
27 // Cache cwd
28 static Buf *cwdbuf{nullptr};
29 static Slice<const char> cwd;
30
31 if (cwdbuf == nullptr) {
32 cwdbuf = buf_alloc();
33 Error err = os_get_cwd(cwdbuf);
34 if (err != ErrorNone)
35 zig_panic("get cwd failed");
36 buf_append_char(cwdbuf, ZIG_OS_SEP_CHAR);
37 cwd.ptr = buf_ptr(cwdbuf);
38 cwd.len = strlen(cwd.ptr);
39 }
40
2441 const size_t line = err->line_start + 1;
2542 const size_t col = err->column_start + 1;
26
2743 if (use_colors) os_stderr_set_color(TermColorBold);
28 fprintf(stderr, "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": ", buf_ptr(err->path), line, col);
44
45 // Strip cwd from path
46 if (memStartsWith(pathslice, cwd))
47 fprintf(stderr, ".%c%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": ", ZIG_OS_SEP_CHAR, path+cwd.len, line, col);
48 else
49 fprintf(stderr, "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": ", path, line, col);
2950 }
3051
3152 // Write out the error type