Replace argvCmd with std.mem.join

This commit is contained in:
Cody Tapscott 2022-02-05 09:09:55 -07:00 committed by Andrew Kelley
parent 5065830aa0
commit c1cf158729
3 changed files with 10 additions and 43 deletions

View File

@ -138,17 +138,6 @@ pub fn setEnvironmentVariable(self: *RunStep, key: []const u8, value: []const u8
) catch unreachable;
}
fn argvCmd(allocator: Allocator, argv: []const []const u8) ![]u8 {
var cmd = std.ArrayList(u8).init(allocator);
defer cmd.deinit();
for (argv[0 .. argv.len - 1]) |arg| {
try cmd.appendSlice(arg);
try cmd.append(' ');
}
try cmd.appendSlice(argv[argv.len - 1]);
return cmd.toOwnedSlice();
}
pub fn expectStdErrEqual(self: *RunStep, bytes: []const u8) void {
self.stderr_action = .{ .expect_exact = self.builder.dupe(bytes) };
}
@ -189,7 +178,7 @@ fn make(step: *Step) !void {
const argv = argv_list.items;
if (!std.process.can_spawn) {
const cmd = try argvCmd(self.builder.allocator, argv);
const cmd = try std.mem.join(self.builder.allocator, " ", argv);
std.debug.print("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });
self.builder.allocator.free(cmd);
return ExecError.ExecNotSupported;

View File

@ -2881,7 +2881,7 @@ fn runOrTest(
// execv releases the locks; no need to destroy the Compilation here.
const err = std.process.execv(gpa, argv.items);
try warnAboutForeignBinaries(gpa, arena, arg_mode, target_info, link_libc);
const cmd = try argvCmd(arena, argv.items);
const cmd = try std.mem.join(arena, " ", argv.items);
fatal("the following command failed to execve with '{s}':\n{s}", .{ @errorName(err), cmd });
} else if (std.process.can_spawn) {
const child = try std.ChildProcess.init(argv.items, gpa);
@ -2900,7 +2900,7 @@ fn runOrTest(
const term = child.spawnAndWait() catch |err| {
try warnAboutForeignBinaries(gpa, arena, arg_mode, target_info, link_libc);
const cmd = try argvCmd(arena, argv.items);
const cmd = try std.mem.join(arena, " ", argv.items);
fatal("the following command failed with '{s}':\n{s}", .{ @errorName(err), cmd });
};
switch (arg_mode) {
@ -2931,12 +2931,12 @@ fn runOrTest(
if (code == 0) {
if (!watch) return cleanExit();
} else {
const cmd = try argvCmd(arena, argv.items);
const cmd = try std.mem.join(arena, " ", argv.items);
fatal("the following test command failed with exit code {d}:\n{s}", .{ code, cmd });
}
},
else => {
const cmd = try argvCmd(arena, argv.items);
const cmd = try std.mem.join(arena, " ", argv.items);
fatal("the following test command crashed:\n{s}", .{cmd});
},
}
@ -2944,7 +2944,7 @@ fn runOrTest(
else => unreachable,
}
} else {
const cmd = try argvCmd(arena, argv.items);
const cmd = try std.mem.join(arena, " ", argv.items);
fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });
}
}
@ -3573,32 +3573,21 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
if (prominent_compile_errors) {
fatal("the build command failed with exit code {d}", .{code});
} else {
const cmd = try argvCmd(arena, child_argv);
const cmd = try std.mem.join(arena, " ", child_argv);
fatal("the following build command failed with exit code {d}:\n{s}", .{ code, cmd });
}
},
else => {
const cmd = try argvCmd(arena, child_argv);
const cmd = try std.mem.join(arena, " ", child_argv);
fatal("the following build command crashed:\n{s}", .{cmd});
},
}
} else {
const cmd = try argvCmd(arena, child_argv);
const cmd = try std.mem.join(arena, " ", child_argv);
fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });
}
}
fn argvCmd(allocator: Allocator, argv: []const []const u8) ![]u8 {
var cmd = std.ArrayList(u8).init(allocator);
defer cmd.deinit();
for (argv[0 .. argv.len - 1]) |arg| {
try cmd.appendSlice(arg);
try cmd.append(' ');
}
try cmd.appendSlice(argv[argv.len - 1]);
return cmd.toOwnedSlice();
}
fn readSourceFileToEndAlloc(
allocator: mem.Allocator,
input: *const fs.File,

View File

@ -28,17 +28,6 @@ pub const TranslateCContext = @import("src/translate_c.zig").TranslateCContext;
pub const RunTranslatedCContext = @import("src/run_translated_c.zig").RunTranslatedCContext;
pub const CompareOutputContext = @import("src/compare_output.zig").CompareOutputContext;
fn argvCmd(allocator: Allocator, argv: []const []const u8) ![]u8 {
var cmd = std.ArrayList(u8).init(allocator);
defer cmd.deinit();
for (argv[0 .. argv.len - 1]) |arg| {
try cmd.appendSlice(arg);
try cmd.append(' ');
}
try cmd.appendSlice(argv[argv.len - 1]);
return cmd.toOwnedSlice();
}
const TestTarget = struct {
target: CrossTarget = @as(CrossTarget, .{}),
mode: std.builtin.Mode = .Debug,
@ -736,7 +725,7 @@ pub const StackTracesContext = struct {
std.debug.print("Test {d}/{d} {s}...", .{ self.test_index + 1, self.context.test_index, self.name });
if (!std.process.can_spawn) {
const cmd = try argvCmd(b.allocator, args.items);
const cmd = try std.mem.join(b.allocator, " ", args.items);
std.debug.print("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });
b.allocator.free(cmd);
return ExecError.ExecNotSupported;