authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-08-19 17:53:08-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-08-19 17:54:39-07:00
log5ee54cd52ad5f03ce24ec8c0ffee35972df3a5f3
tree6ae58cc4a9c3efb731a2784d5c8366c675a64e88
parent7b0f777ffdd2900e7dcd5db096b27a06bc416263

Compilation: avoid putting superfluous dot in error paths


1 files changed, 11 insertions(+), 13 deletions(-)

src/Compilation.zig+11-13
...@@ -435,7 +435,7 @@ pub const Path = struct {...@@ -435,7 +435,7 @@ pub const Path = struct {
435 const dir = switch (p.root) {435 const dir = switch (p.root) {
436 .none => {436 .none => {
437 const cwd_sub_path = absToCwdRelative(p.sub_path, dirs.cwd);437 const cwd_sub_path = absToCwdRelative(p.sub_path, dirs.cwd);
438 return .{ Io.Dir.cwd(), cwd_sub_path };438 return .{ Io.Dir.cwd(), if (cwd_sub_path.len == 0) "." else cwd_sub_path };
439 },439 },
440 .zig_lib => dirs.zig_lib.handle,440 .zig_lib => dirs.zig_lib.handle,
441 .global_cache => dirs.global_cache.handle,441 .global_cache => dirs.global_cache.handle,
...@@ -456,20 +456,18 @@ pub const Path = struct {...@@ -456,20 +456,18 @@ pub const Path = struct {
456 comp: *Compilation,456 comp: *Compilation,
457 pub fn format(f: Formatter, w: *Writer) Writer.Error!void {457 pub fn format(f: Formatter, w: *Writer) Writer.Error!void {
458 const root_path: []const u8 = switch (f.p.root) {458 const root_path: []const u8 = switch (f.p.root) {
459 .zig_lib => f.comp.dirs.zig_lib.path orelse ".",459 .zig_lib => f.comp.dirs.zig_lib.path orelse "",
460 .global_cache => f.comp.dirs.global_cache.path orelse ".",460 .global_cache => f.comp.dirs.global_cache.path orelse "",
461 .local_cache => f.comp.dirs.local_cache.path orelse ".",461 .local_cache => f.comp.dirs.local_cache.path orelse "",
462 .build_root => f.comp.dirs.build_root.path orelse ".",462 .build_root => f.comp.dirs.build_root.path orelse "",
463 .none => {463 .none => {
464 const cwd_sub_path = absToCwdRelative(f.p.sub_path, f.comp.dirs.cwd);464 try w.writeAll(absToCwdRelative(f.p.sub_path, f.comp.dirs.cwd));
465 try w.writeAll(cwd_sub_path);
466 return;465 return;
467 },466 },
468 };467 };
469 assert(root_path.len != 0);
470 try w.writeAll(root_path);468 try w.writeAll(root_path);
471 if (f.p.sub_path.len > 0) {469 if (f.p.sub_path.len > 0) {
472 try w.writeByte(fs.path.sep);470 if (root_path.len != 0) try w.writeByte(fs.path.sep);
473 try w.writeAll(f.p.sub_path);471 try w.writeAll(f.p.sub_path);
474 }472 }
475 }473 }
...@@ -477,16 +475,16 @@ pub const Path = struct {...@@ -477,16 +475,16 @@ pub const Path = struct {
477475
478 /// Given the `sub_path` of a `Path` with `Path.root == .none`, attempts to convert476 /// Given the `sub_path` of a `Path` with `Path.root == .none`, attempts to convert
479 /// the (absolute) path to a cwd-relative path. Otherwise, returns the absolute path477 /// the (absolute) path to a cwd-relative path. Otherwise, returns the absolute path
480 /// unmodified. The returned string is never empty: "" is converted to ".".478 /// unmodified. The returned string is never "."; empty string will be returned instead.
481 fn absToCwdRelative(sub_path: []const u8, cwd_path: []const u8) []const u8 {479 fn absToCwdRelative(sub_path: []const u8, cwd_path: []const u8) []const u8 {
482 if (builtin.target.os.tag == .wasi) {480 if (builtin.target.os.tag == .wasi) {
483 if (sub_path.len == 0) return ".";481 if (sub_path.len == 0) return "";
484 assert(!fs.path.isAbsolute(sub_path));482 assert(!fs.path.isAbsolute(sub_path));
485 return sub_path;483 return sub_path;
486 }484 }
487 assert(fs.path.isAbsolute(sub_path));485 assert(fs.path.isAbsolute(sub_path));
488 if (!std.mem.startsWith(u8, sub_path, cwd_path)) return sub_path;486 if (!std.mem.startsWith(u8, sub_path, cwd_path)) return sub_path;
489 if (sub_path.len == cwd_path.len) return "."; // the strings are equal487 if (sub_path.len == cwd_path.len) return ""; // the strings are equal
490 const path_sep_index = path_sep_index: {488 const path_sep_index = path_sep_index: {
491 // cwd is just a root, e.g. / or C:\489 // cwd is just a root, e.g. / or C:\
492 if (cwd_path[cwd_path.len - 1] == fs.path.sep) break :path_sep_index cwd_path.len - 1;490 if (cwd_path[cwd_path.len - 1] == fs.path.sep) break :path_sep_index cwd_path.len - 1;
...@@ -647,7 +645,7 @@ pub const Path = struct {...@@ -647,7 +645,7 @@ pub const Path = struct {
647 const cwd_sub_path = absToCwdRelative(p.sub_path, dirs.cwd);645 const cwd_sub_path = absToCwdRelative(p.sub_path, dirs.cwd);
648 return .{646 return .{
649 .root_dir = .cwd(),647 .root_dir = .cwd(),
650 .sub_path = cwd_sub_path,648 .sub_path = if (cwd_sub_path.len == 0) null else cwd_sub_path,
651 };649 };
652 },650 },
653 };651 };