diff --git a/build.zig b/build.zig index b46e73f..275a80b 100644 --- a/build.zig +++ b/build.zig @@ -7,8 +7,6 @@ pub fn build(b: *std.Build) !void { "Filter tests to run", ) orelse &.{}; - const trace = b.option(bool, "trace", "enable tracy tracing") orelse false; - const coverage = b.option( bool, "coverage", @@ -21,7 +19,6 @@ pub fn build(b: *std.Build) !void { "version", try getVersionString(b, coreutils_version, b.build_root.path.?), ); - options.addOption(bool, "trace", trace); const options_module = options.createModule(); // exe @@ -29,7 +26,7 @@ pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const coreutils_target = CoreutilsTarget.fromOsTag(target.result.os.tag) orelse { - std.debug.panic("unsupported target OS {s}", .{@tagName(target.result.os.tag)}); + std.debug.panic("unsupported target OS {t}", .{target.result.os.tag}); }; const coreutils_exe = b.addExecutable(.{ @@ -38,7 +35,6 @@ pub fn build(b: *std.Build) !void { b, target, optimize, - trace, coreutils_target, options_module, ), @@ -79,7 +75,6 @@ pub fn build(b: *std.Build) !void { b, target, optimize, - trace, coreutils_target, options_module, target.result.os.tag == builtin.os.tag, @@ -97,15 +92,9 @@ fn createRootModule( b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, - trace: bool, coreutils_target: CoreutilsTarget, options_module: *std.Build.Module, ) *std.Build.Module { - const tracy_dep = b.dependency("tracy", .{ - .target = target, - .optimize = optimize, - }); - const coreutils_module = b.createModule(.{ .root_source_file = b.path("src/main.zig"), .target = target, @@ -113,13 +102,6 @@ fn createRootModule( }); coreutils_module.addImport("options", options_module); - coreutils_module.addImport("tracy", tracy_dep.module("tracy")); - - if (trace) { - coreutils_module.addImport("tracy_impl", tracy_dep.module("tracy_impl_enabled")); - } else { - coreutils_module.addImport("tracy_impl", tracy_dep.module("tracy_impl_disabled")); - } const target_options = b.addOptions(); target_options.addOption(CoreutilsTarget, "target_os", coreutils_target); @@ -132,7 +114,6 @@ fn createTestAndCheckSteps( b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, - trace: bool, coreutils_target: CoreutilsTarget, options_module: *std.Build.Module, is_native_target: bool, @@ -146,13 +127,12 @@ fn createTestAndCheckSteps( b, target, optimize, - trace, coreutils_target, options_module, ); const coreutils_test = b.addTest(.{ - .name = b.fmt("test_zig-coreutils-{s}", .{@tagName(target.result.os.tag)}), + .name = b.fmt("test_zig-coreutils-{t}", .{target.result.os.tag}), .root_module = module, .filters = test_filters, }); @@ -178,8 +158,8 @@ fn createTestAndCheckSteps( } const target_test_step = b.step( - b.fmt("test_{s}", .{@tagName(target.result.os.tag)}), - b.fmt("Run the tests for {s}", .{@tagName(target.result.os.tag)}), + b.fmt("test_{t}", .{target.result.os.tag}), + b.fmt("Run the tests for {t}", .{target.result.os.tag}), ); if (is_native_target or run_non_native_tests) { @@ -197,7 +177,7 @@ fn createTestAndCheckSteps( } const build_exe = b.addExecutable(.{ - .name = b.fmt("build_zig-coreutils-{s}", .{@tagName(target.result.os.tag)}), + .name = b.fmt("build_zig-coreutils-{t}", .{target.result.os.tag}), .root_module = module, }); target_test_step.dependOn(&build_exe.step); @@ -206,23 +186,21 @@ fn createTestAndCheckSteps( { const coreutils_exe_check = b.addExecutable(.{ - .name = b.fmt("check_zig-coreutils-{s}", .{@tagName(target.result.os.tag)}), + .name = b.fmt("check_zig-coreutils-{t}", .{target.result.os.tag}), .root_module = createRootModule( b, target, optimize, - trace, coreutils_target, options_module, ), }); const coreutils_test_check = b.addTest(.{ - .name = b.fmt("check_test_zig-coreutils-{s}", .{@tagName(target.result.os.tag)}), + .name = b.fmt("check_test_zig-coreutils-{t}", .{target.result.os.tag}), .root_module = createRootModule( b, target, optimize, - trace, coreutils_target, options_module, ), @@ -304,7 +282,7 @@ fn getVersionString(b: *std.Build, base_semantic_version: std.SemanticVersion, r const ancestor_version = try std.SemanticVersion.parse(tagged_ancestor_version_string); if (base_semantic_version.order(ancestor_version) != .gt) { std.debug.print( - "version '{}' must be greater than tagged ancestor '{}'\n", + "version '{f}' must be greater than tagged ancestor '{f}'\n", .{ base_semantic_version, ancestor_version }, ); std.process.exit(1); diff --git a/build.zig.zon b/build.zig.zon index 6bad5a6..bb01ed1 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -6,7 +6,7 @@ .version = "0.3.0", - .minimum_zig_version = "0.15.0-dev.784+4a02e080d", + .minimum_zig_version = "0.15.0-dev.1149+4e6a04929", .paths = .{ "build.zig", @@ -14,12 +14,5 @@ "src", }, - .dependencies = .{ - .tracy = .{ - .url = "git+https://github.com/Games-by-Mason/tracy_zig.git?ref=main#0cad4646be2791982f692a7a47716ec92b62eb2e", - .hash = "tracy-0.0.0-R7l8BdlCAQBFp6uysnan3Alaxap65HBF1mzGdabdKe8z", - }, - }, - .fingerprint = 0x3bcfe8c5bc4f06d3, } diff --git a/src/Arg.zig b/src/Arg.zig index 9f864e3..3b4cf3c 100644 --- a/src/Arg.zig +++ b/src/Arg.zig @@ -50,12 +50,8 @@ pub const Iterator = union(enum) { }, pub fn nextRaw(self: *Iterator) ?[]const u8 { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "raw next arg" }); - defer z.end(); - if (self.dispatchNext()) |arg| { @branchHint(.likely); - z.text(arg); return arg; } @@ -63,16 +59,11 @@ pub const Iterator = union(enum) { } pub fn next(self: *Iterator) ?Arg { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "next arg" }); - defer z.end(); - const current_arg = self.dispatchNext() orelse { @branchHint(.unlikely); return null; }; - z.text(current_arg); - // the length checks in the below ifs allow '-' and '--' to fall through as positional arguments if (current_arg.len > 1 and current_arg[0] == '-') longhand_shorthand_blk: { if (current_arg.len > 2 and current_arg[1] == '-') { @@ -125,9 +116,6 @@ pub const Iterator = union(enum) { self: *Iterator, comptime include_shorthand: bool, ) error{ ShortHelp, FullHelp, Version }!?Arg { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "next arg with help/version" }); - defer z.end(); - var arg = self.next() orelse return null; switch (arg.arg_type) { @@ -174,4 +162,3 @@ const log = std.log.scoped(.arg); const builtin = @import("builtin"); const std = @import("std"); -const tracy = @import("tracy"); diff --git a/src/Command.zig b/src/Command.zig index a980cb4..761b16e 100644 --- a/src/Command.zig +++ b/src/Command.zig @@ -55,9 +55,6 @@ pub fn narrowError( } fn printShortHelp(command: Command, io: IO, exe_path: []const u8) error{AlreadyHandled}!void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "print short help" }); - defer z.end(); - std.debug.assert(command.short_help.len != 0); // short help should not be empty std.debug.assert(command.short_help[command.short_help.len - 1] == '\n'); // short help should end with a newline @@ -70,9 +67,6 @@ fn printShortHelp(command: Command, io: IO, exe_path: []const u8) error{AlreadyH } fn printFullHelp(command: Command, io: IO, exe_path: []const u8) error{AlreadyHandled}!void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "print full help" }); - defer z.end(); - std.debug.assert(command.short_help.len != 0); // short help should not be empty std.debug.assert(command.short_help[command.short_help.len - 1] == '\n'); // short help should end with a newline @@ -97,9 +91,6 @@ fn printFullHelp(command: Command, io: IO, exe_path: []const u8) error{AlreadyHa } fn printVersion(command: Command, io: IO) error{AlreadyHandled}!void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "print version" }); - defer z.end(); - var iter: NameReplacementIterator = .{ .slice = shared.version_string }; while (iter.next()) |result| { @@ -111,10 +102,6 @@ fn printVersion(command: Command, io: IO) error{AlreadyHandled}!void { pub fn printError(command: Command, io: IO, error_message: []const u8) error{AlreadyHandled} { @branchHint(.cold); - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "print error" }); - defer z.end(); - z.text(error_message); - output: { io._stderr.writeAll(command.name) catch break :output; io._stderr.writeAll(": ") catch break :output; @@ -134,9 +121,6 @@ pub fn printErrorAlloc( ) error{ OutOfMemory, AlreadyHandled } { @branchHint(.cold); - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "print error alloc" }); - defer z.end(); - const error_message = try std.fmt.allocPrint(allocator, msg, args); defer if (shared.free_on_close) allocator.free(error_message); @@ -151,10 +135,6 @@ pub fn printInvalidUsage( ) error{AlreadyHandled} { @branchHint(.cold); - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "print invalid usage" }); - defer z.end(); - z.text(error_message); - output: { io._stderr.writeAll(exe_path) catch break :output; io._stderr.writeAll(": ") catch break :output; @@ -177,9 +157,6 @@ pub fn printInvalidUsageAlloc( ) error{ OutOfMemory, AlreadyHandled } { @branchHint(.cold); - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "print invalid usage alloc" }); - defer z.end(); - const error_message = try std.fmt.allocPrint(allocator, msg, args); defer if (shared.free_on_close) allocator.free(error_message); @@ -187,9 +164,9 @@ pub fn printInvalidUsageAlloc( } pub const TestExecuteSettings = struct { - stdin: ?std.io.AnyReader = null, - stdout: ?std.io.AnyWriter = null, - stderr: ?std.io.AnyWriter = null, + stdin: ?*std.Io.Reader = null, + stdout: ?*std.Io.Writer = null, + stderr: ?*std.Io.Writer = null, system_description: System.TestBackend.Description = .{}, test_backend_behaviour: TestBackendBehaviour = .free, @@ -220,7 +197,7 @@ pub fn testExecute( std.testing.allocator, settings.system_description, ) catch |err| { - std.debug.panic("unable to create system backend: {s}", .{@errorName(err)}); + std.debug.panic("unable to create system backend: {t}", .{err}); }, }; defer switch (settings.test_backend_behaviour) { @@ -231,9 +208,9 @@ pub fn testExecute( var arg_iter: Arg.Iterator = .{ .slice = .{ .slice = arguments } }; const io: IO = .{ - ._stderr = if (settings.stderr) |s| s else VoidWriter.writer().any(), - ._stdin = if (settings.stdin) |s| s else VoidReader.reader().any(), - ._stdout = if (settings.stdout) |s| s else VoidWriter.writer().any(), + ._stdin = if (settings.stdin) |s| s else void_reader, + ._stdout = if (settings.stdout) |s| s else void_writer, + ._stderr = if (settings.stderr) |s| s else void_writer, }; return command.execute( @@ -257,19 +234,19 @@ pub fn testError( @panic("`stderr` cannot be provided with `testError`"); } - var stderr = std.ArrayList(u8).init(std.testing.allocator); + var stderr: std.Io.Writer.Allocating = .init(std.testing.allocator); defer stderr.deinit(); var settings_copy = settings; - settings_copy.stderr = stderr.writer().any(); + settings_copy.stderr = &stderr.writer; try std.testing.expectError(error.AlreadyHandled, command.testExecute( arguments, settings_copy, )); - std.testing.expect(std.mem.indexOf(u8, stderr.items, expected_error) != null) catch |err| { - std.debug.print("\nEXPECTED: {s}\n\nACTUAL: {s}\n", .{ expected_error, stderr.items }); + std.testing.expect(std.mem.indexOf(u8, stderr.getWritten(), expected_error) != null) catch |err| { + std.debug.print("\nEXPECTED: {s}\n\nACTUAL: {s}\n", .{ expected_error, stderr.getWritten() }); return err; }; } @@ -300,15 +277,15 @@ pub fn testHelp(command: Command, comptime include_shorthand: bool) !void { }; defer std.testing.allocator.free(full_expected_help); - var out = std.ArrayList(u8).init(std.testing.allocator); - defer out.deinit(); + var stdout: std.Io.Writer.Allocating = .init(std.testing.allocator); + defer stdout.deinit(); try command.testExecute( &.{"--help"}, - .{ .stdout = out.writer().any() }, + .{ .stdout = &stdout.writer }, ); - try std.testing.expectEqualStrings(full_expected_help, out.items); + try std.testing.expectEqualStrings(full_expected_help, stdout.getWritten()); if (include_shorthand) { const short_expected_help = blk: { @@ -327,28 +304,28 @@ pub fn testHelp(command: Command, comptime include_shorthand: bool) !void { }; defer std.testing.allocator.free(short_expected_help); - out.clearRetainingCapacity(); + stdout.clearRetainingCapacity(); try testExecute( command, &.{"-h"}, - .{ .stdout = out.writer().any() }, + .{ .stdout = &stdout.writer }, ); - try std.testing.expectEqualStrings(short_expected_help, out.items); + try std.testing.expectEqualStrings(short_expected_help, stdout.getWritten()); } } pub fn testVersion(command: Command) !void { std.debug.assert(builtin.is_test); - var out = std.ArrayList(u8).init(std.testing.allocator); - defer out.deinit(); + var stdout: std.Io.Writer.Allocating = .init(std.testing.allocator); + defer stdout.deinit(); try command.testExecute( &.{"--version"}, .{ - .stdout = out.writer().any(), + .stdout = &stdout.writer, }, ); @@ -366,10 +343,9 @@ pub fn testVersion(command: Command) !void { break :blk try sb.toOwnedSlice(std.testing.allocator); }; - defer std.testing.allocator.free(expected); - try std.testing.expectEqualStrings(expected, out.items); + try std.testing.expectEqualStrings(expected, stdout.getWritten()); } pub const TestFuzzOptions = struct { @@ -406,17 +382,17 @@ pub fn testFuzz(command: Command, options: TestFuzzOptions) !void { }; defer std.testing.allocator.free(arguments); - var stdout: std.ArrayList(u8) = .init(std.testing.allocator); + var stdout: std.Io.Writer.Allocating = .init(std.testing.allocator); defer stdout.deinit(); - var stderr: std.ArrayList(u8) = .init(std.testing.allocator); + var stderr: std.Io.Writer.Allocating = .init(std.testing.allocator); defer stderr.deinit(); context.inner_command.testExecute( arguments, .{ - .stdout = stdout.writer().any(), - .stderr = stderr.writer().any(), + .stdout = &stdout.writer, + .stderr = &stderr.writer, .system_description = context.options.system_description, }, ) catch |err| { @@ -425,15 +401,15 @@ pub fn testFuzz(command: Command, options: TestFuzzOptions) !void { // this error is output by main and some output may or not have been written to stderr }, error.AlreadyHandled => if (context.options.expect_stderr_output_on_failure) { - try std.testing.expect(stderr.items.len != 0); + try std.testing.expect(stderr.getWritten().len != 0); }, } return; }; - try std.testing.expect(stderr.items.len == 0); + try std.testing.expect(stderr.getWritten().len == 0); if (context.options.expect_stdout_output_on_success) { - try std.testing.expect(stdout.items.len != 0); + try std.testing.expect(stdout.getWritten().len != 0); } } }; @@ -449,27 +425,40 @@ pub fn testFuzz(command: Command, options: TestFuzzOptions) !void { ); } -const VoidReader = struct { - pub const Reader = std.io.Reader(void, error{}, read); - pub fn reader() Reader { - return .{ .context = {} }; - } +const void_reader: *std.Io.Reader = blk: { + const void_reader_inner: std.Io.Reader = .{ + .vtable = &.{ + .stream = struct { + fn stream(_: *std.Io.Reader, _: *std.Io.Writer, _: std.Io.Limit) !usize { + return 0; + } + }.stream, + }, + .buffer = &.{}, + .seek = 0, + .end = 0, + }; - fn read(_: void, buffer: []u8) error{}!usize { - _ = buffer; - return 0; - } + break :blk @constCast(&void_reader_inner); }; -const VoidWriter = struct { - pub const Writer = std.io.Writer(void, error{}, write); - pub fn writer() Writer { - return .{ .context = {} }; - } - - fn write(_: void, bytes: []const u8) error{}!usize { - return bytes.len; - } +// TODO: replace with `std.Io.null_writer` once it is updated to use `std.Io.Writer` +const void_writer: *std.Io.Writer = blk: { + const void_writer_inner: std.Io.Writer = .{ + .vtable = &.{ + .drain = struct { + fn drain(_: *std.Io.Writer, data: []const []const u8, _: usize) !usize { + var len: usize = 0; + for (data) |bytes| { + len += bytes.len; + } + return len; + } + }.drain, + }, + .buffer = &.{}, + }; + break :blk @constCast(&void_writer_inner); }; const NameReplacementIterator = struct { @@ -527,4 +516,3 @@ const System = @import("system/System.zig"); const builtin = @import("builtin"); const std = @import("std"); -const tracy = @import("tracy"); diff --git a/src/IO.zig b/src/IO.zig index ea7e876..dc5995a 100644 --- a/src/IO.zig +++ b/src/IO.zig @@ -3,9 +3,9 @@ const IO = @This(); -_stderr: std.io.AnyWriter, -_stdin: std.io.AnyReader, -_stdout: std.io.AnyWriter, +_stdin: *std.Io.Reader, +_stdout: *std.Io.Writer, +_stderr: *std.Io.Writer, pub inline fn stdoutWriteByte(io: IO, byte: u8) error{AlreadyHandled}!void { io._stdout.writeByte(byte) catch |err| { @@ -58,4 +58,3 @@ pub fn unableToWriteTo(io: IO, destination: []const u8, err: anyerror) error{Alr } const std = @import("std"); -const tracy = @import("tracy"); diff --git a/src/commands/basename.zig b/src/commands/basename.zig index 9f298a9..0c6b496 100644 --- a/src/commands/basename.zig +++ b/src/commands/basename.zig @@ -44,13 +44,10 @@ const impl = struct { system: System, exe_path: []const u8, ) Command.Error!void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = command.name }); - defer z.end(); - _ = system; const options = try parseArguments(allocator, io, args, exe_path); - log.debug("{}", .{options}); + log.debug("{f}", .{options}); return switch (options.mode) { .single => singleArgument(allocator, io, args, exe_path, options), @@ -65,16 +62,9 @@ const impl = struct { exe_path: []const u8, options: BasenameOptions, ) !void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "single argument" }); - defer z.end(); - z.text(options.first_arg); - log.debug("singleArgument called", .{}); const opt_suffix: ?[]const u8 = blk: { - const suffix_zone: tracy.Zone = .begin(.{ .src = @src(), .name = "get suffix" }); - defer suffix_zone.end(); - const arg = args.nextRaw() orelse break :blk null; if (args.nextRaw()) |additional_arg| { @@ -87,8 +77,6 @@ const impl = struct { ); } - suffix_zone.text(arg); - break :blk arg; }; @@ -103,18 +91,11 @@ const impl = struct { args: *Arg.Iterator, options: BasenameOptions, ) !void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "multiple arguments" }); - defer z.end(); - log.debug("multipleArguments called", .{}); var opt_arg: ?[]const u8 = options.first_arg; while (opt_arg) |arg| : (opt_arg = args.nextRaw()) { - const argument_zone: tracy.Zone = .begin(.{ .src = @src(), .name = "process arg" }); - defer argument_zone.end(); - argument_zone.text(arg); - const basename = getBasename(arg, options.mode.multiple); try io.stdoutWriteAll(basename); @@ -148,12 +129,7 @@ const impl = struct { multiple: ?[]const u8, }; - pub fn format( - options: BasenameOptions, - comptime _: []const u8, - _: std.fmt.FormatOptions, - writer: anytype, - ) !void { + pub fn format(options: BasenameOptions, writer: *std.Io.Writer) !void { try writer.writeAll("BasenameOptions {"); try writer.writeAll(comptime "\n" ++ shared.option_log_indentation ++ ".line_end = ."); @@ -185,9 +161,6 @@ const impl = struct { args: *Arg.Iterator, exe_path: []const u8, ) !BasenameOptions { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "parse arguments" }); - defer z.end(); - var opt_arg: ?Arg = try args.nextWithHelpOrVersion(true); var basename_options: BasenameOptions = .{}; @@ -336,19 +309,19 @@ const impl = struct { } test "basename single" { - var stdout = std.ArrayList(u8).init(std.testing.allocator); + var stdout: std.Io.Writer.Allocating = .init(std.testing.allocator); defer stdout.deinit(); try command.testExecute( &.{"hello/world"}, - .{ .stdout = stdout.writer().any() }, + .{ .stdout = &stdout.writer }, ); - try std.testing.expectEqualStrings("world\n", stdout.items); + try std.testing.expectEqualStrings("world\n", stdout.getWritten()); } test "basename multiple" { - var stdout = std.ArrayList(u8).init(std.testing.allocator); + var stdout: std.Io.Writer.Allocating = .init(std.testing.allocator); defer stdout.deinit(); try command.testExecute( @@ -358,7 +331,7 @@ const impl = struct { "this/is/a/test", "a/b/c/d", }, - .{ .stdout = stdout.writer().any() }, + .{ .stdout = &stdout.writer }, ); try std.testing.expectEqualStrings( @@ -366,7 +339,7 @@ const impl = struct { \\test \\d \\ - , stdout.items); + , stdout.getWritten()); } test "basename help" { @@ -393,4 +366,3 @@ const System = @import("../system/System.zig"); const log = std.log.scoped(.basename); const std = @import("std"); -const tracy = @import("tracy"); diff --git a/src/commands/clear.zig b/src/commands/clear.zig index b016a8e..2a34e56 100644 --- a/src/commands/clear.zig +++ b/src/commands/clear.zig @@ -37,13 +37,10 @@ const impl = struct { system: System, exe_path: []const u8, ) Command.Error!void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = command.name }); - defer z.end(); - _ = system; const options = try parseArguments(allocator, io, args, exe_path); - log.debug("{}", .{options}); + log.debug("{f}", .{options}); try io.stdoutWriteAll( if (options.clear_scrollback) @@ -56,12 +53,7 @@ const impl = struct { const ClearOptions = struct { clear_scrollback: bool = true, - pub fn format( - options: ClearOptions, - comptime _: []const u8, - _: std.fmt.FormatOptions, - writer: anytype, - ) !void { + pub fn format(options: ClearOptions, writer: *std.Io.Writer) !void { try writer.writeAll("ClearOptions {"); try writer.writeAll(comptime "\n" ++ shared.option_log_indentation ++ ".clear_scrollback = ."); try writer.writeAll(if (options.clear_scrollback) "true" else "false"); @@ -75,9 +67,6 @@ const impl = struct { args: *Arg.Iterator, exe_path: []const u8, ) !ClearOptions { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "parse arguments" }); - defer z.end(); - var opt_arg: ?Arg = try args.nextWithHelpOrVersion(true); var clear_options: ClearOptions = .{}; @@ -153,27 +142,27 @@ const impl = struct { } test "clear no args" { - var stdout = std.ArrayList(u8).init(std.testing.allocator); + var stdout: std.Io.Writer.Allocating = .init(std.testing.allocator); defer stdout.deinit(); try command.testExecute( &.{}, - .{ .stdout = stdout.writer().any() }, + .{ .stdout = &stdout.writer }, ); - try std.testing.expectEqualStrings("\x1b[H\x1b[2J\x1b[3J", stdout.items); + try std.testing.expectEqualStrings("\x1b[H\x1b[2J\x1b[3J", stdout.getWritten()); } test "clear - don't clear scrollback" { - var stdout = std.ArrayList(u8).init(std.testing.allocator); + var stdout: std.Io.Writer.Allocating = .init(std.testing.allocator); defer stdout.deinit(); try command.testExecute( &.{"-x"}, - .{ .stdout = stdout.writer().any() }, + .{ .stdout = &stdout.writer }, ); - try std.testing.expectEqualStrings("\x1b[H\x1b[2J", stdout.items); + try std.testing.expectEqualStrings("\x1b[H\x1b[2J", stdout.getWritten()); } test "clear help" { @@ -200,4 +189,3 @@ const System = @import("../system/System.zig"); const log = std.log.scoped(.clear); const std = @import("std"); -const tracy = @import("tracy"); diff --git a/src/commands/dirname.zig b/src/commands/dirname.zig index 84c05fa..4c62379 100644 --- a/src/commands/dirname.zig +++ b/src/commands/dirname.zig @@ -39,13 +39,10 @@ const impl = struct { system: System, exe_path: []const u8, ) Command.Error!void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = command.name }); - defer z.end(); - _ = system; const options = try parseArguments(allocator, io, args, exe_path); - log.debug("{}", .{options}); + log.debug("{f}", .{options}); return performDirname(io, args, options); } @@ -59,12 +56,7 @@ const impl = struct { zero = 0, }; - pub fn format( - options: DirnameOptions, - comptime _: []const u8, - _: std.fmt.FormatOptions, - writer: anytype, - ) !void { + pub fn format(options: DirnameOptions, writer: *std.Io.Writer) !void { try writer.writeAll("DirnameOptions {"); try writer.writeAll(comptime ",\n" ++ shared.option_log_indentation ++ ".line_end = ."); @@ -81,16 +73,9 @@ const impl = struct { args: *Arg.Iterator, options: DirnameOptions, ) !void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "perform dirname" }); - defer z.end(); - var opt_arg: ?[]const u8 = options.first_arg; while (opt_arg) |arg| : (opt_arg = args.nextRaw()) { - const argument_zone: tracy.Zone = .begin(.{ .src = @src(), .name = "process arg" }); - defer argument_zone.end(); - argument_zone.text(arg); - const dirname = if (std.fs.path.dirname(arg)) |dir| dir else @@ -107,9 +92,6 @@ const impl = struct { args: *Arg.Iterator, exe_path: []const u8, ) !DirnameOptions { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "parse arguments" }); - defer z.end(); - var opt_arg: ?Arg = try args.nextWithHelpOrVersion(true); var dir_options: DirnameOptions = .{}; @@ -199,21 +181,21 @@ const impl = struct { } test "dirname single" { - var stdout = std.ArrayList(u8).init(std.testing.allocator); + var stdout: std.Io.Writer.Allocating = .init(std.testing.allocator); defer stdout.deinit(); try command.testExecute( &.{ "hello/world", }, - .{ .stdout = stdout.writer().any() }, + .{ .stdout = &stdout.writer }, ); - try std.testing.expectEqualStrings("hello\n", stdout.items); + try std.testing.expectEqualStrings("hello\n", stdout.getWritten()); } test "dirname multiple" { - var stdout = std.ArrayList(u8).init(std.testing.allocator); + var stdout: std.Io.Writer.Allocating = .init(std.testing.allocator); defer stdout.deinit(); try command.testExecute( @@ -222,7 +204,7 @@ const impl = struct { "this/is/a/test", "a/b/c/d", }, - .{ .stdout = stdout.writer().any() }, + .{ .stdout = &stdout.writer }, ); try std.testing.expectEqualStrings( @@ -230,7 +212,7 @@ const impl = struct { \\this/is/a \\a/b/c \\ - , stdout.items); + , stdout.getWritten()); } test "dirname help" { @@ -257,4 +239,3 @@ const System = @import("../system/System.zig"); const log = std.log.scoped(.dirname); const std = @import("std"); -const tracy = @import("tracy"); diff --git a/src/commands/false.zig b/src/commands/false.zig index 18b0138..fe9377e 100644 --- a/src/commands/false.zig +++ b/src/commands/false.zig @@ -30,9 +30,6 @@ const impl = struct { system: System, exe_path: []const u8, ) Command.Error!void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = command.name }); - defer z.end(); - _ = io; _ = exe_path; _ = system; @@ -52,7 +49,7 @@ const impl = struct { } test "false ignores args" { - var stdout = std.ArrayList(u8).init(std.testing.allocator); + var stdout: std.Io.Writer.Allocating = .init(std.testing.allocator); defer stdout.deinit(); try std.testing.expectError( @@ -63,7 +60,7 @@ const impl = struct { ), ); - try std.testing.expectEqualStrings("", stdout.items); + try std.testing.expectEqualStrings("", stdout.getWritten()); } test "false help" { @@ -89,4 +86,3 @@ const shared = @import("../shared.zig"); const System = @import("../system/System.zig"); const std = @import("std"); -const tracy = @import("tracy"); diff --git a/src/commands/groups.zig b/src/commands/groups.zig index 778e897..c5d1df5 100644 --- a/src/commands/groups.zig +++ b/src/commands/groups.zig @@ -41,9 +41,6 @@ const impl = struct { system: System, exe_path: []const u8, ) Command.Error!void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = command.name }); - defer z.end(); - _ = exe_path; const opt_arg = try args.nextWithHelpOrVersion(true); @@ -53,8 +50,8 @@ const impl = struct { return command.printErrorAlloc( allocator, io, - "unable to open '/etc/passwd': {s}", - .{@errorName(err)}, + "unable to open '/etc/passwd': {t}", + .{err}, ); errdefer if (shared.free_on_close) passwd_file.close(); @@ -62,16 +59,16 @@ const impl = struct { return command.printErrorAlloc( allocator, io, - "unable to stat '/etc/passwd': {s}", - .{@errorName(err)}, + "unable to stat '/etc/passwd': {t}", + .{err}, ); break :blk passwd_file.mapReadonly(stat.size) catch |err| return command.printErrorAlloc( allocator, io, - "unable to map '/etc/passwd': {s}", - .{@errorName(err)}, + "unable to map '/etc/passwd': {t}", + .{err}, ); }; defer if (shared.free_on_close) mapped_passwd_file.close(); @@ -88,9 +85,6 @@ const impl = struct { passwd_file_contents: []const u8, system: System, ) Command.Error!void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "current user" }); - defer z.end(); - const euid = system.getEffectiveUserId(); log.debug("currentUser called, euid: {}", .{euid}); @@ -141,10 +135,6 @@ const impl = struct { passwd_file_contents: []const u8, system: System, ) Command.Error!void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "namedUser" }); - defer z.end(); - z.text(user); - log.debug("namedUser called, user='{s}'", .{user}); var passwd_file_iter = shared.passwdFileIterator(passwd_file_contents); @@ -180,10 +170,6 @@ const impl = struct { io: IO, system: System, ) !void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "print groups" }); - defer z.end(); - z.text(user); - log.debug( "printGroups called, user='{s}', primary_group_id={}", .{ user, primary_group_id }, @@ -194,8 +180,8 @@ const impl = struct { return command.printErrorAlloc( allocator, io, - "unable to open '/etc/group': {s}", - .{@errorName(err)}, + "unable to open '/etc/group': {t}", + .{err}, ); errdefer if (shared.free_on_close) group_file.close(); @@ -203,16 +189,16 @@ const impl = struct { return command.printErrorAlloc( allocator, io, - "unable to stat '/etc/group': {s}", - .{@errorName(err)}, + "unable to stat '/etc/group': {t}", + .{err}, ); break :blk group_file.mapReadonly(stat.size) catch |err| return command.printErrorAlloc( allocator, io, - "unable to map '/etc/group': {s}", - .{@errorName(err)}, + "unable to map '/etc/group': {t}", + .{err}, ); }; defer if (shared.free_on_close) mapped_group_file.close(); @@ -292,11 +278,11 @@ const impl = struct { _ = try etc_dir.addFile("passwd", passwd_contents); _ = try etc_dir.addFile("group", group_contents); - var stdout: std.ArrayList(u8) = .init(std.testing.allocator); + var stdout: std.Io.Writer.Allocating = .init(std.testing.allocator); defer stdout.deinit(); try command.testExecute(&.{}, .{ - .stdout = stdout.writer().any(), + .stdout = &stdout.writer, .system_description = .{ .file_system = fs_description, .user_group = .{ @@ -305,7 +291,7 @@ const impl = struct { }, }); - try std.testing.expectEqualStrings("sys user wheel\n", stdout.items); + try std.testing.expectEqualStrings("sys user wheel\n", stdout.getWritten()); } }; @@ -318,4 +304,3 @@ const System = @import("../system/System.zig"); const log = std.log.scoped(.groups); const std = @import("std"); -const tracy = @import("tracy"); diff --git a/src/commands/nproc.zig b/src/commands/nproc.zig index a41cbb0..8d94ac4 100644 --- a/src/commands/nproc.zig +++ b/src/commands/nproc.zig @@ -31,9 +31,6 @@ const impl = struct { system: System, exe_path: []const u8, ) Command.Error!void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = command.name }); - defer z.end(); - _ = exe_path; _ = try args.nextWithHelpOrVersion(true); @@ -47,8 +44,8 @@ const impl = struct { return command.printErrorAlloc( allocator, io, - "unable to open '{s}': {s}", - .{ path, @errorName(err) }, + "unable to open '{s}': {t}", + .{ path, err }, ); defer if (shared.free_on_close) file.close(); @@ -56,8 +53,8 @@ const impl = struct { return command.printErrorAlloc( allocator, io, - "unable to read file '{s}': {s}", - .{ path, @errorName(err) }, + "unable to read file '{s}': {t}", + .{ path, err }, ); break :blk buffer[0..read]; @@ -120,17 +117,17 @@ const impl = struct { const cpu_dir = try system_dir.addDirectory("cpu"); _ = try cpu_dir.addFile("online", "0-15"); - var stdout: std.ArrayList(u8) = .init(std.testing.allocator); + var stdout: std.Io.Writer.Allocating = .init(std.testing.allocator); defer stdout.deinit(); try command.testExecute(&.{}, .{ - .stdout = stdout.writer().any(), + .stdout = &stdout.writer, .system_description = .{ .file_system = fs_description, }, }); - try std.testing.expectEqualStrings("16\n", stdout.items); + try std.testing.expectEqualStrings("16\n", stdout.getWritten()); } }; @@ -141,4 +138,3 @@ const shared = @import("../shared.zig"); const System = @import("../system/System.zig"); const std = @import("std"); -const tracy = @import("tracy"); diff --git a/src/commands/template.zig b/src/commands/template.zig index 32097e1..01b81c8 100644 --- a/src/commands/template.zig +++ b/src/commands/template.zig @@ -43,22 +43,14 @@ const impl = struct { system: System, exe_path: []const u8, ) Command.Error!void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = command.name }); - defer z.end(); - _ = system; const options = try parseArguments(allocator, io, args, exe_path); - log.debug("{}", .{options}); + log.debug("{f}", .{options}); } const TemplateOptions = struct { // CHANGE THIS - IF NO OPTIONS ARE NEEDED DELETE THIS - pub fn format( - options: TemplateOptions, - comptime _: []const u8, - _: std.fmt.FormatOptions, - writer: anytype, - ) !void { + pub fn format(options: TemplateOptions, writer: *std.Io.Writer) !void { _ = options; try writer.writeAll("TemplateOptions {}"); } @@ -70,9 +62,6 @@ const impl = struct { args: *Arg.Iterator, exe_path: []const u8, ) !TemplateOptions { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "parse arguments" }); - defer z.end(); - var opt_arg: ?Arg = try args.nextWithHelpOrVersion(true); const options: TemplateOptions = .{}; @@ -167,4 +156,3 @@ const System = @import("../system/System.zig"); const log = std.log.scoped(.template); // CHANGE THIS const std = @import("std"); -const tracy = @import("tracy"); diff --git a/src/commands/touch.zig b/src/commands/touch.zig index 69bd3cd..2d8a70b 100644 --- a/src/commands/touch.zig +++ b/src/commands/touch.zig @@ -50,11 +50,8 @@ const impl = struct { system: System, exe_path: []const u8, ) Command.Error!void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = command.name }); - defer z.end(); - const options = try parseArguments(allocator, io, args, exe_path); - log.debug("{}", .{options}); + log.debug("{f}", .{options}); return performTouch(allocator, io, args, options, system); } @@ -66,9 +63,6 @@ const impl = struct { options: TouchOptions, system: System, ) !void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "perform touch" }); - defer z.end(); - const cwd = system.cwd(); const times = try getTimes(allocator, io, options.time_to_use, cwd); @@ -77,10 +71,6 @@ const impl = struct { var opt_file_path: ?[]const u8 = options.first_file_path; argument_loop: while (opt_file_path) |file_path| : (opt_file_path = args.nextRaw()) { - const file_zone: tracy.Zone = .begin(.{ .src = @src(), .name = "process file" }); - defer file_zone.end(); - file_zone.text(file_path); - const file: System.File = blk: { const file_or_error = switch (options.create) { true => cwd.createFile(file_path, .{ .truncate = false }), @@ -94,8 +84,8 @@ const impl = struct { return command.printErrorAlloc( allocator, io, - "failed to open '{s}': {s}", - .{ file_path, @errorName(err) }, + "failed to open '{s}': {t}", + .{ file_path, err }, ); }; }; @@ -108,8 +98,8 @@ const impl = struct { return command.printErrorAlloc( allocator, io, - "failed to stat '{s}': {s}", - .{ file_path, @errorName(err) }, + "failed to stat '{s}': {t}", + .{ file_path, err }, ); break :blk switch (options.update) { @@ -123,8 +113,8 @@ const impl = struct { return command.printErrorAlloc( allocator, io, - "failed to update times on '{s}': {s}", - .{ file_path, @errorName(err) }, + "failed to update times on '{s}': {t}", + .{ file_path, err }, ); } } @@ -148,8 +138,8 @@ const impl = struct { return command.printErrorAlloc( allocator, io, - "unable to open '{s}': {s}", - .{ reference_file_path, @errorName(err) }, + "unable to open '{s}': {t}", + .{ reference_file_path, err }, ); defer reference_file.close(); @@ -157,8 +147,8 @@ const impl = struct { return command.printErrorAlloc( allocator, io, - "unable to stat '{s}': {s}", - .{ reference_file_path, @errorName(err) }, + "unable to stat '{s}': {t}", + .{ reference_file_path, err }, ); return .{ @@ -192,29 +182,24 @@ const impl = struct { reference_file: []const u8, }; - pub fn format( - value: TouchOptions, - comptime fmt: []const u8, - options: std.fmt.FormatOptions, - writer: anytype, - ) !void { - _ = options; - _ = fmt; - + pub fn format(options: TouchOptions, writer: *std.Io.Writer) !void { try writer.writeAll("TouchOptions {"); try writer.writeAll(comptime "\n" ++ shared.option_log_indentation ++ ".update = ."); - try writer.writeAll(@tagName(value.update)); + try writer.writeAll(@tagName(options.update)); try writer.writeAll(comptime ",\n" ++ shared.option_log_indentation ++ ".create = "); - const create = if (value.create) "true" else "false"; + const create = if (options.create) "true" else "false"; try writer.writeAll(create); try writer.writeAll(comptime ",\n" ++ shared.option_log_indentation ++ ".time_to_use = "); - switch (value.time_to_use) { + switch (options.time_to_use) { .current_time => try writer.writeAll(".current_time"), - inline else => |val| try writer.print(".{{ .{s} = \"{s}\" }}", .{ @tagName(value.time_to_use), val }), + inline else => |val| try writer.print( + ".{{ .{t} = \"{s}\" }}", + .{ options.time_to_use, val }, + ), } try writer.writeAll(",\n}"); @@ -227,9 +212,6 @@ const impl = struct { args: *Arg.Iterator, exe_path: []const u8, ) !TouchOptions { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "parse arguments" }); - defer z.end(); - // `-h` not supported to allow for future no dereference shorthand var opt_arg: ?Arg = try args.nextWithHelpOrVersion(false); @@ -498,4 +480,3 @@ const System = @import("../system/System.zig"); const log = std.log.scoped(.touch); const std = @import("std"); -const tracy = @import("tracy"); diff --git a/src/commands/true.zig b/src/commands/true.zig index ac0aaf2..3a00b6f 100644 --- a/src/commands/true.zig +++ b/src/commands/true.zig @@ -30,9 +30,6 @@ const impl = struct { system: System, exe_path: []const u8, ) Command.Error!void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = command.name }); - defer z.end(); - _ = io; _ = exe_path; _ = system; @@ -49,17 +46,17 @@ const impl = struct { } test "true ignores args" { - var stdout = std.ArrayList(u8).init(std.testing.allocator); + var stdout: std.Io.Writer.Allocating = .init(std.testing.allocator); defer stdout.deinit(); try command.testExecute( &.{ "these", "arguments", "are", "ignored", }, - .{ .stdout = stdout.writer().any() }, + .{ .stdout = &stdout.writer }, ); - try std.testing.expectEqualStrings("", stdout.items); + try std.testing.expectEqualStrings("", stdout.getWritten()); } test "true help" { @@ -82,4 +79,3 @@ const shared = @import("../shared.zig"); const System = @import("../system/System.zig"); const std = @import("std"); -const tracy = @import("tracy"); diff --git a/src/commands/uname.zig b/src/commands/uname.zig index a449579..b4847e4 100644 --- a/src/commands/uname.zig +++ b/src/commands/uname.zig @@ -41,11 +41,8 @@ const impl = struct { system: System, exe_path: []const u8, ) Command.Error!void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = command.name }); - defer z.end(); - const options = try parseArguments(allocator, io, args, exe_path); - log.debug("{}", .{options}); + log.debug("{f}", .{options}); return performUname(allocator, io, system, options); } @@ -56,9 +53,6 @@ const impl = struct { system: System, options: UnameOptions, ) !void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "perform uname" }); - defer z.end(); - _ = allocator; const uname = system.uname(); @@ -150,12 +144,7 @@ const impl = struct { non_empty, }; - pub fn format( - options: UnameOptions, - comptime _: []const u8, - _: std.fmt.FormatOptions, - writer: anytype, - ) !void { + pub fn format(options: UnameOptions, writer: *std.Io.Writer) !void { try writer.writeAll("UnameOptions {"); try writer.writeAll(comptime "\n" ++ shared.option_log_indentation ++ ".kernel_name = ."); @@ -195,9 +184,6 @@ const impl = struct { args: *Arg.Iterator, exe_path: []const u8, ) !UnameOptions { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "parse arguments" }); - defer z.end(); - var opt_arg: ?Arg = try args.nextWithHelpOrVersion(true); var options: UnameOptions = .{}; @@ -387,11 +373,11 @@ const impl = struct { } test "uname" { - var stdout = std.ArrayList(u8).init(std.testing.allocator); + var stdout: std.Io.Writer.Allocating = .init(std.testing.allocator); defer stdout.deinit(); try command.testExecute(&.{"-a"}, .{ - .stdout = stdout.writer().any(), + .stdout = &stdout.writer, .system_description = .{ .uname = .{ .sysname = "sysname", @@ -409,7 +395,7 @@ const impl = struct { else "sysname nodename release version machine sysname\n"; - try std.testing.expectEqualStrings(expected, stdout.items); + try std.testing.expectEqualStrings(expected, stdout.getWritten()); } }; @@ -422,4 +408,3 @@ const System = @import("../system/System.zig"); const log = std.log.scoped(.uname); const std = @import("std"); -const tracy = @import("tracy"); diff --git a/src/commands/unlink.zig b/src/commands/unlink.zig index 8e34591..34c6f62 100644 --- a/src/commands/unlink.zig +++ b/src/commands/unlink.zig @@ -37,9 +37,6 @@ const impl = struct { system: System, exe_path: []const u8, ) Command.Error!void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = command.name }); - defer z.end(); - var opt_arg: ?Arg = (try args.nextWithHelpOrVersion(true)) orelse return command.printInvalidUsage( io, @@ -52,17 +49,13 @@ const impl = struct { while (opt_arg) |file_arg| : (opt_arg = args.next()) { const file_path = file_arg.raw; - const file_zone: tracy.Zone = .begin(.{ .src = @src(), .name = "unlink file" }); - defer file_zone.end(); - file_zone.text(file_path); - log.debug("unlinking file '{s}'", .{file_path}); cwd.unlinkFile(file_path) catch |err| return command.printErrorAlloc( allocator, io, - "failed to unlink '{s}': {s}", - .{ file_path, @errorName(err) }, + "failed to unlink '{s}': {t}", + .{ file_path, err }, ); } } @@ -255,4 +248,3 @@ const System = @import("../system/System.zig"); const log = std.log.scoped(.unlink); const std = @import("std"); -const tracy = @import("tracy"); diff --git a/src/commands/whoami.zig b/src/commands/whoami.zig index e5ae4ae..e8c5514 100644 --- a/src/commands/whoami.zig +++ b/src/commands/whoami.zig @@ -30,9 +30,6 @@ const impl = struct { system: System, exe_path: []const u8, ) Command.Error!void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = command.name }); - defer z.end(); - _ = exe_path; _ = try args.nextWithHelpOrVersion(true); @@ -44,8 +41,8 @@ const impl = struct { return command.printErrorAlloc( allocator, io, - "unable to open '/etc/passwd': {s}", - .{@errorName(err)}, + "unable to open '/etc/passwd': {t}", + .{err}, ); errdefer if (shared.free_on_close) passwd_file.close(); @@ -53,16 +50,16 @@ const impl = struct { return command.printErrorAlloc( allocator, io, - "unable to stat '/etc/passwd': {s}", - .{@errorName(err)}, + "unable to stat '/etc/passwd': {t}", + .{err}, ); break :blk passwd_file.mapReadonly(stat.size) catch |err| return command.printErrorAlloc( allocator, io, - "unable to map '/etc/passwd': {s}", - .{@errorName(err)}, + "unable to map '/etc/passwd': {t}", + .{err}, ); }; defer if (shared.free_on_close) mapped_passwd_file.close(); @@ -119,11 +116,11 @@ const impl = struct { const etc_dir = try fs_description.root.addDirectory("etc"); _ = try etc_dir.addFile("passwd", passwd_contents); - var stdout: std.ArrayList(u8) = .init(std.testing.allocator); + var stdout: std.Io.Writer.Allocating = .init(std.testing.allocator); defer stdout.deinit(); try command.testExecute(&.{}, .{ - .stdout = stdout.writer().any(), + .stdout = &stdout.writer, .system_description = .{ .file_system = fs_description, .user_group = .{ @@ -132,7 +129,7 @@ const impl = struct { }, }); - try std.testing.expectEqualStrings("user\n", stdout.items); + try std.testing.expectEqualStrings("user\n", stdout.getWritten()); } }; @@ -145,4 +142,3 @@ const System = @import("../system/System.zig"); const log = std.log.scoped(.whoami); const std = @import("std"); -const tracy = @import("tracy"); diff --git a/src/commands/yes.zig b/src/commands/yes.zig index 2764584..cd56b8e 100644 --- a/src/commands/yes.zig +++ b/src/commands/yes.zig @@ -30,9 +30,6 @@ const impl = struct { system: System, exe_path: []const u8, ) Command.Error!void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = command.name }); - defer z.end(); - _ = exe_path; _ = system; @@ -57,9 +54,6 @@ const impl = struct { } fn getString(allocator: std.mem.Allocator, args: *Arg.Iterator) !shared.MaybeAllocatedString { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "get string" }); - defer z.end(); - var buffer = std.ArrayList(u8).init(allocator); defer if (shared.free_on_close) buffer.deinit(); @@ -88,10 +82,10 @@ const impl = struct { } test "yes no args" { - var stdout: std.ArrayList(u8) = .init(std.testing.allocator); + var stdout: std.Io.Writer.Allocating = .init(std.testing.allocator); defer stdout.deinit(); - try command.testExecute(&.{}, .{ .stdout = stdout.writer().any() }); + try command.testExecute(&.{}, .{ .stdout = &stdout.writer }); const expected = blk: { var expected: std.ArrayList(u8) = .init(std.testing.allocator); @@ -105,16 +99,16 @@ const impl = struct { }; defer std.testing.allocator.free(expected); - try std.testing.expectEqualStrings(expected, stdout.items); + try std.testing.expectEqualStrings(expected, stdout.getWritten()); } test "yes with args" { - var stdout: std.ArrayList(u8) = .init(std.testing.allocator); + var stdout: std.Io.Writer.Allocating = .init(std.testing.allocator); defer stdout.deinit(); try command.testExecute( &.{ "arg1", "arg2" }, - .{ .stdout = stdout.writer().any() }, + .{ .stdout = &stdout.writer }, ); const expected = blk: { @@ -129,7 +123,7 @@ const impl = struct { }; defer std.testing.allocator.free(expected); - try std.testing.expectEqualStrings(expected, stdout.items); + try std.testing.expectEqualStrings(expected, stdout.getWritten()); } test "yes fuzz" { @@ -146,4 +140,3 @@ const shared = @import("../shared.zig"); const System = @import("../system/System.zig"); const std = @import("std"); -const tracy = @import("tracy"); diff --git a/src/main.zig b/src/main.zig index e50bb25..59ec244 100644 --- a/src/main.zig +++ b/src/main.zig @@ -6,44 +6,26 @@ pub fn main() if (shared.is_debug_or_test) Command.ExposedError!u8 else u8 { var debug_allocator: if (shared.is_debug_or_test) std.heap.DebugAllocator(.{}) else void = if (shared.is_debug_or_test) .init else {}; - const gpa_allocator = if (shared.is_debug_or_test) + const allocator = if (shared.is_debug_or_test) debug_allocator.allocator() else std.heap.smp_allocator; - var tracy_allocator: if (options.trace) tracy.Allocator else void = - if (options.trace) .{ .parent = gpa_allocator } else {}; - - const allocator = - if (options.trace) - tracy_allocator.allocator() - else - gpa_allocator; - - var std_in_buffered: std.io.BufferedReader(4096, std.fs.File.Reader) = .{ - .unbuffered_reader = undefined, - }; - var std_out_buffered: std.io.BufferedWriter(4096, std.fs.File.Writer) = .{ - .unbuffered_writer = undefined, - }; + var stdin_buffer: [4096]u8 = undefined; + var stdout_buffer: [4096]u8 = undefined; }; - - // this causes the frame to start with our main instead of `std.start` - tracy.frameMark(null); - const main_z: tracy.Zone = .begin(.{ .src = @src(), .name = "main" }); - defer main_z.end(); - defer { if (shared.is_debug_or_test) _ = static.debug_allocator.deinit(); } - static.std_in_buffered.unbuffered_reader = std.io.getStdIn().reader(); - static.std_out_buffered.unbuffered_writer = std.io.getStdOut().writer(); + var stdin = std.fs.File.stdin().reader(&static.stdin_buffer); + var stdout = std.fs.File.stdout().writer(&static.stdout_buffer); + var stderr = std.fs.File.stderr().writer(&.{}); const io: IO = .{ - ._stderr = std.io.getStdErr().writer().any(), - ._stdin = static.std_in_buffered.reader().any(), - ._stdout = static.std_out_buffered.writer().any(), + ._stdin = &stdin.interface, + ._stdout = &stdout.interface, + ._stderr = &stderr.interface, }; var arg_iter = std.process.argsWithAllocator(static.allocator) catch |err| { @@ -73,7 +55,7 @@ pub fn main() if (shared.is_debug_or_test) Command.ExposedError!u8 else u8 { return 1; }; - static.std_out_buffered.flush() catch |err| { + stdout.interface.flush() catch |err| { io.unableToWriteTo("stdout", err) catch {}; return 1; }; @@ -88,16 +70,12 @@ fn tryExecute( basename: []const u8, exe_path: []const u8, ) Command.ExposedError!void { - const z: tracy.Zone = .begin(.{ .src = @src(), .name = "tryExecute" }); - defer z.end(); - var arg_iter: Arg.Iterator = .{ .args = os_arg_iter }; const system: System = .{}; // attempt to match the basename to a command if (Command.enabled_command_lookup.get(basename)) |command| { - z.text(basename); log.debug("executing command '{s}' due to basename", .{command.name}); return command.execute( allocator, @@ -156,8 +134,6 @@ fn tryExecute( return error.AlreadyHandled; }; - z.text(possible_command); - const exe_path_with_command = try std.fmt.allocPrint(allocator, "{s} {s}", .{ exe_path, command.name, @@ -244,12 +220,6 @@ const log = std.log.scoped(.main); const builtin = @import("builtin"); const options = @import("options"); const std = @import("std"); -const tracy = @import("tracy"); - -pub const tracy_options: tracy.Options = .{ - .default_callstack_depth = 10, -}; -pub const tracy_impl = @import("tracy_impl"); comptime { if (builtin.is_test) { diff --git a/src/shared.zig b/src/shared.zig index 3256341..a64009f 100644 --- a/src/shared.zig +++ b/src/shared.zig @@ -183,4 +183,3 @@ const log = std.log.scoped(.shared); const builtin = @import("builtin"); const options = @import("options"); const std = @import("std"); -const tracy = @import("tracy"); diff --git a/src/system/backend/FileSystem.zig b/src/system/backend/FileSystem.zig index 9591045..ff25aba 100644 --- a/src/system/backend/FileSystem.zig +++ b/src/system/backend/FileSystem.zig @@ -117,7 +117,7 @@ pub fn openFile( if (options.mode != .read_only) { // TODO: Implement *not* read_only - std.debug.panic("file mode '{s}' is unimplemented", .{@tagName(options.mode)}); + std.debug.panic("file mode '{t}' is unimplemented", .{options.mode}); } const dir_entry = self.cwdOrEntry(ptr) orelse unreachable; // no such directory diff --git a/src/system/backend/TestBackend.zig b/src/system/backend/TestBackend.zig index f46499f..478ff85 100644 --- a/src/system/backend/TestBackend.zig +++ b/src/system/backend/TestBackend.zig @@ -58,4 +58,3 @@ const log = std.log.scoped(.system_test_backend); const is_test = @import("builtin").is_test; const target_os = @import("target_os").target_os; const std = @import("std"); -const tracy = @import("tracy");