diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-10-10 00:41:58 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-10-10 14:21:52 -0700 |
| commit | 14c8e270bb47c4e10ee3392661d4c62ab5c2f89d (patch) | |
| tree | c74fe79e74d3fc6bff7dd61f372153906e29e040 /lib/std/Build/Cache/Path.zig | |
| parent | 58349b2c8ebc57718bbfbf939c30b586d5c85466 (diff) | |
| download | zig-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.zig | 22 |
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; |
