aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Build/Cache/Path.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-10-10 00:41:58 -0700
committerAndrew Kelley <andrew@ziglang.org>2024-10-10 14:21:52 -0700
commit14c8e270bb47c4e10ee3392661d4c62ab5c2f89d (patch)
treec74fe79e74d3fc6bff7dd61f372153906e29e040 /lib/std/Build/Cache/Path.zig
parent58349b2c8ebc57718bbfbf939c30b586d5c85466 (diff)
downloadzig-14c8e270bb47c4e10ee3392661d4c62ab5c2f89d.tar.gz
zig-14c8e270bb47c4e10ee3392661d4c62ab5c2f89d.zip
link: fix false positive crtbegin/crtend detection
Embrace the Path abstraction, doing more operations based on directory handles rather than absolute file paths. Most of the diff noise here comes from this one. Fix sorting of crtbegin/crtend atoms. Previously it would look at all path components for those strings. Make the C runtime path detection partially a pure function, and move some logic to glibc.zig where it belongs.
Diffstat (limited to 'lib/std/Build/Cache/Path.zig')
-rw-r--r--lib/std/Build/Cache/Path.zig22
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/std/Build/Cache/Path.zig b/lib/std/Build/Cache/Path.zig
index ee0666b70a..edd306d06d 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,
@@ -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;