| author | |
| committer | |
| log | 50c585227ed2a57a4c1cf3f3b44914881999559d |
| tree | 1abd9e3bda5967c994e69397582cce0dd1b2d5cc |
| parent | 7d955274bb40bc937275b3d59c6304dd44c85d40 |
15 files changed, 262 insertions(+), 213 deletions(-)
tools/docgen.zig+3-3| ... | ... | @@ -73,15 +73,15 @@ pub fn main() !void { |
| 73 | 73 | const code_dir_path = opt_code_dir orelse fatal("missing --code-dir argument", .{}); |
| 74 | 74 | |
| 75 | 75 | var in_file = try fs.cwd().openFile(input_path, .{}); |
| 76 | defer in_file.close(); | |
| 76 | defer in_file.close(io); | |
| 77 | 77 | |
| 78 | 78 | var out_file = try fs.cwd().createFile(output_path, .{}); |
| 79 | defer out_file.close(); | |
| 79 | defer out_file.close(io); | |
| 80 | 80 | var out_file_buffer: [4096]u8 = undefined; |
| 81 | 81 | var out_file_writer = out_file.writer(&out_file_buffer); |
| 82 | 82 | |
| 83 | 83 | var code_dir = try fs.cwd().openDir(code_dir_path, .{}); |
| 84 | defer code_dir.close(); | |
| 84 | defer code_dir.close(io); | |
| 85 | 85 | |
| 86 | 86 | var in_file_reader = in_file.reader(io, &.{}); |
| 87 | 87 | const input_file_bytes = try in_file_reader.interface.allocRemaining(arena, .limited(max_doc_file_size)); |
tools/doctest.zig+7-7| ... | ... | @@ -85,16 +85,16 @@ pub fn main() !void { |
| 85 | 85 | const tmp_dir_path = try std.fmt.allocPrint(arena, "{s}/tmp/{x}", .{ |
| 86 | 86 | cache_root, std.crypto.random.int(u64), |
| 87 | 87 | }); |
| 88 | fs.cwd().makePath(tmp_dir_path) catch |err| | |
| 89 | fatal("unable to create tmp dir '{s}': {s}", .{ tmp_dir_path, @errorName(err) }); | |
| 90 | defer fs.cwd().deleteTree(tmp_dir_path) catch |err| std.log.err("unable to delete '{s}': {s}", .{ | |
| 91 | tmp_dir_path, @errorName(err), | |
| 88 | fs.cwd().createDirPath(io, tmp_dir_path) catch |err| | |
| 89 | fatal("unable to create tmp dir '{s}': {t}", .{ tmp_dir_path, err }); | |
| 90 | defer fs.cwd().deleteTree(io, tmp_dir_path) catch |err| std.log.err("unable to delete '{s}': {t}", .{ | |
| 91 | tmp_dir_path, err, | |
| 92 | 92 | }); |
| 93 | 93 | |
| 94 | var out_file = try fs.cwd().createFile(output_path, .{}); | |
| 95 | defer out_file.close(); | |
| 94 | var out_file = try fs.cwd().createFile(io, output_path, .{}); | |
| 95 | defer out_file.close(io); | |
| 96 | 96 | var out_file_buffer: [4096]u8 = undefined; |
| 97 | var out_file_writer = out_file.writer(&out_file_buffer); | |
| 97 | var out_file_writer = out_file.writer(io, &out_file_buffer); | |
| 98 | 98 | |
| 99 | 99 | const out = &out_file_writer.interface; |
| 100 | 100 |
tools/fetch_them_macos_headers.zig+21-21| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const Io = std.Io; |
| 3 | const fs = std.fs; | |
| 3 | const Dir = std.Io.Dir; | |
| 4 | 4 | const mem = std.mem; |
| 5 | 5 | const process = std.process; |
| 6 | 6 | const assert = std.debug.assert; |
| ... | ... | @@ -96,9 +96,9 @@ pub fn main() anyerror!void { |
| 96 | 96 | fatal("no SDK found; you can provide one explicitly with '--sysroot' flag", .{}); |
| 97 | 97 | }; |
| 98 | 98 | |
| 99 | var sdk_dir = try std.fs.cwd().openDir(sysroot_path, .{}); | |
| 100 | defer sdk_dir.close(); | |
| 101 | const sdk_info = try sdk_dir.readFileAlloc("SDKSettings.json", allocator, .limited(std.math.maxInt(u32))); | |
| 99 | var sdk_dir = try Dir.cwd().openDir(io, sysroot_path, .{}); | |
| 100 | defer sdk_dir.close(io); | |
| 101 | const sdk_info = try sdk_dir.readFileAlloc(io, "SDKSettings.json", allocator, .limited(std.math.maxInt(u32))); | |
| 102 | 102 | |
| 103 | 103 | const parsed_json = try std.json.parseFromSlice(struct { |
| 104 | 104 | DefaultProperties: struct { MACOSX_DEPLOYMENT_TARGET: []const u8 }, |
| ... | ... | @@ -135,8 +135,8 @@ fn fetchTarget( |
| 135 | 135 | const tmp_filename = "macos-headers"; |
| 136 | 136 | const headers_list_filename = "macos-headers.o.d"; |
| 137 | 137 | const tmp_path = try tmp.dir.realpathAlloc(arena, "."); |
| 138 | const tmp_file_path = try fs.path.join(arena, &[_][]const u8{ tmp_path, tmp_filename }); | |
| 139 | const headers_list_path = try fs.path.join(arena, &[_][]const u8{ tmp_path, headers_list_filename }); | |
| 138 | const tmp_file_path = try Dir.path.join(arena, &[_][]const u8{ tmp_path, tmp_filename }); | |
| 139 | const headers_list_path = try Dir.path.join(arena, &[_][]const u8{ tmp_path, headers_list_filename }); | |
| 140 | 140 | |
| 141 | 141 | const macos_version = try std.fmt.allocPrint(arena, "-mmacosx-version-min={d}.{d}", .{ |
| 142 | 142 | ver.major, |
| ... | ... | @@ -176,10 +176,10 @@ fn fetchTarget( |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | // Read in the contents of `macos-headers.o.d` |
| 179 | const headers_list_file = try tmp.dir.openFile(headers_list_filename, .{}); | |
| 180 | defer headers_list_file.close(); | |
| 179 | const headers_list_file = try tmp.dir.openFile(io, headers_list_filename, .{}); | |
| 180 | defer headers_list_file.close(io); | |
| 181 | 181 | |
| 182 | var headers_dir = fs.cwd().openDir(headers_source_prefix, .{}) catch |err| switch (err) { | |
| 182 | var headers_dir = Dir.cwd().openDir(headers_source_prefix, .{}) catch |err| switch (err) { | |
| 183 | 183 | error.FileNotFound, |
| 184 | 184 | error.NotDir, |
| 185 | 185 | => fatal("path '{s}' not found or not a directory. Did you accidentally delete it?", .{ |
| ... | ... | @@ -187,13 +187,13 @@ fn fetchTarget( |
| 187 | 187 | }), |
| 188 | 188 | else => return err, |
| 189 | 189 | }; |
| 190 | defer headers_dir.close(); | |
| 190 | defer headers_dir.close(io); | |
| 191 | 191 | |
| 192 | 192 | const dest_path = try target.fullName(arena); |
| 193 | try headers_dir.deleteTree(dest_path); | |
| 193 | try headers_dir.deleteTree(io, dest_path); | |
| 194 | 194 | |
| 195 | var dest_dir = try headers_dir.makeOpenPath(dest_path, .{}); | |
| 196 | var dirs = std.StringHashMap(fs.Dir).init(arena); | |
| 195 | var dest_dir = try headers_dir.createDirPathOpen(io, dest_path, .{}); | |
| 196 | var dirs = std.StringHashMap(Dir).init(arena); | |
| 197 | 197 | try dirs.putNoClobber(".", dest_dir); |
| 198 | 198 | |
| 199 | 199 | var headers_list_file_reader = headers_list_file.reader(io, &.{}); |
| ... | ... | @@ -206,25 +206,25 @@ fn fetchTarget( |
| 206 | 206 | if (mem.lastIndexOf(u8, line, prefix[0..])) |idx| { |
| 207 | 207 | const out_rel_path = line[idx + prefix.len + 1 ..]; |
| 208 | 208 | const out_rel_path_stripped = mem.trim(u8, out_rel_path, " \\"); |
| 209 | const dirname = fs.path.dirname(out_rel_path_stripped) orelse "."; | |
| 209 | const dirname = Dir.path.dirname(out_rel_path_stripped) orelse "."; | |
| 210 | 210 | const maybe_dir = try dirs.getOrPut(dirname); |
| 211 | 211 | if (!maybe_dir.found_existing) { |
| 212 | maybe_dir.value_ptr.* = try dest_dir.makeOpenPath(dirname, .{}); | |
| 212 | maybe_dir.value_ptr.* = try dest_dir.createDirPathOpen(io, dirname, .{}); | |
| 213 | 213 | } |
| 214 | const basename = fs.path.basename(out_rel_path_stripped); | |
| 214 | const basename = Dir.path.basename(out_rel_path_stripped); | |
| 215 | 215 | |
| 216 | 216 | const line_stripped = mem.trim(u8, line, " \\"); |
| 217 | const abs_dirname = fs.path.dirname(line_stripped).?; | |
| 218 | var orig_subdir = try fs.cwd().openDir(abs_dirname, .{}); | |
| 219 | defer orig_subdir.close(); | |
| 217 | const abs_dirname = Dir.path.dirname(line_stripped).?; | |
| 218 | var orig_subdir = try Dir.cwd().openDir(abs_dirname, .{}); | |
| 219 | defer orig_subdir.close(io); | |
| 220 | 220 | |
| 221 | 221 | try orig_subdir.copyFile(basename, maybe_dir.value_ptr.*, basename, .{}); |
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | var dir_it = dirs.iterator(); |
| 226 | while (dir_it.next()) |entry| { | |
| 227 | entry.value_ptr.close(); | |
| 226 | while (dir_it.next(io)) |entry| { | |
| 227 | entry.value_ptr.close(io); | |
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 |
tools/gen_macos_headers_c.zig+14-8| ... | ... | @@ -1,8 +1,9 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const Io = std.Io; | |
| 3 | const Dir = std.Io.Dir; | |
| 2 | 4 | const assert = std.debug.assert; |
| 3 | 5 | const info = std.log.info; |
| 4 | 6 | const fatal = std.process.fatal; |
| 5 | ||
| 6 | 7 | const Allocator = std.mem.Allocator; |
| 7 | 8 | |
| 8 | 9 | var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){}; |
| ... | ... | @@ -20,6 +21,10 @@ pub fn main() anyerror!void { |
| 20 | 21 | defer arena_allocator.deinit(); |
| 21 | 22 | const arena = arena_allocator.allocator(); |
| 22 | 23 | |
| 24 | var threaded: Io.Threaded = .init(gpa); | |
| 25 | defer threaded.deinit(); | |
| 26 | const io = threaded.io(); | |
| 27 | ||
| 23 | 28 | const args = try std.process.argsAlloc(arena); |
| 24 | 29 | if (args.len == 1) fatal("no command or option specified", .{}); |
| 25 | 30 | |
| ... | ... | @@ -33,10 +38,10 @@ pub fn main() anyerror!void { |
| 33 | 38 | |
| 34 | 39 | if (positionals.items.len != 1) fatal("expected one positional argument: [dir]", .{}); |
| 35 | 40 | |
| 36 | var dir = try std.fs.cwd().openDir(positionals.items[0], .{ .follow_symlinks = false }); | |
| 37 | defer dir.close(); | |
| 41 | var dir = try std.fs.cwd().openDir(io, positionals.items[0], .{ .follow_symlinks = false }); | |
| 42 | defer dir.close(io); | |
| 38 | 43 | var paths = std.array_list.Managed([]const u8).init(arena); |
| 39 | try findHeaders(arena, dir, "", &paths); | |
| 44 | try findHeaders(arena, io, dir, "", &paths); | |
| 40 | 45 | |
| 41 | 46 | const SortFn = struct { |
| 42 | 47 | pub fn lessThan(ctx: void, lhs: []const u8, rhs: []const u8) bool { |
| ... | ... | @@ -64,7 +69,8 @@ pub fn main() anyerror!void { |
| 64 | 69 | |
| 65 | 70 | fn findHeaders( |
| 66 | 71 | arena: Allocator, |
| 67 | dir: std.fs.Dir, | |
| 72 | io: Io, | |
| 73 | dir: Dir, | |
| 68 | 74 | prefix: []const u8, |
| 69 | 75 | paths: *std.array_list.Managed([]const u8), |
| 70 | 76 | ) anyerror!void { |
| ... | ... | @@ -73,9 +79,9 @@ fn findHeaders( |
| 73 | 79 | switch (entry.kind) { |
| 74 | 80 | .directory => { |
| 75 | 81 | const path = try std.fs.path.join(arena, &.{ prefix, entry.name }); |
| 76 | var subdir = try dir.openDir(entry.name, .{ .follow_symlinks = false }); | |
| 77 | defer subdir.close(); | |
| 78 | try findHeaders(arena, subdir, path, paths); | |
| 82 | var subdir = try dir.openDir(io, entry.name, .{ .follow_symlinks = false }); | |
| 83 | defer subdir.close(io); | |
| 84 | try findHeaders(arena, io, subdir, path, paths); | |
| 79 | 85 | }, |
| 80 | 86 | .file, .sym_link => { |
| 81 | 87 | const ext = std.fs.path.extension(entry.name); |
tools/generate_linux_syscalls.zig+7-3| ... | ... | @@ -175,6 +175,10 @@ pub fn main() !void { |
| 175 | 175 | defer arena.deinit(); |
| 176 | 176 | const gpa = arena.allocator(); |
| 177 | 177 | |
| 178 | var threaded: Io.Threaded = .init(gpa); | |
| 179 | defer threaded.deinit(); | |
| 180 | const io = threaded.io(); | |
| 181 | ||
| 178 | 182 | const args = try std.process.argsAlloc(gpa); |
| 179 | 183 | if (args.len < 2 or mem.eql(u8, args[1], "--help")) { |
| 180 | 184 | const w, _ = std.debug.lockStderrWriter(&.{}); |
| ... | ... | @@ -188,8 +192,8 @@ pub fn main() !void { |
| 188 | 192 | var stdout_writer = std.fs.File.stdout().writerStreaming(&stdout_buffer); |
| 189 | 193 | const stdout = &stdout_writer.interface; |
| 190 | 194 | |
| 191 | var linux_dir = try std.fs.cwd().openDir(linux_path, .{}); | |
| 192 | defer linux_dir.close(); | |
| 195 | var linux_dir = try std.fs.cwd().openDir(io, linux_path, .{}); | |
| 196 | defer linux_dir.close(io); | |
| 193 | 197 | |
| 194 | 198 | // As of 6.11, the largest table is 24195 bytes. |
| 195 | 199 | // 32k should be enough for now. |
| ... | ... | @@ -198,7 +202,7 @@ pub fn main() !void { |
| 198 | 202 | |
| 199 | 203 | // Fetch the kernel version from the Makefile variables. |
| 200 | 204 | const version = blk: { |
| 201 | const head = try linux_dir.readFile("Makefile", buf[0..128]); | |
| 205 | const head = try linux_dir.readFile(io, "Makefile", buf[0..128]); | |
| 202 | 206 | var lines = mem.tokenizeScalar(u8, head, '\n'); |
| 203 | 207 | _ = lines.next(); // Skip SPDX identifier |
| 204 | 208 |
tools/incr-check.zig+54-44| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const Io = std.Io; |
| 3 | const Dir = std.Io.Dir; | |
| 3 | 4 | const Allocator = std.mem.Allocator; |
| 4 | 5 | const Cache = std.Build.Cache; |
| 5 | 6 | |
| ... | ... | @@ -59,7 +60,7 @@ pub fn main() !void { |
| 59 | 60 | const zig_exe = opt_zig_exe orelse fatal("missing path to zig\n{s}", .{usage}); |
| 60 | 61 | const input_file_name = opt_input_file_name orelse fatal("missing input file\n{s}", .{usage}); |
| 61 | 62 | |
| 62 | const input_file_bytes = try std.fs.cwd().readFileAlloc(input_file_name, arena, .limited(std.math.maxInt(u32))); | |
| 63 | const input_file_bytes = try Dir.cwd().readFileAlloc(io, input_file_name, arena, .limited(std.math.maxInt(u32))); | |
| 63 | 64 | const case = try Case.parse(arena, io, input_file_bytes); |
| 64 | 65 | |
| 65 | 66 | // Check now: if there are any targets using the `cbe` backend, we need the lib dir. |
| ... | ... | @@ -71,25 +72,25 @@ pub fn main() !void { |
| 71 | 72 | } |
| 72 | 73 | } |
| 73 | 74 | |
| 74 | const prog_node = std.Progress.start(.{}); | |
| 75 | const prog_node = std.Progress.start(io, .{}); | |
| 75 | 76 | defer prog_node.end(); |
| 76 | 77 | |
| 77 | 78 | const rand_int = std.crypto.random.int(u64); |
| 78 | 79 | const tmp_dir_path = "tmp_" ++ std.fmt.hex(rand_int); |
| 79 | var tmp_dir = try std.fs.cwd().makeOpenPath(tmp_dir_path, .{}); | |
| 80 | var tmp_dir = try Dir.cwd().createDirPathOpen(io, tmp_dir_path, .{}); | |
| 80 | 81 | defer { |
| 81 | tmp_dir.close(); | |
| 82 | tmp_dir.close(io); | |
| 82 | 83 | if (!preserve_tmp) { |
| 83 | std.fs.cwd().deleteTree(tmp_dir_path) catch |err| { | |
| 84 | std.log.warn("failed to delete tree '{s}': {s}", .{ tmp_dir_path, @errorName(err) }); | |
| 84 | Dir.cwd().deleteTree(io, tmp_dir_path) catch |err| { | |
| 85 | std.log.warn("failed to delete tree '{s}': {t}", .{ tmp_dir_path, err }); | |
| 85 | 86 | }; |
| 86 | 87 | } |
| 87 | 88 | } |
| 88 | 89 | |
| 89 | 90 | // Convert paths to be relative to the cwd of the subprocess. |
| 90 | const resolved_zig_exe = try std.fs.path.relative(arena, tmp_dir_path, zig_exe); | |
| 91 | const resolved_zig_exe = try Dir.path.relative(arena, tmp_dir_path, zig_exe); | |
| 91 | 92 | const opt_resolved_lib_dir = if (opt_lib_dir) |lib_dir| |
| 92 | try std.fs.path.relative(arena, tmp_dir_path, lib_dir) | |
| 93 | try Dir.path.relative(arena, tmp_dir_path, lib_dir) | |
| 93 | 94 | else |
| 94 | 95 | null; |
| 95 | 96 | |
| ... | ... | @@ -164,7 +165,7 @@ pub fn main() !void { |
| 164 | 165 | var cc_child_args: std.ArrayList([]const u8) = .empty; |
| 165 | 166 | if (target.backend == .cbe) { |
| 166 | 167 | const resolved_cc_zig_exe = if (opt_cc_zig) |cc_zig_exe| |
| 167 | try std.fs.path.relative(arena, tmp_dir_path, cc_zig_exe) | |
| 168 | try Dir.path.relative(arena, tmp_dir_path, cc_zig_exe) | |
| 168 | 169 | else |
| 169 | 170 | resolved_zig_exe; |
| 170 | 171 | |
| ... | ... | @@ -185,6 +186,7 @@ pub fn main() !void { |
| 185 | 186 | |
| 186 | 187 | var eval: Eval = .{ |
| 187 | 188 | .arena = arena, |
| 189 | .io = io, | |
| 188 | 190 | .case = case, |
| 189 | 191 | .host = host, |
| 190 | 192 | .target = target, |
| ... | ... | @@ -196,9 +198,9 @@ pub fn main() !void { |
| 196 | 198 | .cc_child_args = &cc_child_args, |
| 197 | 199 | }; |
| 198 | 200 | |
| 199 | try child.spawn(); | |
| 201 | try child.spawn(io); | |
| 200 | 202 | errdefer { |
| 201 | _ = child.kill() catch {}; | |
| 203 | _ = child.kill(io) catch {}; | |
| 202 | 204 | } |
| 203 | 205 | |
| 204 | 206 | var poller = Io.poll(arena, Eval.StreamEnum, .{ |
| ... | ... | @@ -228,10 +230,11 @@ pub fn main() !void { |
| 228 | 230 | |
| 229 | 231 | const Eval = struct { |
| 230 | 232 | arena: Allocator, |
| 233 | io: Io, | |
| 231 | 234 | host: std.Target, |
| 232 | 235 | case: Case, |
| 233 | 236 | target: Case.Target, |
| 234 | tmp_dir: std.fs.Dir, | |
| 237 | tmp_dir: Dir, | |
| 235 | 238 | tmp_dir_path: []const u8, |
| 236 | 239 | child: *std.process.Child, |
| 237 | 240 | allow_stderr: bool, |
| ... | ... | @@ -245,17 +248,18 @@ const Eval = struct { |
| 245 | 248 | |
| 246 | 249 | /// Currently this function assumes the previous updates have already been written. |
| 247 | 250 | fn write(eval: *Eval, update: Case.Update) void { |
| 251 | const io = eval.io; | |
| 248 | 252 | for (update.changes) |full_contents| { |
| 249 | eval.tmp_dir.writeFile(.{ | |
| 253 | eval.tmp_dir.writeFile(io, .{ | |
| 250 | 254 | .sub_path = full_contents.name, |
| 251 | 255 | .data = full_contents.bytes, |
| 252 | 256 | }) catch |err| { |
| 253 | eval.fatal("failed to update '{s}': {s}", .{ full_contents.name, @errorName(err) }); | |
| 257 | eval.fatal("failed to update '{s}': {t}", .{ full_contents.name, err }); | |
| 254 | 258 | }; |
| 255 | 259 | } |
| 256 | 260 | for (update.deletes) |doomed_name| { |
| 257 | eval.tmp_dir.deleteFile(doomed_name) catch |err| { | |
| 258 | eval.fatal("failed to delete '{s}': {s}", .{ doomed_name, @errorName(err) }); | |
| 261 | eval.tmp_dir.deleteFile(io, doomed_name) catch |err| { | |
| 262 | eval.fatal("failed to delete '{s}': {t}", .{ doomed_name, err }); | |
| 259 | 263 | }; |
| 260 | 264 | } |
| 261 | 265 | } |
| ... | ... | @@ -307,14 +311,14 @@ const Eval = struct { |
| 307 | 311 | } |
| 308 | 312 | |
| 309 | 313 | const digest = r.takeArray(Cache.bin_digest_len) catch unreachable; |
| 310 | const result_dir = ".local-cache" ++ std.fs.path.sep_str ++ "o" ++ std.fs.path.sep_str ++ Cache.binToHex(digest.*); | |
| 314 | const result_dir = ".local-cache" ++ Dir.path.sep_str ++ "o" ++ Dir.path.sep_str ++ Cache.binToHex(digest.*); | |
| 311 | 315 | |
| 312 | 316 | const bin_name = try std.zig.EmitArtifact.bin.cacheName(arena, .{ |
| 313 | 317 | .root_name = "root", // corresponds to the module name "root" |
| 314 | 318 | .target = &eval.target.resolved, |
| 315 | 319 | .output_mode = .Exe, |
| 316 | 320 | }); |
| 317 | const bin_path = try std.fs.path.join(arena, &.{ result_dir, bin_name }); | |
| 321 | const bin_path = try Dir.path.join(arena, &.{ result_dir, bin_name }); | |
| 318 | 322 | |
| 319 | 323 | try eval.checkSuccessOutcome(update, bin_path, prog_node); |
| 320 | 324 | // This message indicates the end of the update. |
| ... | ... | @@ -338,11 +342,12 @@ const Eval = struct { |
| 338 | 342 | } |
| 339 | 343 | |
| 340 | 344 | fn checkErrorOutcome(eval: *Eval, update: Case.Update, error_bundle: std.zig.ErrorBundle) !void { |
| 345 | const io = eval.io; | |
| 341 | 346 | const expected = switch (update.outcome) { |
| 342 | 347 | .unknown => return, |
| 343 | 348 | .compile_errors => |ce| ce, |
| 344 | 349 | .stdout, .exit_code => { |
| 345 | error_bundle.renderToStdErr(.{}, .auto); | |
| 350 | try error_bundle.renderToStderr(io, .{}, .auto); | |
| 346 | 351 | eval.fatal("update '{s}': unexpected compile errors", .{update.name}); |
| 347 | 352 | }, |
| 348 | 353 | }; |
| ... | ... | @@ -351,7 +356,7 @@ const Eval = struct { |
| 351 | 356 | |
| 352 | 357 | for (error_bundle.getMessages()) |err_idx| { |
| 353 | 358 | if (expected_idx == expected.errors.len) { |
| 354 | error_bundle.renderToStdErr(.{}, .auto); | |
| 359 | try error_bundle.renderToStderr(io, .{}, .auto); | |
| 355 | 360 | eval.fatal("update '{s}': more errors than expected", .{update.name}); |
| 356 | 361 | } |
| 357 | 362 | try eval.checkOneError(update, error_bundle, expected.errors[expected_idx], false, err_idx); |
| ... | ... | @@ -359,7 +364,7 @@ const Eval = struct { |
| 359 | 364 | |
| 360 | 365 | for (error_bundle.getNotes(err_idx)) |note_idx| { |
| 361 | 366 | if (expected_idx == expected.errors.len) { |
| 362 | error_bundle.renderToStdErr(.{}, .auto); | |
| 367 | try error_bundle.renderToStderr(io, .{}, .auto); | |
| 363 | 368 | eval.fatal("update '{s}': more error notes than expected", .{update.name}); |
| 364 | 369 | } |
| 365 | 370 | try eval.checkOneError(update, error_bundle, expected.errors[expected_idx], true, note_idx); |
| ... | ... | @@ -368,7 +373,7 @@ const Eval = struct { |
| 368 | 373 | } |
| 369 | 374 | |
| 370 | 375 | if (!std.mem.eql(u8, error_bundle.getCompileLogOutput(), expected.compile_log_output)) { |
| 371 | error_bundle.renderToStdErr(.{}, .auto); | |
| 376 | try error_bundle.renderToStderr(io, .{}, .auto); | |
| 372 | 377 | eval.fatal("update '{s}': unexpected compile log output", .{update.name}); |
| 373 | 378 | } |
| 374 | 379 | } |
| ... | ... | @@ -388,6 +393,8 @@ const Eval = struct { |
| 388 | 393 | const src = eb.getSourceLocation(err.src_loc); |
| 389 | 394 | const raw_filename = eb.nullTerminatedString(src.src_path); |
| 390 | 395 | |
| 396 | const io = eval.io; | |
| 397 | ||
| 391 | 398 | // We need to replace backslashes for consistency between platforms. |
| 392 | 399 | const filename = name: { |
| 393 | 400 | if (std.mem.indexOfScalar(u8, raw_filename, '\\') == null) break :name raw_filename; |
| ... | ... | @@ -402,7 +409,7 @@ const Eval = struct { |
| 402 | 409 | expected.column != src.column + 1 or |
| 403 | 410 | !std.mem.eql(u8, expected.msg, msg)) |
| 404 | 411 | { |
| 405 | eb.renderToStdErr(.{}, .auto); | |
| 412 | eb.renderToStderr(io, .{}, .auto) catch {}; | |
| 406 | 413 | eval.fatal("update '{s}': compile error did not match expected error", .{update.name}); |
| 407 | 414 | } |
| 408 | 415 | } |
| ... | ... | @@ -429,8 +436,11 @@ const Eval = struct { |
| 429 | 436 | }, |
| 430 | 437 | }; |
| 431 | 438 | |
| 439 | const io = eval.io; | |
| 440 | ||
| 432 | 441 | var argv_buf: [2][]const u8 = undefined; |
| 433 | 442 | const argv: []const []const u8, const is_foreign: bool = switch (std.zig.system.getExternalExecutor( |
| 443 | io, | |
| 434 | 444 | &eval.host, |
| 435 | 445 | &eval.target.resolved, |
| 436 | 446 | .{ .link_libc = eval.target.backend == .cbe }, |
| ... | ... | @@ -459,8 +469,7 @@ const Eval = struct { |
| 459 | 469 | const run_prog_node = prog_node.start("run generated executable", 0); |
| 460 | 470 | defer run_prog_node.end(); |
| 461 | 471 | |
| 462 | const result = std.process.Child.run(.{ | |
| 463 | .allocator = eval.arena, | |
| 472 | const result = std.process.Child.run(eval.arena, io, .{ | |
| 464 | 473 | .argv = argv, |
| 465 | 474 | .cwd_dir = eval.tmp_dir, |
| 466 | 475 | .cwd = eval.tmp_dir_path, |
| ... | ... | @@ -468,17 +477,17 @@ const Eval = struct { |
| 468 | 477 | if (is_foreign) { |
| 469 | 478 | // Chances are the foreign executor isn't available. Skip this evaluation. |
| 470 | 479 | if (eval.allow_stderr) { |
| 471 | std.log.warn("update '{s}': skipping execution of '{s}' via executor for foreign target '{s}': {s}", .{ | |
| 480 | std.log.warn("update '{s}': skipping execution of '{s}' via executor for foreign target '{s}': {t}", .{ | |
| 472 | 481 | update.name, |
| 473 | 482 | binary_path, |
| 474 | 483 | try eval.target.resolved.zigTriple(eval.arena), |
| 475 | @errorName(err), | |
| 484 | err, | |
| 476 | 485 | }); |
| 477 | 486 | } |
| 478 | 487 | return; |
| 479 | 488 | } |
| 480 | eval.fatal("update '{s}': failed to run the generated executable '{s}': {s}", .{ | |
| 481 | update.name, binary_path, @errorName(err), | |
| 489 | eval.fatal("update '{s}': failed to run the generated executable '{s}': {t}", .{ | |
| 490 | update.name, binary_path, err, | |
| 482 | 491 | }); |
| 483 | 492 | }; |
| 484 | 493 | |
| ... | ... | @@ -514,11 +523,12 @@ const Eval = struct { |
| 514 | 523 | } |
| 515 | 524 | |
| 516 | 525 | fn requestUpdate(eval: *Eval) !void { |
| 526 | const io = eval.io; | |
| 517 | 527 | const header: std.zig.Client.Message.Header = .{ |
| 518 | 528 | .tag = .update, |
| 519 | 529 | .bytes_len = 0, |
| 520 | 530 | }; |
| 521 | var w = eval.child.stdin.?.writer(&.{}); | |
| 531 | var w = eval.child.stdin.?.writer(io, &.{}); | |
| 522 | 532 | w.interface.writeStruct(header, .little) catch |err| switch (err) { |
| 523 | 533 | error.WriteFailed => return w.err.?, |
| 524 | 534 | }; |
| ... | ... | @@ -552,16 +562,13 @@ const Eval = struct { |
| 552 | 562 | try eval.cc_child_args.appendSlice(eval.arena, &.{ out_path, c_path }); |
| 553 | 563 | defer eval.cc_child_args.items.len -= 2; |
| 554 | 564 | |
| 555 | const result = std.process.Child.run(.{ | |
| 556 | .allocator = eval.arena, | |
| 565 | const result = std.process.Child.run(eval.arena, eval.io, .{ | |
| 557 | 566 | .argv = eval.cc_child_args.items, |
| 558 | 567 | .cwd_dir = eval.tmp_dir, |
| 559 | 568 | .cwd = eval.tmp_dir_path, |
| 560 | 569 | .progress_node = child_prog_node, |
| 561 | 570 | }) catch |err| { |
| 562 | eval.fatal("update '{s}': failed to spawn zig cc for '{s}': {s}", .{ | |
| 563 | update.name, c_path, @errorName(err), | |
| 564 | }); | |
| 571 | eval.fatal("update '{s}': failed to spawn zig cc for '{s}': {t}", .{ update.name, c_path, err }); | |
| 565 | 572 | }; |
| 566 | 573 | switch (result.term) { |
| 567 | 574 | .Exited => |code| if (code != 0) { |
| ... | ... | @@ -588,12 +595,13 @@ const Eval = struct { |
| 588 | 595 | } |
| 589 | 596 | |
| 590 | 597 | fn fatal(eval: *Eval, comptime fmt: []const u8, args: anytype) noreturn { |
| 591 | eval.tmp_dir.close(); | |
| 598 | const io = eval.io; | |
| 599 | eval.tmp_dir.close(io); | |
| 592 | 600 | if (!eval.preserve_tmp_on_fatal) { |
| 593 | 601 | // Kill the child since it holds an open handle to its CWD which is the tmp dir path |
| 594 | _ = eval.child.kill() catch {}; | |
| 595 | std.fs.cwd().deleteTree(eval.tmp_dir_path) catch |err| { | |
| 596 | std.log.warn("failed to delete tree '{s}': {s}", .{ eval.tmp_dir_path, @errorName(err) }); | |
| 602 | _ = eval.child.kill(io) catch {}; | |
| 603 | Dir.cwd().deleteTree(io, eval.tmp_dir_path) catch |err| { | |
| 604 | std.log.warn("failed to delete tree '{s}': {t}", .{ eval.tmp_dir_path, err }); | |
| 597 | 605 | }; |
| 598 | 606 | } |
| 599 | 607 | std.process.fatal(fmt, args); |
| ... | ... | @@ -759,7 +767,7 @@ const Case = struct { |
| 759 | 767 | if (last_update.outcome != .unknown) fatal("line {d}: conflicting expect directive", .{line_n}); |
| 760 | 768 | last_update.outcome = .{ |
| 761 | 769 | .stdout = std.zig.string_literal.parseAlloc(arena, val) catch |err| { |
| 762 | fatal("line {d}: bad string literal: {s}", .{ line_n, @errorName(err) }); | |
| 770 | fatal("line {d}: bad string literal: {t}", .{ line_n, err }); | |
| 763 | 771 | }, |
| 764 | 772 | }; |
| 765 | 773 | } else if (std.mem.eql(u8, key, "expect_error")) { |
| ... | ... | @@ -833,27 +841,29 @@ const Case = struct { |
| 833 | 841 | |
| 834 | 842 | fn requestExit(child: *std.process.Child, eval: *Eval) void { |
| 835 | 843 | if (child.stdin == null) return; |
| 844 | const io = eval.io; | |
| 836 | 845 | |
| 837 | 846 | const header: std.zig.Client.Message.Header = .{ |
| 838 | 847 | .tag = .exit, |
| 839 | 848 | .bytes_len = 0, |
| 840 | 849 | }; |
| 841 | var w = eval.child.stdin.?.writer(&.{}); | |
| 850 | var w = eval.child.stdin.?.writer(io, &.{}); | |
| 842 | 851 | w.interface.writeStruct(header, .little) catch |err| switch (err) { |
| 843 | 852 | error.WriteFailed => switch (w.err.?) { |
| 844 | 853 | error.BrokenPipe => {}, |
| 845 | else => |e| eval.fatal("failed to send exit: {s}", .{@errorName(e)}), | |
| 854 | else => |e| eval.fatal("failed to send exit: {t}", .{e}), | |
| 846 | 855 | }, |
| 847 | 856 | }; |
| 848 | 857 | |
| 849 | 858 | // Send EOF to stdin. |
| 850 | child.stdin.?.close(); | |
| 859 | child.stdin.?.close(io); | |
| 851 | 860 | child.stdin = null; |
| 852 | 861 | } |
| 853 | 862 | |
| 854 | 863 | fn waitChild(child: *std.process.Child, eval: *Eval) void { |
| 864 | const io = eval.io; | |
| 855 | 865 | requestExit(child, eval); |
| 856 | const term = child.wait() catch |err| eval.fatal("child process failed: {s}", .{@errorName(err)}); | |
| 866 | const term = child.wait(io) catch |err| eval.fatal("child process failed: {t}", .{err}); | |
| 857 | 867 | switch (term) { |
| 858 | 868 | .Exited => |code| if (code != 0) eval.fatal("compiler failed with code {d}", .{code}), |
| 859 | 869 | .Signal, .Stopped, .Unknown => eval.fatal("compiler terminated unexpectedly", .{}), |
tools/migrate_langref.zig+14-11| ... | ... | @@ -1,13 +1,16 @@ |
| 1 | const std = @import("std"); | |
| 2 | 1 | const builtin = @import("builtin"); |
| 3 | const fs = std.fs; | |
| 2 | ||
| 3 | const std = @import("std"); | |
| 4 | const Io = std.Io; | |
| 5 | const Dir = std.Io.Dir; | |
| 4 | 6 | const print = std.debug.print; |
| 5 | 7 | const mem = std.mem; |
| 6 | 8 | const testing = std.testing; |
| 7 | 9 | const Allocator = std.mem.Allocator; |
| 8 | const max_doc_file_size = 10 * 1024 * 1024; | |
| 9 | 10 | const fatal = std.process.fatal; |
| 10 | 11 | |
| 12 | const max_doc_file_size = 10 * 1024 * 1024; | |
| 13 | ||
| 11 | 14 | pub fn main() !void { |
| 12 | 15 | var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator); |
| 13 | 16 | defer arena_instance.deinit(); |
| ... | ... | @@ -23,16 +26,16 @@ pub fn main() !void { |
| 23 | 26 | defer threaded.deinit(); |
| 24 | 27 | const io = threaded.io(); |
| 25 | 28 | |
| 26 | var in_file = try fs.cwd().openFile(input_file, .{ .mode = .read_only }); | |
| 27 | defer in_file.close(); | |
| 29 | var in_file = try Dir.cwd().openFile(input_file, .{ .mode = .read_only }); | |
| 30 | defer in_file.close(io); | |
| 28 | 31 | |
| 29 | var out_file = try fs.cwd().createFile(output_file, .{}); | |
| 30 | defer out_file.close(); | |
| 32 | var out_file = try Dir.cwd().createFile(output_file, .{}); | |
| 33 | defer out_file.close(io); | |
| 31 | 34 | var out_file_buffer: [4096]u8 = undefined; |
| 32 | 35 | var out_file_writer = out_file.writer(&out_file_buffer); |
| 33 | 36 | |
| 34 | var out_dir = try fs.cwd().openDir(fs.path.dirname(output_file).?, .{}); | |
| 35 | defer out_dir.close(); | |
| 37 | var out_dir = try Dir.cwd().openDir(Dir.path.dirname(output_file).?, .{}); | |
| 38 | defer out_dir.close(io); | |
| 36 | 39 | |
| 37 | 40 | var in_file_reader = in_file.reader(io, &.{}); |
| 38 | 41 | const input_file_bytes = try in_file_reader.interface.allocRemaining(arena, .unlimited); |
| ... | ... | @@ -266,7 +269,7 @@ const Code = struct { |
| 266 | 269 | }; |
| 267 | 270 | }; |
| 268 | 271 | |
| 269 | fn walk(arena: Allocator, tokenizer: *Tokenizer, out_dir: std.fs.Dir, w: anytype) !void { | |
| 272 | fn walk(arena: Allocator, io: Io, tokenizer: *Tokenizer, out_dir: Dir, w: anytype) !void { | |
| 270 | 273 | while (true) { |
| 271 | 274 | const token = tokenizer.next(); |
| 272 | 275 | switch (token.id) { |
| ... | ... | @@ -387,7 +390,7 @@ fn walk(arena: Allocator, tokenizer: *Tokenizer, out_dir: std.fs.Dir, w: anytype |
| 387 | 390 | var file = out_dir.createFile(basename, .{ .exclusive = true }) catch |err| { |
| 388 | 391 | fatal("unable to create file '{s}': {s}", .{ name, @errorName(err) }); |
| 389 | 392 | }; |
| 390 | defer file.close(); | |
| 393 | defer file.close(io); | |
| 391 | 394 | var file_buffer: [1024]u8 = undefined; |
| 392 | 395 | var file_writer = file.writer(&file_buffer); |
| 393 | 396 | const code = &file_writer.interface; |
tools/process_headers.zig+20-13| ... | ... | @@ -12,6 +12,8 @@ |
| 12 | 12 | //! You'll then have to manually update Zig source repo with these new files. |
| 13 | 13 | |
| 14 | 14 | const std = @import("std"); |
| 15 | const Io = std.Io; | |
| 16 | const Dir = std.Io.Dir; | |
| 15 | 17 | const Arch = std.Target.Cpu.Arch; |
| 16 | 18 | const Abi = std.Target.Abi; |
| 17 | 19 | const OsTag = std.Target.Os.Tag; |
| ... | ... | @@ -128,6 +130,11 @@ const LibCVendor = enum { |
| 128 | 130 | pub fn main() !void { |
| 129 | 131 | var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); |
| 130 | 132 | const allocator = arena.allocator(); |
| 133 | ||
| 134 | var threaded: Io.Threaded = .init(allocator); | |
| 135 | defer threaded.deinit(); | |
| 136 | const io = threaded.io(); | |
| 137 | ||
| 131 | 138 | const args = try std.process.argsAlloc(allocator); |
| 132 | 139 | var search_paths = std.array_list.Managed([]const u8).init(allocator); |
| 133 | 140 | var opt_out_dir: ?[]const u8 = null; |
| ... | ... | @@ -232,28 +239,28 @@ pub fn main() !void { |
| 232 | 239 | => &[_][]const u8{ search_path, libc_dir, "usr", "include" }, |
| 233 | 240 | .musl => &[_][]const u8{ search_path, libc_dir, "usr", "local", "musl", "include" }, |
| 234 | 241 | }; |
| 235 | const target_include_dir = try std.fs.path.join(allocator, sub_path); | |
| 242 | const target_include_dir = try Dir.path.join(allocator, sub_path); | |
| 236 | 243 | var dir_stack = std.array_list.Managed([]const u8).init(allocator); |
| 237 | 244 | try dir_stack.append(target_include_dir); |
| 238 | 245 | |
| 239 | 246 | while (dir_stack.pop()) |full_dir_name| { |
| 240 | var dir = std.fs.cwd().openDir(full_dir_name, .{ .iterate = true }) catch |err| switch (err) { | |
| 247 | var dir = Dir.cwd().openDir(io, full_dir_name, .{ .iterate = true }) catch |err| switch (err) { | |
| 241 | 248 | error.FileNotFound => continue :search, |
| 242 | 249 | error.AccessDenied => continue :search, |
| 243 | 250 | else => return err, |
| 244 | 251 | }; |
| 245 | defer dir.close(); | |
| 252 | defer dir.close(io); | |
| 246 | 253 | |
| 247 | 254 | var dir_it = dir.iterate(); |
| 248 | 255 | |
| 249 | 256 | while (try dir_it.next()) |entry| { |
| 250 | const full_path = try std.fs.path.join(allocator, &[_][]const u8{ full_dir_name, entry.name }); | |
| 257 | const full_path = try Dir.path.join(allocator, &[_][]const u8{ full_dir_name, entry.name }); | |
| 251 | 258 | switch (entry.kind) { |
| 252 | 259 | .directory => try dir_stack.append(full_path), |
| 253 | 260 | .file, .sym_link => { |
| 254 | const rel_path = try std.fs.path.relative(allocator, target_include_dir, full_path); | |
| 261 | const rel_path = try Dir.path.relative(allocator, target_include_dir, full_path); | |
| 255 | 262 | const max_size = 2 * 1024 * 1024 * 1024; |
| 256 | const raw_bytes = try std.fs.cwd().readFileAlloc(full_path, allocator, .limited(max_size)); | |
| 263 | const raw_bytes = try Dir.cwd().readFileAlloc(full_path, allocator, .limited(max_size)); | |
| 257 | 264 | const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t"); |
| 258 | 265 | total_bytes += raw_bytes.len; |
| 259 | 266 | const hash = try allocator.alloc(u8, 32); |
| ... | ... | @@ -314,7 +321,7 @@ pub fn main() !void { |
| 314 | 321 | total_bytes, |
| 315 | 322 | total_bytes - max_bytes_saved, |
| 316 | 323 | }); |
| 317 | try std.fs.cwd().makePath(out_dir); | |
| 324 | try Dir.cwd().createDirPath(io, out_dir); | |
| 318 | 325 | |
| 319 | 326 | var missed_opportunity_bytes: usize = 0; |
| 320 | 327 | // iterate path_table. for each path, put all the hashes into a list. sort by hit_count. |
| ... | ... | @@ -334,9 +341,9 @@ pub fn main() !void { |
| 334 | 341 | const best_contents = contents_list.pop().?; |
| 335 | 342 | if (best_contents.hit_count > 1) { |
| 336 | 343 | // worth it to make it generic |
| 337 | const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* }); | |
| 338 | try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?); | |
| 339 | try std.fs.cwd().writeFile(.{ .sub_path = full_path, .data = best_contents.bytes }); | |
| 344 | const full_path = try Dir.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* }); | |
| 345 | try Dir.cwd().createDirPath(io, Dir.path.dirname(full_path).?); | |
| 346 | try Dir.cwd().writeFile(io, .{ .sub_path = full_path, .data = best_contents.bytes }); | |
| 340 | 347 | best_contents.is_generic = true; |
| 341 | 348 | while (contents_list.pop()) |contender| { |
| 342 | 349 | if (contender.hit_count > 1) { |
| ... | ... | @@ -355,9 +362,9 @@ pub fn main() !void { |
| 355 | 362 | if (contents.is_generic) continue; |
| 356 | 363 | |
| 357 | 364 | const dest_target = hash_kv.key_ptr.*; |
| 358 | const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, dest_target, path_kv.key_ptr.* }); | |
| 359 | try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?); | |
| 360 | try std.fs.cwd().writeFile(.{ .sub_path = full_path, .data = contents.bytes }); | |
| 365 | const full_path = try Dir.path.join(allocator, &[_][]const u8{ out_dir, dest_target, path_kv.key_ptr.* }); | |
| 366 | try Dir.cwd().createDirPath(io, Dir.path.dirname(full_path).?); | |
| 367 | try Dir.cwd().writeFile(io, .{ .sub_path = full_path, .data = contents.bytes }); | |
| 361 | 368 | } |
| 362 | 369 | } |
| 363 | 370 | } |
tools/update-linux-headers.zig+22-15| ... | ... | @@ -15,6 +15,8 @@ |
| 15 | 15 | //! You'll then have to manually update Zig source repo with these new files. |
| 16 | 16 | |
| 17 | 17 | const std = @import("std"); |
| 18 | const Io = std.Io; | |
| 19 | const Dir = std.Io.Dir; | |
| 18 | 20 | const Arch = std.Target.Cpu.Arch; |
| 19 | 21 | const Abi = std.Target.Abi; |
| 20 | 22 | const assert = std.debug.assert; |
| ... | ... | @@ -142,6 +144,11 @@ const PathTable = std.StringHashMap(*TargetToHash); |
| 142 | 144 | pub fn main() !void { |
| 143 | 145 | var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator); |
| 144 | 146 | const arena = arena_state.allocator(); |
| 147 | ||
| 148 | var threaded: Io.Threaded = .init(arena); | |
| 149 | defer threaded.deinit(); | |
| 150 | const io = threaded.io(); | |
| 151 | ||
| 145 | 152 | const args = try std.process.argsAlloc(arena); |
| 146 | 153 | var search_paths = std.array_list.Managed([]const u8).init(arena); |
| 147 | 154 | var opt_out_dir: ?[]const u8 = null; |
| ... | ... | @@ -183,30 +190,30 @@ pub fn main() !void { |
| 183 | 190 | .arch = linux_target.arch, |
| 184 | 191 | }; |
| 185 | 192 | search: for (search_paths.items) |search_path| { |
| 186 | const target_include_dir = try std.fs.path.join(arena, &.{ | |
| 193 | const target_include_dir = try Dir.path.join(arena, &.{ | |
| 187 | 194 | search_path, linux_target.name, "include", |
| 188 | 195 | }); |
| 189 | 196 | var dir_stack = std.array_list.Managed([]const u8).init(arena); |
| 190 | 197 | try dir_stack.append(target_include_dir); |
| 191 | 198 | |
| 192 | 199 | while (dir_stack.pop()) |full_dir_name| { |
| 193 | var dir = std.fs.cwd().openDir(full_dir_name, .{ .iterate = true }) catch |err| switch (err) { | |
| 200 | var dir = Dir.cwd().openDir(full_dir_name, .{ .iterate = true }) catch |err| switch (err) { | |
| 194 | 201 | error.FileNotFound => continue :search, |
| 195 | 202 | error.AccessDenied => continue :search, |
| 196 | 203 | else => return err, |
| 197 | 204 | }; |
| 198 | defer dir.close(); | |
| 205 | defer dir.close(io); | |
| 199 | 206 | |
| 200 | 207 | var dir_it = dir.iterate(); |
| 201 | 208 | |
| 202 | 209 | while (try dir_it.next()) |entry| { |
| 203 | const full_path = try std.fs.path.join(arena, &[_][]const u8{ full_dir_name, entry.name }); | |
| 210 | const full_path = try Dir.path.join(arena, &[_][]const u8{ full_dir_name, entry.name }); | |
| 204 | 211 | switch (entry.kind) { |
| 205 | 212 | .directory => try dir_stack.append(full_path), |
| 206 | 213 | .file => { |
| 207 | const rel_path = try std.fs.path.relative(arena, target_include_dir, full_path); | |
| 214 | const rel_path = try Dir.path.relative(arena, target_include_dir, full_path); | |
| 208 | 215 | const max_size = 2 * 1024 * 1024 * 1024; |
| 209 | const raw_bytes = try std.fs.cwd().readFileAlloc(full_path, arena, .limited(max_size)); | |
| 216 | const raw_bytes = try Dir.cwd().readFileAlloc(full_path, arena, .limited(max_size)); | |
| 210 | 217 | const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t"); |
| 211 | 218 | total_bytes += raw_bytes.len; |
| 212 | 219 | const hash = try arena.alloc(u8, 32); |
| ... | ... | @@ -253,7 +260,7 @@ pub fn main() !void { |
| 253 | 260 | total_bytes, |
| 254 | 261 | total_bytes - max_bytes_saved, |
| 255 | 262 | }); |
| 256 | try std.fs.cwd().makePath(out_dir); | |
| 263 | try Dir.cwd().createDirPath(io, out_dir); | |
| 257 | 264 | |
| 258 | 265 | var missed_opportunity_bytes: usize = 0; |
| 259 | 266 | // iterate path_table. for each path, put all the hashes into a list. sort by hit_count. |
| ... | ... | @@ -273,9 +280,9 @@ pub fn main() !void { |
| 273 | 280 | const best_contents = contents_list.pop().?; |
| 274 | 281 | if (best_contents.hit_count > 1) { |
| 275 | 282 | // worth it to make it generic |
| 276 | const full_path = try std.fs.path.join(arena, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* }); | |
| 277 | try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?); | |
| 278 | try std.fs.cwd().writeFile(.{ .sub_path = full_path, .data = best_contents.bytes }); | |
| 283 | const full_path = try Dir.path.join(arena, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* }); | |
| 284 | try Dir.cwd().createDirPath(io, Dir.path.dirname(full_path).?); | |
| 285 | try Dir.cwd().writeFile(io, .{ .sub_path = full_path, .data = best_contents.bytes }); | |
| 279 | 286 | best_contents.is_generic = true; |
| 280 | 287 | while (contents_list.pop()) |contender| { |
| 281 | 288 | if (contender.hit_count > 1) { |
| ... | ... | @@ -299,9 +306,9 @@ pub fn main() !void { |
| 299 | 306 | else => @tagName(dest_target.arch), |
| 300 | 307 | }; |
| 301 | 308 | const out_subpath = try std.fmt.allocPrint(arena, "{s}-linux-any", .{arch_name}); |
| 302 | const full_path = try std.fs.path.join(arena, &[_][]const u8{ out_dir, out_subpath, path_kv.key_ptr.* }); | |
| 303 | try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?); | |
| 304 | try std.fs.cwd().writeFile(.{ .sub_path = full_path, .data = contents.bytes }); | |
| 309 | const full_path = try Dir.path.join(arena, &[_][]const u8{ out_dir, out_subpath, path_kv.key_ptr.* }); | |
| 310 | try Dir.cwd().createDirPath(io, Dir.path.dirname(full_path).?); | |
| 311 | try Dir.cwd().writeFile(io, .{ .sub_path = full_path, .data = contents.bytes }); | |
| 305 | 312 | } |
| 306 | 313 | } |
| 307 | 314 | |
| ... | ... | @@ -316,8 +323,8 @@ pub fn main() !void { |
| 316 | 323 | "any-linux-any/linux/netfilter_ipv6/ip6t_HL.h", |
| 317 | 324 | }; |
| 318 | 325 | for (bad_files) |bad_file| { |
| 319 | const full_path = try std.fs.path.join(arena, &[_][]const u8{ out_dir, bad_file }); | |
| 320 | try std.fs.cwd().deleteFile(full_path); | |
| 326 | const full_path = try Dir.path.join(arena, &[_][]const u8{ out_dir, bad_file }); | |
| 327 | try Dir.cwd().deleteFile(io, full_path); | |
| 321 | 328 | } |
| 322 | 329 | } |
| 323 | 330 |
tools/update_cpu_features.zig+16-14| ... | ... | @@ -1,6 +1,8 @@ |
| 1 | const std = @import("std"); | |
| 2 | 1 | const builtin = @import("builtin"); |
| 3 | const fs = std.fs; | |
| 2 | ||
| 3 | const std = @import("std"); | |
| 4 | const Io = std.Io; | |
| 5 | const Dir = std.Io.Dir; | |
| 4 | 6 | const mem = std.mem; |
| 5 | 7 | const json = std.json; |
| 6 | 8 | const assert = std.debug.assert; |
| ... | ... | @@ -1927,26 +1929,26 @@ pub fn main() anyerror!void { |
| 1927 | 1929 | // there shouldn't be any more argument after the optional filter |
| 1928 | 1930 | if (args.skip()) usageAndExit(args0, 1); |
| 1929 | 1931 | |
| 1930 | var zig_src_dir = try fs.cwd().openDir(zig_src_root, .{}); | |
| 1931 | defer zig_src_dir.close(); | |
| 1932 | var zig_src_dir = try Dir.cwd().openDir(io, zig_src_root, .{}); | |
| 1933 | defer zig_src_dir.close(io); | |
| 1932 | 1934 | |
| 1933 | const root_progress = std.Progress.start(.{ .estimated_total_items = targets.len }); | |
| 1935 | const root_progress = std.Progress.start(io, .{ .estimated_total_items = targets.len }); | |
| 1934 | 1936 | defer root_progress.end(); |
| 1935 | 1937 | |
| 1936 | var group: std.Io.Group = .init; | |
| 1938 | var group: Io.Group = .init; | |
| 1937 | 1939 | defer group.cancel(io); |
| 1938 | 1940 | |
| 1939 | 1941 | for (targets) |target| { |
| 1940 | 1942 | if (filter) |zig_name| { |
| 1941 | 1943 | if (!std.mem.eql(u8, target.zig_name, zig_name)) continue; |
| 1942 | 1944 | } |
| 1943 | group.async(io, processOneTarget, .{.{ | |
| 1945 | group.async(io, processOneTarget, .{ io, .{ | |
| 1944 | 1946 | .llvm_tblgen_exe = llvm_tblgen_exe, |
| 1945 | 1947 | .llvm_src_root = llvm_src_root, |
| 1946 | 1948 | .zig_src_dir = zig_src_dir, |
| 1947 | 1949 | .root_progress = root_progress, |
| 1948 | 1950 | .target = target, |
| 1949 | }}); | |
| 1951 | } }); | |
| 1950 | 1952 | } |
| 1951 | 1953 | |
| 1952 | 1954 | group.wait(io); |
| ... | ... | @@ -1955,12 +1957,12 @@ pub fn main() anyerror!void { |
| 1955 | 1957 | const Job = struct { |
| 1956 | 1958 | llvm_tblgen_exe: []const u8, |
| 1957 | 1959 | llvm_src_root: []const u8, |
| 1958 | zig_src_dir: std.fs.Dir, | |
| 1960 | zig_src_dir: Dir, | |
| 1959 | 1961 | root_progress: std.Progress.Node, |
| 1960 | 1962 | target: ArchTarget, |
| 1961 | 1963 | }; |
| 1962 | 1964 | |
| 1963 | fn processOneTarget(job: Job) void { | |
| 1965 | fn processOneTarget(io: Io, job: Job) void { | |
| 1964 | 1966 | errdefer |err| std.debug.panic("panic: {s}", .{@errorName(err)}); |
| 1965 | 1967 | const target = job.target; |
| 1966 | 1968 | |
| ... | ... | @@ -2240,12 +2242,12 @@ fn processOneTarget(job: Job) void { |
| 2240 | 2242 | |
| 2241 | 2243 | const render_progress = progress_node.start("rendering Zig code", 0); |
| 2242 | 2244 | |
| 2243 | var target_dir = try job.zig_src_dir.openDir("lib/std/Target", .{}); | |
| 2244 | defer target_dir.close(); | |
| 2245 | var target_dir = try job.zig_src_dir.openDir(io, "lib/std/Target", .{}); | |
| 2246 | defer target_dir.close(io); | |
| 2245 | 2247 | |
| 2246 | 2248 | const zig_code_basename = try std.fmt.allocPrint(arena, "{s}.zig", .{target.zig_name}); |
| 2247 | var zig_code_file = try target_dir.createFile(zig_code_basename, .{}); | |
| 2248 | defer zig_code_file.close(); | |
| 2249 | var zig_code_file = try target_dir.createFile(io, zig_code_basename, .{}); | |
| 2250 | defer zig_code_file.close(io); | |
| 2249 | 2251 | |
| 2250 | 2252 | var zig_code_file_buffer: [4096]u8 = undefined; |
| 2251 | 2253 | var zig_code_file_writer = zig_code_file.writer(&zig_code_file_buffer); |
tools/update_crc_catalog.zig+18-13| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const fs = std.fs; | |
| 2 | const Io = std.Io; | |
| 3 | const Dir = std.Io.Dir; | |
| 3 | 4 | const mem = std.mem; |
| 4 | 5 | const ascii = std.ascii; |
| 5 | 6 | |
| ... | ... | @@ -10,25 +11,29 @@ pub fn main() anyerror!void { |
| 10 | 11 | defer arena_state.deinit(); |
| 11 | 12 | const arena = arena_state.allocator(); |
| 12 | 13 | |
| 14 | var threaded: Io.Threaded = .init(arena); | |
| 15 | defer threaded.deinit(); | |
| 16 | const io = threaded.io(); | |
| 17 | ||
| 13 | 18 | const args = try std.process.argsAlloc(arena); |
| 14 | 19 | if (args.len <= 1) printUsageAndExit(args[0]); |
| 15 | 20 | |
| 16 | 21 | const zig_src_root = args[1]; |
| 17 | 22 | if (mem.startsWith(u8, zig_src_root, "-")) printUsageAndExit(args[0]); |
| 18 | 23 | |
| 19 | var zig_src_dir = try fs.cwd().openDir(zig_src_root, .{}); | |
| 20 | defer zig_src_dir.close(); | |
| 24 | var zig_src_dir = try Dir.cwd().openDir(io, zig_src_root, .{}); | |
| 25 | defer zig_src_dir.close(io); | |
| 21 | 26 | |
| 22 | const hash_sub_path = try fs.path.join(arena, &.{ "lib", "std", "hash" }); | |
| 23 | var hash_target_dir = try zig_src_dir.makeOpenPath(hash_sub_path, .{}); | |
| 24 | defer hash_target_dir.close(); | |
| 27 | const hash_sub_path = try Dir.path.join(arena, &.{ "lib", "std", "hash" }); | |
| 28 | var hash_target_dir = try zig_src_dir.createDirPathOpen(io, hash_sub_path, .{}); | |
| 29 | defer hash_target_dir.close(io); | |
| 25 | 30 | |
| 26 | const crc_sub_path = try fs.path.join(arena, &.{ "lib", "std", "hash", "crc" }); | |
| 27 | var crc_target_dir = try zig_src_dir.makeOpenPath(crc_sub_path, .{}); | |
| 28 | defer crc_target_dir.close(); | |
| 31 | const crc_sub_path = try Dir.path.join(arena, &.{ "lib", "std", "hash", "crc" }); | |
| 32 | var crc_target_dir = try zig_src_dir.createDirPathOpen(io, crc_sub_path, .{}); | |
| 33 | defer crc_target_dir.close(io); | |
| 29 | 34 | |
| 30 | var zig_code_file = try hash_target_dir.createFile("crc.zig", .{}); | |
| 31 | defer zig_code_file.close(); | |
| 35 | var zig_code_file = try hash_target_dir.createFile(io, "crc.zig", .{}); | |
| 36 | defer zig_code_file.close(io); | |
| 32 | 37 | var zig_code_file_buffer: [4096]u8 = undefined; |
| 33 | 38 | var zig_code_file_writer = zig_code_file.writer(&zig_code_file_buffer); |
| 34 | 39 | const code_writer = &zig_code_file_writer.interface; |
| ... | ... | @@ -51,8 +56,8 @@ pub fn main() anyerror!void { |
| 51 | 56 | \\ |
| 52 | 57 | ); |
| 53 | 58 | |
| 54 | var zig_test_file = try crc_target_dir.createFile("test.zig", .{}); | |
| 55 | defer zig_test_file.close(); | |
| 59 | var zig_test_file = try crc_target_dir.createFile(io, "test.zig", .{}); | |
| 60 | defer zig_test_file.close(io); | |
| 56 | 61 | var zig_test_file_buffer: [4096]u8 = undefined; |
| 57 | 62 | var zig_test_file_writer = zig_test_file.writer(&zig_test_file_buffer); |
| 58 | 63 | const test_writer = &zig_test_file_writer.interface; |
tools/update_freebsd_libc.zig+10-7| ... | ... | @@ -5,6 +5,7 @@ |
| 5 | 5 | //! `zig run tools/update_freebsd_libc.zig -- ~/Downloads/freebsd-src .` |
| 6 | 6 | |
| 7 | 7 | const std = @import("std"); |
| 8 | const Io = std.Io; | |
| 8 | 9 | |
| 9 | 10 | const exempt_files = [_][]const u8{ |
| 10 | 11 | // This file is maintained by a separate project and does not come from FreeBSD. |
| ... | ... | @@ -16,22 +17,24 @@ pub fn main() !void { |
| 16 | 17 | defer arena_instance.deinit(); |
| 17 | 18 | const arena = arena_instance.allocator(); |
| 18 | 19 | |
| 20 | var threaded: Io.Threaded = .init(arena); | |
| 21 | defer threaded.deinit(); | |
| 22 | const io = threaded.io(); | |
| 23 | ||
| 19 | 24 | const args = try std.process.argsAlloc(arena); |
| 20 | 25 | const freebsd_src_path = args[1]; |
| 21 | 26 | const zig_src_path = args[2]; |
| 22 | 27 | |
| 23 | 28 | const dest_dir_path = try std.fmt.allocPrint(arena, "{s}/lib/libc/freebsd", .{zig_src_path}); |
| 24 | 29 | |
| 25 | var dest_dir = std.fs.cwd().openDir(dest_dir_path, .{ .iterate = true }) catch |err| { | |
| 26 | std.log.err("unable to open destination directory '{s}': {s}", .{ | |
| 27 | dest_dir_path, @errorName(err), | |
| 28 | }); | |
| 30 | var dest_dir = std.fs.cwd().openDir(io, dest_dir_path, .{ .iterate = true }) catch |err| { | |
| 31 | std.log.err("unable to open destination directory '{s}': {t}", .{ dest_dir_path, err }); | |
| 29 | 32 | std.process.exit(1); |
| 30 | 33 | }; |
| 31 | defer dest_dir.close(); | |
| 34 | defer dest_dir.close(io); | |
| 32 | 35 | |
| 33 | 36 | var freebsd_src_dir = try std.fs.cwd().openDir(freebsd_src_path, .{}); |
| 34 | defer freebsd_src_dir.close(); | |
| 37 | defer freebsd_src_dir.close(io); | |
| 35 | 38 | |
| 36 | 39 | // Copy updated files from upstream. |
| 37 | 40 | { |
| ... | ... | @@ -57,7 +60,7 @@ pub fn main() !void { |
| 57 | 60 | @errorName(err), |
| 58 | 61 | }); |
| 59 | 62 | if (err == error.FileNotFound) { |
| 60 | try dest_dir.deleteFile(entry.path); | |
| 63 | try dest_dir.deleteFile(io, entry.path); | |
| 61 | 64 | } |
| 62 | 65 | }; |
| 63 | 66 | } |
tools/update_glibc.zig+20-25| ... | ... | @@ -7,9 +7,11 @@ |
| 7 | 7 | //! `zig run ../tools/update_glibc.zig -- ~/Downloads/glibc ..` |
| 8 | 8 | |
| 9 | 9 | const std = @import("std"); |
| 10 | const Io = std.Io; | |
| 11 | const Dir = std.Io.Dir; | |
| 10 | 12 | const mem = std.mem; |
| 11 | 13 | const log = std.log; |
| 12 | const fs = std.fs; | |
| 14 | const fatal = std.process.fatal; | |
| 13 | 15 | |
| 14 | 16 | const exempt_files = [_][]const u8{ |
| 15 | 17 | // This file is maintained by a separate project and does not come from glibc. |
| ... | ... | @@ -41,21 +43,23 @@ pub fn main() !void { |
| 41 | 43 | defer arena_instance.deinit(); |
| 42 | 44 | const arena = arena_instance.allocator(); |
| 43 | 45 | |
| 46 | var threaded: Io.Threaded = .init(arena); | |
| 47 | defer threaded.deinit(); | |
| 48 | const io = threaded.io(); | |
| 49 | ||
| 44 | 50 | const args = try std.process.argsAlloc(arena); |
| 45 | 51 | const glibc_src_path = args[1]; |
| 46 | 52 | const zig_src_path = args[2]; |
| 47 | 53 | |
| 48 | 54 | const dest_dir_path = try std.fmt.allocPrint(arena, "{s}/lib/libc/glibc", .{zig_src_path}); |
| 49 | 55 | |
| 50 | var dest_dir = fs.cwd().openDir(dest_dir_path, .{ .iterate = true }) catch |err| { | |
| 51 | fatal("unable to open destination directory '{s}': {s}", .{ | |
| 52 | dest_dir_path, @errorName(err), | |
| 53 | }); | |
| 56 | var dest_dir = Dir.cwd().openDir(io, dest_dir_path, .{ .iterate = true }) catch |err| { | |
| 57 | fatal("unable to open destination directory '{s}': {t}", .{ dest_dir_path, err }); | |
| 54 | 58 | }; |
| 55 | defer dest_dir.close(); | |
| 59 | defer dest_dir.close(io); | |
| 56 | 60 | |
| 57 | var glibc_src_dir = try fs.cwd().openDir(glibc_src_path, .{}); | |
| 58 | defer glibc_src_dir.close(); | |
| 61 | var glibc_src_dir = try Dir.cwd().openDir(io, glibc_src_path, .{}); | |
| 62 | defer glibc_src_dir.close(io); | |
| 59 | 63 | |
| 60 | 64 | // Copy updated files from upstream. |
| 61 | 65 | { |
| ... | ... | @@ -73,13 +77,11 @@ pub fn main() !void { |
| 73 | 77 | } |
| 74 | 78 | |
| 75 | 79 | glibc_src_dir.copyFile(entry.path, dest_dir, entry.path, .{}) catch |err| { |
| 76 | log.warn("unable to copy '{s}/{s}' to '{s}/{s}': {s}", .{ | |
| 77 | glibc_src_path, entry.path, | |
| 78 | dest_dir_path, entry.path, | |
| 79 | @errorName(err), | |
| 80 | log.warn("unable to copy '{s}/{s}' to '{s}/{s}': {t}", .{ | |
| 81 | glibc_src_path, entry.path, dest_dir_path, entry.path, err, | |
| 80 | 82 | }); |
| 81 | 83 | if (err == error.FileNotFound) { |
| 82 | try dest_dir.deleteFile(entry.path); | |
| 84 | try dest_dir.deleteFile(io, entry.path); | |
| 83 | 85 | } |
| 84 | 86 | }; |
| 85 | 87 | } |
| ... | ... | @@ -88,20 +90,18 @@ pub fn main() !void { |
| 88 | 90 | // Warn about duplicated files inside glibc/include/* that can be omitted |
| 89 | 91 | // because they are already in generic-glibc/*. |
| 90 | 92 | |
| 91 | var include_dir = dest_dir.openDir("include", .{ .iterate = true }) catch |err| { | |
| 92 | fatal("unable to open directory '{s}/include': {s}", .{ | |
| 93 | dest_dir_path, @errorName(err), | |
| 94 | }); | |
| 93 | var include_dir = dest_dir.openDir(io, "include", .{ .iterate = true }) catch |err| { | |
| 94 | fatal("unable to open directory '{s}/include': {t}", .{ dest_dir_path, err }); | |
| 95 | 95 | }; |
| 96 | defer include_dir.close(); | |
| 96 | defer include_dir.close(io); | |
| 97 | 97 | |
| 98 | 98 | const generic_glibc_path = try std.fmt.allocPrint( |
| 99 | 99 | arena, |
| 100 | 100 | "{s}/lib/libc/include/generic-glibc", |
| 101 | 101 | .{zig_src_path}, |
| 102 | 102 | ); |
| 103 | var generic_glibc_dir = try fs.cwd().openDir(generic_glibc_path, .{}); | |
| 104 | defer generic_glibc_dir.close(); | |
| 103 | var generic_glibc_dir = try Dir.cwd().openDir(io, generic_glibc_path, .{}); | |
| 104 | defer generic_glibc_dir.close(io); | |
| 105 | 105 | |
| 106 | 106 | var walker = try include_dir.walk(arena); |
| 107 | 107 | defer walker.deinit(); |
| ... | ... | @@ -146,8 +146,3 @@ pub fn main() !void { |
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | ||
| 150 | fn fatal(comptime format: []const u8, args: anytype) noreturn { | |
| 151 | log.err(format, args); | |
| 152 | std.process.exit(1); | |
| 153 | } |
tools/update_mingw.zig+23-17| ... | ... | @@ -1,35 +1,41 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const Io = std.Io; | |
| 3 | const Dir = std.Io.Dir; | |
| 2 | 4 | |
| 3 | 5 | pub fn main() !void { |
| 4 | 6 | var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator); |
| 5 | 7 | defer arena_instance.deinit(); |
| 6 | 8 | const arena = arena_instance.allocator(); |
| 7 | 9 | |
| 10 | var threaded: Io.Threaded = .init(arena); | |
| 11 | defer threaded.deinit(); | |
| 12 | const io = threaded.io(); | |
| 13 | ||
| 8 | 14 | const args = try std.process.argsAlloc(arena); |
| 9 | 15 | const zig_src_lib_path = args[1]; |
| 10 | 16 | const mingw_src_path = args[2]; |
| 11 | 17 | |
| 12 | const dest_mingw_crt_path = try std.fs.path.join(arena, &.{ | |
| 18 | const dest_mingw_crt_path = try Dir.path.join(arena, &.{ | |
| 13 | 19 | zig_src_lib_path, "libc", "mingw", |
| 14 | 20 | }); |
| 15 | const src_mingw_crt_path = try std.fs.path.join(arena, &.{ | |
| 21 | const src_mingw_crt_path = try Dir.path.join(arena, &.{ | |
| 16 | 22 | mingw_src_path, "mingw-w64-crt", |
| 17 | 23 | }); |
| 18 | 24 | |
| 19 | 25 | // Update only the set of existing files we have already chosen to include |
| 20 | 26 | // in zig's installation. |
| 21 | 27 | |
| 22 | var dest_crt_dir = std.fs.cwd().openDir(dest_mingw_crt_path, .{ .iterate = true }) catch |err| { | |
| 28 | var dest_crt_dir = Dir.cwd().openDir(io, dest_mingw_crt_path, .{ .iterate = true }) catch |err| { | |
| 23 | 29 | std.log.err("unable to open directory '{s}': {s}", .{ dest_mingw_crt_path, @errorName(err) }); |
| 24 | 30 | std.process.exit(1); |
| 25 | 31 | }; |
| 26 | defer dest_crt_dir.close(); | |
| 32 | defer dest_crt_dir.close(io); | |
| 27 | 33 | |
| 28 | var src_crt_dir = std.fs.cwd().openDir(src_mingw_crt_path, .{ .iterate = true }) catch |err| { | |
| 34 | var src_crt_dir = Dir.cwd().openDir(io, src_mingw_crt_path, .{ .iterate = true }) catch |err| { | |
| 29 | 35 | std.log.err("unable to open directory '{s}': {s}", .{ src_mingw_crt_path, @errorName(err) }); |
| 30 | 36 | std.process.exit(1); |
| 31 | 37 | }; |
| 32 | defer src_crt_dir.close(); | |
| 38 | defer src_crt_dir.close(io); | |
| 33 | 39 | |
| 34 | 40 | { |
| 35 | 41 | var walker = try dest_crt_dir.walk(arena); |
| ... | ... | @@ -49,11 +55,11 @@ pub fn main() !void { |
| 49 | 55 | |
| 50 | 56 | if (!keep) { |
| 51 | 57 | std.log.warn("deleting {s}", .{entry.path}); |
| 52 | try dest_crt_dir.deleteFile(entry.path); | |
| 58 | try dest_crt_dir.deleteFile(io, entry.path); | |
| 53 | 59 | } |
| 54 | 60 | }, |
| 55 | 61 | else => { |
| 56 | std.log.err("unable to copy {s}: {s}", .{ entry.path, @errorName(err) }); | |
| 62 | std.log.err("unable to copy {s}: {t}", .{ entry.path, err }); | |
| 57 | 63 | fail = true; |
| 58 | 64 | }, |
| 59 | 65 | }; |
| ... | ... | @@ -63,24 +69,24 @@ pub fn main() !void { |
| 63 | 69 | } |
| 64 | 70 | |
| 65 | 71 | { |
| 66 | const dest_mingw_winpthreads_path = try std.fs.path.join(arena, &.{ | |
| 72 | const dest_mingw_winpthreads_path = try Dir.path.join(arena, &.{ | |
| 67 | 73 | zig_src_lib_path, "libc", "mingw", "winpthreads", |
| 68 | 74 | }); |
| 69 | const src_mingw_libraries_winpthreads_src_path = try std.fs.path.join(arena, &.{ | |
| 75 | const src_mingw_libraries_winpthreads_src_path = try Dir.path.join(arena, &.{ | |
| 70 | 76 | mingw_src_path, "mingw-w64-libraries", "winpthreads", "src", |
| 71 | 77 | }); |
| 72 | 78 | |
| 73 | var dest_winpthreads_dir = std.fs.cwd().openDir(dest_mingw_winpthreads_path, .{ .iterate = true }) catch |err| { | |
| 79 | var dest_winpthreads_dir = Dir.cwd().openDir(io, dest_mingw_winpthreads_path, .{ .iterate = true }) catch |err| { | |
| 74 | 80 | std.log.err("unable to open directory '{s}': {s}", .{ dest_mingw_winpthreads_path, @errorName(err) }); |
| 75 | 81 | std.process.exit(1); |
| 76 | 82 | }; |
| 77 | defer dest_winpthreads_dir.close(); | |
| 83 | defer dest_winpthreads_dir.close(io); | |
| 78 | 84 | |
| 79 | var src_winpthreads_dir = std.fs.cwd().openDir(src_mingw_libraries_winpthreads_src_path, .{ .iterate = true }) catch |err| { | |
| 85 | var src_winpthreads_dir = Dir.cwd().openDir(io, src_mingw_libraries_winpthreads_src_path, .{ .iterate = true }) catch |err| { | |
| 80 | 86 | std.log.err("unable to open directory '{s}': {s}", .{ src_mingw_libraries_winpthreads_src_path, @errorName(err) }); |
| 81 | 87 | std.process.exit(1); |
| 82 | 88 | }; |
| 83 | defer src_winpthreads_dir.close(); | |
| 89 | defer src_winpthreads_dir.close(io); | |
| 84 | 90 | |
| 85 | 91 | { |
| 86 | 92 | var walker = try dest_winpthreads_dir.walk(arena); |
| ... | ... | @@ -94,10 +100,10 @@ pub fn main() !void { |
| 94 | 100 | src_winpthreads_dir.copyFile(entry.path, dest_winpthreads_dir, entry.path, .{}) catch |err| switch (err) { |
| 95 | 101 | error.FileNotFound => { |
| 96 | 102 | std.log.warn("deleting {s}", .{entry.path}); |
| 97 | try dest_winpthreads_dir.deleteFile(entry.path); | |
| 103 | try dest_winpthreads_dir.deleteFile(io, entry.path); | |
| 98 | 104 | }, |
| 99 | 105 | else => { |
| 100 | std.log.err("unable to copy {s}: {s}", .{ entry.path, @errorName(err) }); | |
| 106 | std.log.err("unable to copy {s}: {t}", .{ entry.path, err }); | |
| 101 | 107 | fail = true; |
| 102 | 108 | }, |
| 103 | 109 | }; |
| ... | ... | @@ -164,7 +170,7 @@ pub fn main() !void { |
| 164 | 170 | |
| 165 | 171 | const kept_crt_files = [_][]const u8{ |
| 166 | 172 | "COPYING", |
| 167 | "include" ++ std.fs.path.sep_str ++ "config.h", | |
| 173 | "include" ++ Dir.path.sep_str ++ "config.h", | |
| 168 | 174 | }; |
| 169 | 175 | |
| 170 | 176 | const def_exts = [_][]const u8{ |
tools/update_netbsd_libc.zig+13-12| ... | ... | @@ -5,6 +5,7 @@ |
| 5 | 5 | //! `zig run tools/update_netbsd_libc.zig -- ~/Downloads/netbsd-src .` |
| 6 | 6 | |
| 7 | 7 | const std = @import("std"); |
| 8 | const Io = std.Io; | |
| 8 | 9 | |
| 9 | 10 | const exempt_files = [_][]const u8{ |
| 10 | 11 | // This file is maintained by a separate project and does not come from NetBSD. |
| ... | ... | @@ -16,22 +17,24 @@ pub fn main() !void { |
| 16 | 17 | defer arena_instance.deinit(); |
| 17 | 18 | const arena = arena_instance.allocator(); |
| 18 | 19 | |
| 20 | var threaded: Io.Threaded = .init(arena); | |
| 21 | defer threaded.deinit(); | |
| 22 | const io = threaded.io(); | |
| 23 | ||
| 19 | 24 | const args = try std.process.argsAlloc(arena); |
| 20 | 25 | const netbsd_src_path = args[1]; |
| 21 | 26 | const zig_src_path = args[2]; |
| 22 | 27 | |
| 23 | 28 | const dest_dir_path = try std.fmt.allocPrint(arena, "{s}/lib/libc/netbsd", .{zig_src_path}); |
| 24 | 29 | |
| 25 | var dest_dir = std.fs.cwd().openDir(dest_dir_path, .{ .iterate = true }) catch |err| { | |
| 26 | std.log.err("unable to open destination directory '{s}': {s}", .{ | |
| 27 | dest_dir_path, @errorName(err), | |
| 28 | }); | |
| 30 | var dest_dir = std.fs.cwd().openDir(io, dest_dir_path, .{ .iterate = true }) catch |err| { | |
| 31 | std.log.err("unable to open destination directory '{s}': {t}", .{ dest_dir_path, err }); | |
| 29 | 32 | std.process.exit(1); |
| 30 | 33 | }; |
| 31 | defer dest_dir.close(); | |
| 34 | defer dest_dir.close(io); | |
| 32 | 35 | |
| 33 | var netbsd_src_dir = try std.fs.cwd().openDir(netbsd_src_path, .{}); | |
| 34 | defer netbsd_src_dir.close(); | |
| 36 | var netbsd_src_dir = try std.fs.cwd().openDir(io, netbsd_src_path, .{}); | |
| 37 | defer netbsd_src_dir.close(io); | |
| 35 | 38 | |
| 36 | 39 | // Copy updated files from upstream. |
| 37 | 40 | { |
| ... | ... | @@ -51,13 +54,11 @@ pub fn main() !void { |
| 51 | 54 | }); |
| 52 | 55 | |
| 53 | 56 | netbsd_src_dir.copyFile(entry.path, dest_dir, entry.path, .{}) catch |err| { |
| 54 | std.log.warn("unable to copy '{s}/{s}' to '{s}/{s}': {s}", .{ | |
| 55 | netbsd_src_path, entry.path, | |
| 56 | dest_dir_path, entry.path, | |
| 57 | @errorName(err), | |
| 57 | std.log.warn("unable to copy '{s}/{s}' to '{s}/{s}': {t}", .{ | |
| 58 | netbsd_src_path, entry.path, dest_dir_path, entry.path, err, | |
| 58 | 59 | }); |
| 59 | 60 | if (err == error.FileNotFound) { |
| 60 | try dest_dir.deleteFile(entry.path); | |
| 61 | try dest_dir.deleteFile(io, entry.path); | |
| 61 | 62 | } |
| 62 | 63 | }; |
| 63 | 64 | } |