zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit f2856403c6997ff1317c968abed0871df9586c7c (tree)
parent 5c3fae3a329bed39f780827b4c5bfc494dee1c6b
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Wed, 10 Jul 2024 15:08:23 -0700

introduce std.Build.Cache.Manifest.addFilePath

and deprecate `addFile`. Part of an effort to move towards using
`std.Build.Cache.Path` abstraction in more places, which makes it easier
to avoid absolute paths and path resolution.

Diffstat:
Mlib/std/Build/Cache.zig | 17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)

diff --git a/lib/std/Build/Cache.zig b/lib/std/Build/Cache.zig @@ -354,6 +354,19 @@ pub const Manifest = struct { /// ``` /// var file_contents = cache_hash.files.keys()[file_index].contents.?; /// ``` + pub fn addFilePath(m: *Manifest, file_path: Path, max_file_size: ?usize) !usize { + const gpa = m.cache.gpa; + try m.files.ensureUnusedCapacity(gpa, 1); + const resolved_path = try fs.path.resolve(gpa, &.{ + file_path.root_dir.path orelse ".", + file_path.subPathOrDot(), + }); + errdefer gpa.free(resolved_path); + const prefixed_path = try m.cache.findPrefixResolved(resolved_path); + return addFileInner(m, prefixed_path, max_file_size); + } + + /// Deprecated; use `addFilePath`. pub fn addFile(self: *Manifest, file_path: []const u8, max_file_size: ?usize) !usize { assert(self.manifest_file == null); @@ -362,6 +375,10 @@ pub const Manifest = struct { const prefixed_path = try self.cache.findPrefix(file_path); errdefer gpa.free(prefixed_path.sub_path); + return addFileInner(self, prefixed_path, max_file_size); + } + + fn addFileInner(self: *Manifest, prefixed_path: PrefixedPath, max_file_size: ?usize) !usize { const gop = self.files.getOrPutAssumeCapacityAdapted(prefixed_path, FilesAdapter{}); if (gop.found_existing) { gop.key_ptr.updateMaxSize(max_file_size);