authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-08 17:21:52-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:08-08:00
log4218344dd3178f2fd3d9d00e9ff6895ee344df6d
tree38a1378b45349bcd182f6bdb721dadb275c1d02e
parent950d18ef695bb7a28397e080dc3c201559ec4ee2

std.Build.Cache: remove readSmallFile and writeSmallFile

These were to support optimizations involving detecting when to avoid calling into LLD, which are no longer implemented.

18 files changed, 63 insertions(+), 75 deletions(-)

lib/compiler/build_runner.zig+1-1
...@@ -459,7 +459,7 @@ pub fn main() !void {...@@ -459,7 +459,7 @@ pub fn main() !void {
459 }459 }
460 const s = std.fs.path.sep_str;460 const s = std.fs.path.sep_str;
461 const tmp_sub_path = "tmp" ++ s ++ (output_tmp_nonce orelse fatal("missing -Z arg", .{}));461 const tmp_sub_path = "tmp" ++ s ++ (output_tmp_nonce orelse fatal("missing -Z arg", .{}));
462 local_cache_directory.handle.writeFile(.{462 local_cache_directory.handle.writeFile(io, .{
463 .sub_path = tmp_sub_path,463 .sub_path = tmp_sub_path,
464 .data = buffer.items,464 .data = buffer.items,
465 .flags = .{ .exclusive = true },465 .flags = .{ .exclusive = true },
lib/compiler/reduce.zig+8-4
...@@ -55,6 +55,10 @@ pub fn main() !void {...@@ -55,6 +55,10 @@ pub fn main() !void {
55 var general_purpose_allocator: std.heap.GeneralPurposeAllocator(.{}) = .init;55 var general_purpose_allocator: std.heap.GeneralPurposeAllocator(.{}) = .init;
56 const gpa = general_purpose_allocator.allocator();56 const gpa = general_purpose_allocator.allocator();
5757
58 var threaded: std.Io.Threaded = .init(gpa);
59 defer threaded.deinit();
60 const io = threaded.io();
61
58 const args = try std.process.argsAlloc(arena);62 const args = try std.process.argsAlloc(arena);
5963
60 var opt_checker_path: ?[]const u8 = null;64 var opt_checker_path: ?[]const u8 = null;
...@@ -233,12 +237,12 @@ pub fn main() !void {...@@ -233,12 +237,12 @@ pub fn main() !void {
233 }237 }
234 }238 }
235239
236 try Io.Dir.cwd().writeFile(.{ .sub_path = root_source_file_path, .data = rendered.written() });240 try Io.Dir.cwd().writeFile(io, .{ .sub_path = root_source_file_path, .data = rendered.written() });
237 // std.debug.print("trying this code:\n{s}\n", .{rendered.items});241 // std.debug.print("trying this code:\n{s}\n", .{rendered.items});
238242
239 const interestingness = try runCheck(arena, interestingness_argv.items);243 const interestingness = try runCheck(arena, interestingness_argv.items);
240 std.debug.print("{d} random transformations: {s}. {d}/{d}\n", .{244 std.debug.print("{d} random transformations: {t}. {d}/{d}\n", .{
241 subset_size, @tagName(interestingness), start_index, transformations.items.len,245 subset_size, interestingness, start_index, transformations.items.len,
242 });246 });
243 switch (interestingness) {247 switch (interestingness) {
244 .interesting => {248 .interesting => {
...@@ -274,7 +278,7 @@ pub fn main() !void {...@@ -274,7 +278,7 @@ pub fn main() !void {
274 fixups.clearRetainingCapacity();278 fixups.clearRetainingCapacity();
275 rendered.clearRetainingCapacity();279 rendered.clearRetainingCapacity();
276 try tree.render(gpa, &rendered.writer, fixups);280 try tree.render(gpa, &rendered.writer, fixups);
277 try Io.Dir.cwd().writeFile(.{ .sub_path = root_source_file_path, .data = rendered.written() });281 try Io.Dir.cwd().writeFile(io, .{ .sub_path = root_source_file_path, .data = rendered.written() });
278282
279 return std.process.cleanExit();283 return std.process.cleanExit();
280 }284 }
lib/compiler/resinator/main.zig+1-1
...@@ -212,7 +212,7 @@ pub fn main() !void {...@@ -212,7 +212,7 @@ pub fn main() !void {
212 try output_file.writeAll(full_input);212 try output_file.writeAll(full_input);
213 },213 },
214 .filename => |output_filename| {214 .filename => |output_filename| {
215 try Io.Dir.cwd().writeFile(.{ .sub_path = output_filename, .data = full_input });215 try Io.Dir.cwd().writeFile(io, .{ .sub_path = output_filename, .data = full_input });
216 },216 },
217 }217 }
218 return;218 return;
lib/compiler/std-docs.zig+1-1
...@@ -233,7 +233,7 @@ fn serveSourcesTar(request: *std.http.Server.Request, context: *Context) !void {...@@ -233,7 +233,7 @@ fn serveSourcesTar(request: *std.http.Server.Request, context: *Context) !void {
233 .interface = std.Io.File.Reader.initInterface(&.{}),233 .interface = std.Io.File.Reader.initInterface(&.{}),
234 .size = stat.size,234 .size = stat.size,
235 };235 };
236 try archiver.writeFile(entry.path, &file_reader, stat.mtime);236 try archiver.writeFile(io, entry.path, &file_reader, stat.mtime);
237 }237 }
238238
239 {239 {
lib/std/Build/Cache.zig+6-30
...@@ -1276,30 +1276,6 @@ pub const Manifest = struct {...@@ -1276,30 +1276,6 @@ pub const Manifest = struct {
1276 }1276 }
1277};1277};
12781278
1279/// On operating systems that support symlinks, does a readlink. On other operating systems,
1280/// uses the file contents. Windows supports symlinks but only with elevated privileges, so
1281/// it is treated as not supporting symlinks.
1282pub fn readSmallFile(dir: Io.Dir, sub_path: []const u8, buffer: []u8) ![]u8 {
1283 if (builtin.os.tag == .windows) {
1284 return dir.readFile(sub_path, buffer);
1285 } else {
1286 return dir.readLink(sub_path, buffer);
1287 }
1288}
1289
1290/// On operating systems that support symlinks, does a symlink. On other operating systems,
1291/// uses the file contents. Windows supports symlinks but only with elevated privileges, so
1292/// it is treated as not supporting symlinks.
1293/// `data` must be a valid UTF-8 encoded file path and 255 bytes or fewer.
1294pub fn writeSmallFile(dir: Io.Dir, sub_path: []const u8, data: []const u8) !void {
1295 assert(data.len <= 255);
1296 if (builtin.os.tag == .windows) {
1297 return dir.writeFile(.{ .sub_path = sub_path, .data = data });
1298 } else {
1299 return dir.symLink(data, sub_path, .{});
1300 }
1301}
1302
1303fn hashFile(io: Io, file: Io.File, bin_digest: *[Hasher.mac_length]u8) Io.File.ReadPositionalError!void {1279fn hashFile(io: Io, file: Io.File, bin_digest: *[Hasher.mac_length]u8) Io.File.ReadPositionalError!void {
1304 var buffer: [2048]u8 = undefined;1280 var buffer: [2048]u8 = undefined;
1305 var hasher = hasher_init;1281 var hasher = hasher_init;
...@@ -1338,7 +1314,7 @@ test "cache file and then recall it" {...@@ -1338,7 +1314,7 @@ test "cache file and then recall it" {
1338 const temp_file = "test.txt";1314 const temp_file = "test.txt";
1339 const temp_manifest_dir = "temp_manifest_dir";1315 const temp_manifest_dir = "temp_manifest_dir";
13401316
1341 try tmp.dir.writeFile(.{ .sub_path = temp_file, .data = "Hello, world!\n" });1317 try tmp.dir.writeFile(io, .{ .sub_path = temp_file, .data = "Hello, world!\n" });
13421318
1343 // Wait for file timestamps to tick1319 // Wait for file timestamps to tick
1344 const initial_time = try testGetCurrentFileTimestamp(io, tmp.dir);1320 const initial_time = try testGetCurrentFileTimestamp(io, tmp.dir);
...@@ -1404,7 +1380,7 @@ test "check that changing a file makes cache fail" {...@@ -1404,7 +1380,7 @@ test "check that changing a file makes cache fail" {
1404 const original_temp_file_contents = "Hello, world!\n";1380 const original_temp_file_contents = "Hello, world!\n";
1405 const updated_temp_file_contents = "Hello, world; but updated!\n";1381 const updated_temp_file_contents = "Hello, world; but updated!\n";
14061382
1407 try tmp.dir.writeFile(.{ .sub_path = temp_file, .data = original_temp_file_contents });1383 try tmp.dir.writeFile(io, .{ .sub_path = temp_file, .data = original_temp_file_contents });
14081384
1409 // Wait for file timestamps to tick1385 // Wait for file timestamps to tick
1410 const initial_time = try testGetCurrentFileTimestamp(tmp.dir);1386 const initial_time = try testGetCurrentFileTimestamp(tmp.dir);
...@@ -1441,7 +1417,7 @@ test "check that changing a file makes cache fail" {...@@ -1441,7 +1417,7 @@ test "check that changing a file makes cache fail" {
1441 try ch.writeManifest();1417 try ch.writeManifest();
1442 }1418 }
14431419
1444 try tmp.dir.writeFile(.{ .sub_path = temp_file, .data = updated_temp_file_contents });1420 try tmp.dir.writeFile(io, .{ .sub_path = temp_file, .data = updated_temp_file_contents });
14451421
1446 {1422 {
1447 var ch = cache.obtain();1423 var ch = cache.obtain();
...@@ -1521,8 +1497,8 @@ test "Manifest with files added after initial hash work" {...@@ -1521,8 +1497,8 @@ test "Manifest with files added after initial hash work" {
1521 const temp_file2 = "cache_hash_post_file_test2.txt";1497 const temp_file2 = "cache_hash_post_file_test2.txt";
1522 const temp_manifest_dir = "cache_hash_post_file_manifest_dir";1498 const temp_manifest_dir = "cache_hash_post_file_manifest_dir";
15231499
1524 try tmp.dir.writeFile(.{ .sub_path = temp_file1, .data = "Hello, world!\n" });1500 try tmp.dir.writeFile(io, .{ .sub_path = temp_file1, .data = "Hello, world!\n" });
1525 try tmp.dir.writeFile(.{ .sub_path = temp_file2, .data = "Hello world the second!\n" });1501 try tmp.dir.writeFile(io, .{ .sub_path = temp_file2, .data = "Hello world the second!\n" });
15261502
1527 // Wait for file timestamps to tick1503 // Wait for file timestamps to tick
1528 const initial_time = try testGetCurrentFileTimestamp(tmp.dir);1504 const initial_time = try testGetCurrentFileTimestamp(tmp.dir);
...@@ -1573,7 +1549,7 @@ test "Manifest with files added after initial hash work" {...@@ -1573,7 +1549,7 @@ test "Manifest with files added after initial hash work" {
1573 try testing.expect(mem.eql(u8, &digest1, &digest2));1549 try testing.expect(mem.eql(u8, &digest1, &digest2));
15741550
1575 // Modify the file added after initial hash1551 // Modify the file added after initial hash
1576 try tmp.dir.writeFile(.{ .sub_path = temp_file2, .data = "Hello world the second, updated\n" });1552 try tmp.dir.writeFile(io, .{ .sub_path = temp_file2, .data = "Hello world the second, updated\n" });
15771553
1578 // Wait for file timestamps to tick1554 // Wait for file timestamps to tick
1579 const initial_time2 = try testGetCurrentFileTimestamp(tmp.dir);1555 const initial_time2 = try testGetCurrentFileTimestamp(tmp.dir);
lib/std/Build/Step/ConfigHeader.zig+1-1
...@@ -264,7 +264,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {...@@ -264,7 +264,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
264 });264 });
265 };265 };
266266
267 b.cache_root.handle.writeFile(.{ .sub_path = sub_path, .data = output }) catch |err| {267 b.cache_root.handle.writeFile(io, .{ .sub_path = sub_path, .data = output }) catch |err| {
268 return step.fail("unable to write file '{f}{s}': {s}", .{268 return step.fail("unable to write file '{f}{s}': {s}", .{
269 b.cache_root, sub_path, @errorName(err),269 b.cache_root, sub_path, @errorName(err),
270 });270 });
lib/std/Build/Step/Run.zig+1-1
...@@ -1482,7 +1482,7 @@ fn runCommand(...@@ -1482,7 +1482,7 @@ fn runCommand(
1482 .leading => mem.trimStart(u8, stream.bytes.?, &std.ascii.whitespace),1482 .leading => mem.trimStart(u8, stream.bytes.?, &std.ascii.whitespace),
1483 .trailing => mem.trimEnd(u8, stream.bytes.?, &std.ascii.whitespace),1483 .trailing => mem.trimEnd(u8, stream.bytes.?, &std.ascii.whitespace),
1484 };1484 };
1485 b.cache_root.handle.writeFile(.{ .sub_path = sub_path, .data = data }) catch |err| {1485 b.cache_root.handle.writeFile(io, .{ .sub_path = sub_path, .data = data }) catch |err| {
1486 return step.fail("unable to write file '{f}{s}': {s}", .{1486 return step.fail("unable to write file '{f}{s}': {s}", .{
1487 b.cache_root, sub_path, @errorName(err),1487 b.cache_root, sub_path, @errorName(err),
1488 });1488 });
lib/std/Build/Step/UpdateSourceFiles.zig+1-1
...@@ -84,7 +84,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {...@@ -84,7 +84,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
84 }84 }
85 switch (output_source_file.contents) {85 switch (output_source_file.contents) {
86 .bytes => |bytes| {86 .bytes => |bytes| {
87 b.build_root.handle.writeFile(.{ .sub_path = output_source_file.sub_path, .data = bytes }) catch |err| {87 b.build_root.handle.writeFile(io, .{ .sub_path = output_source_file.sub_path, .data = bytes }) catch |err| {
88 return step.fail("unable to write file '{f}{s}': {t}", .{88 return step.fail("unable to write file '{f}{s}': {t}", .{
89 b.build_root, output_source_file.sub_path, err,89 b.build_root, output_source_file.sub_path, err,
90 });90 });
lib/std/Build/Step/WriteFile.zig+1-1
...@@ -273,7 +273,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {...@@ -273,7 +273,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
273 }273 }
274 switch (file.contents) {274 switch (file.contents) {
275 .bytes => |bytes| {275 .bytes => |bytes| {
276 cache_dir.writeFile(.{ .sub_path = file.sub_path, .data = bytes }) catch |err| {276 cache_dir.writeFile(io, .{ .sub_path = file.sub_path, .data = bytes }) catch |err| {
277 return step.fail("unable to write file '{f}{s}{c}{s}': {t}", .{277 return step.fail("unable to write file '{f}{s}{c}{s}': {t}", .{
278 b.cache_root, cache_path, fs.path.sep, file.sub_path, err,278 b.cache_root, cache_path, fs.path.sep, file.sub_path, err,
279 });279 });
lib/std/Build/WebServer.zig+1-1
...@@ -523,7 +523,7 @@ pub fn serveTarFile(ws: *WebServer, request: *http.Server.Request, paths: []cons...@@ -523,7 +523,7 @@ pub fn serveTarFile(ws: *WebServer, request: *http.Server.Request, paths: []cons
523 if (cached_cwd_path == null) cached_cwd_path = try std.process.getCwdAlloc(gpa);523 if (cached_cwd_path == null) cached_cwd_path = try std.process.getCwdAlloc(gpa);
524 break :cwd cached_cwd_path.?;524 break :cwd cached_cwd_path.?;
525 };525 };
526 try archiver.writeFile(path.sub_path, &file_reader, @intCast(stat.mtime.toSeconds()));526 try archiver.writeFile(io, path.sub_path, &file_reader, @intCast(stat.mtime.toSeconds()));
527 }527 }
528528
529 // intentionally not calling `archiver.finishPedantically`529 // intentionally not calling `archiver.finishPedantically`
lib/std/debug.zig+2-2
...@@ -1243,7 +1243,7 @@ test printLineFromFile {...@@ -1243,7 +1243,7 @@ test printLineFromFile {
1243 {1243 {
1244 const path = try join(gpa, &.{ test_dir_path, "one_line.zig" });1244 const path = try join(gpa, &.{ test_dir_path, "one_line.zig" });
1245 defer gpa.free(path);1245 defer gpa.free(path);
1246 try test_dir.dir.writeFile(.{ .sub_path = "one_line.zig", .data = "no new lines in this file, but one is printed anyway" });1246 try test_dir.dir.writeFile(io, .{ .sub_path = "one_line.zig", .data = "no new lines in this file, but one is printed anyway" });
12471247
1248 try expectError(error.EndOfFile, printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 }));1248 try expectError(error.EndOfFile, printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 }));
12491249
...@@ -1254,7 +1254,7 @@ test printLineFromFile {...@@ -1254,7 +1254,7 @@ test printLineFromFile {
1254 {1254 {
1255 const path = try fs.path.join(gpa, &.{ test_dir_path, "three_lines.zig" });1255 const path = try fs.path.join(gpa, &.{ test_dir_path, "three_lines.zig" });
1256 defer gpa.free(path);1256 defer gpa.free(path);
1257 try test_dir.dir.writeFile(.{1257 try test_dir.dir.writeFile(io, .{
1258 .sub_path = "three_lines.zig",1258 .sub_path = "three_lines.zig",
1259 .data =1259 .data =
1260 \\11260 \\1
lib/std/fs/test.zig+28-20
...@@ -184,7 +184,7 @@ test "Dir.readLink" {...@@ -184,7 +184,7 @@ test "Dir.readLink" {
184 fn impl(ctx: *TestContext) !void {184 fn impl(ctx: *TestContext) !void {
185 // Create some targets185 // Create some targets
186 const file_target_path = try ctx.transformPath("file.txt");186 const file_target_path = try ctx.transformPath("file.txt");
187 try ctx.dir.writeFile(.{ .sub_path = file_target_path, .data = "nonsense" });187 try ctx.dir.writeFile(io, .{ .sub_path = file_target_path, .data = "nonsense" });
188 const dir_target_path = try ctx.transformPath("subdir");188 const dir_target_path = try ctx.transformPath("subdir");
189 try ctx.dir.makeDir(dir_target_path);189 try ctx.dir.makeDir(dir_target_path);
190190
...@@ -487,11 +487,13 @@ test "readLinkAbsolute" {...@@ -487,11 +487,13 @@ test "readLinkAbsolute" {
487 if (native_os == .wasi) return error.SkipZigTest;487 if (native_os == .wasi) return error.SkipZigTest;
488 if (native_os == .openbsd) return error.SkipZigTest;488 if (native_os == .openbsd) return error.SkipZigTest;
489489
490 const io = testing.io;
491
490 var tmp = tmpDir(.{});492 var tmp = tmpDir(.{});
491 defer tmp.cleanup();493 defer tmp.cleanup();
492494
493 // Create some targets495 // Create some targets
494 try tmp.dir.writeFile(.{ .sub_path = "file.txt", .data = "nonsense" });496 try tmp.dir.writeFile(io, .{ .sub_path = "file.txt", .data = "nonsense" });
495 try tmp.dir.makeDir("subdir");497 try tmp.dir.makeDir("subdir");
496498
497 // Get base abs path499 // Get base abs path
...@@ -708,6 +710,7 @@ test "Dir.realpath smoke test" {...@@ -708,6 +710,7 @@ test "Dir.realpath smoke test" {
708710
709 try testWithAllSupportedPathTypes(struct {711 try testWithAllSupportedPathTypes(struct {
710 fn impl(ctx: *TestContext) !void {712 fn impl(ctx: *TestContext) !void {
713 const io = ctx.io;
711 const allocator = ctx.arena.allocator();714 const allocator = ctx.arena.allocator();
712 const test_file_path = try ctx.transformPath("test_file");715 const test_file_path = try ctx.transformPath("test_file");
713 const test_dir_path = try ctx.transformPath("test_dir");716 const test_dir_path = try ctx.transformPath("test_dir");
...@@ -720,7 +723,7 @@ test "Dir.realpath smoke test" {...@@ -720,7 +723,7 @@ test "Dir.realpath smoke test" {
720 try testing.expectError(error.FileNotFound, ctx.dir.realpath(test_dir_path, &buf));723 try testing.expectError(error.FileNotFound, ctx.dir.realpath(test_dir_path, &buf));
721724
722 // Now create the file and dir725 // Now create the file and dir
723 try ctx.dir.writeFile(.{ .sub_path = test_file_path, .data = "" });726 try ctx.dir.writeFile(io, .{ .sub_path = test_file_path, .data = "" });
724 try ctx.dir.makeDir(test_dir_path);727 try ctx.dir.makeDir(test_dir_path);
725728
726 const base_path = try ctx.transformPath(".");729 const base_path = try ctx.transformPath(".");
...@@ -803,11 +806,12 @@ test "readFileAlloc" {...@@ -803,11 +806,12 @@ test "readFileAlloc" {
803test "Dir.statFile" {806test "Dir.statFile" {
804 try testWithAllSupportedPathTypes(struct {807 try testWithAllSupportedPathTypes(struct {
805 fn impl(ctx: *TestContext) !void {808 fn impl(ctx: *TestContext) !void {
809 const io = ctx.io;
806 const test_file_name = try ctx.transformPath("test_file");810 const test_file_name = try ctx.transformPath("test_file");
807811
808 try testing.expectError(error.FileNotFound, ctx.dir.statFile(test_file_name));812 try testing.expectError(error.FileNotFound, ctx.dir.statFile(test_file_name));
809813
810 try ctx.dir.writeFile(.{ .sub_path = test_file_name, .data = "" });814 try ctx.dir.writeFile(io, .{ .sub_path = test_file_name, .data = "" });
811815
812 const stat = try ctx.dir.statFile(test_file_name);816 const stat = try ctx.dir.statFile(test_file_name);
813 try testing.expectEqual(File.Kind.file, stat.kind);817 try testing.expectEqual(File.Kind.file, stat.kind);
...@@ -925,6 +929,7 @@ test "makeOpenPath parent dirs do not exist" {...@@ -925,6 +929,7 @@ test "makeOpenPath parent dirs do not exist" {
925test "deleteDir" {929test "deleteDir" {
926 try testWithAllSupportedPathTypes(struct {930 try testWithAllSupportedPathTypes(struct {
927 fn impl(ctx: *TestContext) !void {931 fn impl(ctx: *TestContext) !void {
932 const io = ctx.io;
928 const test_dir_path = try ctx.transformPath("test_dir");933 const test_dir_path = try ctx.transformPath("test_dir");
929 const test_file_path = try ctx.transformPath("test_dir" ++ fs.path.sep_str ++ "test_file");934 const test_file_path = try ctx.transformPath("test_dir" ++ fs.path.sep_str ++ "test_file");
930935
...@@ -933,7 +938,7 @@ test "deleteDir" {...@@ -933,7 +938,7 @@ test "deleteDir" {
933938
934 // deleting a non-empty directory939 // deleting a non-empty directory
935 try ctx.dir.makeDir(test_dir_path);940 try ctx.dir.makeDir(test_dir_path);
936 try ctx.dir.writeFile(.{ .sub_path = test_file_path, .data = "" });941 try ctx.dir.writeFile(io, .{ .sub_path = test_file_path, .data = "" });
937 try testing.expectError(error.DirNotEmpty, ctx.dir.deleteDir(test_dir_path));942 try testing.expectError(error.DirNotEmpty, ctx.dir.deleteDir(test_dir_path));
938943
939 // deleting an empty directory944 // deleting an empty directory
...@@ -1217,7 +1222,7 @@ test "deleteTree on a symlink" {...@@ -1217,7 +1222,7 @@ test "deleteTree on a symlink" {
1217 defer tmp.cleanup();1222 defer tmp.cleanup();
12181223
1219 // Symlink to a file1224 // Symlink to a file
1220 try tmp.dir.writeFile(.{ .sub_path = "file", .data = "" });1225 try tmp.dir.writeFile(io, .{ .sub_path = "file", .data = "" });
1221 try setupSymlink(tmp.dir, "file", "filelink", .{});1226 try setupSymlink(tmp.dir, "file", "filelink", .{});
12221227
1223 try tmp.dir.deleteTree("filelink");1228 try tmp.dir.deleteTree("filelink");
...@@ -1241,11 +1246,11 @@ test "makePath, put some files in it, deleteTree" {...@@ -1241,11 +1246,11 @@ test "makePath, put some files in it, deleteTree" {
1241 const dir_path = try ctx.transformPath("os_test_tmp");1246 const dir_path = try ctx.transformPath("os_test_tmp");
12421247
1243 try ctx.dir.makePath(io, try fs.path.join(allocator, &.{ "os_test_tmp", "b", "c" }));1248 try ctx.dir.makePath(io, try fs.path.join(allocator, &.{ "os_test_tmp", "b", "c" }));
1244 try ctx.dir.writeFile(.{1249 try ctx.dir.writeFile(io, .{
1245 .sub_path = try fs.path.join(allocator, &.{ "os_test_tmp", "b", "c", "file.txt" }),1250 .sub_path = try fs.path.join(allocator, &.{ "os_test_tmp", "b", "c", "file.txt" }),
1246 .data = "nonsense",1251 .data = "nonsense",
1247 });1252 });
1248 try ctx.dir.writeFile(.{1253 try ctx.dir.writeFile(io, .{
1249 .sub_path = try fs.path.join(allocator, &.{ "os_test_tmp", "b", "file2.txt" }),1254 .sub_path = try fs.path.join(allocator, &.{ "os_test_tmp", "b", "file2.txt" }),
1250 .data = "blah",1255 .data = "blah",
1251 });1256 });
...@@ -1264,11 +1269,11 @@ test "makePath, put some files in it, deleteTreeMinStackSize" {...@@ -1264,11 +1269,11 @@ test "makePath, put some files in it, deleteTreeMinStackSize" {
1264 const dir_path = try ctx.transformPath("os_test_tmp");1269 const dir_path = try ctx.transformPath("os_test_tmp");
12651270
1266 try ctx.dir.makePath(io, try fs.path.join(allocator, &.{ "os_test_tmp", "b", "c" }));1271 try ctx.dir.makePath(io, try fs.path.join(allocator, &.{ "os_test_tmp", "b", "c" }));
1267 try ctx.dir.writeFile(.{1272 try ctx.dir.writeFile(io, .{
1268 .sub_path = try fs.path.join(allocator, &.{ "os_test_tmp", "b", "c", "file.txt" }),1273 .sub_path = try fs.path.join(allocator, &.{ "os_test_tmp", "b", "c", "file.txt" }),
1269 .data = "nonsense",1274 .data = "nonsense",
1270 });1275 });
1271 try ctx.dir.writeFile(.{1276 try ctx.dir.writeFile(io, .{
1272 .sub_path = try fs.path.join(allocator, &.{ "os_test_tmp", "b", "file2.txt" }),1277 .sub_path = try fs.path.join(allocator, &.{ "os_test_tmp", "b", "file2.txt" }),
1273 .data = "blah",1278 .data = "blah",
1274 });1279 });
...@@ -1298,7 +1303,7 @@ test "makePath but sub_path contains pre-existing file" {...@@ -1298,7 +1303,7 @@ test "makePath but sub_path contains pre-existing file" {
1298 defer tmp.cleanup();1303 defer tmp.cleanup();
12991304
1300 try tmp.dir.makeDir("foo");1305 try tmp.dir.makeDir("foo");
1301 try tmp.dir.writeFile(.{ .sub_path = "foo/bar", .data = "" });1306 try tmp.dir.writeFile(io, .{ .sub_path = "foo/bar", .data = "" });
13021307
1303 try testing.expectError(error.NotDir, tmp.dir.makePath(io, "foo/bar/baz"));1308 try testing.expectError(error.NotDir, tmp.dir.makePath(io, "foo/bar/baz"));
1304}1309}
...@@ -1400,7 +1405,7 @@ fn testFilenameLimits(io: Io, iterable_dir: Dir, maxed_filename: []const u8) !vo...@@ -1400,7 +1405,7 @@ fn testFilenameLimits(io: Io, iterable_dir: Dir, maxed_filename: []const u8) !vo
1400 var maxed_dir = try iterable_dir.makeOpenPath(maxed_filename, .{});1405 var maxed_dir = try iterable_dir.makeOpenPath(maxed_filename, .{});
1401 defer maxed_dir.close(io);1406 defer maxed_dir.close(io);
14021407
1403 try maxed_dir.writeFile(.{ .sub_path = maxed_filename, .data = "" });1408 try maxed_dir.writeFile(io, .{ .sub_path = maxed_filename, .data = "" });
14041409
1405 var walker = try iterable_dir.walk(testing.allocator);1410 var walker = try iterable_dir.walk(testing.allocator);
1406 defer walker.deinit();1411 defer walker.deinit();
...@@ -1513,7 +1518,7 @@ test "setEndPos" {...@@ -1513,7 +1518,7 @@ test "setEndPos" {
1513 defer tmp.cleanup();1518 defer tmp.cleanup();
15141519
1515 const file_name = "afile.txt";1520 const file_name = "afile.txt";
1516 try tmp.dir.writeFile(.{ .sub_path = file_name, .data = "ninebytes" });1521 try tmp.dir.writeFile(io, .{ .sub_path = file_name, .data = "ninebytes" });
1517 const f = try tmp.dir.openFile(io, file_name, .{ .mode = .read_write });1522 const f = try tmp.dir.openFile(io, file_name, .{ .mode = .read_write });
1518 defer f.close(io);1523 defer f.close(io);
15191524
...@@ -1563,7 +1568,7 @@ test "access file" {...@@ -1563,7 +1568,7 @@ test "access file" {
1563 try ctx.dir.makePath(io, dir_path);1568 try ctx.dir.makePath(io, dir_path);
1564 try testing.expectError(error.FileNotFound, ctx.dir.access(io, file_path, .{}));1569 try testing.expectError(error.FileNotFound, ctx.dir.access(io, file_path, .{}));
15651570
1566 try ctx.dir.writeFile(.{ .sub_path = file_path, .data = "" });1571 try ctx.dir.writeFile(io, .{ .sub_path = file_path, .data = "" });
1567 try ctx.dir.access(io, file_path, .{});1572 try ctx.dir.access(io, file_path, .{});
1568 try ctx.dir.deleteTree(dir_path);1573 try ctx.dir.deleteTree(dir_path);
1569 }1574 }
...@@ -1659,12 +1664,13 @@ test "sendfile with buffered data" {...@@ -1659,12 +1664,13 @@ test "sendfile with buffered data" {
1659test "copyFile" {1664test "copyFile" {
1660 try testWithAllSupportedPathTypes(struct {1665 try testWithAllSupportedPathTypes(struct {
1661 fn impl(ctx: *TestContext) !void {1666 fn impl(ctx: *TestContext) !void {
1667 const io = ctx.io;
1662 const data = "u6wj+JmdF3qHsFPE BUlH2g4gJCmEz0PP";1668 const data = "u6wj+JmdF3qHsFPE BUlH2g4gJCmEz0PP";
1663 const src_file = try ctx.transformPath("tmp_test_copy_file.txt");1669 const src_file = try ctx.transformPath("tmp_test_copy_file.txt");
1664 const dest_file = try ctx.transformPath("tmp_test_copy_file2.txt");1670 const dest_file = try ctx.transformPath("tmp_test_copy_file2.txt");
1665 const dest_file2 = try ctx.transformPath("tmp_test_copy_file3.txt");1671 const dest_file2 = try ctx.transformPath("tmp_test_copy_file3.txt");
16661672
1667 try ctx.dir.writeFile(.{ .sub_path = src_file, .data = data });1673 try ctx.dir.writeFile(io, .{ .sub_path = src_file, .data = data });
1668 defer ctx.dir.deleteFile(src_file) catch {};1674 defer ctx.dir.deleteFile(src_file) catch {};
16691675
1670 try ctx.dir.copyFile(src_file, ctx.dir, dest_file, .{});1676 try ctx.dir.copyFile(src_file, ctx.dir, dest_file, .{});
...@@ -2050,7 +2056,7 @@ test "'.' and '..' in Io.Dir functions" {...@@ -2050,7 +2056,7 @@ test "'.' and '..' in Io.Dir functions" {
2050 renamed_file.close(io);2056 renamed_file.close(io);
2051 try ctx.dir.deleteFile(rename_path);2057 try ctx.dir.deleteFile(rename_path);
20522058
2053 try ctx.dir.writeFile(.{ .sub_path = update_path, .data = "something" });2059 try ctx.dir.writeFile(io, .{ .sub_path = update_path, .data = "something" });
2054 var dir = ctx.dir;2060 var dir = ctx.dir;
2055 const prev_status = try dir.updateFile(io, file_path, dir, update_path, .{});2061 const prev_status = try dir.updateFile(io, file_path, dir, update_path, .{});
2056 try testing.expectEqual(Io.Dir.PrevStatus.stale, prev_status);2062 try testing.expectEqual(Io.Dir.PrevStatus.stale, prev_status);
...@@ -2187,7 +2193,7 @@ test "invalid UTF-8/WTF-8 paths" {...@@ -2187,7 +2193,7 @@ test "invalid UTF-8/WTF-8 paths" {
2187 try testing.expectError(expected_err, ctx.dir.deleteTree(invalid_path));2193 try testing.expectError(expected_err, ctx.dir.deleteTree(invalid_path));
2188 try testing.expectError(expected_err, ctx.dir.deleteTreeMinStackSize(invalid_path));2194 try testing.expectError(expected_err, ctx.dir.deleteTreeMinStackSize(invalid_path));
21892195
2190 try testing.expectError(expected_err, ctx.dir.writeFile(.{ .sub_path = invalid_path, .data = "" }));2196 try testing.expectError(expected_err, ctx.dir.writeFile(io, .{ .sub_path = invalid_path, .data = "" }));
21912197
2192 try testing.expectError(expected_err, ctx.dir.access(invalid_path, .{}));2198 try testing.expectError(expected_err, ctx.dir.access(invalid_path, .{}));
21932199
...@@ -2304,7 +2310,7 @@ test "seekBy" {...@@ -2304,7 +2310,7 @@ test "seekBy" {
2304 var tmp_dir = testing.tmpDir(.{});2310 var tmp_dir = testing.tmpDir(.{});
2305 defer tmp_dir.cleanup();2311 defer tmp_dir.cleanup();
23062312
2307 try tmp_dir.dir.writeFile(.{ .sub_path = "blah.txt", .data = "let's test seekBy" });2313 try tmp_dir.dir.writeFile(io, .{ .sub_path = "blah.txt", .data = "let's test seekBy" });
2308 const f = try tmp_dir.dir.openFile(io, "blah.txt", .{ .mode = .read_only });2314 const f = try tmp_dir.dir.openFile(io, "blah.txt", .{ .mode = .read_only });
2309 defer f.close(io);2315 defer f.close(io);
2310 var reader = f.readerStreaming(io, &.{});2316 var reader = f.readerStreaming(io, &.{});
...@@ -2350,7 +2356,7 @@ test "File.Writer sendfile with buffered contents" {...@@ -2350,7 +2356,7 @@ test "File.Writer sendfile with buffered contents" {
2350 defer tmp_dir.cleanup();2356 defer tmp_dir.cleanup();
23512357
2352 {2358 {
2353 try tmp_dir.dir.writeFile(.{ .sub_path = "a", .data = "bcd" });2359 try tmp_dir.dir.writeFile(io, .{ .sub_path = "a", .data = "bcd" });
2354 const in = try tmp_dir.dir.openFile(io, "a", .{});2360 const in = try tmp_dir.dir.openFile(io, "a", .{});
2355 defer in.close(io);2361 defer in.close(io);
2356 const out = try tmp_dir.dir.createFile(io, "b", .{});2362 const out = try tmp_dir.dir.createFile(io, "b", .{});
...@@ -2391,11 +2397,13 @@ fn testReadlink(target_path: []const u8, symlink_path: []const u8) !void {...@@ -2391,11 +2397,13 @@ fn testReadlink(target_path: []const u8, symlink_path: []const u8) !void {
2391}2397}
23922398
2393test "readlinkat" {2399test "readlinkat" {
2400 const io = testing.io;
2401
2394 var tmp = tmpDir(.{});2402 var tmp = tmpDir(.{});
2395 defer tmp.cleanup();2403 defer tmp.cleanup();
23962404
2397 // create file2405 // create file
2398 try tmp.dir.writeFile(.{ .sub_path = "file.txt", .data = "nonsense" });2406 try tmp.dir.writeFile(io, .{ .sub_path = "file.txt", .data = "nonsense" });
23992407
2400 // create a symbolic link2408 // create a symbolic link
2401 if (native_os == .windows) {2409 if (native_os == .windows) {
lib/std/posix/test.zig+1-1
...@@ -145,7 +145,7 @@ test "linkat with different directories" {...@@ -145,7 +145,7 @@ test "linkat with different directories" {
145 const subdir = try tmp.dir.makeOpenPath("subdir", .{});145 const subdir = try tmp.dir.makeOpenPath("subdir", .{});
146146
147 defer tmp.dir.deleteFile(target_name) catch {};147 defer tmp.dir.deleteFile(target_name) catch {};
148 try tmp.dir.writeFile(.{ .sub_path = target_name, .data = "example" });148 try tmp.dir.writeFile(io, .{ .sub_path = target_name, .data = "example" });
149149
150 // Test 1: link from file in subdir back up to target in parent directory150 // Test 1: link from file in subdir back up to target in parent directory
151 try posix.linkat(tmp.dir.handle, target_name, subdir.handle, link_name, 0);151 try posix.linkat(tmp.dir.handle, target_name, subdir.handle, link_name, 0);
src/Compilation.zig+2-2
...@@ -5715,7 +5715,7 @@ pub fn translateC(...@@ -5715,7 +5715,7 @@ pub fn translateC(
5715 const out_h_sub_path = tmp_sub_path ++ fs.path.sep_str ++ cimport_basename;5715 const out_h_sub_path = tmp_sub_path ++ fs.path.sep_str ++ cimport_basename;
5716 const out_h_path = try comp.dirs.local_cache.join(arena, &.{out_h_sub_path});5716 const out_h_path = try comp.dirs.local_cache.join(arena, &.{out_h_sub_path});
5717 if (comp.verbose_cimport) log.info("writing C import source to {s}", .{out_h_path});5717 if (comp.verbose_cimport) log.info("writing C import source to {s}", .{out_h_path});
5718 try cache_dir.writeFile(.{ .sub_path = out_h_sub_path, .data = c_src });5718 try cache_dir.writeFile(io, .{ .sub_path = out_h_sub_path, .data = c_src });
5719 break :path out_h_path;5719 break :path out_h_path;
5720 },5720 },
5721 .path => |p| p,5721 .path => |p| p,
...@@ -6572,7 +6572,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32...@@ -6572,7 +6572,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
6572 resource_id, resource_type, fmtRcEscape(src_path),6572 resource_id, resource_type, fmtRcEscape(src_path),
6573 });6573 });
65746574
6575 try o_dir.writeFile(.{ .sub_path = rc_basename, .data = input });6575 try o_dir.writeFile(io, .{ .sub_path = rc_basename, .data = input });
65766576
6577 var argv = std.array_list.Managed([]const u8).init(comp.gpa);6577 var argv = std.array_list.Managed([]const u8).init(comp.gpa);
6578 defer argv.deinit();6578 defer argv.deinit();
src/libs/freebsd.zig+2-2
...@@ -520,7 +520,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -520,7 +520,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
520 for (metadata.all_versions[0 .. target_ver_index + 1]) |ver| {520 for (metadata.all_versions[0 .. target_ver_index + 1]) |ver| {
521 try map_contents.print("FBSD_{d}.{d} {{ }};\n", .{ ver.major, ver.minor });521 try map_contents.print("FBSD_{d}.{d} {{ }};\n", .{ ver.major, ver.minor });
522 }522 }
523 try o_directory.handle.writeFile(.{ .sub_path = all_map_basename, .data = map_contents.items });523 try o_directory.handle.writeFile(io, .{ .sub_path = all_map_basename, .data = map_contents.items });
524 map_contents.deinit();524 map_contents.deinit();
525 }525 }
526526
...@@ -974,7 +974,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -974,7 +974,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
974974
975 var lib_name_buf: [32]u8 = undefined; // Larger than each of the names "c", "stdthreads", etc.975 var lib_name_buf: [32]u8 = undefined; // Larger than each of the names "c", "stdthreads", etc.
976 const asm_file_basename = std.fmt.bufPrint(&lib_name_buf, "{s}.s", .{lib.name}) catch unreachable;976 const asm_file_basename = std.fmt.bufPrint(&lib_name_buf, "{s}.s", .{lib.name}) catch unreachable;
977 try o_directory.handle.writeFile(.{ .sub_path = asm_file_basename, .data = stubs_asm.items });977 try o_directory.handle.writeFile(io, .{ .sub_path = asm_file_basename, .data = stubs_asm.items });
978 try buildSharedLib(comp, arena, o_directory, asm_file_basename, lib, prog_node);978 try buildSharedLib(comp, arena, o_directory, asm_file_basename, lib, prog_node);
979 }979 }
980980
src/libs/glibc.zig+2-2
...@@ -759,7 +759,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -759,7 +759,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
759 try map_contents.print("GLIBC_{d}.{d}.{d} {{ }};\n", .{ ver.major, ver.minor, ver.patch });759 try map_contents.print("GLIBC_{d}.{d}.{d} {{ }};\n", .{ ver.major, ver.minor, ver.patch });
760 }760 }
761 }761 }
762 try o_directory.handle.writeFile(.{ .sub_path = all_map_basename, .data = map_contents.items });762 try o_directory.handle.writeFile(io, .{ .sub_path = all_map_basename, .data = map_contents.items });
763 map_contents.deinit(); // The most recent allocation of an arena can be freed :)763 map_contents.deinit(); // The most recent allocation of an arena can be freed :)
764 }764 }
765765
...@@ -1118,7 +1118,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -1118,7 +1118,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
11181118
1119 var lib_name_buf: [32]u8 = undefined; // Larger than each of the names "c", "pthread", etc.1119 var lib_name_buf: [32]u8 = undefined; // Larger than each of the names "c", "pthread", etc.
1120 const asm_file_basename = std.fmt.bufPrint(&lib_name_buf, "{s}.s", .{lib.name}) catch unreachable;1120 const asm_file_basename = std.fmt.bufPrint(&lib_name_buf, "{s}.s", .{lib.name}) catch unreachable;
1121 try o_directory.handle.writeFile(.{ .sub_path = asm_file_basename, .data = stubs_asm.items });1121 try o_directory.handle.writeFile(io, .{ .sub_path = asm_file_basename, .data = stubs_asm.items });
1122 try buildSharedLib(comp, arena, o_directory, asm_file_basename, lib, prog_node);1122 try buildSharedLib(comp, arena, o_directory, asm_file_basename, lib, prog_node);
1123 }1123 }
11241124
src/libs/netbsd.zig+1-1
...@@ -628,7 +628,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -628,7 +628,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
628628
629 var lib_name_buf: [32]u8 = undefined; // Larger than each of the names "c", "pthread", etc.629 var lib_name_buf: [32]u8 = undefined; // Larger than each of the names "c", "pthread", etc.
630 const asm_file_basename = std.fmt.bufPrint(&lib_name_buf, "{s}.s", .{lib.name}) catch unreachable;630 const asm_file_basename = std.fmt.bufPrint(&lib_name_buf, "{s}.s", .{lib.name}) catch unreachable;
631 try o_directory.handle.writeFile(.{ .sub_path = asm_file_basename, .data = stubs_asm.items });631 try o_directory.handle.writeFile(io, .{ .sub_path = asm_file_basename, .data = stubs_asm.items });
632 try buildSharedLib(comp, arena, o_directory, asm_file_basename, lib, prog_node);632 try buildSharedLib(comp, arena, o_directory, asm_file_basename, lib, prog_node);
633 }633 }
634634
src/main.zig+3-3
...@@ -7164,7 +7164,7 @@ fn cmdFetch(...@@ -7164,7 +7164,7 @@ fn cmdFetch(
7164 try ast.render(gpa, &aw.writer, fixups);7164 try ast.render(gpa, &aw.writer, fixups);
7165 const rendered = aw.written();7165 const rendered = aw.written();
71667166
7167 build_root.directory.handle.writeFile(.{ .sub_path = Package.Manifest.basename, .data = rendered }) catch |err| {7167 build_root.directory.handle.writeFile(io, .{ .sub_path = Package.Manifest.basename, .data = rendered }) catch |err| {
7168 fatal("unable to write {s} file: {t}", .{ Package.Manifest.basename, err });7168 fatal("unable to write {s} file: {t}", .{ Package.Manifest.basename, err });
7169 };7169 };
71707170
...@@ -7207,7 +7207,7 @@ fn createDependenciesModule(...@@ -7207,7 +7207,7 @@ fn createDependenciesModule(
7207 {7207 {
7208 var tmp_dir = try dirs.local_cache.handle.makeOpenPath(tmp_dir_sub_path, .{});7208 var tmp_dir = try dirs.local_cache.handle.makeOpenPath(tmp_dir_sub_path, .{});
7209 defer tmp_dir.close(io);7209 defer tmp_dir.close(io);
7210 try tmp_dir.writeFile(.{ .sub_path = basename, .data = source });7210 try tmp_dir.writeFile(io, .{ .sub_path = basename, .data = source });
7211 }7211 }
72127212
7213 var hh: Cache.HashHelper = .{};7213 var hh: Cache.HashHelper = .{};
...@@ -7438,7 +7438,7 @@ const Templates = struct {...@@ -7438,7 +7438,7 @@ const Templates = struct {
7438 i += 1;7438 i += 1;
7439 }7439 }
74407440
7441 return out_dir.writeFile(.{7441 return out_dir.writeFile(io, .{
7442 .sub_path = template_path,7442 .sub_path = template_path,
7443 .data = templates.buffer.items,7443 .data = templates.buffer.items,
7444 .flags = .{ .exclusive = true },7444 .flags = .{ .exclusive = true },