| author | |
| committer | |
| log | 649aaf4814f8b74d9f90c0aaa09cbaf1901a6650 |
| tree | 4fccf7c255e4423b03db0541956e4978856282b1 |
| parent | 9b415761dd66904aef363e387b4501f3ddd0bf76 |
progress towards #3015024 files changed, 122 insertions(+), 154 deletions(-)
lib/compiler/build_runner.zig+1-1| ... | ... | @@ -83,7 +83,7 @@ pub fn main(init: process.Init.Minimal) !void { |
| 83 | 83 | .io = io, |
| 84 | 84 | .gpa = gpa, |
| 85 | 85 | .manifest_dir = try local_cache_directory.handle.createDirPathOpen(io, "h", .{}), |
| 86 | .cwd = try process.getCwdAlloc(single_threaded_arena.allocator()), | |
| 86 | .cwd = try process.currentDirAlloc(io, single_threaded_arena.allocator()), | |
| 87 | 87 | }, |
| 88 | 88 | .zig_exe = zig_exe, |
| 89 | 89 | .environ_map = try init.environ.createMap(arena), |
lib/std/Build/Cache.zig+4-4| ... | ... | @@ -1315,7 +1315,7 @@ test "cache file and then recall it" { |
| 1315 | 1315 | var tmp = testing.tmpDir(.{}); |
| 1316 | 1316 | defer tmp.cleanup(); |
| 1317 | 1317 | |
| 1318 | const cwd = try std.process.getCwdAlloc(testing.allocator); | |
| 1318 | const cwd = try std.process.currentDirAlloc(io, testing.allocator); | |
| 1319 | 1319 | defer testing.allocator.free(cwd); |
| 1320 | 1320 | |
| 1321 | 1321 | const temp_file = "test.txt"; |
| ... | ... | @@ -1383,7 +1383,7 @@ test "check that changing a file makes cache fail" { |
| 1383 | 1383 | var tmp = testing.tmpDir(.{}); |
| 1384 | 1384 | defer tmp.cleanup(); |
| 1385 | 1385 | |
| 1386 | const cwd = try std.process.getCwdAlloc(testing.allocator); | |
| 1386 | const cwd = try std.process.currentDirAlloc(io, testing.allocator); | |
| 1387 | 1387 | defer testing.allocator.free(cwd); |
| 1388 | 1388 | |
| 1389 | 1389 | const temp_file = "cache_hash_change_file_test.txt"; |
| ... | ... | @@ -1459,7 +1459,7 @@ test "no file inputs" { |
| 1459 | 1459 | var tmp = testing.tmpDir(.{}); |
| 1460 | 1460 | defer tmp.cleanup(); |
| 1461 | 1461 | |
| 1462 | const cwd = try std.process.getCwdAlloc(testing.allocator); | |
| 1462 | const cwd = try std.process.currentDirAlloc(io, testing.allocator); | |
| 1463 | 1463 | defer testing.allocator.free(cwd); |
| 1464 | 1464 | |
| 1465 | 1465 | const temp_manifest_dir = "no_file_inputs_manifest_dir"; |
| ... | ... | @@ -1509,7 +1509,7 @@ test "Manifest with files added after initial hash work" { |
| 1509 | 1509 | var tmp = testing.tmpDir(.{}); |
| 1510 | 1510 | defer tmp.cleanup(); |
| 1511 | 1511 | |
| 1512 | const cwd = try std.process.getCwdAlloc(testing.allocator); | |
| 1512 | const cwd = try std.process.currentDirAlloc(io, testing.allocator); | |
| 1513 | 1513 | defer testing.allocator.free(cwd); |
| 1514 | 1514 | |
| 1515 | 1515 | const temp_file1 = "cache_hash_post_file_test1.txt"; |
lib/std/Build/Step/Options.zig+1-1| ... | ... | @@ -519,7 +519,7 @@ test Options { |
| 519 | 519 | var arena = std.heap.ArenaAllocator.init(std.testing.allocator); |
| 520 | 520 | defer arena.deinit(); |
| 521 | 521 | |
| 522 | const cwd = try std.process.getCwdAlloc(std.testing.allocator); | |
| 522 | const cwd = try std.process.currentDirAlloc(io, std.testing.allocator); | |
| 523 | 523 | defer std.testing.allocator.free(cwd); |
| 524 | 524 | |
| 525 | 525 | var graph: std.Build.Graph = .{ |
lib/std/Io.zig+1| ... | ... | @@ -665,6 +665,7 @@ pub const VTable = struct { |
| 665 | 665 | lockStderr: *const fn (?*anyopaque, ?Terminal.Mode) Cancelable!LockedStderr, |
| 666 | 666 | tryLockStderr: *const fn (?*anyopaque, ?Terminal.Mode) Cancelable!?LockedStderr, |
| 667 | 667 | unlockStderr: *const fn (?*anyopaque) void, |
| 668 | processCurrentDir: *const fn (?*anyopaque, buffer: []u8) std.process.CurrentDirError!usize, | |
| 668 | 669 | processSetCurrentDir: *const fn (?*anyopaque, Dir) std.process.SetCurrentDirError!void, |
| 669 | 670 | processReplace: *const fn (?*anyopaque, std.process.ReplaceOptions) std.process.ReplaceError, |
| 670 | 671 | processReplacePath: *const fn (?*anyopaque, Dir, std.process.ReplaceOptions) std.process.ReplaceError, |
lib/std/Io/Threaded.zig+42| ... | ... | @@ -1643,6 +1643,7 @@ pub fn io(t: *Threaded) Io { |
| 1643 | 1643 | .lockStderr = lockStderr, |
| 1644 | 1644 | .tryLockStderr = tryLockStderr, |
| 1645 | 1645 | .unlockStderr = unlockStderr, |
| 1646 | .processCurrentDir = processCurrentDir, | |
| 1646 | 1647 | .processSetCurrentDir = processSetCurrentDir, |
| 1647 | 1648 | .processReplace = processReplace, |
| 1648 | 1649 | .processReplacePath = processReplacePath, |
| ... | ... | @@ -1801,6 +1802,7 @@ pub fn ioBasic(t: *Threaded) Io { |
| 1801 | 1802 | .lockStderr = lockStderr, |
| 1802 | 1803 | .tryLockStderr = tryLockStderr, |
| 1803 | 1804 | .unlockStderr = unlockStderr, |
| 1805 | .processCurrentDir = processCurrentDir, | |
| 1804 | 1806 | .processSetCurrentDir = processSetCurrentDir, |
| 1805 | 1807 | .processReplace = processReplace, |
| 1806 | 1808 | .processReplacePath = processReplacePath, |
| ... | ... | @@ -12600,6 +12602,46 @@ fn unlockStderr(userdata: ?*anyopaque) void { |
| 12600 | 12602 | process.stderr_thread_mutex.unlock(); |
| 12601 | 12603 | } |
| 12602 | 12604 | |
| 12605 | fn processCurrentDir(userdata: ?*anyopaque, buffer: []u8) process.CurrentDirError!usize { | |
| 12606 | const t: *Threaded = @ptrCast(@alignCast(userdata)); | |
| 12607 | _ = t; | |
| 12608 | if (is_windows) { | |
| 12609 | var wtf16le_buf: [windows.PATH_MAX_WIDE:0]u16 = undefined; | |
| 12610 | const n = windows.ntdll.RtlGetCurrentDirectory_U(wtf16le_buf.len + 1, &wtf16le_buf); | |
| 12611 | if (n == 0) return error.Unexpected; | |
| 12612 | assert(n <= wtf16le_buf.len); | |
| 12613 | const wtf16le_slice = wtf16le_buf[0..n]; | |
| 12614 | var end_index: usize = 0; | |
| 12615 | var it = std.unicode.Wtf16LeIterator.init(wtf16le_slice); | |
| 12616 | while (it.nextCodepoint()) |codepoint| { | |
| 12617 | const seq_len = std.unicode.utf8CodepointSequenceLength(codepoint) catch unreachable; | |
| 12618 | if (end_index + seq_len >= buffer.len) | |
| 12619 | return error.NameTooLong; | |
| 12620 | end_index += std.unicode.wtf8Encode(codepoint, buffer[end_index..]) catch unreachable; | |
| 12621 | } | |
| 12622 | return end_index; | |
| 12623 | } else if (native_os == .wasi and !builtin.link_libc) { | |
| 12624 | if (buffer.len == 0) return error.NameTooLong; | |
| 12625 | buffer[0] = '.'; | |
| 12626 | return 1; | |
| 12627 | } | |
| 12628 | ||
| 12629 | const err: posix.E = if (builtin.link_libc) err: { | |
| 12630 | const c_err = if (std.c.getcwd(buffer.ptr, buffer.len)) |_| 0 else std.c._errno().*; | |
| 12631 | break :err @enumFromInt(c_err); | |
| 12632 | } else err: { | |
| 12633 | break :err posix.errno(posix.system.getcwd(buffer.ptr, buffer.len)); | |
| 12634 | }; | |
| 12635 | switch (err) { | |
| 12636 | .SUCCESS => return std.mem.findScalar(u8, buffer, 0).?, | |
| 12637 | .NOENT => return error.CurrentWorkingDirectoryUnlinked, | |
| 12638 | .RANGE => return error.NameTooLong, | |
| 12639 | .FAULT => |e| return errnoBug(e), | |
| 12640 | .INVAL => |e| return errnoBug(e), | |
| 12641 | else => return posix.unexpectedErrno(err), | |
| 12642 | } | |
| 12643 | } | |
| 12644 | ||
| 12603 | 12645 | fn processSetCurrentDir(userdata: ?*anyopaque, dir: Dir) process.SetCurrentDirError!void { |
| 12604 | 12646 | if (native_os == .wasi) return error.OperationUnsupported; |
| 12605 | 12647 | const t: *Threaded = @ptrCast(@alignCast(userdata)); |
lib/std/fs/test.zig+1-1| ... | ... | @@ -1787,7 +1787,7 @@ test "open file with exclusive nonblocking lock twice (absolute paths)" { |
| 1787 | 1787 | |
| 1788 | 1788 | const gpa = testing.allocator; |
| 1789 | 1789 | |
| 1790 | const cwd = try std.process.getCwdAlloc(gpa); | |
| 1790 | const cwd = try std.process.currentDirAlloc(io, gpa); | |
| 1791 | 1791 | defer gpa.free(cwd); |
| 1792 | 1792 | |
| 1793 | 1793 | const filename = try Dir.path.resolve(gpa, &.{ cwd, sub_path }); |
lib/std/os/windows.zig-28| ... | ... | @@ -2878,34 +2878,6 @@ pub fn CloseHandle(hObject: HANDLE) void { |
| 2878 | 2878 | assert(ntdll.NtClose(hObject) == .SUCCESS); |
| 2879 | 2879 | } |
| 2880 | 2880 | |
| 2881 | pub const GetCurrentDirectoryError = error{ | |
| 2882 | NameTooLong, | |
| 2883 | Unexpected, | |
| 2884 | }; | |
| 2885 | ||
| 2886 | /// The result is a slice of `buffer`, indexed from 0. | |
| 2887 | /// The result is encoded as [WTF-8](https://wtf-8.codeberg.page/). | |
| 2888 | pub fn GetCurrentDirectory(buffer: []u8) GetCurrentDirectoryError![]u8 { | |
| 2889 | var wtf16le_buf: [PATH_MAX_WIDE:0]u16 = undefined; | |
| 2890 | const result = kernel32.GetCurrentDirectoryW(wtf16le_buf.len + 1, &wtf16le_buf); | |
| 2891 | if (result == 0) { | |
| 2892 | switch (GetLastError()) { | |
| 2893 | else => |err| return unexpectedError(err), | |
| 2894 | } | |
| 2895 | } | |
| 2896 | assert(result <= wtf16le_buf.len); | |
| 2897 | const wtf16le_slice = wtf16le_buf[0..result]; | |
| 2898 | var end_index: usize = 0; | |
| 2899 | var it = std.unicode.Wtf16LeIterator.init(wtf16le_slice); | |
| 2900 | while (it.nextCodepoint()) |codepoint| { | |
| 2901 | const seq_len = std.unicode.utf8CodepointSequenceLength(codepoint) catch unreachable; | |
| 2902 | if (end_index + seq_len >= buffer.len) | |
| 2903 | return error.NameTooLong; | |
| 2904 | end_index += std.unicode.wtf8Encode(codepoint, buffer[end_index..]) catch unreachable; | |
| 2905 | } | |
| 2906 | return buffer[0..end_index]; | |
| 2907 | } | |
| 2908 | ||
| 2909 | 2881 | pub const GetStdHandleError = error{ |
| 2910 | 2882 | NoStandardHandleAttached, |
| 2911 | 2883 | Unexpected, |
lib/std/os/windows/kernel32.zig-6| ... | ... | @@ -128,12 +128,6 @@ pub extern "kernel32" fn SetFileCompletionNotificationModes( |
| 128 | 128 | Flags: UCHAR, |
| 129 | 129 | ) callconv(.winapi) BOOL; |
| 130 | 130 | |
| 131 | // TODO: `RtlGetCurrentDirectory_U(nBufferLength * 2, lpBuffer)` | |
| 132 | pub extern "kernel32" fn GetCurrentDirectoryW( | |
| 133 | nBufferLength: DWORD, | |
| 134 | lpBuffer: ?[*]WCHAR, | |
| 135 | ) callconv(.winapi) DWORD; | |
| 136 | ||
| 137 | 131 | pub extern "kernel32" fn ReadFile( |
| 138 | 132 | hFile: HANDLE, |
| 139 | 133 | lpBuffer: LPVOID, |
lib/std/os/windows/ntdll.zig+5| ... | ... | @@ -496,6 +496,11 @@ pub extern "ntdll" fn RtlGetFullPathName_U( |
| 496 | 496 | ShortName: ?*[*:0]const u16, |
| 497 | 497 | ) callconv(.winapi) ULONG; |
| 498 | 498 | |
| 499 | pub extern "ntdll" fn RtlGetCurrentDirectory_U( | |
| 500 | BufferLength: ULONG, | |
| 501 | Buffer: [*]u16, | |
| 502 | ) callconv(.winapi) ULONG; | |
| 503 | ||
| 499 | 504 | pub extern "ntdll" fn RtlGetSystemTimePrecise() callconv(.winapi) LARGE_INTEGER; |
| 500 | 505 | |
| 501 | 506 | pub extern "ntdll" fn RtlInitializeCriticalSection( |
lib/std/posix.zig-34| ... | ... | @@ -519,40 +519,6 @@ pub fn getppid() pid_t { |
| 519 | 519 | return system.getppid(); |
| 520 | 520 | } |
| 521 | 521 | |
| 522 | pub const GetCwdError = error{ | |
| 523 | NameTooLong, | |
| 524 | /// Not possible on Windows. | |
| 525 | CurrentWorkingDirectoryUnlinked, | |
| 526 | } || UnexpectedError; | |
| 527 | ||
| 528 | /// The result is a slice of out_buffer, indexed from 0. | |
| 529 | pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 { | |
| 530 | if (native_os == .windows) { | |
| 531 | return windows.GetCurrentDirectory(out_buffer); | |
| 532 | } else if (native_os == .wasi and !builtin.link_libc) { | |
| 533 | const path = "."; | |
| 534 | if (out_buffer.len < path.len) return error.NameTooLong; | |
| 535 | const result = out_buffer[0..path.len]; | |
| 536 | @memcpy(result, path); | |
| 537 | return result; | |
| 538 | } | |
| 539 | ||
| 540 | const err: E = if (builtin.link_libc) err: { | |
| 541 | const c_err = if (std.c.getcwd(out_buffer.ptr, out_buffer.len)) |_| 0 else std.c._errno().*; | |
| 542 | break :err @enumFromInt(c_err); | |
| 543 | } else err: { | |
| 544 | break :err errno(system.getcwd(out_buffer.ptr, out_buffer.len)); | |
| 545 | }; | |
| 546 | switch (err) { | |
| 547 | .SUCCESS => return mem.sliceTo(out_buffer, 0), | |
| 548 | .FAULT => unreachable, | |
| 549 | .INVAL => unreachable, | |
| 550 | .NOENT => return error.CurrentWorkingDirectoryUnlinked, | |
| 551 | .RANGE => return error.NameTooLong, | |
| 552 | else => return unexpectedErrno(err), | |
| 553 | } | |
| 554 | } | |
| 555 | ||
| 556 | 522 | pub const SocketError = error{ |
| 557 | 523 | /// Permission to create a socket of the specified type and/or |
| 558 | 524 | /// pro‐tocol is denied. |
lib/std/process.zig+26-39| ... | ... | @@ -63,53 +63,40 @@ pub const Init = struct { |
| 63 | 63 | }; |
| 64 | 64 | }; |
| 65 | 65 | |
| 66 | pub const GetCwdError = posix.GetCwdError; | |
| 66 | pub const CurrentDirError = error{ | |
| 67 | NameTooLong, | |
| 68 | /// Not possible on Windows. Always returned on WASI. | |
| 69 | CurrentWorkingDirectoryUnlinked, | |
| 70 | } || Io.UnexpectedError; | |
| 67 | 71 | |
| 68 | /// The result is a slice of `out_buffer`, from index `0`. | |
| 69 | 72 | /// On Windows, the result is encoded as [WTF-8](https://wtf-8.codeberg.page/). |
| 70 | /// On other platforms, the result is an opaque sequence of bytes with no particular encoding. | |
| 71 | pub fn getCwd(out_buffer: []u8) GetCwdError![]u8 { | |
| 72 | return posix.getcwd(out_buffer); | |
| 73 | /// On other platforms, the result is an opaque sequence of bytes with no | |
| 74 | /// particular encoding. | |
| 75 | pub fn currentDir(io: Io, buffer: []u8) CurrentDirError!usize { | |
| 76 | return io.vtable.processCurrentDir(io.userdata, buffer); | |
| 73 | 77 | } |
| 74 | 78 | |
| 75 | // Same as GetCwdError, minus error.NameTooLong + Allocator.Error | |
| 76 | pub const GetCwdAllocError = Allocator.Error || error{ | |
| 77 | /// Not possible on Windows. | |
| 79 | pub const CurrentDirAllocError = Allocator.Error || error{ | |
| 80 | /// Not possible on Windows. Always returned on WASI. | |
| 78 | 81 | CurrentWorkingDirectoryUnlinked, |
| 79 | } || posix.UnexpectedError; | |
| 82 | } || Io.UnexpectedError; | |
| 80 | 83 | |
| 81 | /// Caller must free the returned memory. | |
| 82 | 84 | /// On Windows, the result is encoded as [WTF-8](https://wtf-8.codeberg.page/). |
| 83 | /// On other platforms, the result is an opaque sequence of bytes with no particular encoding. | |
| 84 | pub fn getCwdAlloc(allocator: Allocator) GetCwdAllocError![]u8 { | |
| 85 | // The use of max_path_bytes here is just a heuristic: most paths will fit | |
| 86 | // in stack_buf, avoiding an extra allocation in the common case. | |
| 87 | var stack_buf: [max_path_bytes]u8 = undefined; | |
| 88 | var heap_buf: ?[]u8 = null; | |
| 89 | defer if (heap_buf) |buf| allocator.free(buf); | |
| 90 | ||
| 91 | var current_buf: []u8 = &stack_buf; | |
| 92 | while (true) { | |
| 93 | if (posix.getcwd(current_buf)) |slice| { | |
| 94 | return allocator.dupe(u8, slice); | |
| 95 | } else |err| switch (err) { | |
| 96 | error.NameTooLong => { | |
| 97 | // The path is too long to fit in stack_buf. Allocate geometrically | |
| 98 | // increasing buffers until we find one that works | |
| 99 | const new_capacity = current_buf.len * 2; | |
| 100 | if (heap_buf) |buf| allocator.free(buf); | |
| 101 | current_buf = try allocator.alloc(u8, new_capacity); | |
| 102 | heap_buf = current_buf; | |
| 103 | }, | |
| 104 | else => |e| return e, | |
| 105 | } | |
| 106 | } | |
| 85 | /// On other platforms, the result is an opaque sequence of bytes with no | |
| 86 | /// particular encoding. | |
| 87 | /// | |
| 88 | /// Caller owns returned memory. | |
| 89 | pub fn currentDirAlloc(io: Io, allocator: Allocator) CurrentDirAllocError![:0]u8 { | |
| 90 | var buffer: [max_path_bytes]u8 = undefined; | |
| 91 | const n = currentDir(io, &buffer) catch |err| switch (err) { | |
| 92 | error.NameTooLong => unreachable, | |
| 93 | else => |e| return e, | |
| 94 | }; | |
| 95 | return allocator.dupeZ(u8, buffer[0..n]); | |
| 107 | 96 | } |
| 108 | 97 | |
| 109 | test getCwdAlloc { | |
| 110 | if (native_os == .wasi) return error.SkipZigTest; | |
| 111 | ||
| 112 | const cwd = try getCwdAlloc(testing.allocator); | |
| 98 | test currentDirAlloc { | |
| 99 | const cwd = try currentDirAlloc(testing.io, testing.allocator); | |
| 113 | 100 | testing.allocator.free(cwd); |
| 114 | 101 | } |
| 115 | 102 | |
| ... | ... | @@ -466,7 +453,7 @@ pub fn spawnPath(io: Io, dir: Io.Dir, options: SpawnOptions) SpawnError!Child { |
| 466 | 453 | return io.vtable.processSpawnPath(io.userdata, dir, options); |
| 467 | 454 | } |
| 468 | 455 | |
| 469 | pub const RunError = posix.GetCwdError || posix.ReadError || SpawnError || posix.PollError || error{ | |
| 456 | pub const RunError = CurrentDirError || posix.ReadError || SpawnError || posix.PollError || error{ | |
| 470 | 457 | StdoutStreamTooLong, |
| 471 | 458 | StderrStreamTooLong, |
| 472 | 459 | }; |
src/Compilation.zig+1-1| ... | ... | @@ -767,7 +767,7 @@ pub const Directories = struct { |
| 767 | 767 | ) Directories { |
| 768 | 768 | const wasi = builtin.target.os.tag == .wasi; |
| 769 | 769 | |
| 770 | const cwd = introspect.getResolvedCwd(arena) catch |err| { | |
| 770 | const cwd = introspect.getResolvedCwd(io, arena) catch |err| { | |
| 771 | 771 | fatal("unable to get cwd: {t}", .{err}); |
| 772 | 772 | }; |
| 773 | 773 |
src/introspect.zig+5-5| ... | ... | @@ -43,7 +43,7 @@ fn testZigInstallPrefix(io: Io, base_dir: Io.Dir) ?Cache.Directory { |
| 43 | 43 | |
| 44 | 44 | /// Both the directory handle and the path are newly allocated resources which the caller now owns. |
| 45 | 45 | pub fn findZigLibDir(gpa: Allocator, io: Io) !Cache.Directory { |
| 46 | const cwd_path = try getResolvedCwd(gpa); | |
| 46 | const cwd_path = try getResolvedCwd(io, gpa); | |
| 47 | 47 | defer gpa.free(cwd_path); |
| 48 | 48 | const self_exe_path = try std.process.executablePathAlloc(io, gpa); |
| 49 | 49 | defer gpa.free(self_exe_path); |
| ... | ... | @@ -51,23 +51,23 @@ pub fn findZigLibDir(gpa: Allocator, io: Io) !Cache.Directory { |
| 51 | 51 | return findZigLibDirFromSelfExe(gpa, io, cwd_path, self_exe_path); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | /// Like `std.process.getCwdAlloc`, but also resolves the path with `Dir.path.resolve`. This | |
| 54 | /// Like `std.process.currentDirAlloc`, but also resolves the path with `Dir.path.resolve`. This | |
| 55 | 55 | /// means the path has no repeated separators, no "." or ".." components, and no trailing separator. |
| 56 | 56 | /// On WASI, "" is returned instead of ".". |
| 57 | pub fn getResolvedCwd(gpa: Allocator) error{ | |
| 57 | pub fn getResolvedCwd(io: Io, gpa: Allocator) error{ | |
| 58 | 58 | OutOfMemory, |
| 59 | 59 | CurrentWorkingDirectoryUnlinked, |
| 60 | 60 | Unexpected, |
| 61 | 61 | }![]u8 { |
| 62 | 62 | if (builtin.target.os.tag == .wasi) { |
| 63 | 63 | if (std.debug.runtime_safety) { |
| 64 | const cwd = try std.process.getCwdAlloc(gpa); | |
| 64 | const cwd = try std.process.currentDirAlloc(io, gpa); | |
| 65 | 65 | defer gpa.free(cwd); |
| 66 | 66 | assert(mem.eql(u8, cwd, ".")); |
| 67 | 67 | } |
| 68 | 68 | return ""; |
| 69 | 69 | } |
| 70 | const cwd = try std.process.getCwdAlloc(gpa); | |
| 70 | const cwd = try std.process.currentDirAlloc(io, gpa); | |
| 71 | 71 | defer gpa.free(cwd); |
| 72 | 72 | const resolved = try Dir.path.resolve(gpa, &.{cwd}); |
| 73 | 73 | assert(Dir.path.isAbsolute(resolved)); |
src/main.zig+5-5| ... | ... | @@ -4775,7 +4775,7 @@ fn cmdInit(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) ! |
| 4775 | 4775 | } |
| 4776 | 4776 | } |
| 4777 | 4777 | |
| 4778 | const cwd_path = try introspect.getResolvedCwd(arena); | |
| 4778 | const cwd_path = try introspect.getResolvedCwd(io, arena); | |
| 4779 | 4779 | const cwd_basename = fs.path.basename(cwd_path); |
| 4780 | 4780 | const sanitized_root_name = try sanitizeExampleName(arena, cwd_basename); |
| 4781 | 4781 | |
| ... | ... | @@ -5141,7 +5141,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8, |
| 5141 | 5141 | |
| 5142 | 5142 | process.raiseFileDescriptorLimit(); |
| 5143 | 5143 | |
| 5144 | const cwd_path = try introspect.getResolvedCwd(arena); | |
| 5144 | const cwd_path = try introspect.getResolvedCwd(io, arena); | |
| 5145 | 5145 | const build_root = try findBuildRoot(arena, io, .{ |
| 5146 | 5146 | .cwd_path = cwd_path, |
| 5147 | 5147 | .build_file = build_file, |
| ... | ... | @@ -7077,7 +7077,7 @@ fn cmdFetch( |
| 7077 | 7077 | }, |
| 7078 | 7078 | }; |
| 7079 | 7079 | |
| 7080 | const cwd_path = try introspect.getResolvedCwd(arena); | |
| 7080 | const cwd_path = try introspect.getResolvedCwd(io, arena); | |
| 7081 | 7081 | |
| 7082 | 7082 | var build_root = try findBuildRoot(arena, io, .{ |
| 7083 | 7083 | .cwd_path = cwd_path, |
| ... | ... | @@ -7288,7 +7288,7 @@ const FindBuildRootOptions = struct { |
| 7288 | 7288 | }; |
| 7289 | 7289 | |
| 7290 | 7290 | fn findBuildRoot(arena: Allocator, io: Io, options: FindBuildRootOptions) !BuildRoot { |
| 7291 | const cwd_path = options.cwd_path orelse try introspect.getResolvedCwd(arena); | |
| 7291 | const cwd_path = options.cwd_path orelse try introspect.getResolvedCwd(io, arena); | |
| 7292 | 7292 | const build_zig_basename = if (options.build_file) |bf| |
| 7293 | 7293 | fs.path.basename(bf) |
| 7294 | 7294 | else |
| ... | ... | @@ -7490,7 +7490,7 @@ fn writeSimpleTemplateFile(io: Io, file_name: []const u8, comptime fmt: []const |
| 7490 | 7490 | } |
| 7491 | 7491 | |
| 7492 | 7492 | fn findTemplates(gpa: Allocator, arena: Allocator, io: Io) Templates { |
| 7493 | const cwd_path = introspect.getResolvedCwd(arena) catch |err| { | |
| 7493 | const cwd_path = introspect.getResolvedCwd(io, arena) catch |err| { | |
| 7494 | 7494 | fatal("unable to get cwd: {t}", .{err}); |
| 7495 | 7495 | }; |
| 7496 | 7496 | const self_exe_path = process.executablePathAlloc(io, arena) catch |err| { |
test/standalone/child_process/main.zig+8-8| ... | ... | @@ -9,7 +9,14 @@ pub fn main(init: std.process.Init.Minimal) !void { |
| 9 | 9 | }; |
| 10 | 10 | const gpa = gpa_state.allocator(); |
| 11 | 11 | |
| 12 | const process_cwd_path = try std.process.getCwdAlloc(gpa); | |
| 12 | var threaded: Io.Threaded = .init(gpa, .{ | |
| 13 | .argv0 = .init(init.args), | |
| 14 | .environ = init.environ, | |
| 15 | }); | |
| 16 | defer threaded.deinit(); | |
| 17 | const io = threaded.io(); | |
| 18 | ||
| 19 | const process_cwd_path = try std.process.currentDirAlloc(io, gpa); | |
| 13 | 20 | defer gpa.free(process_cwd_path); |
| 14 | 21 | |
| 15 | 22 | var environ_map = try init.environ.createMap(gpa); |
| ... | ... | @@ -27,13 +34,6 @@ pub fn main(init: std.process.Init.Minimal) !void { |
| 27 | 34 | }; |
| 28 | 35 | defer if (needs_free) gpa.free(child_path); |
| 29 | 36 | |
| 30 | var threaded: Io.Threaded = .init(gpa, .{ | |
| 31 | .argv0 = .init(init.args), | |
| 32 | .environ = init.environ, | |
| 33 | }); | |
| 34 | defer threaded.deinit(); | |
| 35 | const io = threaded.io(); | |
| 36 | ||
| 37 | 37 | var child = try std.process.spawn(io, .{ |
| 38 | 38 | .argv = &.{ child_path, "hello arg" }, |
| 39 | 39 | .stdin = .pipe, |
test/standalone/posix/cwd.zig+14-13| ... | ... | @@ -13,43 +13,44 @@ pub fn main(init: std.process.Init) !void { |
| 13 | 13 | .windows => return, // POSIX is not implemented by Windows |
| 14 | 14 | else => {}, |
| 15 | 15 | } |
| 16 | const io = init.io; | |
| 16 | 17 | const args = try init.minimal.args.toSlice(init.arena.allocator()); |
| 17 | 18 | const tmp_dir_path = args[1]; |
| 18 | 19 | |
| 19 | 20 | var tmp_dir = try Io.Dir.cwd().openDir(init.io, tmp_dir_path, .{}); |
| 20 | 21 | defer tmp_dir.close(init.io); |
| 21 | 22 | |
| 22 | try test_chdir_self(); | |
| 23 | try test_chdir_absolute(); | |
| 24 | try test_chdir_relative(init.gpa, init.io, tmp_dir); | |
| 23 | try test_chdir_self(io); | |
| 24 | try test_chdir_absolute(io); | |
| 25 | try test_chdir_relative(init.gpa, io, tmp_dir); | |
| 25 | 26 | } |
| 26 | 27 | |
| 27 | 28 | // get current working directory and expect it to match given path |
| 28 | fn expect_cwd(expected_cwd: []const u8) !void { | |
| 29 | fn expect_cwd(io: Io, expected_cwd: []const u8) !void { | |
| 29 | 30 | var cwd_buf: [path_max]u8 = undefined; |
| 30 | const actual_cwd = try std.posix.getcwd(cwd_buf[0..]); | |
| 31 | const actual_cwd = cwd_buf[0..try std.process.currentDir(io, &cwd_buf)]; | |
| 31 | 32 | try std.testing.expectEqualStrings(actual_cwd, expected_cwd); |
| 32 | 33 | } |
| 33 | 34 | |
| 34 | fn test_chdir_self() !void { | |
| 35 | fn test_chdir_self(io: Io) !void { | |
| 35 | 36 | var old_cwd_buf: [path_max]u8 = undefined; |
| 36 | const old_cwd = try std.posix.getcwd(old_cwd_buf[0..]); | |
| 37 | const old_cwd = old_cwd_buf[0..try std.process.currentDir(io, &old_cwd_buf)]; | |
| 37 | 38 | |
| 38 | 39 | // Try changing to the current directory |
| 39 | 40 | try std.Io.Threaded.chdir(old_cwd); |
| 40 | try expect_cwd(old_cwd); | |
| 41 | try expect_cwd(io, old_cwd); | |
| 41 | 42 | } |
| 42 | 43 | |
| 43 | fn test_chdir_absolute() !void { | |
| 44 | fn test_chdir_absolute(io: Io) !void { | |
| 44 | 45 | var old_cwd_buf: [path_max]u8 = undefined; |
| 45 | const old_cwd = try std.posix.getcwd(old_cwd_buf[0..]); | |
| 46 | const old_cwd = old_cwd_buf[0..try std.process.currentDir(io, &old_cwd_buf)]; | |
| 46 | 47 | |
| 47 | 48 | const parent = std.fs.path.dirname(old_cwd) orelse unreachable; // old_cwd should be absolute |
| 48 | 49 | |
| 49 | 50 | // Try changing to the parent via a full path |
| 50 | 51 | try std.Io.Threaded.chdir(parent); |
| 51 | 52 | |
| 52 | try expect_cwd(parent); | |
| 53 | try expect_cwd(io, parent); | |
| 53 | 54 | } |
| 54 | 55 | |
| 55 | 56 | fn test_chdir_relative(gpa: Allocator, io: Io, tmp_dir: Io.Dir) !void { |
| ... | ... | @@ -61,7 +62,7 @@ fn test_chdir_relative(gpa: Allocator, io: Io, tmp_dir: Io.Dir) !void { |
| 61 | 62 | |
| 62 | 63 | // Capture base working directory path, to build expected full path |
| 63 | 64 | var base_cwd_buf: [path_max]u8 = undefined; |
| 64 | const base_cwd = try std.posix.getcwd(base_cwd_buf[0..]); | |
| 65 | const base_cwd = base_cwd_buf[0..try std.process.currentDir(io, &base_cwd_buf)]; | |
| 65 | 66 | |
| 66 | 67 | const expected_path = try std.fs.path.resolve(gpa, &.{ base_cwd, subdir_path }); |
| 67 | 68 | defer gpa.free(expected_path); |
| ... | ... | @@ -70,7 +71,7 @@ fn test_chdir_relative(gpa: Allocator, io: Io, tmp_dir: Io.Dir) !void { |
| 70 | 71 | try std.Io.Threaded.chdir(subdir_path); |
| 71 | 72 | |
| 72 | 73 | var new_cwd_buf: [path_max]u8 = undefined; |
| 73 | const new_cwd = try std.posix.getcwd(new_cwd_buf[0..]); | |
| 74 | const new_cwd = new_cwd_buf[0..try std.process.currentDir(io, &new_cwd_buf)]; | |
| 74 | 75 | |
| 75 | 76 | // On Windows, fs.path.resolve returns an uppercase drive letter, but the drive letter returned by getcwd may be lowercase |
| 76 | 77 | const resolved_cwd = try std.fs.path.resolve(gpa, &.{new_cwd}); |
test/standalone/self_exe_symlink/create-symlink.zig+1-1| ... | ... | @@ -9,7 +9,7 @@ pub fn main(init: std.process.Init) !void { |
| 9 | 9 | const exe_path = it.next() orelse unreachable; |
| 10 | 10 | const symlink_path = it.next() orelse unreachable; |
| 11 | 11 | |
| 12 | const cwd = try std.process.getCwdAlloc(init.arena.allocator()); | |
| 12 | const cwd = try std.process.currentDirAlloc(io, init.arena.allocator()); | |
| 13 | 13 | |
| 14 | 14 | // If `exe_path` is relative to our cwd, we need to convert it to be relative to the dirname of `symlink_path`. |
| 15 | 15 | const exe_rel_path = try std.fs.path.relative(gpa, cwd, init.environ_map, std.fs.path.dirname(symlink_path) orelse ".", exe_path); |
test/standalone/windows_paths/relative.zig+1-1| ... | ... | @@ -4,7 +4,7 @@ pub fn main(init: std.process.Init) !void { |
| 4 | 4 | const arena = init.arena.allocator(); |
| 5 | 5 | const args = try init.minimal.args.toSlice(arena); |
| 6 | 6 | const io = init.io; |
| 7 | const cwd_path = try std.process.getCwdAlloc(arena); | |
| 7 | const cwd_path = try std.process.currentDirAlloc(io, arena); | |
| 8 | 8 | |
| 9 | 9 | if (args.len < 3) return error.MissingArgs; |
| 10 | 10 |
test/standalone/windows_paths/test.zig+1-1| ... | ... | @@ -10,7 +10,7 @@ pub fn main(init: std.process.Init) !void { |
| 10 | 10 | |
| 11 | 11 | const exe_path = args[1]; |
| 12 | 12 | |
| 13 | const cwd_path = try std.process.getCwdAlloc(arena); | |
| 13 | const cwd_path = try std.process.currentDirAlloc(io, arena); | |
| 14 | 14 | const parsed_cwd_path = std.fs.path.parsePathWindows(u8, cwd_path); |
| 15 | 15 | |
| 16 | 16 | if (parsed_cwd_path.kind == .drive_absolute and !std.ascii.isAlphabetic(cwd_path[0])) { |
test/standalone/windows_spawn/main.zig+1-1| ... | ... | @@ -8,7 +8,7 @@ const utf16Literal = std.unicode.utf8ToUtf16LeStringLiteral; |
| 8 | 8 | pub fn main(init: std.process.Init) !void { |
| 9 | 9 | const gpa = init.gpa; |
| 10 | 10 | const io = init.io; |
| 11 | const process_cwd_path = try std.process.getCwdAlloc(init.arena.allocator()); | |
| 11 | const process_cwd_path = try std.process.currentDirAlloc(io, init.arena.allocator()); | |
| 12 | 12 | var initial_process_cwd = try Io.Dir.cwd().openDir(io, ".", .{}); |
| 13 | 13 | defer initial_process_cwd.close(io); |
| 14 | 14 |
tools/doctest.zig+1-1| ... | ... | @@ -33,7 +33,7 @@ pub fn main(init: std.process.Init) !void { |
| 33 | 33 | const arena = init.arena.allocator(); |
| 34 | 34 | const io = init.io; |
| 35 | 35 | const environ_map = init.environ_map; |
| 36 | const cwd_path = try std.process.getCwdAlloc(arena); | |
| 36 | const cwd_path = try std.process.currentDirAlloc(io, arena); | |
| 37 | 37 | |
| 38 | 38 | try environ_map.put("CLICOLOR_FORCE", "1"); |
| 39 | 39 |
tools/incr-check.zig+1-1| ... | ... | @@ -32,7 +32,7 @@ pub fn main(init: std.process.Init) !void { |
| 32 | 32 | const arena = init.arena.allocator(); |
| 33 | 33 | const io = init.io; |
| 34 | 34 | const environ_map = init.environ_map; |
| 35 | const cwd_path = try std.process.getCwdAlloc(arena); | |
| 35 | const cwd_path = try std.process.currentDirAlloc(io, arena); | |
| 36 | 36 | |
| 37 | 37 | var opt_zig_exe: ?[]const u8 = null; |
| 38 | 38 | var opt_input_file_name: ?[]const u8 = null; |
tools/process_headers.zig+1-1| ... | ... | @@ -145,7 +145,7 @@ pub fn main(init: std.process.Init) !void { |
| 145 | 145 | const arena = init.arena.allocator(); |
| 146 | 146 | const io = init.io; |
| 147 | 147 | const args = try init.minimal.args.toSlice(arena); |
| 148 | const cwd_path = try std.process.getCwdAlloc(arena); | |
| 148 | const cwd_path = try std.process.currentDirAlloc(io, arena); | |
| 149 | 149 | const environ_map = init.environ_map; |
| 150 | 150 | |
| 151 | 151 | var search_paths = std.array_list.Managed([]const u8).init(arena); |
tools/update-linux-headers.zig+1-1| ... | ... | @@ -146,7 +146,7 @@ pub fn main(init: std.process.Init) !void { |
| 146 | 146 | const io = init.io; |
| 147 | 147 | const args = try init.minimal.args.toSlice(arena); |
| 148 | 148 | const environ_map = init.environ_map; |
| 149 | const cwd = try std.process.getCwdAlloc(arena); | |
| 149 | const cwd = try std.process.currentDirAlloc(io, arena); | |
| 150 | 150 | |
| 151 | 151 | var search_paths = std.array_list.Managed([]const u8).init(arena); |
| 152 | 152 | var opt_out_dir: ?[]const u8 = null; |