aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Build/Cache
diff options
context:
space:
mode:
authorAndrew Kelley <andrewrk@noreply.codeberg.org>2025-12-27 14:10:46 +0100
committerAndrew Kelley <andrewrk@noreply.codeberg.org>2025-12-27 14:10:46 +0100
commite55e6b5528bb2f01de242fcf32b172e244e98e74 (patch)
tree3a5eb3193d3d192c54ab0c2b7295a7f21861c27e /lib/std/Build/Cache
parentc3f2de5e519926eb0029062fe8e782a6f9df9c05 (diff)
parent60a1ba0a8f3517356fa2941462f002a7f580545b (diff)
downloadzig-e55e6b5528bb2f01de242fcf32b172e244e98e74.tar.gz
zig-e55e6b5528bb2f01de242fcf32b172e244e98e74.zip
Merge pull request 'std: migrate all `fs` APIs to `Io`' (#30232) from std.Io-fs into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30232
Diffstat (limited to 'lib/std/Build/Cache')
-rw-r--r--lib/std/Build/Cache/Directory.zig14
-rw-r--r--lib/std/Build/Cache/Path.zig46
2 files changed, 30 insertions, 30 deletions
diff --git a/lib/std/Build/Cache/Directory.zig b/lib/std/Build/Cache/Directory.zig
index a105a91ed6..ce5f5b02bb 100644
--- a/lib/std/Build/Cache/Directory.zig
+++ b/lib/std/Build/Cache/Directory.zig
@@ -1,7 +1,9 @@
const Directory = @This();
+
const std = @import("../../std.zig");
-const assert = std.debug.assert;
+const Io = std.Io;
const fs = std.fs;
+const assert = std.debug.assert;
const fmt = std.fmt;
const Allocator = std.mem.Allocator;
@@ -9,7 +11,7 @@ const Allocator = std.mem.Allocator;
/// directly, but it is needed when passing the directory to a child process.
/// `null` means cwd.
path: ?[]const u8,
-handle: fs.Dir,
+handle: Io.Dir,
pub fn clone(d: Directory, arena: Allocator) Allocator.Error!Directory {
return .{
@@ -21,7 +23,7 @@ pub fn clone(d: Directory, arena: Allocator) Allocator.Error!Directory {
pub fn cwd() Directory {
return .{
.path = null,
- .handle = fs.cwd(),
+ .handle = .cwd(),
};
}
@@ -50,8 +52,8 @@ pub fn joinZ(self: Directory, allocator: Allocator, paths: []const []const u8) !
/// Whether or not the handle should be closed, or the path should be freed
/// is determined by usage, however this function is provided for convenience
/// if it happens to be what the caller needs.
-pub fn closeAndFree(self: *Directory, gpa: Allocator) void {
- self.handle.close();
+pub fn closeAndFree(self: *Directory, gpa: Allocator, io: Io) void {
+ self.handle.close(io);
if (self.path) |p| gpa.free(p);
self.* = undefined;
}
@@ -64,5 +66,5 @@ pub fn format(self: Directory, writer: *std.Io.Writer) std.Io.Writer.Error!void
}
pub fn eql(self: Directory, other: Directory) bool {
- return self.handle.fd == other.handle.fd;
+ return self.handle.handle == other.handle.handle;
}
diff --git a/lib/std/Build/Cache/Path.zig b/lib/std/Build/Cache/Path.zig
index 92290cfdf4..2b7814c544 100644
--- a/lib/std/Build/Cache/Path.zig
+++ b/lib/std/Build/Cache/Path.zig
@@ -2,8 +2,8 @@ const Path = @This();
const std = @import("../../std.zig");
const Io = std.Io;
-const assert = std.debug.assert;
const fs = std.fs;
+const assert = std.debug.assert;
const Allocator = std.mem.Allocator;
const Cache = std.Build.Cache;
@@ -59,58 +59,56 @@ pub fn joinStringZ(p: Path, gpa: Allocator, sub_path: []const u8) Allocator.Erro
return p.root_dir.joinZ(gpa, parts);
}
-pub fn openFile(
- p: Path,
- sub_path: []const u8,
- flags: fs.File.OpenFlags,
-) !fs.File {
+pub fn openFile(p: Path, io: Io, sub_path: []const u8, flags: Io.File.OpenFlags) !Io.File {
var buf: [fs.max_path_bytes]u8 = undefined;
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
p.sub_path, sub_path,
}) catch return error.NameTooLong;
};
- return p.root_dir.handle.openFile(joined_path, flags);
+ return p.root_dir.handle.openFile(io, joined_path, flags);
}
pub fn openDir(
p: Path,
+ io: Io,
sub_path: []const u8,
- args: fs.Dir.OpenOptions,
-) fs.Dir.OpenError!fs.Dir {
+ args: Io.Dir.OpenOptions,
+) Io.Dir.OpenError!Io.Dir {
var buf: [fs.max_path_bytes]u8 = undefined;
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
p.sub_path, sub_path,
}) catch return error.NameTooLong;
};
- return p.root_dir.handle.openDir(joined_path, args);
+ return p.root_dir.handle.openDir(io, joined_path, args);
}
-pub fn makeOpenPath(p: Path, sub_path: []const u8, opts: fs.Dir.OpenOptions) !fs.Dir {
+pub fn createDirPathOpen(p: Path, io: Io, sub_path: []const u8, opts: Io.Dir.OpenOptions) !Io.Dir {
var buf: [fs.max_path_bytes]u8 = undefined;
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
p.sub_path, sub_path,
}) catch return error.NameTooLong;
};
- return p.root_dir.handle.makeOpenPath(joined_path, opts);
+ return p.root_dir.handle.createDirPathOpen(io, joined_path, opts);
}
-pub fn statFile(p: Path, sub_path: []const u8) !fs.Dir.Stat {
+pub fn statFile(p: Path, io: Io, sub_path: []const u8) !Io.Dir.Stat {
var buf: [fs.max_path_bytes]u8 = undefined;
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
p.sub_path, sub_path,
}) catch return error.NameTooLong;
};
- return p.root_dir.handle.statFile(joined_path);
+ return p.root_dir.handle.statFile(io, joined_path, .{});
}
pub fn atomicFile(
p: Path,
+ io: Io,
sub_path: []const u8,
- options: fs.Dir.AtomicFileOptions,
+ options: Io.Dir.AtomicFileOptions,
buf: *[fs.max_path_bytes]u8,
) !fs.AtomicFile {
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
@@ -118,27 +116,27 @@ pub fn atomicFile(
p.sub_path, sub_path,
}) catch return error.NameTooLong;
};
- return p.root_dir.handle.atomicFile(joined_path, options);
+ return p.root_dir.handle.atomicFile(io, joined_path, options);
}
-pub fn access(p: Path, sub_path: []const u8, flags: Io.Dir.AccessOptions) !void {
+pub fn access(p: Path, io: Io, sub_path: []const u8, flags: Io.Dir.AccessOptions) !void {
var buf: [fs.max_path_bytes]u8 = undefined;
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
p.sub_path, sub_path,
}) catch return error.NameTooLong;
};
- return p.root_dir.handle.access(joined_path, flags);
+ return p.root_dir.handle.access(io, joined_path, flags);
}
-pub fn makePath(p: Path, sub_path: []const u8) !void {
+pub fn createDirPath(p: Path, io: Io, sub_path: []const u8) !void {
var buf: [fs.max_path_bytes]u8 = undefined;
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
p.sub_path, sub_path,
}) catch return error.NameTooLong;
};
- return p.root_dir.handle.makePath(joined_path);
+ return p.root_dir.handle.createDirPath(io, joined_path);
}
pub fn toString(p: Path, allocator: Allocator) Allocator.Error![]u8 {
@@ -180,7 +178,7 @@ pub fn formatEscapeChar(path: Path, writer: *Io.Writer) Io.Writer.Error!void {
}
pub fn format(self: Path, writer: *Io.Writer) Io.Writer.Error!void {
- if (std.fs.path.isAbsolute(self.sub_path)) {
+ if (fs.path.isAbsolute(self.sub_path)) {
try writer.writeAll(self.sub_path);
return;
}
@@ -225,9 +223,9 @@ pub const TableAdapter = struct {
pub fn hash(self: TableAdapter, a: Cache.Path) u32 {
_ = self;
- const seed = switch (@typeInfo(@TypeOf(a.root_dir.handle.fd))) {
- .pointer => @intFromPtr(a.root_dir.handle.fd),
- .int => @as(u32, @bitCast(a.root_dir.handle.fd)),
+ const seed = switch (@typeInfo(@TypeOf(a.root_dir.handle.handle))) {
+ .pointer => @intFromPtr(a.root_dir.handle.handle),
+ .int => @as(u32, @bitCast(a.root_dir.handle.handle)),
else => @compileError("unimplemented hash function"),
};
return @truncate(Hash.hash(seed, a.sub_path));