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 {...@@ -938,7 +938,7 @@ pub const Manifest = struct {
938 if (manifest_size == 0 or manifest_size < m.contents.items.len) {938 if (manifest_size == 0 or manifest_size < m.contents.items.len) {
939 // Manifest file was never finalized.939 // Manifest file was never finalized.
940 try m.contents.ensureUnusedCapacity(gpa, 1);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 }
943943
944 // We must not clobber existing `Manifest.contents` because it possibly contains prepopulated stat and digest944 // We must not clobber existing `Manifest.contents` because it possibly contains prepopulated stat and digest
...@@ -1030,14 +1030,14 @@ pub const Manifest = struct {...@@ -1030,14 +1030,14 @@ pub const Manifest = struct {
1030 else1030 else
1031 @backingInt(file_offs[next_file_index]);1031 @backingInt(file_offs[next_file_index]);
1032 const copy_len = input_contents_len - off;1032 const copy_len = input_contents_len - off;
1033 @memcpy(1033 if (manifest_size > 0) @memcpy(
1034 m.contents.items[off..][0..copy_len],1034 m.contents.items[off..][0..copy_len],
1035 m.contents.items[manifest_size + off ..][0..copy_len],1035 m.contents.items[manifest_size + off ..][0..copy_len],
1036 );1036 );
1037 m.contents.shrinkRetainingCapacity(input_contents_len);1037 m.contents.shrinkRetainingCapacity(input_contents_len);
1038 // And now iterate over remaining input files and populate the missing input file hashes.1038 // And now iterate over remaining input files and populate the missing input file hashes.
1039 const contents = m.contents.items;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 assert(@backingInt(input_file_off) == off);1041 assert(@backingInt(input_file_off) == off);
1042 try populateInputPath(m, input_file_off, input_path, contents);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,6 +2214,11 @@ test "check that changing a file makes cache fail" {
2214 const updated_temp_file_contents = "Hello, world; but updated!\n";2214 const updated_temp_file_contents = "Hello, world; but updated!\n";
22152215
2216 try tmp.dir.writeFile(io, .{ .sub_path = temp_file, .data = original_temp_file_contents });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.?);
22172222
2218 // Wait for file timestamps to tick2223 // Wait for file timestamps to tick
2219 const initial_time = try testGetCurrentFileTimestamp(io, tmp.dir);2224 const initial_time = try testGetCurrentFileTimestamp(io, tmp.dir);
...@@ -2231,7 +2236,8 @@ test "check that changing a file makes cache fail" {...@@ -2231,7 +2236,8 @@ test "check that changing a file makes cache fail" {
2231 .manifest_dir = try tmp.dir.createDirPathOpen(io, temp_manifest_dir, .{}),2236 .manifest_dir = try tmp.dir.createDirPathOpen(io, temp_manifest_dir, .{}),
2232 .cwd = cwd,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 defer cache.manifest_dir.close(io);2241 defer cache.manifest_dir.close(io);
22362242
2237 {2243 {
...@@ -2239,7 +2245,10 @@ test "check that changing a file makes cache fail" {...@@ -2239,7 +2245,10 @@ test "check that changing a file makes cache fail" {
2239 defer man.deinit();2245 defer man.deinit();
22402246
2241 man.hash.addBytes("1234");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 });
22432252
2244 try testing.expectEqual(.incomplete_manifest, try man.check(.none));2253 try testing.expectEqual(.incomplete_manifest, try man.check(.none));
22452254
...@@ -2257,7 +2266,10 @@ test "check that changing a file makes cache fail" {...@@ -2257,7 +2266,10 @@ test "check that changing a file makes cache fail" {
2257 defer man.deinit();2266 defer man.deinit();
22582267
2259 man.hash.addBytes("1234");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 });
22612273
2262 // The one input file changed.2274 // The one input file changed.
2263 try testing.expectEqual(2275 try testing.expectEqual(
...@@ -2340,6 +2352,11 @@ test "Manifest with files added after initial hash work" {...@@ -2340,6 +2352,11 @@ test "Manifest with files added after initial hash work" {
23402352
2341 try tmp.dir.writeFile(io, .{ .sub_path = temp_file1, .data = "Hello, world!\n" });2353 try tmp.dir.writeFile(io, .{ .sub_path = temp_file1, .data = "Hello, world!\n" });
2342 try tmp.dir.writeFile(io, .{ .sub_path = temp_file2, .data = "Hello world the second!\n" });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.?);
23432360
2344 // Wait for file timestamps to tick2361 // Wait for file timestamps to tick
2345 const initial_time = try testGetCurrentFileTimestamp(io, tmp.dir);2362 const initial_time = try testGetCurrentFileTimestamp(io, tmp.dir);
...@@ -2358,7 +2375,8 @@ test "Manifest with files added after initial hash work" {...@@ -2358,7 +2375,8 @@ test "Manifest with files added after initial hash work" {
2358 .manifest_dir = try tmp.dir.createDirPathOpen(io, temp_manifest_dir, .{}),2375 .manifest_dir = try tmp.dir.createDirPathOpen(io, temp_manifest_dir, .{}),
2359 .cwd = cwd,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 defer cache.manifest_dir.close(io);2380 defer cache.manifest_dir.close(io);
23632381
2364 {2382 {
...@@ -2366,11 +2384,17 @@ test "Manifest with files added after initial hash work" {...@@ -2366,11 +2384,17 @@ test "Manifest with files added after initial hash work" {
2366 defer man.deinit();2384 defer man.deinit();
23672385
2368 man.hash.addBytes("1234");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 }, .{});
23702391
2371 try testing.expectEqual(.incomplete_manifest, try man.check(.none));2392 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
2375 digest1 = man.final();2399 digest1 = man.final();
2376 try man.finalize();2400 try man.finalize();
...@@ -2380,7 +2404,10 @@ test "Manifest with files added after initial hash work" {...@@ -2380,7 +2404,10 @@ test "Manifest with files added after initial hash work" {
2380 defer man.deinit();2404 defer man.deinit();
23812405
2382 man.hash.addBytes("1234");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 }, .{});
23842411
2385 try testing.expect(.hit == try man.check(.none));2412 try testing.expect(.hit == try man.check(.none));
2386 digest2 = man.final();2413 digest2 = man.final();
...@@ -2403,7 +2430,10 @@ test "Manifest with files added after initial hash work" {...@@ -2403,7 +2430,10 @@ test "Manifest with files added after initial hash work" {
2403 defer man.deinit();2430 defer man.deinit();
24042431
2405 man.hash.addBytes("1234");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 }, .{});
24072437
2408 switch (try man.check(.none)) {2438 switch (try man.check(.none)) {
2409 .contents_changed => |off| {2439 .contents_changed => |off| {
...@@ -2412,7 +2442,10 @@ test "Manifest with files added after initial hash work" {...@@ -2412,7 +2442,10 @@ test "Manifest with files added after initial hash work" {
2412 else => return error.TestFailed,2442 else => return error.TestFailed,
2413 }2443 }
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
2417 digest3 = man.final();2450 digest3 = man.final();
24182451