authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-09-11 23:28:40-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-09-16 13:12:47-07:00
log29531cc9c056775dda9960c59b6644e4559d14bd
treecf3bfc66fa4218025b2d0bf566017c45ad87ff0a
parent30c3c666ab88702c5a684ea489a2867260eab22a

finish fixing one unit test


1 files changed, 45 insertions(+), 12 deletions(-)

lib/std/Build/Cache.zig+45-12
......@@ -938,7 +938,7 @@ pub const Manifest = struct {
938938 if (manifest_size == 0 or manifest_size < m.contents.items.len) {
939939 // Manifest file was never finalized.
940940 try m.contents.ensureUnusedCapacity(gpa, 1);
941 return .incomplete_manifest;
941 return missInput(m, 0, m.contents.items.len, manifest_size, .incomplete_manifest);
942942 }
943943
944944 // We must not clobber existing `Manifest.contents` because it possibly contains prepopulated stat and digest
......@@ -1030,14 +1030,14 @@ pub const Manifest = struct {
10301030 else
10311031 @backingInt(file_offs[next_file_index]);
10321032 const copy_len = input_contents_len - off;
1033 @memcpy(
1033 if (manifest_size > 0) @memcpy(
10341034 m.contents.items[off..][0..copy_len],
10351035 m.contents.items[manifest_size + off ..][0..copy_len],
10361036 );
10371037 m.contents.shrinkRetainingCapacity(input_contents_len);
10381038 // And now iterate over remaining input files and populate the missing input file hashes.
10391039 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| {
10411041 assert(@backingInt(input_file_off) == off);
10421042 try populateInputPath(m, input_file_off, input_path, contents);
10431043 }
......@@ -2214,6 +2214,11 @@ test "check that changing a file makes cache fail" {
22142214 const updated_temp_file_contents = "Hello, world; but updated!\n";
22152215
22162216 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.?);
22172222
22182223 // Wait for file timestamps to tick
22192224 const initial_time = try testGetCurrentFileTimestamp(io, tmp.dir);
......@@ -2231,7 +2236,8 @@ test "check that changing a file makes cache fail" {
22312236 .manifest_dir = try tmp.dir.createDirPathOpen(io, temp_manifest_dir, .{}),
22322237 .cwd = cwd,
22332238 };
2234 cache.addPrefix(.{ .path = null, .handle = tmp.dir });
2239 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
2240 cache.addPrefix(tmp_directory);
22352241 defer cache.manifest_dir.close(io);
22362242
22372243 {
......@@ -2239,7 +2245,10 @@ test "check that changing a file makes cache fail" {
22392245 defer man.deinit();
22402246
22412247 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 });
22432252
22442253 try testing.expectEqual(.incomplete_manifest, try man.check(.none));
22452254
......@@ -2257,7 +2266,10 @@ test "check that changing a file makes cache fail" {
22572266 defer man.deinit();
22582267
22592268 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 });
22612273
22622274 // The one input file changed.
22632275 try testing.expectEqual(
......@@ -2340,6 +2352,11 @@ test "Manifest with files added after initial hash work" {
23402352
23412353 try tmp.dir.writeFile(io, .{ .sub_path = temp_file1, .data = "Hello, world!\n" });
23422354 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.?);
23432360
23442361 // Wait for file timestamps to tick
23452362 const initial_time = try testGetCurrentFileTimestamp(io, tmp.dir);
......@@ -2358,7 +2375,8 @@ test "Manifest with files added after initial hash work" {
23582375 .manifest_dir = try tmp.dir.createDirPathOpen(io, temp_manifest_dir, .{}),
23592376 .cwd = cwd,
23602377 };
2361 cache.addPrefix(.{ .path = null, .handle = tmp.dir });
2378 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
2379 cache.addPrefix(tmp_directory);
23622380 defer cache.manifest_dir.close(io);
23632381
23642382 {
......@@ -2366,11 +2384,17 @@ test "Manifest with files added after initial hash work" {
23662384 defer man.deinit();
23672385
23682386 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 }, .{});
23702391
23712392 try testing.expectEqual(.incomplete_manifest, try man.check(.none));
23722393
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 } } });
23742398
23752399 digest1 = man.final();
23762400 try man.finalize();
......@@ -2380,7 +2404,10 @@ test "Manifest with files added after initial hash work" {
23802404 defer man.deinit();
23812405
23822406 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 }, .{});
23842411
23852412 try testing.expect(.hit == try man.check(.none));
23862413 digest2 = man.final();
......@@ -2403,7 +2430,10 @@ test "Manifest with files added after initial hash work" {
24032430 defer man.deinit();
24042431
24052432 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 }, .{});
24072437
24082438 switch (try man.check(.none)) {
24092439 .contents_changed => |off| {
......@@ -2412,7 +2442,10 @@ test "Manifest with files added after initial hash work" {
24122442 else => return error.TestFailed,
24132443 }
24142444
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 } } });
24162449
24172450 digest3 = man.final();
24182451