| ... | @@ -1675,11 +1675,12 @@ pub const Manifest = struct { | ... | @@ -1675,11 +1675,12 @@ pub const Manifest = struct { |
| 1675 | FileSystemFailure, | 1675 | FileSystemFailure, |
| 1676 | } || Allocator.Error || Io.Cancelable; | 1676 | } || Allocator.Error || Io.Cancelable; |
| 1677 | | 1677 | |
| 1678 | /// Add a file as a dependency of process being cached, after cache miss | 1678 | /// Add a file or directory as a dependency of process being cached, after cache miss occurs. |
| 1679 | /// occurs. | | |
| 1680 | /// | 1679 | /// |
| 1681 | /// See also: | 1680 | /// See also: |
| 1682 | /// * `addInputPath` | 1681 | /// * `addInputPath` |
| | 1682 | /// * `addDiscoveredDepFile` |
| | 1683 | /// * `addDiscoveredManifest` |
| 1683 | pub fn addDiscoveredPath(m: *Manifest, options: AddDiscoveredPathOptions) AddDiscoveredPathError!void { | 1684 | pub fn addDiscoveredPath(m: *Manifest, options: AddDiscoveredPathOptions) AddDiscoveredPathError!void { |
| 1684 | assert(m.manifest_file != null); | 1685 | assert(m.manifest_file != null); |
| 1685 | transitionToMissDiscovered(m); | 1686 | transitionToMissDiscovered(m); |
| ... | @@ -1788,6 +1789,11 @@ pub const Manifest = struct { | ... | @@ -1788,6 +1789,11 @@ pub const Manifest = struct { |
| 1788 | dep_tokenizer: DepTokenizer.Token, | 1789 | dep_tokenizer: DepTokenizer.Token, |
| 1789 | }; | 1790 | }; |
| 1790 | | 1791 | |
| | 1792 | /// Add a GNU make style dep file as a dependency of process being cached, after cache miss occurs. |
| | 1793 | /// |
| | 1794 | /// See also: |
| | 1795 | /// * `addDiscoveredPath |
| | 1796 | /// * `addDiscoveredManifest` |
| 1791 | pub fn addDiscoveredDepFile( | 1797 | pub fn addDiscoveredDepFile( |
| 1792 | m: *Manifest, | 1798 | m: *Manifest, |
| 1793 | path: Path, | 1799 | path: Path, |
| ... | @@ -2077,7 +2083,7 @@ pub const Manifest = struct { | ... | @@ -2077,7 +2083,7 @@ pub const Manifest = struct { |
| 2077 | m.* = undefined; | 2083 | m.* = undefined; |
| 2078 | } | 2084 | } |
| 2079 | | 2085 | |
| 2080 | pub fn populateFileSystemInputs(man: *Manifest, buf: *std.ArrayList(u8)) Allocator.Error!void { | 2086 | pub fn populateFileSystemInputs(man: *const Manifest, buf: *std.ArrayList(u8)) Allocator.Error!void { |
| 2081 | assert(@typeInfo(std.zig.Server.Message.PathPrefix).@"enum".field_names.len == man.cache.prefixes_len); | 2087 | assert(@typeInfo(std.zig.Server.Message.PathPrefix).@"enum".field_names.len == man.cache.prefixes_len); |
| 2082 | buf.clearRetainingCapacity(); | 2088 | buf.clearRetainingCapacity(); |
| 2083 | const gpa = man.cache.gpa; | 2089 | const gpa = man.cache.gpa; |
| ... | @@ -2096,42 +2102,49 @@ pub const Manifest = struct { | ... | @@ -2096,42 +2102,49 @@ pub const Manifest = struct { |
| 2096 | } | 2102 | } |
| 2097 | } | 2103 | } |
| 2098 | | 2104 | |
| 2099 | pub fn populateOtherManifest(man: *Manifest, other: *Manifest, prefix_map: [5]u8) Allocator.Error!void { | 2105 | /// Add the full set of paths from another `Manifest` as a dependency of process being cached, after cache miss |
| 2100 | const gpa = other.cache.gpa; | 2106 | /// occurs. |
| 2101 | assert(other.manifest_file != null); | 2107 | /// |
| 2102 | assert(@typeInfo(std.zig.Server.Message.PathPrefix).@"enum".field_names.len == man.cache.prefixes_len); | 2108 | /// See also: |
| 2103 | assert(man.cache.prefixes_len == 5); | 2109 | /// * `addDiscoveredPath |
| | 2110 | /// * `addDiscoveredDepFile` |
| | 2111 | pub fn addDiscoveredManifest(m: *Manifest, discovered: *const Manifest, prefix_map: [5]u8) Allocator.Error!void { |
| | 2112 | const gpa = m.cache.gpa; |
| | 2113 | assert(m.manifest_file != null); |
| | 2114 | transitionToMissDiscovered(m); |
| | 2115 | assert(@typeInfo(std.zig.Server.Message.PathPrefix).@"enum".field_names.len == discovered.cache.prefixes_len); |
| | 2116 | assert(discovered.cache.prefixes_len == 5); |
| 2104 | | 2117 | |
| 2105 | const orig_files_len = other.files.count(); | 2118 | const orig_files_len = m.files.count(); |
| 2106 | const orig_contents_len = other.contents.items.len; | 2119 | const orig_contents_len = m.contents.items.len; |
| 2107 | errdefer { | 2120 | errdefer { |
| 2108 | other.files.shrinkRetainingCapacityContext(orig_files_len, .{ .contents = other.contents.items }); | 2121 | m.files.shrinkRetainingCapacityContext(orig_files_len, .{ .contents = m.contents.items }); |
| 2109 | other.contents.shrinkRetainingCapacity(orig_contents_len); | 2122 | m.contents.shrinkRetainingCapacity(orig_contents_len); |
| 2110 | } | 2123 | } |
| 2111 | | 2124 | |
| 2112 | for (man.files.keys(), 0..) |off, file_index| { | 2125 | for (discovered.files.keys(), 0..) |off, file_index| { |
| 2113 | try other.files.ensureUnusedCapacityContext(gpa, 1, .{ .contents = other.contents.items }); | 2126 | try m.files.ensureUnusedCapacityContext(gpa, 1, .{ .contents = m.contents.items }); |
| 2114 | | 2127 | |
| 2115 | const next_off = if (file_index < man.files.count()) | 2128 | const next_off = if (file_index < discovered.files.count()) |
| 2116 | @backingInt(man.files.keys()[file_index + 1]) | 2129 | @backingInt(discovered.files.keys()[file_index + 1]) |
| 2117 | else | 2130 | else |
| 2118 | man.contents.items.len; | 2131 | discovered.contents.items.len; |
| 2119 | | 2132 | |
| 2120 | const copy_bytes = man.contents.items[@backingInt(off)..next_off]; | 2133 | const copy_bytes = discovered.contents.items[@backingInt(off)..next_off]; |
| 2121 | const prev_contents_len: File.Offset = @fromBackingInt(@intCast(other.contents.items.len)); | 2134 | const prev_contents_len: File.Offset = @fromBackingInt(@intCast(m.contents.items.len)); |
| 2122 | try other.contents.appendSlice(gpa, copy_bytes); | 2135 | try m.contents.appendSlice(gpa, copy_bytes); |
| 2123 | | 2136 | |
| 2124 | const gop = other.files.getOrPutAssumeCapacityContext(prev_contents_len, .{ | 2137 | const gop = m.files.getOrPutAssumeCapacityContext(prev_contents_len, .{ |
| 2125 | .contents = other.contents.items, | 2138 | .contents = m.contents.items, |
| 2126 | }); | 2139 | }); |
| 2127 | | 2140 | |
| 2128 | if (gop.found_existing) { | 2141 | if (gop.found_existing) { |
| 2129 | other.contents.shrinkRetainingCapacity(@backingInt(prev_contents_len)); | 2142 | m.contents.shrinkRetainingCapacity(@backingInt(prev_contents_len)); |
| 2130 | continue; | 2143 | continue; |
| 2131 | } | 2144 | } |
| 2132 | | 2145 | |
| 2133 | // Flags are already copied but the prefix is supposed to be filtered by `prefix_map`. | 2146 | // Flags are already copied but the prefix is supposed to be filtered by `prefix_map`. |
| 2134 | const other_file = prev_contents_len.get(other.contents.items); | 2147 | const other_file = prev_contents_len.get(m.contents.items); |
| 2135 | other_file.flags.prefix = @intCast(prefix_map[other_file.flags.prefix]); | 2148 | other_file.flags.prefix = @intCast(prefix_map[other_file.flags.prefix]); |
| 2136 | } | 2149 | } |
| 2137 | } | 2150 | } |