From 7594bbd621508d4b950b65e277682a021fca1d00 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 5 Nov 2023 15:27:46 -0800 Subject: [PATCH] shuffle some source around --- src/Command.zig | 28 ++++++++++++++++------------ src/Pty.zig | 3 +-- src/os/main.zig | 1 + src/{ => os}/windows.zig | 0 src/termio/Exec.zig | 4 ++-- 5 files changed, 20 insertions(+), 16 deletions(-) rename src/{ => os}/windows.zig (100%) diff --git a/src/Command.zig b/src/Command.zig index de284040e..5c9a6d590 100644 --- a/src/Command.zig +++ b/src/Command.zig @@ -14,16 +14,12 @@ //! * posix_spawn is used for Mac, but doesn't support the necessary //! features for tty setup. //! -//! TODO: -//! -//! * Mac -//! const Command = @This(); const std = @import("std"); const builtin = @import("builtin"); const internal_os = @import("os/main.zig"); -const windows = @import("windows.zig"); +const windows = internal_os.windows; const TempDir = internal_os.TempDir; const mem = std.mem; const os = std.os; @@ -297,15 +293,19 @@ fn setupFd(src: File.Handle, target: i32) !void { /// Wait for the command to exit and return information about how it exited. pub fn wait(self: Command, block: bool) !Exit { - if (builtin.os.tag == .windows) { - - // Block until the process exits. This returns immediately if the process already exited. + if (comptime builtin.os.tag == .windows) { + // Block until the process exits. This returns immediately if the + // process already exited. const result = windows.kernel32.WaitForSingleObject(self.pid.?, windows.INFINITE); - if (result == windows.WAIT_FAILED) return windows.unexpectedError(windows.kernel32.GetLastError()); + if (result == windows.WAIT_FAILED) { + return windows.unexpectedError(windows.kernel32.GetLastError()); + } var exit_code: windows.DWORD = undefined; var has_code = windows.kernel32.GetExitCodeProcess(self.pid.?, &exit_code) != 0; - if (!has_code) return windows.unexpectedError(windows.kernel32.GetLastError()); + if (!has_code) { + return windows.unexpectedError(windows.kernel32.GetLastError()); + } return .{ .Exited = exit_code }; } @@ -444,7 +444,7 @@ fn createNullDelimitedEnvMap(arena: mem.Allocator, env_map: *const EnvMap) ![:nu // Copied from Zig. This is a publicly exported function but there is no // way to get it from the std package. -pub fn createWindowsEnvBlock(allocator: mem.Allocator, env_map: *const EnvMap) ![]u16 { +fn createWindowsEnvBlock(allocator: mem.Allocator, env_map: *const EnvMap) ![]u16 { // count bytes needed const max_chars_needed = x: { var max_chars_needed: usize = 4; // 4 for the final 4 null bytes @@ -571,7 +571,11 @@ test "Command: pre exec" { fn createTestStdout(dir: std.fs.Dir) !File { const file = try dir.createFile("stdout.txt", .{ .read = true }); if (builtin.os.tag == .windows) { - try windows.SetHandleInformation(file.handle, windows.HANDLE_FLAG_INHERIT, windows.HANDLE_FLAG_INHERIT); + try windows.SetHandleInformation( + file.handle, + windows.HANDLE_FLAG_INHERIT, + windows.HANDLE_FLAG_INHERIT, + ); } return file; diff --git a/src/Pty.zig b/src/Pty.zig index 90108a4a7..7e8c0bf7c 100644 --- a/src/Pty.zig +++ b/src/Pty.zig @@ -1,6 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); -const windows = @import("windows.zig"); +const windows = @import("os/main.zig").windows; const fd_t = std.os.fd_t; const c = switch (builtin.os.tag) { @@ -37,7 +37,6 @@ else /// of Linux syscalls. The caller is responsible for detail-oriented handling /// of the returned file handles. pub const PosixPty = struct { - // https://github.com/ziglang/zig/issues/13277 // Once above is fixed, use `c.TIOCSCTTY` const TIOCSCTTY = if (builtin.os.tag == .macos) 536900705 else c.TIOCSCTTY; diff --git a/src/os/main.zig b/src/os/main.zig index 9b9b2d549..b2d073f55 100644 --- a/src/os/main.zig +++ b/src/os/main.zig @@ -13,3 +13,4 @@ pub usingnamespace @import("resourcesdir.zig"); pub const TempDir = @import("TempDir.zig"); pub const passwd = @import("passwd.zig"); pub const xdg = @import("xdg.zig"); +pub const windows = @import("windows.zig"); diff --git a/src/windows.zig b/src/os/windows.zig similarity index 100% rename from src/windows.zig rename to src/os/windows.zig diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 1e4e2ed63..2dba63fd6 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -10,7 +10,7 @@ const ArenaAllocator = std.heap.ArenaAllocator; const EnvMap = std.process.EnvMap; const termio = @import("../termio.zig"); const Command = @import("../Command.zig"); -const Pty = @import("../Pty.zig").Pty; +const Pty = @import("../pty.zig").Pty; const SegmentedPool = @import("../segmented_pool.zig").SegmentedPool; const terminal = @import("../terminal/main.zig"); const terminfo = @import("../terminfo/main.zig"); @@ -21,9 +21,9 @@ const trace = tracy.trace; const apprt = @import("../apprt.zig"); const fastmem = @import("../fastmem.zig"); const internal_os = @import("../os/main.zig"); +const windows = internal_os.windows; const configpkg = @import("../config.zig"); const shell_integration = @import("shell_integration.zig"); -const windows = @import("../windows.zig"); const log = std.log.scoped(.io_exec);