| ... | @@ -248,7 +248,7 @@ const Contents = struct { | ... | @@ -248,7 +248,7 @@ const Contents = struct { |
| 248 | }; | 248 | }; |
| 249 | | 249 | |
| 250 | const HashToContents = std.StringHashMap(Contents); | 250 | const HashToContents = std.StringHashMap(Contents); |
| 251 | const TargetToHash = std.HashMap(DestTarget, []const u8, DestTarget.hash, DestTarget.eql); | 251 | const TargetToHash = std.HashMap(DestTarget, []const u8, DestTarget.hash, DestTarget.eql, true); |
| 252 | const PathTable = std.StringHashMap(*TargetToHash); | 252 | const PathTable = std.StringHashMap(*TargetToHash); |
| 253 | | 253 | |
| 254 | const LibCVendor = enum { | 254 | const LibCVendor = enum { |
| ... | @@ -339,7 +339,7 @@ pub fn main() !void { | ... | @@ -339,7 +339,7 @@ pub fn main() !void { |
| 339 | try dir_stack.append(target_include_dir); | 339 | try dir_stack.append(target_include_dir); |
| 340 | | 340 | |
| 341 | while (dir_stack.popOrNull()) |full_dir_name| { | 341 | while (dir_stack.popOrNull()) |full_dir_name| { |
| 342 | var dir = std.fs.cwd().openDirList(full_dir_name) catch |err| switch (err) { | 342 | var dir = std.fs.cwd().openDir(full_dir_name, .{ .iterate = true }) catch |err| switch (err) { |
| 343 | error.FileNotFound => continue :search, | 343 | error.FileNotFound => continue :search, |
| 344 | error.AccessDenied => continue :search, | 344 | error.AccessDenied => continue :search, |
| 345 | else => return err, | 345 | else => return err, |
| ... | @@ -354,7 +354,8 @@ pub fn main() !void { | ... | @@ -354,7 +354,8 @@ pub fn main() !void { |
| 354 | .Directory => try dir_stack.append(full_path), | 354 | .Directory => try dir_stack.append(full_path), |
| 355 | .File => { | 355 | .File => { |
| 356 | const rel_path = try std.fs.path.relative(allocator, target_include_dir, full_path); | 356 | const rel_path = try std.fs.path.relative(allocator, target_include_dir, full_path); |
| 357 | const raw_bytes = try std.io.readFileAlloc(allocator, full_path); | 357 | const max_size = 2 * 1024 * 1024 * 1024; |
| | 358 | const raw_bytes = try std.fs.cwd().readFileAlloc(allocator, full_path, max_size); |
| 358 | const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t"); | 359 | const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t"); |
| 359 | total_bytes += raw_bytes.len; | 360 | total_bytes += raw_bytes.len; |
| 360 | const hash = try allocator.alloc(u8, 32); | 361 | const hash = try allocator.alloc(u8, 32); |
| ... | @@ -365,14 +366,14 @@ pub fn main() !void { | ... | @@ -365,14 +366,14 @@ pub fn main() !void { |
| 365 | const gop = try hash_to_contents.getOrPut(hash); | 366 | const gop = try hash_to_contents.getOrPut(hash); |
| 366 | if (gop.found_existing) { | 367 | if (gop.found_existing) { |
| 367 | max_bytes_saved += raw_bytes.len; | 368 | max_bytes_saved += raw_bytes.len; |
| 368 | gop.kv.value.hit_count += 1; | 369 | gop.entry.value.hit_count += 1; |
| 369 | std.debug.warn("duplicate: {} {} ({Bi:2})\n", .{ | 370 | std.debug.warn("duplicate: {} {} ({Bi:2})\n", .{ |
| 370 | libc_target.name, | 371 | libc_target.name, |
| 371 | rel_path, | 372 | rel_path, |
| 372 | raw_bytes.len, | 373 | raw_bytes.len, |
| 373 | }); | 374 | }); |
| 374 | } else { | 375 | } else { |
| 375 | gop.kv.value = Contents{ | 376 | gop.entry.value = Contents{ |
| 376 | .bytes = trimmed, | 377 | .bytes = trimmed, |
| 377 | .hit_count = 1, | 378 | .hit_count = 1, |
| 378 | .hash = hash, | 379 | .hash = hash, |
| ... | @@ -380,13 +381,13 @@ pub fn main() !void { | ... | @@ -380,13 +381,13 @@ pub fn main() !void { |
| 380 | }; | 381 | }; |
| 381 | } | 382 | } |
| 382 | const path_gop = try path_table.getOrPut(rel_path); | 383 | const path_gop = try path_table.getOrPut(rel_path); |
| 383 | const target_to_hash = if (path_gop.found_existing) path_gop.kv.value else blk: { | 384 | const target_to_hash = if (path_gop.found_existing) path_gop.entry.value else blk: { |
| 384 | const ptr = try allocator.create(TargetToHash); | 385 | const ptr = try allocator.create(TargetToHash); |
| 385 | ptr.* = TargetToHash.init(allocator); | 386 | ptr.* = TargetToHash.init(allocator); |
| 386 | path_gop.kv.value = ptr; | 387 | path_gop.entry.value = ptr; |
| 387 | break :blk ptr; | 388 | break :blk ptr; |
| 388 | }; | 389 | }; |
| 389 | assert((try target_to_hash.put(dest_target, hash)) == null); | 390 | try target_to_hash.putNoClobber(dest_target, hash); |
| 390 | }, | 391 | }, |
| 391 | else => std.debug.warn("warning: weird file: {}\n", .{full_path}), | 392 | else => std.debug.warn("warning: weird file: {}\n", .{full_path}), |
| 392 | } | 393 | } |
| ... | @@ -410,7 +411,7 @@ pub fn main() !void { | ... | @@ -410,7 +411,7 @@ pub fn main() !void { |
| 410 | { | 411 | { |
| 411 | var hash_it = path_kv.value.iterator(); | 412 | var hash_it = path_kv.value.iterator(); |
| 412 | while (hash_it.next()) |hash_kv| { | 413 | while (hash_it.next()) |hash_kv| { |
| 413 | const contents = &hash_to_contents.get(hash_kv.value).?.value; | 414 | const contents = &hash_to_contents.get(hash_kv.value).?; |
| 414 | try contents_list.append(contents); | 415 | try contents_list.append(contents); |
| 415 | } | 416 | } |
| 416 | } | 417 | } |
| ... | @@ -432,7 +433,7 @@ pub fn main() !void { | ... | @@ -432,7 +433,7 @@ pub fn main() !void { |
| 432 | } | 433 | } |
| 433 | var hash_it = path_kv.value.iterator(); | 434 | var hash_it = path_kv.value.iterator(); |
| 434 | while (hash_it.next()) |hash_kv| { | 435 | while (hash_it.next()) |hash_kv| { |
| 435 | const contents = &hash_to_contents.get(hash_kv.value).?.value; | 436 | const contents = &hash_to_contents.get(hash_kv.value).?; |
| 436 | if (contents.is_generic) continue; | 437 | if (contents.is_generic) continue; |
| 437 | | 438 | |
| 438 | const dest_target = hash_kv.key; | 439 | const dest_target = hash_kv.key; |