authorgravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2020-08-09 14:57:49+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-10 21:09:23-04:00
log900a897e90eca08f78ef632fd11e01ec9bcb3674
tree9084da280c1a235fc7e6e55539f0eb8103b1e00e
parent6325d6a48628bff89b2e243e0a1b6eedf39b0ec6

Update tools/process_headers.zig to latest zig


1 files changed, 11 insertions(+), 10 deletions(-)

tools/process_headers.zig+11-10
......@@ -248,7 +248,7 @@ const Contents = struct {
248248};
249249
250250const HashToContents = std.StringHashMap(Contents);
251const TargetToHash = std.HashMap(DestTarget, []const u8, DestTarget.hash, DestTarget.eql);
251const TargetToHash = std.HashMap(DestTarget, []const u8, DestTarget.hash, DestTarget.eql, true);
252252const PathTable = std.StringHashMap(*TargetToHash);
253253
254254const 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,14 +366,14 @@ 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,
......@@ -380,13 +381,13 @@ pub fn main() !void {
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;