aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Build/Cache
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-10-10 22:30:04 -0700
committerGitHub <noreply@github.com>2024-10-10 22:30:04 -0700
commit1340565e22e154db41e90a8d4f0b552176711ba0 (patch)
tree0fcb0dde8105082065f46d1f477c97903f69b7e5 /lib/std/Build/Cache
parent92ae5818d26925af7816fabcaec85236133b9e46 (diff)
parent2857a3bcb61ad8f119f46acf3a76fd70195f9bd5 (diff)
downloadzig-1340565e22e154db41e90a8d4f0b552176711ba0.tar.gz
zig-1340565e22e154db41e90a8d4f0b552176711ba0.zip
Merge pull request #21654 from ziglang/embrace-path-abstraction
link: fix false positive crtbegin/crtend detection
Diffstat (limited to 'lib/std/Build/Cache')
-rw-r--r--lib/std/Build/Cache/Path.zig24
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/std/Build/Cache/Path.zig b/lib/std/Build/Cache/Path.zig
index ee0666b70a..a14c6cd7a4 100644
--- a/lib/std/Build/Cache/Path.zig
+++ b/lib/std/Build/Cache/Path.zig
@@ -11,7 +11,11 @@ pub fn clone(p: Path, arena: Allocator) Allocator.Error!Path {
}
pub fn cwd() Path {
- return .{ .root_dir = Cache.Directory.cwd() };
+ return initCwd("");
+}
+
+pub fn initCwd(sub_path: []const u8) Path {
+ return .{ .root_dir = Cache.Directory.cwd(), .sub_path = sub_path };
}
pub fn join(p: Path, arena: Allocator, sub_path: []const u8) Allocator.Error!Path {
@@ -126,6 +130,14 @@ pub fn makePath(p: Path, sub_path: []const u8) !void {
return p.root_dir.handle.makePath(joined_path);
}
+pub fn toString(p: Path, allocator: Allocator) Allocator.Error![]u8 {
+ return std.fmt.allocPrint(allocator, "{}", .{p});
+}
+
+pub fn toStringZ(p: Path, allocator: Allocator) Allocator.Error![:0]u8 {
+ return std.fmt.allocPrintZ(allocator, "{}", .{p});
+}
+
pub fn format(
self: Path,
comptime fmt_string: []const u8,
@@ -137,7 +149,7 @@ pub fn format(
const stringEscape = std.zig.stringEscape;
const f = switch (fmt_string[0]) {
'q' => "",
- '\'' => '\'',
+ '\'' => "\'",
else => @compileError("unsupported format string: " ++ fmt_string),
};
if (self.root_dir.path) |p| {
@@ -182,6 +194,14 @@ pub fn subPathOrDot(self: Path) []const u8 {
return if (self.sub_path.len == 0) "." else self.sub_path;
}
+pub fn stem(p: Path) []const u8 {
+ return fs.path.stem(p.sub_path);
+}
+
+pub fn basename(p: Path) []const u8 {
+ return fs.path.basename(p.sub_path);
+}
+
/// Useful to make `Path` a key in `std.ArrayHashMap`.
pub const TableAdapter = struct {
pub const Hash = std.hash.Wyhash;