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
138138 ) catch unreachable;
139139}
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
152141pub fn expectStdErrEqual(self: *RunStep, bytes: []const u8) void {
153142 self.stderr_action = .{ .expect_exact = self.builder.dupe(bytes) };
154143}
......@@ -189,7 +178,7 @@ fn make(step: *Step) !void {
189178 const argv = argv_list.items;
190179
191180 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);
193182 std.debug.print("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });
194183 self.builder.allocator.free(cmd);
195184 return ExecError.ExecNotSupported;
src/main.zig+8-19
......@@ -2881,7 +2881,7 @@ fn runOrTest(
28812881 // execv releases the locks; no need to destroy the Compilation here.
28822882 const err = std.process.execv(gpa, argv.items);
28832883 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);
28852885 fatal("the following command failed to execve with '{s}':\n{s}", .{ @errorName(err), cmd });
28862886 } else if (std.process.can_spawn) {
28872887 const child = try std.ChildProcess.init(argv.items, gpa);
......@@ -2900,7 +2900,7 @@ fn runOrTest(
29002900
29012901 const term = child.spawnAndWait() catch |err| {
29022902 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);
29042904 fatal("the following command failed with '{s}':\n{s}", .{ @errorName(err), cmd });
29052905 };
29062906 switch (arg_mode) {
......@@ -2931,12 +2931,12 @@ fn runOrTest(
29312931 if (code == 0) {
29322932 if (!watch) return cleanExit();
29332933 } else {
2934 const cmd = try argvCmd(arena, argv.items);
2934 const cmd = try std.mem.join(arena, " ", argv.items);
29352935 fatal("the following test command failed with exit code {d}:\n{s}", .{ code, cmd });
29362936 }
29372937 },
29382938 else => {
2939 const cmd = try argvCmd(arena, argv.items);
2939 const cmd = try std.mem.join(arena, " ", argv.items);
29402940 fatal("the following test command crashed:\n{s}", .{cmd});
29412941 },
29422942 }
......@@ -2944,7 +2944,7 @@ fn runOrTest(
29442944 else => unreachable,
29452945 }
29462946 } else {
2947 const cmd = try argvCmd(arena, argv.items);
2947 const cmd = try std.mem.join(arena, " ", argv.items);
29482948 fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });
29492949 }
29502950}
......@@ -3573,32 +3573,21 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
35733573 if (prominent_compile_errors) {
35743574 fatal("the build command failed with exit code {d}", .{code});
35753575 } else {
3576 const cmd = try argvCmd(arena, child_argv);
3576 const cmd = try std.mem.join(arena, " ", child_argv);
35773577 fatal("the following build command failed with exit code {d}:\n{s}", .{ code, cmd });
35783578 }
35793579 },
35803580 else => {
3581 const cmd = try argvCmd(arena, child_argv);
3581 const cmd = try std.mem.join(arena, " ", child_argv);
35823582 fatal("the following build command crashed:\n{s}", .{cmd});
35833583 },
35843584 }
35853585 } else {
3586 const cmd = try argvCmd(arena, child_argv);
3586 const cmd = try std.mem.join(arena, " ", child_argv);
35873587 fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });
35883588 }
35893589}
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
36023591fn readSourceFileToEndAlloc(
36033592 allocator: mem.Allocator,
36043593 input: *const fs.File,
test/tests.zig+1-12
......@@ -28,17 +28,6 @@ pub const TranslateCContext = @import("src/translate_c.zig").TranslateCContext;
2828pub const RunTranslatedCContext = @import("src/run_translated_c.zig").RunTranslatedCContext;
2929pub 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
4231const TestTarget = struct {
4332 target: CrossTarget = @as(CrossTarget, .{}),
4433 mode: std.builtin.Mode = .Debug,
......@@ -736,7 +725,7 @@ pub const StackTracesContext = struct {
736725 std.debug.print("Test {d}/{d} {s}...", .{ self.test_index + 1, self.context.test_index, self.name });
737726
738727 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);
740729 std.debug.print("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });
741730 b.allocator.free(cmd);
742731 return ExecError.ExecNotSupported;