authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-10 15:08:23-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-12 00:14:08-07:00
logf2856403c6997ff1317c968abed0871df9586c7c
tree21367fa927f8ddef77f005fba98eb1902ce5887f
parent5c3fae3a329bed39f780827b4c5bfc494dee1c6b

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.

1 files changed, 17 insertions(+), 0 deletions(-)

lib/std/Build/Cache.zig+17
...@@ -354,6 +354,19 @@ pub const Manifest = struct {...@@ -354,6 +354,19 @@ pub const Manifest = struct {
354 /// ```354 /// ```
355 /// var file_contents = cache_hash.files.keys()[file_index].contents.?;355 /// var file_contents = cache_hash.files.keys()[file_index].contents.?;
356 /// ```356 /// ```
357 pub fn addFilePath(m: *Manifest, file_path: Path, max_file_size: ?usize) !usize {
358 const gpa = m.cache.gpa;
359 try m.files.ensureUnusedCapacity(gpa, 1);
360 const resolved_path = try fs.path.resolve(gpa, &.{
361 file_path.root_dir.path orelse ".",
362 file_path.subPathOrDot(),
363 });
364 errdefer gpa.free(resolved_path);
365 const prefixed_path = try m.cache.findPrefixResolved(resolved_path);
366 return addFileInner(m, prefixed_path, max_file_size);
367 }
368
369 /// Deprecated; use `addFilePath`.
357 pub fn addFile(self: *Manifest, file_path: []const u8, max_file_size: ?usize) !usize {370 pub fn addFile(self: *Manifest, file_path: []const u8, max_file_size: ?usize) !usize {
358 assert(self.manifest_file == null);371 assert(self.manifest_file == null);
359372
...@@ -362,6 +375,10 @@ pub const Manifest = struct {...@@ -362,6 +375,10 @@ pub const Manifest = struct {
362 const prefixed_path = try self.cache.findPrefix(file_path);375 const prefixed_path = try self.cache.findPrefix(file_path);
363 errdefer gpa.free(prefixed_path.sub_path);376 errdefer gpa.free(prefixed_path.sub_path);
364377
378 return addFileInner(self, prefixed_path, max_file_size);
379 }
380
381 fn addFileInner(self: *Manifest, prefixed_path: PrefixedPath, max_file_size: ?usize) !usize {
365 const gop = self.files.getOrPutAssumeCapacityAdapted(prefixed_path, FilesAdapter{});382 const gop = self.files.getOrPutAssumeCapacityAdapted(prefixed_path, FilesAdapter{});
366 if (gop.found_existing) {383 if (gop.found_existing) {
367 gop.key_ptr.updateMaxSize(max_file_size);384 gop.key_ptr.updateMaxSize(max_file_size);