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 {...@@ -248,7 +248,7 @@ const Contents = struct {
248};248};
249249
250const HashToContents = std.StringHashMap(Contents);250const 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);
252const PathTable = std.StringHashMap(*TargetToHash);252const PathTable = std.StringHashMap(*TargetToHash);
253253
254const LibCVendor = enum {254const 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);
340340
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;
437438
438 const dest_target = hash_kv.key;439 const dest_target = hash_kv.key;