mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-26 13:01:34 +03:00
langref: update to new main API
This commit is contained in:
+25
-17
@@ -32,6 +32,10 @@ const usage =
|
||||
pub fn main(init: std.process.Init) !void {
|
||||
const arena = init.arena.allocator();
|
||||
const io = init.io;
|
||||
const env_map = init.env_map;
|
||||
const cwd_path = try std.process.getCwdAlloc(arena);
|
||||
|
||||
try env_map.put("CLICOLOR_FORCE", "1");
|
||||
|
||||
var args_it = try init.minimal.args.iterateAllocator(arena);
|
||||
if (!args_it.skip()) fatal("missing argv[0]", .{});
|
||||
@@ -97,12 +101,13 @@ pub fn main(init: std.process.Init) !void {
|
||||
out,
|
||||
code,
|
||||
tmp_dir_path,
|
||||
try Dir.path.relative(arena, tmp_dir_path, zig_path),
|
||||
try Dir.path.relative(arena, tmp_dir_path, input_path),
|
||||
try Dir.path.relative(arena, cwd_path, env_map, tmp_dir_path, zig_path),
|
||||
try Dir.path.relative(arena, cwd_path, env_map, tmp_dir_path, input_path),
|
||||
if (opt_zig_lib_dir) |zig_lib_dir|
|
||||
try Dir.path.relative(arena, tmp_dir_path, zig_lib_dir)
|
||||
try Dir.path.relative(arena, cwd_path, env_map, tmp_dir_path, zig_lib_dir)
|
||||
else
|
||||
null,
|
||||
env_map,
|
||||
);
|
||||
|
||||
try out_file_writer.end();
|
||||
@@ -121,10 +126,8 @@ fn printOutput(
|
||||
input_path: []const u8,
|
||||
/// Relative to `tmp_dir_path`.
|
||||
opt_zig_lib_dir: ?[]const u8,
|
||||
env_map: *const process.Environ.Map,
|
||||
) !void {
|
||||
var env_map = try process.getEnvMap(arena);
|
||||
try env_map.put("CLICOLOR_FORCE", "1");
|
||||
|
||||
const host = try std.zig.system.resolveTargetQuery(io, .{});
|
||||
const obj_ext = builtin.object_format.fileExt(builtin.cpu.arch);
|
||||
const print = std.debug.print;
|
||||
@@ -196,7 +199,7 @@ fn printOutput(
|
||||
const result = try process.run(arena, io, .{
|
||||
.argv = build_args.items,
|
||||
.cwd = tmp_dir_path,
|
||||
.env_map = &env_map,
|
||||
.env_map = env_map,
|
||||
.max_output_bytes = max_doc_file_size,
|
||||
});
|
||||
switch (result.term) {
|
||||
@@ -218,7 +221,7 @@ fn printOutput(
|
||||
try shell_out.writeAll(colored_stderr);
|
||||
break :code_block;
|
||||
}
|
||||
const exec_result = run(arena, io, &env_map, tmp_dir_path, build_args.items) catch
|
||||
const exec_result = run(arena, io, env_map, tmp_dir_path, build_args.items) catch
|
||||
fatal("example failed to compile", .{});
|
||||
|
||||
if (code.verbose_cimport) {
|
||||
@@ -251,7 +254,7 @@ fn printOutput(
|
||||
const result = if (expected_outcome == .fail) blk: {
|
||||
const result = try process.run(arena, io, .{
|
||||
.argv = run_args,
|
||||
.env_map = &env_map,
|
||||
.env_map = env_map,
|
||||
.cwd = tmp_dir_path,
|
||||
.max_output_bytes = max_doc_file_size,
|
||||
});
|
||||
@@ -268,7 +271,7 @@ fn printOutput(
|
||||
}
|
||||
break :blk result;
|
||||
} else blk: {
|
||||
break :blk run(arena, io, &env_map, tmp_dir_path, run_args) catch
|
||||
break :blk run(arena, io, env_map, tmp_dir_path, run_args) catch
|
||||
fatal("example crashed", .{});
|
||||
};
|
||||
|
||||
@@ -337,7 +340,7 @@ fn printOutput(
|
||||
}
|
||||
}
|
||||
|
||||
const result = run(arena, io, &env_map, tmp_dir_path, test_args.items) catch
|
||||
const result = run(arena, io, env_map, tmp_dir_path, test_args.items) catch
|
||||
fatal("test failed", .{});
|
||||
const escaped_stderr = try escapeHtml(arena, result.stderr);
|
||||
const escaped_stdout = try escapeHtml(arena, result.stdout);
|
||||
@@ -370,7 +373,7 @@ fn printOutput(
|
||||
}
|
||||
const result = try process.run(arena, io, .{
|
||||
.argv = test_args.items,
|
||||
.env_map = &env_map,
|
||||
.env_map = env_map,
|
||||
.cwd = tmp_dir_path,
|
||||
.max_output_bytes = max_doc_file_size,
|
||||
});
|
||||
@@ -426,7 +429,7 @@ fn printOutput(
|
||||
|
||||
const result = try process.run(arena, io, .{
|
||||
.argv = test_args.items,
|
||||
.env_map = &env_map,
|
||||
.env_map = env_map,
|
||||
.cwd = tmp_dir_path,
|
||||
.max_output_bytes = max_doc_file_size,
|
||||
});
|
||||
@@ -502,7 +505,7 @@ fn printOutput(
|
||||
if (maybe_error_match) |error_match| {
|
||||
const result = try process.run(arena, io, .{
|
||||
.argv = build_args.items,
|
||||
.env_map = &env_map,
|
||||
.env_map = env_map,
|
||||
.cwd = tmp_dir_path,
|
||||
.max_output_bytes = max_doc_file_size,
|
||||
});
|
||||
@@ -528,7 +531,7 @@ fn printOutput(
|
||||
const colored_stderr = try termColor(arena, escaped_stderr);
|
||||
try shell_out.print("\n{s} ", .{colored_stderr});
|
||||
} else {
|
||||
_ = run(arena, io, &env_map, tmp_dir_path, build_args.items) catch fatal("example failed to compile", .{});
|
||||
_ = run(arena, io, env_map, tmp_dir_path, build_args.items) catch fatal("example failed to compile", .{});
|
||||
}
|
||||
try shell_out.writeAll("\n");
|
||||
},
|
||||
@@ -587,7 +590,7 @@ fn printOutput(
|
||||
try test_args.append(option);
|
||||
try shell_out.print("{s} ", .{option});
|
||||
}
|
||||
const result = run(arena, io, &env_map, tmp_dir_path, test_args.items) catch fatal("test failed", .{});
|
||||
const result = run(arena, io, env_map, tmp_dir_path, test_args.items) catch fatal("test failed", .{});
|
||||
const escaped_stderr = try escapeHtml(arena, result.stderr);
|
||||
const escaped_stdout = try escapeHtml(arena, result.stdout);
|
||||
try shell_out.print("\n{s}{s}\n", .{ escaped_stderr, escaped_stdout });
|
||||
@@ -1120,7 +1123,7 @@ fn in(slice: []const u8, number: u8) bool {
|
||||
fn run(
|
||||
allocator: Allocator,
|
||||
io: Io,
|
||||
env_map: *process.Environ.Map,
|
||||
env_map: *const process.Environ.Map,
|
||||
cwd: []const u8,
|
||||
args: []const []const u8,
|
||||
) !process.RunResult {
|
||||
@@ -1138,6 +1141,11 @@ fn run(
|
||||
return error.ChildExitError;
|
||||
}
|
||||
},
|
||||
.signal => |sig| {
|
||||
std.debug.print("{s}\nThe following command terminated with signal {t}:\n", .{ result.stderr, sig });
|
||||
dumpArgs(args);
|
||||
return error.ChildCrashed;
|
||||
},
|
||||
else => {
|
||||
std.debug.print("{s}\nThe following command crashed:\n", .{result.stderr});
|
||||
dumpArgs(args);
|
||||
|
||||
Reference in New Issue
Block a user