authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-03 22:40:41-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-03 22:40:41-05:00
log3841acf7ef54afd6f315fe79cf51ffd33726d36d
tree38d2cb523fbf2d2be807444b3e10e6f74de56c57
parent8aaab75af05c6066d8f952259d0d540f92c4772e
signaturelock-open Commit is signed but in an unrecognized format.

update process_headers tool to latest zig


1 files changed, 21 insertions(+), 19 deletions(-)

tools/process_headers.zig+21-19
...@@ -11,10 +11,10 @@...@@ -11,10 +11,10 @@
11// You'll then have to manually update Zig source repo with these new files.11// You'll then have to manually update Zig source repo with these new files.
1212
13const std = @import("std");13const std = @import("std");
14const builtin = @import("builtin");14const builtin = std.builtin;
15const Arch = builtin.Arch;15const Arch = std.Target.Cpu.Arch;
16const Abi = builtin.Abi;16const Abi = std.Target.Abi;
17const Os = builtin.Os;17const OsTag = std.Target.Os.Tag;
18const assert = std.debug.assert;18const assert = std.debug.assert;
1919
20const LibCTarget = struct {20const LibCTarget = struct {
...@@ -29,12 +29,12 @@ const MultiArch = union(enum) {...@@ -29,12 +29,12 @@ const MultiArch = union(enum) {
29 mips,29 mips,
30 mips64,30 mips64,
31 powerpc64,31 powerpc64,
32 specific: @TagType(Arch),32 specific: Arch,
3333
34 fn eql(a: MultiArch, b: MultiArch) bool {34 fn eql(a: MultiArch, b: MultiArch) bool {
35 if (@enumToInt(a) != @enumToInt(b))35 if (@enumToInt(a) != @enumToInt(b))
36 return false;36 return false;
37 if (@TagType(MultiArch)(a) != .specific)37 if (a != .specific)
38 return true;38 return true;
39 return a.specific == b.specific;39 return a.specific == b.specific;
40 }40 }
...@@ -221,7 +221,7 @@ const musl_targets = [_]LibCTarget{...@@ -221,7 +221,7 @@ const musl_targets = [_]LibCTarget{
221221
222const DestTarget = struct {222const DestTarget = struct {
223 arch: MultiArch,223 arch: MultiArch,
224 os: Os,224 os: OsTag,
225 abi: Abi,225 abi: Abi,
226226
227 fn hash(a: DestTarget) u32 {227 fn hash(a: DestTarget) u32 {
...@@ -305,8 +305,8 @@ pub fn main() !void {...@@ -305,8 +305,8 @@ pub fn main() !void {
305 // TODO compiler crashed when I wrote this the canonical way305 // TODO compiler crashed when I wrote this the canonical way
306 var libc_targets: []const LibCTarget = undefined;306 var libc_targets: []const LibCTarget = undefined;
307 switch (vendor) {307 switch (vendor) {
308 .musl => libc_targets = musl_targets,308 .musl => libc_targets = &musl_targets,
309 .glibc => libc_targets = glibc_targets,309 .glibc => libc_targets = &glibc_targets,
310 }310 }
311311
312 var path_table = PathTable.init(allocator);312 var path_table = PathTable.init(allocator);
...@@ -340,15 +340,17 @@ pub fn main() !void {...@@ -340,15 +340,17 @@ pub fn main() !void {
340 try dir_stack.append(target_include_dir);340 try dir_stack.append(target_include_dir);
341341
342 while (dir_stack.popOrNull()) |full_dir_name| {342 while (dir_stack.popOrNull()) |full_dir_name| {
343 var dir = std.fs.Dir.cwd().openDirList(full_dir_name) catch |err| switch (err) {343 var dir = std.fs.cwd().openDirList(full_dir_name) catch |err| switch (err) {
344 error.FileNotFound => continue :search,344 error.FileNotFound => continue :search,
345 error.AccessDenied => continue :search,345 error.AccessDenied => continue :search,
346 else => return err,346 else => return err,
347 };347 };
348 defer dir.close();348 defer dir.close();
349349
350 while (try dir.next()) |entry| {350 var dir_it = dir.iterate();
351 const full_path = try std.fs.path.join(allocator, [_][]const u8{ full_dir_name, entry.name });351
352 while (try dir_it.next()) |entry| {
353 const full_path = try std.fs.path.join(allocator, &[_][]const u8{ full_dir_name, entry.name });
352 switch (entry.kind) {354 switch (entry.kind) {
353 .Directory => try dir_stack.append(full_path),355 .Directory => try dir_stack.append(full_path),
354 .File => {356 .File => {
...@@ -396,8 +398,8 @@ pub fn main() !void {...@@ -396,8 +398,8 @@ pub fn main() !void {
396 std.debug.warn("warning: libc target not found: {}\n", .{libc_target.name});398 std.debug.warn("warning: libc target not found: {}\n", .{libc_target.name});
397 }399 }
398 }400 }
399 std.debug.warn("summary: {Bi:2} could be reduced to {Bi:2}\n", .{total_bytes, total_bytes - max_bytes_saved});401 std.debug.warn("summary: {Bi:2} could be reduced to {Bi:2}\n", .{ total_bytes, total_bytes - max_bytes_saved });
400 try std.fs.makePath(allocator, out_dir);402 try std.fs.cwd().makePath(out_dir);
401403
402 var missed_opportunity_bytes: usize = 0;404 var missed_opportunity_bytes: usize = 0;
403 // iterate path_table. for each path, put all the hashes into a list. sort by hit_count.405 // iterate path_table. for each path, put all the hashes into a list. sort by hit_count.
...@@ -417,15 +419,15 @@ pub fn main() !void {...@@ -417,15 +419,15 @@ pub fn main() !void {
417 var best_contents = contents_list.popOrNull().?;419 var best_contents = contents_list.popOrNull().?;
418 if (best_contents.hit_count > 1) {420 if (best_contents.hit_count > 1) {
419 // worth it to make it generic421 // worth it to make it generic
420 const full_path = try std.fs.path.join(allocator, [_][]const u8{ out_dir, generic_name, path_kv.key });422 const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key });
421 try std.fs.makePath(allocator, std.fs.path.dirname(full_path).?);423 try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);
422 try std.io.writeFile(full_path, best_contents.bytes);424 try std.io.writeFile(full_path, best_contents.bytes);
423 best_contents.is_generic = true;425 best_contents.is_generic = true;
424 while (contents_list.popOrNull()) |contender| {426 while (contents_list.popOrNull()) |contender| {
425 if (contender.hit_count > 1) {427 if (contender.hit_count > 1) {
426 const this_missed_bytes = contender.hit_count * contender.bytes.len;428 const this_missed_bytes = contender.hit_count * contender.bytes.len;
427 missed_opportunity_bytes += this_missed_bytes;429 missed_opportunity_bytes += this_missed_bytes;
428 std.debug.warn("Missed opportunity ({Bi:2}): {}\n", .{this_missed_bytes, path_kv.key});430 std.debug.warn("Missed opportunity ({Bi:2}): {}\n", .{ this_missed_bytes, path_kv.key });
429 } else break;431 } else break;
430 }432 }
431 }433 }
...@@ -444,8 +446,8 @@ pub fn main() !void {...@@ -444,8 +446,8 @@ pub fn main() !void {
444 @tagName(dest_target.os),446 @tagName(dest_target.os),
445 @tagName(dest_target.abi),447 @tagName(dest_target.abi),
446 });448 });
447 const full_path = try std.fs.path.join(allocator, [_][]const u8{ out_dir, out_subpath, path_kv.key });449 const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, out_subpath, path_kv.key });
448 try std.fs.makePath(allocator, std.fs.path.dirname(full_path).?);450 try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);
449 try std.io.writeFile(full_path, contents.bytes);451 try std.io.writeFile(full_path, contents.bytes);
450 }452 }
451 }453 }