Skip to content

Commit 900a897

Browse files
joachimschmidt557andrewrk
authored andcommitted
Update tools/process_headers.zig to latest zig
1 parent 6325d6a commit 900a897

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

tools/process_headers.zig

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ const Contents = struct {
248248
};
249249

250250
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);
252252
const PathTable = std.StringHashMap(*TargetToHash);
253253

254254
const LibCVendor = enum {
@@ -339,7 +339,7 @@ pub fn main() !void {
339339
try dir_stack.append(target_include_dir);
340340

341341
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) {
343343
error.FileNotFound => continue :search,
344344
error.AccessDenied => continue :search,
345345
else => return err,
@@ -354,7 +354,8 @@ pub fn main() !void {
354354
.Directory => try dir_stack.append(full_path),
355355
.File => {
356356
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);
358359
const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t");
359360
total_bytes += raw_bytes.len;
360361
const hash = try allocator.alloc(u8, 32);
@@ -365,28 +366,28 @@ pub fn main() !void {
365366
const gop = try hash_to_contents.getOrPut(hash);
366367
if (gop.found_existing) {
367368
max_bytes_saved += raw_bytes.len;
368-
gop.kv.value.hit_count += 1;
369+
gop.entry.value.hit_count += 1;
369370
std.debug.warn("duplicate: {} {} ({Bi:2})\n", .{
370371
libc_target.name,
371372
rel_path,
372373
raw_bytes.len,
373374
});
374375
} else {
375-
gop.kv.value = Contents{
376+
gop.entry.value = Contents{
376377
.bytes = trimmed,
377378
.hit_count = 1,
378379
.hash = hash,
379380
.is_generic = false,
380381
};
381382
}
382383
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: {
384385
const ptr = try allocator.create(TargetToHash);
385386
ptr.* = TargetToHash.init(allocator);
386-
path_gop.kv.value = ptr;
387+
path_gop.entry.value = ptr;
387388
break :blk ptr;
388389
};
389-
assert((try target_to_hash.put(dest_target, hash)) == null);
390+
try target_to_hash.putNoClobber(dest_target, hash);
390391
},
391392
else => std.debug.warn("warning: weird file: {}\n", .{full_path}),
392393
}
@@ -410,7 +411,7 @@ pub fn main() !void {
410411
{
411412
var hash_it = path_kv.value.iterator();
412413
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).?;
414415
try contents_list.append(contents);
415416
}
416417
}
@@ -432,7 +433,7 @@ pub fn main() !void {
432433
}
433434
var hash_it = path_kv.value.iterator();
434435
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).?;
436437
if (contents.is_generic) continue;
437438

438439
const dest_target = hash_kv.key;

0 commit comments

Comments
 (0)