authorgravatar for kaihlavirta@gmail.comMikko Kaihlavirta <kaihlavirta@gmail.com> 2022-07-09 18:15:03+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-11 11:18:52+03:00
log6f55b294f60385b76187dbeac3d571449466ab3b
tree4b23341382584501c681c2a96994e11297d59f81
parent4bbc95b219ba7ab966e55624d9c9e348a14c3b34

use std.log for logging


1 files changed, 70 insertions(+), 76 deletions(-)

lib/std/build.zig+70-76
......@@ -6,7 +6,7 @@ const mem = std.mem;
66const debug = std.debug;
77const panic = std.debug.panic;
88const assert = debug.assert;
9const warn = std.debug.print; // TODO use the log system instead of this
9const log = std.log;
1010const ArrayList = std.ArrayList;
1111const StringHashMap = std.StringHashMap;
1212const Allocator = mem.Allocator;
......@@ -478,7 +478,7 @@ pub const Builder = struct {
478478 for (self.installed_files.items) |installed_file| {
479479 const full_path = self.getInstallPath(installed_file.dir, installed_file.path);
480480 if (self.verbose) {
481 warn("rm {s}\n", .{full_path});
481 log.info("rm {s}", .{full_path});
482482 }
483483 fs.cwd().deleteTree(full_path) catch {};
484484 }
......@@ -488,7 +488,7 @@ pub const Builder = struct {
488488
489489 fn makeOneStep(self: *Builder, s: *Step) anyerror!void {
490490 if (s.loop_flag) {
491 warn("Dependency loop detected:\n {s}\n", .{s.name});
491 log.err("Dependency loop detected:\n {s}", .{s.name});
492492 return error.DependencyLoopDetected;
493493 }
494494 s.loop_flag = true;
......@@ -496,7 +496,7 @@ pub const Builder = struct {
496496 for (s.dependencies.items) |dep| {
497497 self.makeOneStep(dep) catch |err| {
498498 if (err == error.DependencyLoopDetected) {
499 warn(" {s}\n", .{s.name});
499 log.err(" {s}", .{s.name});
500500 }
501501 return err;
502502 };
......@@ -513,7 +513,7 @@ pub const Builder = struct {
513513 return &top_level_step.step;
514514 }
515515 }
516 warn("Cannot run step '{s}' because it does not exist\n", .{name});
516 log.err("Cannot run step '{s}' because it does not exist", .{name});
517517 return error.InvalidStepName;
518518 }
519519
......@@ -553,32 +553,32 @@ pub const Builder = struct {
553553 } else if (mem.eql(u8, s, "false")) {
554554 return false;
555555 } else {
556 warn("Expected -D{s} to be a boolean, but received '{s}'\n\n", .{ name, s });
556 log.err("Expected -D{s} to be a boolean, but received '{s}'\n", .{ name, s });
557557 self.markInvalidUserInput();
558558 return null;
559559 }
560560 },
561561 .list => {
562 warn("Expected -D{s} to be a boolean, but received a list.\n\n", .{name});
562 log.err("Expected -D{s} to be a boolean, but received a list.\n", .{name});
563563 self.markInvalidUserInput();
564564 return null;
565565 },
566566 },
567567 .int => switch (option_ptr.value) {
568568 .flag => {
569 warn("Expected -D{s} to be an integer, but received a boolean.\n\n", .{name});
569 log.err("Expected -D{s} to be an integer, but received a boolean.\n", .{name});
570570 self.markInvalidUserInput();
571571 return null;
572572 },
573573 .scalar => |s| {
574574 const n = std.fmt.parseInt(T, s, 10) catch |err| switch (err) {
575575 error.Overflow => {
576 warn("-D{s} value {s} cannot fit into type {s}.\n\n", .{ name, s, @typeName(T) });
576 log.err("-D{s} value {s} cannot fit into type {s}.\n", .{ name, s, @typeName(T) });
577577 self.markInvalidUserInput();
578578 return null;
579579 },
580580 else => {
581 warn("Expected -D{s} to be an integer of type {s}.\n\n", .{ name, @typeName(T) });
581 log.err("Expected -D{s} to be an integer of type {s}.\n", .{ name, @typeName(T) });
582582 self.markInvalidUserInput();
583583 return null;
584584 },
......@@ -586,34 +586,34 @@ pub const Builder = struct {
586586 return n;
587587 },
588588 .list => {
589 warn("Expected -D{s} to be an integer, but received a list.\n\n", .{name});
589 log.err("Expected -D{s} to be an integer, but received a list.\n", .{name});
590590 self.markInvalidUserInput();
591591 return null;
592592 },
593593 },
594594 .float => switch (option_ptr.value) {
595595 .flag => {
596 warn("Expected -D{s} to be a float, but received a boolean.\n\n", .{name});
596 log.err("Expected -D{s} to be a float, but received a boolean.\n", .{name});
597597 self.markInvalidUserInput();
598598 return null;
599599 },
600600 .scalar => |s| {
601601 const n = std.fmt.parseFloat(T, s) catch {
602 warn("Expected -D{s} to be a float of type {s}.\n\n", .{ name, @typeName(T) });
602 log.err("Expected -D{s} to be a float of type {s}.\n", .{ name, @typeName(T) });
603603 self.markInvalidUserInput();
604604 return null;
605605 };
606606 return n;
607607 },
608608 .list => {
609 warn("Expected -D{s} to be a float, but received a list.\n\n", .{name});
609 log.err("Expected -D{s} to be a float, but received a list.\n", .{name});
610610 self.markInvalidUserInput();
611611 return null;
612612 },
613613 },
614614 .@"enum" => switch (option_ptr.value) {
615615 .flag => {
616 warn("Expected -D{s} to be a string, but received a boolean.\n\n", .{name});
616 log.err("Expected -D{s} to be a string, but received a boolean.\n", .{name});
617617 self.markInvalidUserInput();
618618 return null;
619619 },
......@@ -621,25 +621,25 @@ pub const Builder = struct {
621621 if (std.meta.stringToEnum(T, s)) |enum_lit| {
622622 return enum_lit;
623623 } else {
624 warn("Expected -D{s} to be of type {s}.\n\n", .{ name, @typeName(T) });
624 log.err("Expected -D{s} to be of type {s}.\n", .{ name, @typeName(T) });
625625 self.markInvalidUserInput();
626626 return null;
627627 }
628628 },
629629 .list => {
630 warn("Expected -D{s} to be a string, but received a list.\n\n", .{name});
630 log.err("Expected -D{s} to be a string, but received a list.\n", .{name});
631631 self.markInvalidUserInput();
632632 return null;
633633 },
634634 },
635635 .string => switch (option_ptr.value) {
636636 .flag => {
637 warn("Expected -D{s} to be a string, but received a boolean.\n\n", .{name});
637 log.err("Expected -D{s} to be a string, but received a boolean.\n", .{name});
638638 self.markInvalidUserInput();
639639 return null;
640640 },
641641 .list => {
642 warn("Expected -D{s} to be a string, but received a list.\n\n", .{name});
642 log.err("Expected -D{s} to be a string, but received a list.\n", .{name});
643643 self.markInvalidUserInput();
644644 return null;
645645 },
......@@ -647,7 +647,7 @@ pub const Builder = struct {
647647 },
648648 .list => switch (option_ptr.value) {
649649 .flag => {
650 warn("Expected -D{s} to be a list, but received a boolean.\n\n", .{name});
650 log.err("Expected -D{s} to be a list, but received a boolean.\n", .{name});
651651 self.markInvalidUserInput();
652652 return null;
653653 },
......@@ -697,7 +697,7 @@ pub const Builder = struct {
697697 else if (!release_fast and !release_safe and !release_small)
698698 std.builtin.Mode.Debug
699699 else x: {
700 warn("Multiple release modes (of -Drelease-safe, -Drelease-fast and -Drelease-small)\n\n", .{});
700 log.err("Multiple release modes (of -Drelease-safe, -Drelease-fast and -Drelease-small)\n", .{});
701701 self.markInvalidUserInput();
702702 break :x std.builtin.Mode.Debug;
703703 };
......@@ -734,19 +734,18 @@ pub const Builder = struct {
734734 .diagnostics = &diags,
735735 }) catch |err| switch (err) {
736736 error.UnknownCpuModel => {
737 warn("Unknown CPU: '{s}'\nAvailable CPUs for architecture '{s}':\n", .{
737 log.err("Unknown CPU: '{s}'\nAvailable CPUs for architecture '{s}':", .{
738738 diags.cpu_name.?,
739739 @tagName(diags.arch.?),
740740 });
741741 for (diags.arch.?.allCpuModels()) |cpu| {
742 warn(" {s}\n", .{cpu.name});
742 log.err(" {s}", .{cpu.name});
743743 }
744 warn("\n", .{});
745744 self.markInvalidUserInput();
746745 return args.default_target;
747746 },
748747 error.UnknownCpuFeature => {
749 warn(
748 log.err(
750749 \\Unknown CPU feature: '{s}'
751750 \\Available CPU features for architecture '{s}':
752751 \\
......@@ -755,27 +754,25 @@ pub const Builder = struct {
755754 @tagName(diags.arch.?),
756755 });
757756 for (diags.arch.?.allFeaturesList()) |feature| {
758 warn(" {s}: {s}\n", .{ feature.name, feature.description });
757 log.err(" {s}: {s}", .{ feature.name, feature.description });
759758 }
760 warn("\n", .{});
761759 self.markInvalidUserInput();
762760 return args.default_target;
763761 },
764762 error.UnknownOperatingSystem => {
765 warn(
763 log.err(
766764 \\Unknown OS: '{s}'
767765 \\Available operating systems:
768766 \\
769767 , .{diags.os_name});
770768 inline for (std.meta.fields(std.Target.Os.Tag)) |field| {
771 warn(" {s}\n", .{field.name});
769 log.err(" {s}", .{field.name});
772770 }
773 warn("\n", .{});
774771 self.markInvalidUserInput();
775772 return args.default_target;
776773 },
777774 else => |e| {
778 warn("Unable to parse target '{s}': {s}\n\n", .{ triple, @errorName(e) });
775 log.err("Unable to parse target '{s}': {s}\n", .{ triple, @errorName(e) });
779776 self.markInvalidUserInput();
780777 return args.default_target;
781778 },
......@@ -805,22 +802,21 @@ pub const Builder = struct {
805802 }
806803 }
807804 if (mismatch_triple) {
808 warn("Chosen target '{s}' does not match one of the supported targets:\n", .{
805 log.err("Chosen target '{s}' does not match one of the supported targets:", .{
809806 selected_canonicalized_triple,
810807 });
811808 for (list) |t| {
812809 const t_triple = t.zigTriple(self.allocator) catch unreachable;
813 warn(" {s}\n", .{t_triple});
810 log.err(" {s}", .{t_triple});
814811 }
815 warn("\n", .{});
816812 } else {
817813 assert(mismatch_cpu_features);
818814 const whitelist_cpu = whitelist_item.getCpu();
819815 const selected_cpu = selected_target.getCpu();
820 warn("Chosen CPU model '{s}' does not match one of the supported targets:\n", .{
816 log.err("Chosen CPU model '{s}' does not match one of the supported targets:", .{
821817 selected_cpu.model.name,
822818 });
823 warn(" Supported feature Set: ", .{});
819 log.err(" Supported feature Set: ", .{});
824820 const all_features = whitelist_cpu.arch.allFeaturesList();
825821 var populated_cpu_features = whitelist_cpu.model.features;
826822 populated_cpu_features.populateDependencies(all_features);
......@@ -828,20 +824,18 @@ pub const Builder = struct {
828824 const i = @intCast(std.Target.Cpu.Feature.Set.Index, i_usize);
829825 const in_cpu_set = populated_cpu_features.isEnabled(i);
830826 if (in_cpu_set) {
831 warn("{s} ", .{feature.name});
827 log.err("{s} ", .{feature.name});
832828 }
833829 }
834 warn("\n", .{});
835 warn(" Remove: ", .{});
830 log.err(" Remove: ", .{});
836831 for (all_features) |feature, i_usize| {
837832 const i = @intCast(std.Target.Cpu.Feature.Set.Index, i_usize);
838833 const in_cpu_set = populated_cpu_features.isEnabled(i);
839834 const in_actual_set = selected_cpu.features.isEnabled(i);
840835 if (in_actual_set and !in_cpu_set) {
841 warn("{s} ", .{feature.name});
836 log.err("{s} ", .{feature.name});
842837 }
843838 }
844 warn("\n", .{});
845839 }
846840 self.markInvalidUserInput();
847841 return args.default_target;
......@@ -886,7 +880,7 @@ pub const Builder = struct {
886880 }) catch unreachable;
887881 },
888882 .flag => {
889 warn("Option '-D{s}={s}' conflicts with flag '-D{s}'.\n", .{ name, value, name });
883 log.warn("Option '-D{s}={s}' conflicts with flag '-D{s}'.", .{ name, value, name });
890884 return true;
891885 },
892886 }
......@@ -908,11 +902,11 @@ pub const Builder = struct {
908902 // option already exists
909903 switch (gop.value_ptr.value) {
910904 .scalar => |s| {
911 warn("Flag '-D{s}' conflicts with option '-D{s}={s}'.\n", .{ name, name, s });
905 log.err("Flag '-D{s}' conflicts with option '-D{s}={s}'.", .{ name, name, s });
912906 return true;
913907 },
914908 .list => {
915 warn("Flag '-D{s}' conflicts with multiple options of the same name.\n", .{name});
909 log.err("Flag '-D{s}' conflicts with multiple options of the same name.", .{name});
916910 return true;
917911 },
918912 .flag => {},
......@@ -943,7 +937,7 @@ pub const Builder = struct {
943937 var it = self.user_input_options.iterator();
944938 while (it.next()) |entry| {
945939 if (!entry.value_ptr.used) {
946 warn("Invalid option: -D{s}\n\n", .{entry.key_ptr.*});
940 log.err("Invalid option: -D{s}\n", .{entry.key_ptr.*});
947941 self.markInvalidUserInput();
948942 }
949943 }
......@@ -956,11 +950,11 @@ pub const Builder = struct {
956950 }
957951
958952 fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void {
959 if (cwd) |yes_cwd| warn("cd {s} && ", .{yes_cwd});
953 if (cwd) |yes_cwd| std.debug.print("cd {s} && ", .{yes_cwd});
960954 for (argv) |arg| {
961 warn("{s} ", .{arg});
955 std.debug.print("{s} ", .{arg});
962956 }
963 warn("\n", .{});
957 std.debug.print("\n", .{});
964958 }
965959
966960 pub fn spawnChildEnvMap(self: *Builder, cwd: ?[]const u8, env_map: *const EnvMap, argv: []const []const u8) !void {
......@@ -976,20 +970,20 @@ pub const Builder = struct {
976970 child.env_map = env_map;
977971
978972 const term = child.spawnAndWait() catch |err| {
979 warn("Unable to spawn {s}: {s}\n", .{ argv[0], @errorName(err) });
973 log.err("Unable to spawn {s}: {s}", .{ argv[0], @errorName(err) });
980974 return err;
981975 };
982976
983977 switch (term) {
984978 .Exited => |code| {
985979 if (code != 0) {
986 warn("The following command exited with error code {}:\n", .{code});
980 log.err("The following command exited with error code {}:", .{code});
987981 printCmd(cwd, argv);
988982 return error.UncleanExit;
989983 }
990984 },
991985 else => {
992 warn("The following command terminated unexpectedly:\n", .{});
986 log.err("The following command terminated unexpectedly:", .{});
993987 printCmd(cwd, argv);
994988
995989 return error.UncleanExit;
......@@ -999,7 +993,7 @@ pub const Builder = struct {
999993
1000994 pub fn makePath(self: *Builder, path: []const u8) !void {
1001995 fs.cwd().makePath(self.pathFromRoot(path)) catch |err| {
1002 warn("Unable to create path {s}: {s}\n", .{ path, @errorName(err) });
996 log.err("Unable to create path {s}: {s}", .{ path, @errorName(err) });
1003997 return err;
1004998 };
1005999 }
......@@ -1087,19 +1081,19 @@ pub const Builder = struct {
10871081
10881082 pub fn updateFile(self: *Builder, source_path: []const u8, dest_path: []const u8) !void {
10891083 if (self.verbose) {
1090 warn("cp {s} {s} ", .{ source_path, dest_path });
1084 log.info("cp {s} {s} ", .{ source_path, dest_path });
10911085 }
10921086 const cwd = fs.cwd();
10931087 const prev_status = try fs.Dir.updateFile(cwd, source_path, cwd, dest_path, .{});
10941088 if (self.verbose) switch (prev_status) {
1095 .stale => warn("# installed\n", .{}),
1096 .fresh => warn("# up-to-date\n", .{}),
1089 .stale => log.info("# installed", .{}),
1090 .fresh => log.info("# up-to-date", .{}),
10971091 };
10981092 }
10991093
11001094 pub fn truncateFile(self: *Builder, dest_path: []const u8) !void {
11011095 if (self.verbose) {
1102 warn("truncate {s}\n", .{dest_path});
1096 log.info("truncate {s}", .{dest_path});
11031097 }
11041098 const cwd = fs.cwd();
11051099 var src_file = cwd.createFile(dest_path, .{}) catch |err| switch (err) {
......@@ -1222,8 +1216,8 @@ pub const Builder = struct {
12221216 }
12231217
12241218 if (!std.process.can_spawn) {
1225 if (src_step) |s| warn("{s}...", .{s.name});
1226 warn("Unable to spawn the following command: cannot spawn child process\n", .{});
1219 if (src_step) |s| log.err("{s}...", .{s.name});
1220 log.err("Unable to spawn the following command: cannot spawn child process", .{});
12271221 printCmd(null, argv);
12281222 std.os.abort();
12291223 }
......@@ -1231,31 +1225,31 @@ pub const Builder = struct {
12311225 var code: u8 = undefined;
12321226 return self.execAllowFail(argv, &code, .Inherit) catch |err| switch (err) {
12331227 error.ExecNotSupported => {
1234 if (src_step) |s| warn("{s}...", .{s.name});
1235 warn("Unable to spawn the following command: cannot spawn child process\n", .{});
1228 if (src_step) |s| log.err("{s}...", .{s.name});
1229 log.err("Unable to spawn the following command: cannot spawn child process", .{});
12361230 printCmd(null, argv);
12371231 std.os.abort();
12381232 },
12391233 error.FileNotFound => {
1240 if (src_step) |s| warn("{s}...", .{s.name});
1241 warn("Unable to spawn the following command: file not found\n", .{});
1234 if (src_step) |s| log.err("{s}...", .{s.name});
1235 log.err("Unable to spawn the following command: file not found", .{});
12421236 printCmd(null, argv);
12431237 std.os.exit(@truncate(u8, code));
12441238 },
12451239 error.ExitCodeFailure => {
1246 if (src_step) |s| warn("{s}...", .{s.name});
1240 if (src_step) |s| log.err("{s}...", .{s.name});
12471241 if (self.prominent_compile_errors) {
1248 warn("The step exited with error code {d}\n", .{code});
1242 log.err("The step exited with error code {d}", .{code});
12491243 } else {
1250 warn("The following command exited with error code {d}:\n", .{code});
1244 log.err("The following command exited with error code {d}:", .{code});
12511245 printCmd(null, argv);
12521246 }
12531247
12541248 std.os.exit(@truncate(u8, code));
12551249 },
12561250 error.ProcessTerminated => {
1257 if (src_step) |s| warn("{s}...", .{s.name});
1258 warn("The following command terminated unexpectedly:\n", .{});
1251 if (src_step) |s| log.err("{s}...", .{s.name});
1252 log.err("The following command terminated unexpectedly:", .{});
12591253 printCmd(null, argv);
12601254 std.os.exit(@truncate(u8, code));
12611255 },
......@@ -2140,7 +2134,7 @@ pub const LibExeObjStep = struct {
21402134 } else if (mem.startsWith(u8, tok, "-D")) {
21412135 try zig_args.append(tok);
21422136 } else if (self.builder.verbose) {
2143 warn("Ignoring pkg-config flag '{s}'\n", .{tok});
2137 log.warn("Ignoring pkg-config flag '{s}'", .{tok});
21442138 }
21452139 }
21462140
......@@ -2435,7 +2429,7 @@ pub const LibExeObjStep = struct {
24352429 const builder = self.builder;
24362430
24372431 if (self.root_src == null and self.link_objects.items.len == 0) {
2438 warn("{s}: linker needs 1 or more objects to link\n", .{self.step.name});
2432 log.err("{s}: linker needs 1 or more objects to link", .{self.step.name});
24392433 return error.NeedAnObject;
24402434 }
24412435
......@@ -2558,7 +2552,7 @@ pub const LibExeObjStep = struct {
25582552 if (system_lib.needed) break :prefix "-needed-l";
25592553 if (system_lib.weak) {
25602554 if (self.target.isDarwin()) break :prefix "-weak-l";
2561 warn("Weak library import used for a non-darwin target, this will be converted to normally library import `-lname`\n", .{});
2555 log.warn("Weak library import used for a non-darwin target, this will be converted to normally library import `-lname`", .{});
25622556 }
25632557 break :prefix "-l";
25642558 };
......@@ -3078,11 +3072,11 @@ pub const LibExeObjStep = struct {
30783072 }
30793073 } else {
30803074 if (self.framework_dirs.items.len > 0) {
3081 warn("Framework directories have been added for a non-darwin target, this will have no affect on the build\n", .{});
3075 log.info("Framework directories have been added for a non-darwin target, this will have no affect on the build", .{});
30823076 }
30833077
30843078 if (self.frameworks.count() > 0) {
3085 warn("Frameworks have been added for a non-darwin target, this will have no affect on the build\n", .{});
3079 log.info("Frameworks have been added for a non-darwin target, this will have no affect on the build", .{});
30863080 }
30873081 }
30883082
......@@ -3530,7 +3524,7 @@ pub const LogStep = struct {
35303524
35313525 fn make(step: *Step) anyerror!void {
35323526 const self = @fieldParentPtr(LogStep, "step", step);
3533 warn("{s}", .{self.data});
3527 log.info("{s}", .{self.data});
35343528 }
35353529};
35363530
......@@ -3554,7 +3548,7 @@ pub const RemoveDirStep = struct {
35543548
35553549 const full_path = self.builder.pathFromRoot(self.dir_path);
35563550 fs.cwd().deleteTree(full_path) catch |err| {
3557 warn("Unable to remove {s}: {s}\n", .{ full_path, @errorName(err) });
3551 log.err("Unable to remove {s}: {s}", .{ full_path, @errorName(err) });
35583552 return err;
35593553 };
35603554 }
......@@ -3639,7 +3633,7 @@ fn doAtomicSymLinks(allocator: Allocator, output_path: []const u8, filename_majo
36393633 &[_][]const u8{ out_dir, filename_major_only },
36403634 ) catch unreachable;
36413635 fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
3642 warn("Unable to symlink {s} -> {s}\n", .{ major_only_path, out_basename });
3636 log.err("Unable to symlink {s} -> {s}", .{ major_only_path, out_basename });
36433637 return err;
36443638 };
36453639 // sym link for libfoo.so to libfoo.so.1
......@@ -3648,7 +3642,7 @@ fn doAtomicSymLinks(allocator: Allocator, output_path: []const u8, filename_majo
36483642 &[_][]const u8{ out_dir, filename_name_only },
36493643 ) catch unreachable;
36503644 fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {
3651 warn("Unable to symlink {s} -> {s}\n", .{ name_only_path, filename_major_only });
3645 log.err("Unable to symlink {s} -> {s}", .{ name_only_path, filename_major_only });
36523646 return err;
36533647 };
36543648}