authorgravatar for topolarity@tapscott.meCody Tapscott <topolarity@tapscott.me> 2022-02-05 09:09:55-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-06 22:21:46-07:00
logc1cf158729f4d726639a5695754957f9f45f89da
treec876a91ac6f02f3e7bdc9097c742cd609a3b6014
parent5065830aa007c374c382be9e80ba924df6cecc78

Replace argvCmd with std.mem.join


3 files changed, 10 insertions(+), 43 deletions(-)

lib/std/build/RunStep.zig+1-12
...@@ -138,17 +138,6 @@ pub fn setEnvironmentVariable(self: *RunStep, key: []const u8, value: []const u8...@@ -138,17 +138,6 @@ pub fn setEnvironmentVariable(self: *RunStep, key: []const u8, value: []const u8
138 ) catch unreachable;138 ) catch unreachable;
139}139}
140140
141fn argvCmd(allocator: Allocator, argv: []const []const u8) ![]u8 {
142 var cmd = std.ArrayList(u8).init(allocator);
143 defer cmd.deinit();
144 for (argv[0 .. argv.len - 1]) |arg| {
145 try cmd.appendSlice(arg);
146 try cmd.append(' ');
147 }
148 try cmd.appendSlice(argv[argv.len - 1]);
149 return cmd.toOwnedSlice();
150}
151
152pub fn expectStdErrEqual(self: *RunStep, bytes: []const u8) void {141pub fn expectStdErrEqual(self: *RunStep, bytes: []const u8) void {
153 self.stderr_action = .{ .expect_exact = self.builder.dupe(bytes) };142 self.stderr_action = .{ .expect_exact = self.builder.dupe(bytes) };
154}143}
...@@ -189,7 +178,7 @@ fn make(step: *Step) !void {...@@ -189,7 +178,7 @@ fn make(step: *Step) !void {
189 const argv = argv_list.items;178 const argv = argv_list.items;
190179
191 if (!std.process.can_spawn) {180 if (!std.process.can_spawn) {
192 const cmd = try argvCmd(self.builder.allocator, argv);181 const cmd = try std.mem.join(self.builder.allocator, " ", argv);
193 std.debug.print("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });182 std.debug.print("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });
194 self.builder.allocator.free(cmd);183 self.builder.allocator.free(cmd);
195 return ExecError.ExecNotSupported;184 return ExecError.ExecNotSupported;
src/main.zig+8-19
...@@ -2881,7 +2881,7 @@ fn runOrTest(...@@ -2881,7 +2881,7 @@ fn runOrTest(
2881 // execv releases the locks; no need to destroy the Compilation here.2881 // execv releases the locks; no need to destroy the Compilation here.
2882 const err = std.process.execv(gpa, argv.items);2882 const err = std.process.execv(gpa, argv.items);
2883 try warnAboutForeignBinaries(gpa, arena, arg_mode, target_info, link_libc);2883 try warnAboutForeignBinaries(gpa, arena, arg_mode, target_info, link_libc);
2884 const cmd = try argvCmd(arena, argv.items);2884 const cmd = try std.mem.join(arena, " ", argv.items);
2885 fatal("the following command failed to execve with '{s}':\n{s}", .{ @errorName(err), cmd });2885 fatal("the following command failed to execve with '{s}':\n{s}", .{ @errorName(err), cmd });
2886 } else if (std.process.can_spawn) {2886 } else if (std.process.can_spawn) {
2887 const child = try std.ChildProcess.init(argv.items, gpa);2887 const child = try std.ChildProcess.init(argv.items, gpa);
...@@ -2900,7 +2900,7 @@ fn runOrTest(...@@ -2900,7 +2900,7 @@ fn runOrTest(
29002900
2901 const term = child.spawnAndWait() catch |err| {2901 const term = child.spawnAndWait() catch |err| {
2902 try warnAboutForeignBinaries(gpa, arena, arg_mode, target_info, link_libc);2902 try warnAboutForeignBinaries(gpa, arena, arg_mode, target_info, link_libc);
2903 const cmd = try argvCmd(arena, argv.items);2903 const cmd = try std.mem.join(arena, " ", argv.items);
2904 fatal("the following command failed with '{s}':\n{s}", .{ @errorName(err), cmd });2904 fatal("the following command failed with '{s}':\n{s}", .{ @errorName(err), cmd });
2905 };2905 };
2906 switch (arg_mode) {2906 switch (arg_mode) {
...@@ -2931,12 +2931,12 @@ fn runOrTest(...@@ -2931,12 +2931,12 @@ fn runOrTest(
2931 if (code == 0) {2931 if (code == 0) {
2932 if (!watch) return cleanExit();2932 if (!watch) return cleanExit();
2933 } else {2933 } else {
2934 const cmd = try argvCmd(arena, argv.items);2934 const cmd = try std.mem.join(arena, " ", argv.items);
2935 fatal("the following test command failed with exit code {d}:\n{s}", .{ code, cmd });2935 fatal("the following test command failed with exit code {d}:\n{s}", .{ code, cmd });
2936 }2936 }
2937 },2937 },
2938 else => {2938 else => {
2939 const cmd = try argvCmd(arena, argv.items);2939 const cmd = try std.mem.join(arena, " ", argv.items);
2940 fatal("the following test command crashed:\n{s}", .{cmd});2940 fatal("the following test command crashed:\n{s}", .{cmd});
2941 },2941 },
2942 }2942 }
...@@ -2944,7 +2944,7 @@ fn runOrTest(...@@ -2944,7 +2944,7 @@ fn runOrTest(
2944 else => unreachable,2944 else => unreachable,
2945 }2945 }
2946 } else {2946 } else {
2947 const cmd = try argvCmd(arena, argv.items);2947 const cmd = try std.mem.join(arena, " ", argv.items);
2948 fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });2948 fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });
2949 }2949 }
2950}2950}
...@@ -3573,32 +3573,21 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi...@@ -3573,32 +3573,21 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
3573 if (prominent_compile_errors) {3573 if (prominent_compile_errors) {
3574 fatal("the build command failed with exit code {d}", .{code});3574 fatal("the build command failed with exit code {d}", .{code});
3575 } else {3575 } else {
3576 const cmd = try argvCmd(arena, child_argv);3576 const cmd = try std.mem.join(arena, " ", child_argv);
3577 fatal("the following build command failed with exit code {d}:\n{s}", .{ code, cmd });3577 fatal("the following build command failed with exit code {d}:\n{s}", .{ code, cmd });
3578 }3578 }
3579 },3579 },
3580 else => {3580 else => {
3581 const cmd = try argvCmd(arena, child_argv);3581 const cmd = try std.mem.join(arena, " ", child_argv);
3582 fatal("the following build command crashed:\n{s}", .{cmd});3582 fatal("the following build command crashed:\n{s}", .{cmd});
3583 },3583 },
3584 }3584 }
3585 } else {3585 } else {
3586 const cmd = try argvCmd(arena, child_argv);3586 const cmd = try std.mem.join(arena, " ", child_argv);
3587 fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });3587 fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });
3588 }3588 }
3589}3589}
35903590
3591fn argvCmd(allocator: Allocator, argv: []const []const u8) ![]u8 {
3592 var cmd = std.ArrayList(u8).init(allocator);
3593 defer cmd.deinit();
3594 for (argv[0 .. argv.len - 1]) |arg| {
3595 try cmd.appendSlice(arg);
3596 try cmd.append(' ');
3597 }
3598 try cmd.appendSlice(argv[argv.len - 1]);
3599 return cmd.toOwnedSlice();
3600}
3601
3602fn readSourceFileToEndAlloc(3591fn readSourceFileToEndAlloc(
3603 allocator: mem.Allocator,3592 allocator: mem.Allocator,
3604 input: *const fs.File,3593 input: *const fs.File,
test/tests.zig+1-12
...@@ -28,17 +28,6 @@ pub const TranslateCContext = @import("src/translate_c.zig").TranslateCContext;...@@ -28,17 +28,6 @@ pub const TranslateCContext = @import("src/translate_c.zig").TranslateCContext;
28pub const RunTranslatedCContext = @import("src/run_translated_c.zig").RunTranslatedCContext;28pub const RunTranslatedCContext = @import("src/run_translated_c.zig").RunTranslatedCContext;
29pub const CompareOutputContext = @import("src/compare_output.zig").CompareOutputContext;29pub const CompareOutputContext = @import("src/compare_output.zig").CompareOutputContext;
3030
31fn argvCmd(allocator: Allocator, argv: []const []const u8) ![]u8 {
32 var cmd = std.ArrayList(u8).init(allocator);
33 defer cmd.deinit();
34 for (argv[0 .. argv.len - 1]) |arg| {
35 try cmd.appendSlice(arg);
36 try cmd.append(' ');
37 }
38 try cmd.appendSlice(argv[argv.len - 1]);
39 return cmd.toOwnedSlice();
40}
41
42const TestTarget = struct {31const TestTarget = struct {
43 target: CrossTarget = @as(CrossTarget, .{}),32 target: CrossTarget = @as(CrossTarget, .{}),
44 mode: std.builtin.Mode = .Debug,33 mode: std.builtin.Mode = .Debug,
...@@ -736,7 +725,7 @@ pub const StackTracesContext = struct {...@@ -736,7 +725,7 @@ pub const StackTracesContext = struct {
736 std.debug.print("Test {d}/{d} {s}...", .{ self.test_index + 1, self.context.test_index, self.name });725 std.debug.print("Test {d}/{d} {s}...", .{ self.test_index + 1, self.context.test_index, self.name });
737726
738 if (!std.process.can_spawn) {727 if (!std.process.can_spawn) {
739 const cmd = try argvCmd(b.allocator, args.items);728 const cmd = try std.mem.join(b.allocator, " ", args.items);
740 std.debug.print("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });729 std.debug.print("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });
741 b.allocator.free(cmd);730 b.allocator.free(cmd);
742 return ExecError.ExecNotSupported;731 return ExecError.ExecNotSupported;