mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
Update tools/process_headers.zig to latest zig
This commit is contained in:
parent
6325d6a486
commit
900a897e90
@ -248,7 +248,7 @@ const Contents = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const HashToContents = std.StringHashMap(Contents);
|
const HashToContents = std.StringHashMap(Contents);
|
||||||
const TargetToHash = std.HashMap(DestTarget, []const u8, DestTarget.hash, DestTarget.eql);
|
const TargetToHash = std.HashMap(DestTarget, []const u8, DestTarget.hash, DestTarget.eql, true);
|
||||||
const PathTable = std.StringHashMap(*TargetToHash);
|
const PathTable = std.StringHashMap(*TargetToHash);
|
||||||
|
|
||||||
const LibCVendor = enum {
|
const LibCVendor = enum {
|
||||||
@ -339,7 +339,7 @@ pub fn main() !void {
|
|||||||
try dir_stack.append(target_include_dir);
|
try dir_stack.append(target_include_dir);
|
||||||
|
|
||||||
while (dir_stack.popOrNull()) |full_dir_name| {
|
while (dir_stack.popOrNull()) |full_dir_name| {
|
||||||
var dir = std.fs.cwd().openDirList(full_dir_name) catch |err| switch (err) {
|
var dir = std.fs.cwd().openDir(full_dir_name, .{ .iterate = true }) catch |err| switch (err) {
|
||||||
error.FileNotFound => continue :search,
|
error.FileNotFound => continue :search,
|
||||||
error.AccessDenied => continue :search,
|
error.AccessDenied => continue :search,
|
||||||
else => return err,
|
else => return err,
|
||||||
@ -354,7 +354,8 @@ pub fn main() !void {
|
|||||||
.Directory => try dir_stack.append(full_path),
|
.Directory => try dir_stack.append(full_path),
|
||||||
.File => {
|
.File => {
|
||||||
const rel_path = try std.fs.path.relative(allocator, target_include_dir, full_path);
|
const rel_path = try std.fs.path.relative(allocator, target_include_dir, full_path);
|
||||||
const raw_bytes = try std.io.readFileAlloc(allocator, full_path);
|
const max_size = 2 * 1024 * 1024 * 1024;
|
||||||
|
const raw_bytes = try std.fs.cwd().readFileAlloc(allocator, full_path, max_size);
|
||||||
const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t");
|
const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t");
|
||||||
total_bytes += raw_bytes.len;
|
total_bytes += raw_bytes.len;
|
||||||
const hash = try allocator.alloc(u8, 32);
|
const hash = try allocator.alloc(u8, 32);
|
||||||
@ -365,14 +366,14 @@ pub fn main() !void {
|
|||||||
const gop = try hash_to_contents.getOrPut(hash);
|
const gop = try hash_to_contents.getOrPut(hash);
|
||||||
if (gop.found_existing) {
|
if (gop.found_existing) {
|
||||||
max_bytes_saved += raw_bytes.len;
|
max_bytes_saved += raw_bytes.len;
|
||||||
gop.kv.value.hit_count += 1;
|
gop.entry.value.hit_count += 1;
|
||||||
std.debug.warn("duplicate: {} {} ({Bi:2})\n", .{
|
std.debug.warn("duplicate: {} {} ({Bi:2})\n", .{
|
||||||
libc_target.name,
|
libc_target.name,
|
||||||
rel_path,
|
rel_path,
|
||||||
raw_bytes.len,
|
raw_bytes.len,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
gop.kv.value = Contents{
|
gop.entry.value = Contents{
|
||||||
.bytes = trimmed,
|
.bytes = trimmed,
|
||||||
.hit_count = 1,
|
.hit_count = 1,
|
||||||
.hash = hash,
|
.hash = hash,
|
||||||
@ -380,13 +381,13 @@ pub fn main() !void {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
const path_gop = try path_table.getOrPut(rel_path);
|
const path_gop = try path_table.getOrPut(rel_path);
|
||||||
const target_to_hash = if (path_gop.found_existing) path_gop.kv.value else blk: {
|
const target_to_hash = if (path_gop.found_existing) path_gop.entry.value else blk: {
|
||||||
const ptr = try allocator.create(TargetToHash);
|
const ptr = try allocator.create(TargetToHash);
|
||||||
ptr.* = TargetToHash.init(allocator);
|
ptr.* = TargetToHash.init(allocator);
|
||||||
path_gop.kv.value = ptr;
|
path_gop.entry.value = ptr;
|
||||||
break :blk ptr;
|
break :blk ptr;
|
||||||
};
|
};
|
||||||
assert((try target_to_hash.put(dest_target, hash)) == null);
|
try target_to_hash.putNoClobber(dest_target, hash);
|
||||||
},
|
},
|
||||||
else => std.debug.warn("warning: weird file: {}\n", .{full_path}),
|
else => std.debug.warn("warning: weird file: {}\n", .{full_path}),
|
||||||
}
|
}
|
||||||
@ -410,7 +411,7 @@ pub fn main() !void {
|
|||||||
{
|
{
|
||||||
var hash_it = path_kv.value.iterator();
|
var hash_it = path_kv.value.iterator();
|
||||||
while (hash_it.next()) |hash_kv| {
|
while (hash_it.next()) |hash_kv| {
|
||||||
const contents = &hash_to_contents.get(hash_kv.value).?.value;
|
const contents = &hash_to_contents.get(hash_kv.value).?;
|
||||||
try contents_list.append(contents);
|
try contents_list.append(contents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -432,7 +433,7 @@ pub fn main() !void {
|
|||||||
}
|
}
|
||||||
var hash_it = path_kv.value.iterator();
|
var hash_it = path_kv.value.iterator();
|
||||||
while (hash_it.next()) |hash_kv| {
|
while (hash_it.next()) |hash_kv| {
|
||||||
const contents = &hash_to_contents.get(hash_kv.value).?.value;
|
const contents = &hash_to_contents.get(hash_kv.value).?;
|
||||||
if (contents.is_generic) continue;
|
if (contents.is_generic) continue;
|
||||||
|
|
||||||
const dest_target = hash_kv.key;
|
const dest_target = hash_kv.key;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user