| ... | ... | @@ -435,7 +435,7 @@ pub const Path = struct { |
| 435 | 435 | const dir = switch (p.root) { |
| 436 | 436 | .none => { |
| 437 | 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 | 440 | .zig_lib => dirs.zig_lib.handle, |
| 441 | 441 | .global_cache => dirs.global_cache.handle, |
| ... | ... | @@ -456,20 +456,18 @@ pub const Path = struct { |
| 456 | 456 | comp: *Compilation, |
| 457 | 457 | pub fn format(f: Formatter, w: *Writer) Writer.Error!void { |
| 458 | 458 | const root_path: []const u8 = switch (f.p.root) { |
| 459 | | .zig_lib => f.comp.dirs.zig_lib.path orelse ".", |
| 460 | | .global_cache => f.comp.dirs.global_cache.path orelse ".", |
| 461 | | .local_cache => f.comp.dirs.local_cache.path orelse ".", |
| 462 | | .build_root => f.comp.dirs.build_root.path orelse ".", |
| 459 | .zig_lib => f.comp.dirs.zig_lib.path orelse "", |
| 460 | .global_cache => f.comp.dirs.global_cache.path orelse "", |
| 461 | .local_cache => f.comp.dirs.local_cache.path orelse "", |
| 462 | .build_root => f.comp.dirs.build_root.path orelse "", |
| 463 | 463 | .none => { |
| 464 | | const cwd_sub_path = absToCwdRelative(f.p.sub_path, f.comp.dirs.cwd); |
| 465 | | try w.writeAll(cwd_sub_path); |
| 464 | try w.writeAll(absToCwdRelative(f.p.sub_path, f.comp.dirs.cwd)); |
| 466 | 465 | return; |
| 467 | 466 | }, |
| 468 | 467 | }; |
| 469 | | assert(root_path.len != 0); |
| 470 | 468 | try w.writeAll(root_path); |
| 471 | 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 | 471 | try w.writeAll(f.p.sub_path); |
| 474 | 472 | } |
| 475 | 473 | } |
| ... | ... | @@ -477,16 +475,16 @@ pub const Path = struct { |
| 477 | 475 | |
| 478 | 476 | /// Given the `sub_path` of a `Path` with `Path.root == .none`, attempts to convert |
| 479 | 477 | /// 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 | 479 | fn absToCwdRelative(sub_path: []const u8, cwd_path: []const u8) []const u8 { |
| 482 | 480 | if (builtin.target.os.tag == .wasi) { |
| 483 | | if (sub_path.len == 0) return "."; |
| 481 | if (sub_path.len == 0) return ""; |
| 484 | 482 | assert(!fs.path.isAbsolute(sub_path)); |
| 485 | 483 | return sub_path; |
| 486 | 484 | } |
| 487 | 485 | assert(fs.path.isAbsolute(sub_path)); |
| 488 | 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 equal |
| 487 | if (sub_path.len == cwd_path.len) return ""; // the strings are equal |
| 490 | 488 | const path_sep_index = path_sep_index: { |
| 491 | 489 | // cwd is just a root, e.g. / or C:\ |
| 492 | 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 | 645 | const cwd_sub_path = absToCwdRelative(p.sub_path, dirs.cwd); |
| 648 | 646 | return .{ |
| 649 | 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 | }; |