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();...@@ -9,6 +9,8 @@ const is_darwin = Target.current.isDarwin();
9const is_windows = Target.current.os.tag == .windows;9const is_windows = Target.current.os.tag == .windows;
10const is_gnu = Target.current.isGnu();10const is_gnu = Target.current.isGnu();
1111
12const log = std.log.scoped(.libc_installation);
13
12usingnamespace @import("windows_sdk.zig");14usingnamespace @import("windows_sdk.zig");
1315
14/// See the render function implementation for documentation of the fields.16/// See the render function implementation for documentation of the fields.
...@@ -37,7 +39,6 @@ pub const LibCInstallation = struct {...@@ -37,7 +39,6 @@ pub const LibCInstallation = struct {
37 pub fn parse(39 pub fn parse(
38 allocator: *Allocator,40 allocator: *Allocator,
39 libc_file: []const u8,41 libc_file: []const u8,
40 stderr: anytype,
41 ) !LibCInstallation {42 ) !LibCInstallation {
42 var self: LibCInstallation = .{};43 var self: LibCInstallation = .{};
4344
...@@ -62,7 +63,7 @@ pub const LibCInstallation = struct {...@@ -62,7 +63,7 @@ pub const LibCInstallation = struct {
62 if (line.len == 0 or line[0] == '#') continue;63 if (line.len == 0 or line[0] == '#') continue;
63 var line_it = std.mem.split(line, "=");64 var line_it = std.mem.split(line, "=");
64 const name = line_it.next() orelse {65 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", .{});
66 return error.ParseError;67 return error.ParseError;
67 };68 };
68 const value = line_it.rest();69 const value = line_it.rest();
...@@ -81,31 +82,31 @@ pub const LibCInstallation = struct {...@@ -81,31 +82,31 @@ pub const LibCInstallation = struct {
81 }82 }
82 inline for (fields) |field, i| {83 inline for (fields) |field, i| {
83 if (!found_keys[i].found) {84 if (!found_keys[i].found) {
84 try stderr.print("missing field: {}\n", .{field.name});85 log.err("missing field: {}\n", .{field.name});
85 return error.ParseError;86 return error.ParseError;
86 }87 }
87 }88 }
88 if (self.include_dir == null) {89 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", .{});
90 return error.ParseError;91 return error.ParseError;
91 }92 }
92 if (self.sys_include_dir == null) {93 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", .{});
94 return error.ParseError;95 return error.ParseError;
95 }96 }
96 if (self.crt_dir == null and !is_darwin) {97 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)});
98 return error.ParseError;99 return error.ParseError;
99 }100 }
100 if (self.msvc_lib_dir == null and is_windows and !is_gnu) {101 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", .{
102 @tagName(Target.current.os.tag),103 @tagName(Target.current.os.tag),
103 @tagName(Target.current.abi),104 @tagName(Target.current.abi),
104 });105 });
105 return error.ParseError;106 return error.ParseError;
106 }107 }
107 if (self.kernel32_lib_dir == null and is_windows and !is_gnu) {108 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", .{
109 @tagName(Target.current.os.tag),110 @tagName(Target.current.os.tag),
110 @tagName(Target.current.abi),111 @tagName(Target.current.abi),
111 });112 });
src-self-hosted/stage2.zig+1-5
...@@ -598,12 +598,9 @@ const Stage2LibCInstallation = extern struct {...@@ -598,12 +598,9 @@ const Stage2LibCInstallation = extern struct {
598598
599// ABI warning599// ABI warning
600export fn stage2_libc_parse(stage1_libc: *Stage2LibCInstallation, libc_file_z: [*:0]const u8) Error {600export 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();
603 const libc_file = mem.spanZ(libc_file_z);601 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) {
605 error.ParseError => return .SemanticAnalyzeFail,603 error.ParseError => return .SemanticAnalyzeFail,
606 error.DiskQuota => return .DiskQuota,
607 error.FileTooBig => return .FileTooBig,604 error.FileTooBig => return .FileTooBig,
608 error.InputOutput => return .FileSystem,605 error.InputOutput => return .FileSystem,
609 error.NoSpaceLeft => return .NoSpaceLeft,606 error.NoSpaceLeft => return .NoSpaceLeft,
...@@ -612,7 +609,6 @@ export fn stage2_libc_parse(stage1_libc: *Stage2LibCInstallation, libc_file_z: [...@@ -612,7 +609,6 @@ export fn stage2_libc_parse(stage1_libc: *Stage2LibCInstallation, libc_file_z: [
612 error.SystemResources => return .SystemResources,609 error.SystemResources => return .SystemResources,
613 error.OperationAborted => return .OperationAborted,610 error.OperationAborted => return .OperationAborted,
614 error.WouldBlock => unreachable,611 error.WouldBlock => unreachable,
615 error.NotOpenForWriting => unreachable,
616 error.NotOpenForReading => unreachable,612 error.NotOpenForReading => unreachable,
617 error.Unexpected => return .Unexpected,613 error.Unexpected => return .Unexpected,
618 error.IsDir => return .IsDir,614 error.IsDir => return .IsDir,