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");
1313const zir = @import("zir.zig");
1414const build_options = @import("build_options");
1515const warn = std.log.warn;
16const info = std.log.info;
1716
1817fn fatal(comptime format: []const u8, args: anytype) noreturn {
1918 std.log.emerg(format, args);
......@@ -67,10 +66,16 @@ pub fn log(
6766 return;
6867 }
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
7277 // 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);
7479}
7580
7681var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};
......@@ -486,8 +491,6 @@ pub fn buildOutputType(
486491 }
487492 }
488493 } else {
489 if (!build_options.have_llvm)
490 fatal("`zig cc` and `zig c++` unavailable: compiler not built with LLVM extensions enabled", .{});
491494 emit_h = false;
492495 strip = true;
493496 ensure_libc_on_non_freestanding = true;
......@@ -994,7 +997,7 @@ fn updateModule(gpa: *Allocator, module: *Module, zir_out_path: ?[]const u8) !vo
994997 });
995998 }
996999 } 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});
9981001 }
9991002
10001003 if (zir_out_path) |zop| {
......@@ -1401,6 +1404,8 @@ extern "c" fn ZigClang_main(argc: c_int, argv: [*:null]?[*:0]u8) c_int;
14011404
14021405/// TODO make it so the return value can be !noreturn
14031406fn 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", .{});
14041409 // Convert the args to the format Clang expects.
14051410 const argv = try arena.alloc(?[*:0]u8, args.len + 1);
14061411 for (args) |arg, i| {