| ... | ... | @@ -938,7 +938,7 @@ pub const Manifest = struct { |
| 938 | 938 | if (manifest_size == 0 or manifest_size < m.contents.items.len) { |
| 939 | 939 | // Manifest file was never finalized. |
| 940 | 940 | try m.contents.ensureUnusedCapacity(gpa, 1); |
| 941 | | return .incomplete_manifest; |
| 941 | return missInput(m, 0, m.contents.items.len, manifest_size, .incomplete_manifest); |
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | // We must not clobber existing `Manifest.contents` because it possibly contains prepopulated stat and digest |
| ... | ... | @@ -1030,14 +1030,14 @@ pub const Manifest = struct { |
| 1030 | 1030 | else |
| 1031 | 1031 | @backingInt(file_offs[next_file_index]); |
| 1032 | 1032 | const copy_len = input_contents_len - off; |
| 1033 | | @memcpy( |
| 1033 | if (manifest_size > 0) @memcpy( |
| 1034 | 1034 | m.contents.items[off..][0..copy_len], |
| 1035 | 1035 | m.contents.items[manifest_size + off ..][0..copy_len], |
| 1036 | 1036 | ); |
| 1037 | 1037 | m.contents.shrinkRetainingCapacity(input_contents_len); |
| 1038 | 1038 | // And now iterate over remaining input files and populate the missing input file hashes. |
| 1039 | 1039 | const contents = m.contents.items; |
| 1040 | | for (file_offs[next_file_index..], m.input_paths.items) |input_file_off, *input_path| { |
| 1040 | for (file_offs[next_file_index..], m.input_paths.items[next_file_index..]) |input_file_off, *input_path| { |
| 1041 | 1041 | assert(@backingInt(input_file_off) == off); |
| 1042 | 1042 | try populateInputPath(m, input_file_off, input_path, contents); |
| 1043 | 1043 | } |
| ... | ... | @@ -2214,6 +2214,11 @@ test "check that changing a file makes cache fail" { |
| 2214 | 2214 | const updated_temp_file_contents = "Hello, world; but updated!\n"; |
| 2215 | 2215 | |
| 2216 | 2216 | try tmp.dir.writeFile(io, .{ .sub_path = temp_file, .data = original_temp_file_contents }); |
| 2217 | const tmp_directory: Directory = .{ |
| 2218 | .path = try std.fs.path.join(testing.allocator, &.{std.testing.TmpDir.parent_dir_path}), |
| 2219 | .handle = tmp.dir, |
| 2220 | }; |
| 2221 | defer testing.allocator.free(tmp_directory.path.?); |
| 2217 | 2222 | |
| 2218 | 2223 | // Wait for file timestamps to tick |
| 2219 | 2224 | const initial_time = try testGetCurrentFileTimestamp(io, tmp.dir); |
| ... | ... | @@ -2231,7 +2236,8 @@ test "check that changing a file makes cache fail" { |
| 2231 | 2236 | .manifest_dir = try tmp.dir.createDirPathOpen(io, temp_manifest_dir, .{}), |
| 2232 | 2237 | .cwd = cwd, |
| 2233 | 2238 | }; |
| 2234 | | cache.addPrefix(.{ .path = null, .handle = tmp.dir }); |
| 2239 | cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() }); |
| 2240 | cache.addPrefix(tmp_directory); |
| 2235 | 2241 | defer cache.manifest_dir.close(io); |
| 2236 | 2242 | |
| 2237 | 2243 | { |
| ... | ... | @@ -2239,7 +2245,10 @@ test "check that changing a file makes cache fail" { |
| 2239 | 2245 | defer man.deinit(); |
| 2240 | 2246 | |
| 2241 | 2247 | man.hash.addBytes("1234"); |
| 2242 | | const temp_file_idx = try man.addInputPath(.initCwd(temp_file), .{ .request_contents = true }); |
| 2248 | const temp_file_idx = try man.addInputPath(.{ |
| 2249 | .root_dir = tmp_directory, |
| 2250 | .sub_path = temp_file, |
| 2251 | }, .{ .request_contents = true }); |
| 2243 | 2252 | |
| 2244 | 2253 | try testing.expectEqual(.incomplete_manifest, try man.check(.none)); |
| 2245 | 2254 | |
| ... | ... | @@ -2257,7 +2266,10 @@ test "check that changing a file makes cache fail" { |
| 2257 | 2266 | defer man.deinit(); |
| 2258 | 2267 | |
| 2259 | 2268 | man.hash.addBytes("1234"); |
| 2260 | | const temp_file_idx = try man.addInputPath(.initCwd(temp_file), .{ .request_contents = true }); |
| 2269 | const temp_file_idx = try man.addInputPath(.{ |
| 2270 | .root_dir = tmp_directory, |
| 2271 | .sub_path = temp_file, |
| 2272 | }, .{ .request_contents = true }); |
| 2261 | 2273 | |
| 2262 | 2274 | // The one input file changed. |
| 2263 | 2275 | try testing.expectEqual( |
| ... | ... | @@ -2340,6 +2352,11 @@ test "Manifest with files added after initial hash work" { |
| 2340 | 2352 | |
| 2341 | 2353 | try tmp.dir.writeFile(io, .{ .sub_path = temp_file1, .data = "Hello, world!\n" }); |
| 2342 | 2354 | try tmp.dir.writeFile(io, .{ .sub_path = temp_file2, .data = "Hello world the second!\n" }); |
| 2355 | const tmp_directory: Directory = .{ |
| 2356 | .path = try std.fs.path.join(testing.allocator, &.{std.testing.TmpDir.parent_dir_path}), |
| 2357 | .handle = tmp.dir, |
| 2358 | }; |
| 2359 | defer testing.allocator.free(tmp_directory.path.?); |
| 2343 | 2360 | |
| 2344 | 2361 | // Wait for file timestamps to tick |
| 2345 | 2362 | const initial_time = try testGetCurrentFileTimestamp(io, tmp.dir); |
| ... | ... | @@ -2358,7 +2375,8 @@ test "Manifest with files added after initial hash work" { |
| 2358 | 2375 | .manifest_dir = try tmp.dir.createDirPathOpen(io, temp_manifest_dir, .{}), |
| 2359 | 2376 | .cwd = cwd, |
| 2360 | 2377 | }; |
| 2361 | | cache.addPrefix(.{ .path = null, .handle = tmp.dir }); |
| 2378 | cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() }); |
| 2379 | cache.addPrefix(tmp_directory); |
| 2362 | 2380 | defer cache.manifest_dir.close(io); |
| 2363 | 2381 | |
| 2364 | 2382 | { |
| ... | ... | @@ -2366,11 +2384,17 @@ test "Manifest with files added after initial hash work" { |
| 2366 | 2384 | defer man.deinit(); |
| 2367 | 2385 | |
| 2368 | 2386 | man.hash.addBytes("1234"); |
| 2369 | | _ = try man.addInputPath(.initCwd(temp_file1), .{}); |
| 2387 | _ = try man.addInputPath(.{ |
| 2388 | .root_dir = tmp_directory, |
| 2389 | .sub_path = temp_file1, |
| 2390 | }, .{}); |
| 2370 | 2391 | |
| 2371 | 2392 | try testing.expectEqual(.incomplete_manifest, try man.check(.none)); |
| 2372 | 2393 | |
| 2373 | | try man.addDiscoveredPath(.{ .discovered_path = .{ .unresolved = .initCwd(temp_file2) } }); |
| 2394 | try man.addDiscoveredPath(.{ .discovered_path = .{ .unresolved = .{ |
| 2395 | .root_dir = tmp_directory, |
| 2396 | .sub_path = temp_file2, |
| 2397 | } } }); |
| 2374 | 2398 | |
| 2375 | 2399 | digest1 = man.final(); |
| 2376 | 2400 | try man.finalize(); |
| ... | ... | @@ -2380,7 +2404,10 @@ test "Manifest with files added after initial hash work" { |
| 2380 | 2404 | defer man.deinit(); |
| 2381 | 2405 | |
| 2382 | 2406 | man.hash.addBytes("1234"); |
| 2383 | | _ = try man.addInputPath(.initCwd(temp_file1), .{}); |
| 2407 | _ = try man.addInputPath(.{ |
| 2408 | .root_dir = tmp_directory, |
| 2409 | .sub_path = temp_file1, |
| 2410 | }, .{}); |
| 2384 | 2411 | |
| 2385 | 2412 | try testing.expect(.hit == try man.check(.none)); |
| 2386 | 2413 | digest2 = man.final(); |
| ... | ... | @@ -2403,7 +2430,10 @@ test "Manifest with files added after initial hash work" { |
| 2403 | 2430 | defer man.deinit(); |
| 2404 | 2431 | |
| 2405 | 2432 | man.hash.addBytes("1234"); |
| 2406 | | _ = try man.addInputPath(.initCwd(temp_file1), .{}); |
| 2433 | _ = try man.addInputPath(.{ |
| 2434 | .root_dir = tmp_directory, |
| 2435 | .sub_path = temp_file1, |
| 2436 | }, .{}); |
| 2407 | 2437 | |
| 2408 | 2438 | switch (try man.check(.none)) { |
| 2409 | 2439 | .contents_changed => |off| { |
| ... | ... | @@ -2412,7 +2442,10 @@ test "Manifest with files added after initial hash work" { |
| 2412 | 2442 | else => return error.TestFailed, |
| 2413 | 2443 | } |
| 2414 | 2444 | |
| 2415 | | try man.addDiscoveredPath(.{ .discovered_path = .{ .unresolved = .initCwd(temp_file2) } }); |
| 2445 | try man.addDiscoveredPath(.{ .discovered_path = .{ .unresolved = .{ |
| 2446 | .root_dir = tmp_directory, |
| 2447 | .sub_path = temp_file2, |
| 2448 | } } }); |
| 2416 | 2449 | |
| 2417 | 2450 | digest3 = man.final(); |
| 2418 | 2451 | |