aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Build/Cache/Path.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-06-27 20:05:22 -0700
committerAndrew Kelley <andrew@ziglang.org>2025-07-07 22:43:51 -0700
commit0e37ff0d591dd75ceec9208196bec29efaec607a (patch)
treec126fa823a1f3864e9c363aac70e3a3db0219957 /lib/std/Build/Cache/Path.zig
parent0b3f0124dc33403d329fb8ee63a93215d9af1f1e (diff)
downloadzig-0e37ff0d591dd75ceec9208196bec29efaec607a.tar.gz
zig-0e37ff0d591dd75ceec9208196bec29efaec607a.zip
std.fmt: breaking API changes
added adapter to AnyWriter and GenericWriter to help bridge the gap between old and new API make std.testing.expectFmt work at compile-time std.fmt no longer has a dependency on std.unicode. Formatted printing was never properly unicode-aware. Now it no longer pretends to be. Breakage/deprecations: * std.fs.File.reader -> std.fs.File.deprecatedReader * std.fs.File.writer -> std.fs.File.deprecatedWriter * std.io.GenericReader -> std.io.Reader * std.io.GenericWriter -> std.io.Writer * std.io.AnyReader -> std.io.Reader * std.io.AnyWriter -> std.io.Writer * std.fmt.format -> std.fmt.deprecatedFormat * std.fmt.fmtSliceEscapeLower -> std.ascii.hexEscape * std.fmt.fmtSliceEscapeUpper -> std.ascii.hexEscape * std.fmt.fmtSliceHexLower -> {x} * std.fmt.fmtSliceHexUpper -> {X} * std.fmt.fmtIntSizeDec -> {B} * std.fmt.fmtIntSizeBin -> {Bi} * std.fmt.fmtDuration -> {D} * std.fmt.fmtDurationSigned -> {D} * {} -> {f} when there is a format method * format method signature - anytype -> *std.io.Writer - inferred error set -> error{WriteFailed} - options -> (deleted) * std.fmt.Formatted - now takes context type explicitly - no fmt string
Diffstat (limited to 'lib/std/Build/Cache/Path.zig')
-rw-r--r--lib/std/Build/Cache/Path.zig45
1 files changed, 20 insertions, 25 deletions
diff --git a/lib/std/Build/Cache/Path.zig b/lib/std/Build/Cache/Path.zig
index 8822fb64be..55af4fdbfa 100644
--- a/lib/std/Build/Cache/Path.zig
+++ b/lib/std/Build/Cache/Path.zig
@@ -1,3 +1,10 @@
+const Path = @This();
+const std = @import("../../std.zig");
+const assert = std.debug.assert;
+const fs = std.fs;
+const Allocator = std.mem.Allocator;
+const Cache = std.Build.Cache;
+
root_dir: Cache.Directory,
/// The path, relative to the root dir, that this `Path` represents.
/// Empty string means the root_dir is the path.
@@ -133,38 +140,32 @@ pub fn makePath(p: Path, sub_path: []const u8) !void {
}
pub fn toString(p: Path, allocator: Allocator) Allocator.Error![]u8 {
- return std.fmt.allocPrint(allocator, "{}", .{p});
+ return std.fmt.allocPrint(allocator, "{f}", .{p});
}
pub fn toStringZ(p: Path, allocator: Allocator) Allocator.Error![:0]u8 {
- return std.fmt.allocPrintZ(allocator, "{}", .{p});
+ return std.fmt.allocPrintSentinel(allocator, "{f}", .{p}, 0);
}
-pub fn format(
- self: Path,
- comptime fmt_string: []const u8,
- options: std.fmt.FormatOptions,
- writer: anytype,
-) !void {
- if (fmt_string.len == 1) {
+pub fn format(self: Path, writer: *std.io.Writer, comptime f: []const u8) std.io.Writer.Error!void {
+ if (f.len == 1) {
// Quote-escape the string.
- const stringEscape = std.zig.stringEscape;
- const f = switch (fmt_string[0]) {
- 'q' => "",
- '\'' => "\'",
- else => @compileError("unsupported format string: " ++ fmt_string),
+ const zigEscape = switch (f[0]) {
+ 'q' => std.zig.stringEscape,
+ '\'' => std.zig.charEscape,
+ else => @compileError("unsupported format string: " ++ f),
};
if (self.root_dir.path) |p| {
- try stringEscape(p, f, options, writer);
- if (self.sub_path.len > 0) try stringEscape(fs.path.sep_str, f, options, writer);
+ try zigEscape(p, writer);
+ if (self.sub_path.len > 0) try zigEscape(fs.path.sep_str, writer);
}
if (self.sub_path.len > 0) {
- try stringEscape(self.sub_path, f, options, writer);
+ try zigEscape(self.sub_path, writer);
}
return;
}
- if (fmt_string.len > 0)
- std.fmt.invalidFmtError(fmt_string, self);
+ if (f.len > 0)
+ std.fmt.invalidFmtError(f, self);
if (std.fs.path.isAbsolute(self.sub_path)) {
try writer.writeAll(self.sub_path);
return;
@@ -223,9 +224,3 @@ pub const TableAdapter = struct {
return a.eql(b);
}
};
-
-const Path = @This();
-const std = @import("../../std.zig");
-const fs = std.fs;
-const Allocator = std.mem.Allocator;
-const Cache = std.Build.Cache;