authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-04 13:23:57-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-09 09:28:05-07:00
logf064f0564fcdd3a163f137f72ecb7a997fdebfd1
tree92c90395f93fbf9e638235b63e6e5a970984450f
parent71687b30a24dc4468944620a5e1514077e6d5325

stage2: improve log message format


1 files changed, 11 insertions(+), 6 deletions(-)

src-self-hosted/main.zig+11-6
...@@ -13,7 +13,6 @@ const Package = @import("Package.zig");...@@ -13,7 +13,6 @@ const Package = @import("Package.zig");
13const zir = @import("zir.zig");13const zir = @import("zir.zig");
14const build_options = @import("build_options");14const build_options = @import("build_options");
15const warn = std.log.warn;15const warn = std.log.warn;
16const info = std.log.info;
1716
18fn fatal(comptime format: []const u8, args: anytype) noreturn {17fn fatal(comptime format: []const u8, args: anytype) noreturn {
19 std.log.emerg(format, args);18 std.log.emerg(format, args);
...@@ -67,10 +66,16 @@ pub fn log(...@@ -67,10 +66,16 @@ pub fn log(
67 return;66 return;
68 }67 }
6968
70 const prefix = "[" ++ @tagName(level) ++ "] " ++ "(" ++ @tagName(scope) ++ "): ";69 const level_txt = switch (level) {
70 .emerg => "error",
71 .warn => "warning",
72 else => @tagName(level),
73 };
74 const prefix1 = level_txt ++ ": ";
75 const prefix2 = if (scope == .default) "" else "(" ++ @tagName(scope) ++ "): ";
7176
72 // Print the message to stderr, silently ignoring any errors77 // Print the message to stderr, silently ignoring any errors
73 std.debug.print(prefix ++ format ++ "\n", args);78 std.debug.print(prefix1 ++ prefix2 ++ format ++ "\n", args);
74}79}
7580
76var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};81var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};
...@@ -486,8 +491,6 @@ pub fn buildOutputType(...@@ -486,8 +491,6 @@ pub fn buildOutputType(
486 }491 }
487 }492 }
488 } else {493 } else {
489 if (!build_options.have_llvm)
490 fatal("`zig cc` and `zig c++` unavailable: compiler not built with LLVM extensions enabled", .{});
491 emit_h = false;494 emit_h = false;
492 strip = true;495 strip = true;
493 ensure_libc_on_non_freestanding = true;496 ensure_libc_on_non_freestanding = true;
...@@ -994,7 +997,7 @@ fn updateModule(gpa: *Allocator, module: *Module, zir_out_path: ?[]const u8) !vo...@@ -994,7 +997,7 @@ fn updateModule(gpa: *Allocator, module: *Module, zir_out_path: ?[]const u8) !vo
994 });997 });
995 }998 }
996 } else {999 } else {
997 info("Update completed in {} ms", .{update_nanos / std.time.ns_per_ms});1000 std.log.info("Update completed in {} ms", .{update_nanos / std.time.ns_per_ms});
998 }1001 }
9991002
1000 if (zir_out_path) |zop| {1003 if (zir_out_path) |zop| {
...@@ -1401,6 +1404,8 @@ extern "c" fn ZigClang_main(argc: c_int, argv: [*:null]?[*:0]u8) c_int;...@@ -1401,6 +1404,8 @@ extern "c" fn ZigClang_main(argc: c_int, argv: [*:null]?[*:0]u8) c_int;
14011404
1402/// TODO make it so the return value can be !noreturn1405/// TODO make it so the return value can be !noreturn
1403fn punt_to_clang(arena: *Allocator, args: []const []const u8) error{OutOfMemory} {1406fn punt_to_clang(arena: *Allocator, args: []const []const u8) error{OutOfMemory} {
1407 if (!build_options.have_llvm)
1408 fatal("`zig cc` and `zig c++` unavailable: compiler not built with LLVM extensions enabled", .{});
1404 // Convert the args to the format Clang expects.1409 // Convert the args to the format Clang expects.
1405 const argv = try arena.alloc(?[*:0]u8, args.len + 1);1410 const argv = try arena.alloc(?[*:0]u8, args.len + 1);
1406 for (args) |arg, i| {1411 for (args) |arg, i| {