mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
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.
This commit is contained in:
parent
5c3fae3a32
commit
f2856403c6
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user