diff options
| author | Michael Dusan <michael.dusan@gmail.com> | 2020-01-11 16:45:57 -0500 |
|---|---|---|
| committer | Michael Dusan <michael.dusan@gmail.com> | 2020-01-11 16:45:57 -0500 |
| commit | fc20a589931ab9aac6f51e7685d724cbec52dd9e (patch) | |
| tree | 7a2b1010481ed3e1f891a5de5ca9b752d5dd7052 /src/errmsg.cpp | |
| parent | 860d88037a0ede87bc192786a8b5f5cce715a529 (diff) | |
| download | zig-fc20a589931ab9aac6f51e7685d724cbec52dd9e.tar.gz zig-fc20a589931ab9aac6f51e7685d724cbec52dd9e.zip | |
strip cwd from compile error paths
closes #43138
Diffstat (limited to 'src/errmsg.cpp')
| -rw-r--r-- | src/errmsg.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/errmsg.cpp b/src/errmsg.cpp index 16d1dcd52f..9425b110c3 100644 --- a/src/errmsg.cpp +++ b/src/errmsg.cpp @@ -21,11 +21,32 @@ static void print_err_msg_type(ErrorMsg *err, ErrColor color, ErrType err_type) // Show the error location, if available if (err->path != nullptr) { + const char *path = buf_ptr(err->path); + Slice<const char> pathslice{path, strlen(path)}; + + // Cache cwd + static Buf *cwdbuf{nullptr}; + static Slice<const char> cwd; + + if (cwdbuf == nullptr) { + cwdbuf = buf_alloc(); + Error err = os_get_cwd(cwdbuf); + if (err != ErrorNone) + zig_panic("get cwd failed"); + buf_append_char(cwdbuf, ZIG_OS_SEP_CHAR); + cwd.ptr = buf_ptr(cwdbuf); + cwd.len = strlen(cwd.ptr); + } + const size_t line = err->line_start + 1; const size_t col = err->column_start + 1; - if (use_colors) os_stderr_set_color(TermColorBold); - fprintf(stderr, "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": ", buf_ptr(err->path), line, col); + + // Strip cwd from path + if (memStartsWith(pathslice, cwd)) + fprintf(stderr, ".%c%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": ", ZIG_OS_SEP_CHAR, path+cwd.len, line, col); + else + fprintf(stderr, "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": ", path, line, col); } // Write out the error type |
