authorgravatar for samratmansingh@gmail.comSamrat Man Singh <samratmansingh@gmail.com> 2020-09-15 15:30:42+05:30
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-15 18:03:55-04:00
logca85e367f4376a9365476386e1edbb6aada487c2
tree21d322f9975ce93104ac26da028cdef7462b3646
parentb3cc36857ebc4bcfc259da361018d70c1a7d9e7b

Use std.log in LibcInstallation `parse` instead of taking `stderr`


2 files changed, 10 insertions(+), 13 deletions(-)

src-self-hosted/libc_installation.zig+9-8
......@@ -9,6 +9,8 @@ const is_darwin = Target.current.isDarwin();
99const is_windows = Target.current.os.tag == .windows;
1010const is_gnu = Target.current.isGnu();
1111
12const log = std.log.scoped(.libc_installation);
13
1214usingnamespace @import("windows_sdk.zig");
1315
1416/// See the render function implementation for documentation of the fields.
......@@ -37,7 +39,6 @@ pub const LibCInstallation = struct {
3739 pub fn parse(
3840 allocator: *Allocator,
3941 libc_file: []const u8,
40 stderr: anytype,
4142 ) !LibCInstallation {
4243 var self: LibCInstallation = .{};
4344
......@@ -62,7 +63,7 @@ pub const LibCInstallation = struct {
6263 if (line.len == 0 or line[0] == '#') continue;
6364 var line_it = std.mem.split(line, "=");
6465 const name = line_it.next() orelse {
65 try stderr.print("missing equal sign after field name\n", .{});
66 log.err("missing equal sign after field name\n", .{});
6667 return error.ParseError;
6768 };
6869 const value = line_it.rest();
......@@ -81,31 +82,31 @@ pub const LibCInstallation = struct {
8182 }
8283 inline for (fields) |field, i| {
8384 if (!found_keys[i].found) {
84 try stderr.print("missing field: {}\n", .{field.name});
85 log.err("missing field: {}\n", .{field.name});
8586 return error.ParseError;
8687 }
8788 }
8889 if (self.include_dir == null) {
89 try stderr.print("include_dir may not be empty\n", .{});
90 log.err("include_dir may not be empty\n", .{});
9091 return error.ParseError;
9192 }
9293 if (self.sys_include_dir == null) {
93 try stderr.print("sys_include_dir may not be empty\n", .{});
94 log.err("sys_include_dir may not be empty\n", .{});
9495 return error.ParseError;
9596 }
9697 if (self.crt_dir == null and !is_darwin) {
97 try stderr.print("crt_dir may not be empty for {}\n", .{@tagName(Target.current.os.tag)});
98 log.err("crt_dir may not be empty for {}\n", .{@tagName(Target.current.os.tag)});
9899 return error.ParseError;
99100 }
100101 if (self.msvc_lib_dir == null and is_windows and !is_gnu) {
101 try stderr.print("msvc_lib_dir may not be empty for {}-{}\n", .{
102 log.err("msvc_lib_dir may not be empty for {}-{}\n", .{
102103 @tagName(Target.current.os.tag),
103104 @tagName(Target.current.abi),
104105 });
105106 return error.ParseError;
106107 }
107108 if (self.kernel32_lib_dir == null and is_windows and !is_gnu) {
108 try stderr.print("kernel32_lib_dir may not be empty for {}-{}\n", .{
109 log.err("kernel32_lib_dir may not be empty for {}-{}\n", .{
109110 @tagName(Target.current.os.tag),
110111 @tagName(Target.current.abi),
111112 });
src-self-hosted/stage2.zig+1-5
......@@ -598,12 +598,9 @@ const Stage2LibCInstallation = extern struct {
598598
599599// ABI warning
600600export fn stage2_libc_parse(stage1_libc: *Stage2LibCInstallation, libc_file_z: [*:0]const u8) Error {
601 stderr_file = std.io.getStdErr();
602 stderr = stderr_file.outStream();
603601 const libc_file = mem.spanZ(libc_file_z);
604 var libc = LibCInstallation.parse(std.heap.c_allocator, libc_file, stderr) catch |err| switch (err) {
602 var libc = LibCInstallation.parse(std.heap.c_allocator, libc_file) catch |err| switch (err) {
605603 error.ParseError => return .SemanticAnalyzeFail,
606 error.DiskQuota => return .DiskQuota,
607604 error.FileTooBig => return .FileTooBig,
608605 error.InputOutput => return .FileSystem,
609606 error.NoSpaceLeft => return .NoSpaceLeft,
......@@ -612,7 +609,6 @@ export fn stage2_libc_parse(stage1_libc: *Stage2LibCInstallation, libc_file_z: [
612609 error.SystemResources => return .SystemResources,
613610 error.OperationAborted => return .OperationAborted,
614611 error.WouldBlock => unreachable,
615 error.NotOpenForWriting => unreachable,
616612 error.NotOpenForReading => unreachable,
617613 error.Unexpected => return .Unexpected,
618614 error.IsDir => return .IsDir,