diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-10-24 16:29:02 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-10-24 16:29:02 -0700 |
| commit | 8819d8b06162da81a6c3b6b3f0ca708fb9acee28 (patch) | |
| tree | 8ded07919b0e0bfdb20aeec4c788238f0cac75ec /lib | |
| parent | 7a46ba73ceb9d5356ac0e1e0afc869b7abfa490c (diff) | |
| download | zig-8819d8b06162da81a6c3b6b3f0ca708fb9acee28.tar.gz zig-8819d8b06162da81a6c3b6b3f0ca708fb9acee28.zip | |
std.Build.Watch: limit to one switch on os tag
DRY
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/std/Build/Watch.zig | 123 |
1 files changed, 61 insertions, 62 deletions
diff --git a/lib/std/Build/Watch.zig b/lib/std/Build/Watch.zig index 95ba940480..8471512964 100644 --- a/lib/std/Build/Watch.zig +++ b/lib/std/Build/Watch.zig @@ -91,6 +91,38 @@ const Os = switch (builtin.os.tag) { }; }; + fn init() !Watch { + const fan_fd = std.posix.fanotify_init(.{ + .CLASS = .NOTIF, + .CLOEXEC = true, + .NONBLOCK = true, + .REPORT_NAME = true, + .REPORT_DIR_FID = true, + .REPORT_FID = true, + .REPORT_TARGET_FID = true, + }, 0) catch |err| switch (err) { + error.UnsupportedFlags => fatal("fanotify_init failed due to old kernel; requires 5.17+", .{}), + else => |e| return e, + }; + return .{ + .dir_table = .{}, + .os = switch (builtin.os.tag) { + .linux => .{ + .handle_table = .{}, + .poll_fds = .{ + .{ + .fd = fan_fd, + .events = std.posix.POLL.IN, + .revents = undefined, + }, + }, + }, + else => {}, + }, + .generation = 0, + }; + } + fn getDirHandle(gpa: Allocator, path: std.Build.Cache.Path) !FileHandle { var file_handle_buffer: [@sizeOf(std.os.linux.file_handle) + 128]u8 align(@alignOf(std.os.linux.file_handle)) = undefined; var mount_id: i32 = undefined; @@ -368,6 +400,21 @@ const Os = switch (builtin.os.tag) { } }; + fn init() !Watch { + return .{ + .dir_table = .{}, + .os = switch (builtin.os.tag) { + .windows => .{ + .handle_table = .{}, + .dir_list = .{}, + .io_cp = null, + }, + else => {}, + }, + .generation = 0, + }; + } + fn getFileId(handle: windows.HANDLE) !FileId { var file_id: FileId = undefined; var io_status: windows.IO_STATUS_BLOCK = undefined; @@ -572,6 +619,19 @@ const Os = switch (builtin.os.tag) { break :f f; }; + fn init() !Watch { + const kq_fd = try posix.kqueue(); + errdefer posix.close(kq_fd); + return .{ + .dir_table = .{}, + .os = .{ + .kq_fd = kq_fd, + .reaction_sets = .{}, + }, + .generation = 0, + }; + } + fn update(w: *Watch, gpa: Allocator, steps: []const *Step) !void { for (steps) |step| { for (step.inputs.table.keys(), step.inputs.table.values()) |path, *files| { @@ -702,68 +762,7 @@ const Os = switch (builtin.os.tag) { }; pub fn init() !Watch { - switch (builtin.os.tag) { - .linux => { - const fan_fd = std.posix.fanotify_init(.{ - .CLASS = .NOTIF, - .CLOEXEC = true, - .NONBLOCK = true, - .REPORT_NAME = true, - .REPORT_DIR_FID = true, - .REPORT_FID = true, - .REPORT_TARGET_FID = true, - }, 0) catch |err| switch (err) { - error.UnsupportedFlags => fatal("fanotify_init failed due to old kernel; requires 5.17+", .{}), - else => |e| return e, - }; - return .{ - .dir_table = .{}, - .os = switch (builtin.os.tag) { - .linux => .{ - .handle_table = .{}, - .poll_fds = .{ - .{ - .fd = fan_fd, - .events = std.posix.POLL.IN, - .revents = undefined, - }, - }, - }, - else => {}, - }, - .generation = 0, - }; - }, - .windows => { - return .{ - .dir_table = .{}, - .os = switch (builtin.os.tag) { - .windows => .{ - .handle_table = .{}, - .dir_list = .{}, - .io_cp = null, - }, - else => {}, - }, - .generation = 0, - }; - }, - .dragonfly, .freebsd, .netbsd, .openbsd, .ios, .macos, .tvos, .visionos, .watchos => { - const posix = std.posix; - - const kq_fd = try posix.kqueue(); - errdefer posix.close(kq_fd); - return .{ - .dir_table = .{}, - .os = .{ - .kq_fd = kq_fd, - .reaction_sets = .{}, - }, - .generation = 0, - }; - }, - else => @panic("unimplemented"), - } + return Os.init(); } pub const Match = struct { |
