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
signature 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 @@
1111// You'll then have to manually update Zig source repo with these new files.
1212
1313const std = @import("std");
14const builtin = @import("builtin");
15const Arch = builtin.Arch;
16const Abi = builtin.Abi;
17const Os = builtin.Os;
14const builtin = std.builtin;
15const Arch = std.Target.Cpu.Arch;
16const Abi = std.Target.Abi;
17const OsTag = std.Target.Os.Tag;
1818const assert = std.debug.assert;
1919
2020const LibCTarget = struct {
......@@ -29,12 +29,12 @@ const MultiArch = union(enum) {
2929 mips,
3030 mips64,
3131 powerpc64,
32 specific: @TagType(Arch),
32 specific: Arch,
3333
3434 fn eql(a: MultiArch, b: MultiArch) bool {
3535 if (@enumToInt(a) != @enumToInt(b))
3636 return false;
37 if (@TagType(MultiArch)(a) != .specific)
37 if (a != .specific)
3838 return true;
3939 return a.specific == b.specific;
4040 }
......@@ -221,7 +221,7 @@ const musl_targets = [_]LibCTarget{
221221
222222const DestTarget = struct {
223223 arch: MultiArch,
224 os: Os,
224 os: OsTag,
225225 abi: Abi,
226226
227227 fn hash(a: DestTarget) u32 {
......@@ -305,8 +305,8 @@ pub fn main() !void {
305305 // TODO compiler crashed when I wrote this the canonical way
306306 var libc_targets: []const LibCTarget = undefined;
307307 switch (vendor) {
308 .musl => libc_targets = musl_targets,
309 .glibc => libc_targets = glibc_targets,
308 .musl => libc_targets = &musl_targets,
309 .glibc => libc_targets = &glibc_targets,
310310 }
311311
312312 var path_table = PathTable.init(allocator);
......@@ -340,15 +340,17 @@ pub fn main() !void {
340340 try dir_stack.append(target_include_dir);
341341
342342 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) {
344344 error.FileNotFound => continue :search,
345345 error.AccessDenied => continue :search,
346346 else => return err,
347347 };
348348 defer dir.close();
349349
350 while (try dir.next()) |entry| {
351 const full_path = try std.fs.path.join(allocator, [_][]const u8{ full_dir_name, entry.name });
350 var dir_it = dir.iterate();
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 });
352354 switch (entry.kind) {
353355 .Directory => try dir_stack.append(full_path),
354356 .File => {
......@@ -396,8 +398,8 @@ pub fn main() !void {
396398 std.debug.warn("warning: libc target not found: {}\n", .{libc_target.name});
397399 }
398400 }
399 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);
401 std.debug.warn("summary: {Bi:2} could be reduced to {Bi:2}\n", .{ total_bytes, total_bytes - max_bytes_saved });
402 try std.fs.cwd().makePath(out_dir);
401403
402404 var missed_opportunity_bytes: usize = 0;
403405 // 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 {
417419 var best_contents = contents_list.popOrNull().?;
418420 if (best_contents.hit_count > 1) {
419421 // 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 });
421 try std.fs.makePath(allocator, std.fs.path.dirname(full_path).?);
422 const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key });
423 try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);
422424 try std.io.writeFile(full_path, best_contents.bytes);
423425 best_contents.is_generic = true;
424426 while (contents_list.popOrNull()) |contender| {
425427 if (contender.hit_count > 1) {
426428 const this_missed_bytes = contender.hit_count * contender.bytes.len;
427429 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 });
429431 } else break;
430432 }
431433 }
......@@ -444,8 +446,8 @@ pub fn main() !void {
444446 @tagName(dest_target.os),
445447 @tagName(dest_target.abi),
446448 });
447 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).?);
449 const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, out_subpath, path_kv.key });
450 try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);
449451 try std.io.writeFile(full_path, contents.bytes);
450452 }
451453 }