| ... | ... | @@ -32,6 +32,10 @@ const usage = |
| 32 | 32 | pub fn main(init: std.process.Init) !void { |
| 33 | 33 | const arena = init.arena.allocator(); |
| 34 | 34 | const io = init.io; |
| 35 | const env_map = init.env_map; |
| 36 | const cwd_path = try std.process.getCwdAlloc(arena); |
| 37 | |
| 38 | try env_map.put("CLICOLOR_FORCE", "1"); |
| 35 | 39 | |
| 36 | 40 | var args_it = try init.minimal.args.iterateAllocator(arena); |
| 37 | 41 | if (!args_it.skip()) fatal("missing argv[0]", .{}); |
| ... | ... | @@ -97,12 +101,13 @@ pub fn main(init: std.process.Init) !void { |
| 97 | 101 | out, |
| 98 | 102 | code, |
| 99 | 103 | tmp_dir_path, |
| 100 | | try Dir.path.relative(arena, tmp_dir_path, zig_path), |
| 101 | | try Dir.path.relative(arena, tmp_dir_path, input_path), |
| 104 | try Dir.path.relative(arena, cwd_path, env_map, tmp_dir_path, zig_path), |
| 105 | try Dir.path.relative(arena, cwd_path, env_map, tmp_dir_path, input_path), |
| 102 | 106 | if (opt_zig_lib_dir) |zig_lib_dir| |
| 103 | | try Dir.path.relative(arena, tmp_dir_path, zig_lib_dir) |
| 107 | try Dir.path.relative(arena, cwd_path, env_map, tmp_dir_path, zig_lib_dir) |
| 104 | 108 | else |
| 105 | 109 | null, |
| 110 | env_map, |
| 106 | 111 | ); |
| 107 | 112 | |
| 108 | 113 | try out_file_writer.end(); |
| ... | ... | @@ -121,10 +126,8 @@ fn printOutput( |
| 121 | 126 | input_path: []const u8, |
| 122 | 127 | /// Relative to `tmp_dir_path`. |
| 123 | 128 | opt_zig_lib_dir: ?[]const u8, |
| 129 | env_map: *const process.Environ.Map, |
| 124 | 130 | ) !void { |
| 125 | | var env_map = try process.getEnvMap(arena); |
| 126 | | try env_map.put("CLICOLOR_FORCE", "1"); |
| 127 | | |
| 128 | 131 | const host = try std.zig.system.resolveTargetQuery(io, .{}); |
| 129 | 132 | const obj_ext = builtin.object_format.fileExt(builtin.cpu.arch); |
| 130 | 133 | const print = std.debug.print; |
| ... | ... | @@ -196,7 +199,7 @@ fn printOutput( |
| 196 | 199 | const result = try process.run(arena, io, .{ |
| 197 | 200 | .argv = build_args.items, |
| 198 | 201 | .cwd = tmp_dir_path, |
| 199 | | .env_map = &env_map, |
| 202 | .env_map = env_map, |
| 200 | 203 | .max_output_bytes = max_doc_file_size, |
| 201 | 204 | }); |
| 202 | 205 | switch (result.term) { |
| ... | ... | @@ -218,7 +221,7 @@ fn printOutput( |
| 218 | 221 | try shell_out.writeAll(colored_stderr); |
| 219 | 222 | break :code_block; |
| 220 | 223 | } |
| 221 | | const exec_result = run(arena, io, &env_map, tmp_dir_path, build_args.items) catch |
| 224 | const exec_result = run(arena, io, env_map, tmp_dir_path, build_args.items) catch |
| 222 | 225 | fatal("example failed to compile", .{}); |
| 223 | 226 | |
| 224 | 227 | if (code.verbose_cimport) { |
| ... | ... | @@ -251,7 +254,7 @@ fn printOutput( |
| 251 | 254 | const result = if (expected_outcome == .fail) blk: { |
| 252 | 255 | const result = try process.run(arena, io, .{ |
| 253 | 256 | .argv = run_args, |
| 254 | | .env_map = &env_map, |
| 257 | .env_map = env_map, |
| 255 | 258 | .cwd = tmp_dir_path, |
| 256 | 259 | .max_output_bytes = max_doc_file_size, |
| 257 | 260 | }); |
| ... | ... | @@ -268,7 +271,7 @@ fn printOutput( |
| 268 | 271 | } |
| 269 | 272 | break :blk result; |
| 270 | 273 | } else blk: { |
| 271 | | break :blk run(arena, io, &env_map, tmp_dir_path, run_args) catch |
| 274 | break :blk run(arena, io, env_map, tmp_dir_path, run_args) catch |
| 272 | 275 | fatal("example crashed", .{}); |
| 273 | 276 | }; |
| 274 | 277 | |
| ... | ... | @@ -337,7 +340,7 @@ fn printOutput( |
| 337 | 340 | } |
| 338 | 341 | } |
| 339 | 342 | |
| 340 | | const result = run(arena, io, &env_map, tmp_dir_path, test_args.items) catch |
| 343 | const result = run(arena, io, env_map, tmp_dir_path, test_args.items) catch |
| 341 | 344 | fatal("test failed", .{}); |
| 342 | 345 | const escaped_stderr = try escapeHtml(arena, result.stderr); |
| 343 | 346 | const escaped_stdout = try escapeHtml(arena, result.stdout); |
| ... | ... | @@ -370,7 +373,7 @@ fn printOutput( |
| 370 | 373 | } |
| 371 | 374 | const result = try process.run(arena, io, .{ |
| 372 | 375 | .argv = test_args.items, |
| 373 | | .env_map = &env_map, |
| 376 | .env_map = env_map, |
| 374 | 377 | .cwd = tmp_dir_path, |
| 375 | 378 | .max_output_bytes = max_doc_file_size, |
| 376 | 379 | }); |
| ... | ... | @@ -426,7 +429,7 @@ fn printOutput( |
| 426 | 429 | |
| 427 | 430 | const result = try process.run(arena, io, .{ |
| 428 | 431 | .argv = test_args.items, |
| 429 | | .env_map = &env_map, |
| 432 | .env_map = env_map, |
| 430 | 433 | .cwd = tmp_dir_path, |
| 431 | 434 | .max_output_bytes = max_doc_file_size, |
| 432 | 435 | }); |
| ... | ... | @@ -502,7 +505,7 @@ fn printOutput( |
| 502 | 505 | if (maybe_error_match) |error_match| { |
| 503 | 506 | const result = try process.run(arena, io, .{ |
| 504 | 507 | .argv = build_args.items, |
| 505 | | .env_map = &env_map, |
| 508 | .env_map = env_map, |
| 506 | 509 | .cwd = tmp_dir_path, |
| 507 | 510 | .max_output_bytes = max_doc_file_size, |
| 508 | 511 | }); |
| ... | ... | @@ -528,7 +531,7 @@ fn printOutput( |
| 528 | 531 | const colored_stderr = try termColor(arena, escaped_stderr); |
| 529 | 532 | try shell_out.print("\n{s} ", .{colored_stderr}); |
| 530 | 533 | } else { |
| 531 | | _ = run(arena, io, &env_map, tmp_dir_path, build_args.items) catch fatal("example failed to compile", .{}); |
| 534 | _ = run(arena, io, env_map, tmp_dir_path, build_args.items) catch fatal("example failed to compile", .{}); |
| 532 | 535 | } |
| 533 | 536 | try shell_out.writeAll("\n"); |
| 534 | 537 | }, |
| ... | ... | @@ -587,7 +590,7 @@ fn printOutput( |
| 587 | 590 | try test_args.append(option); |
| 588 | 591 | try shell_out.print("{s} ", .{option}); |
| 589 | 592 | } |
| 590 | | const result = run(arena, io, &env_map, tmp_dir_path, test_args.items) catch fatal("test failed", .{}); |
| 593 | const result = run(arena, io, env_map, tmp_dir_path, test_args.items) catch fatal("test failed", .{}); |
| 591 | 594 | const escaped_stderr = try escapeHtml(arena, result.stderr); |
| 592 | 595 | const escaped_stdout = try escapeHtml(arena, result.stdout); |
| 593 | 596 | try shell_out.print("\n{s}{s}\n", .{ escaped_stderr, escaped_stdout }); |
| ... | ... | @@ -1120,7 +1123,7 @@ fn in(slice: []const u8, number: u8) bool { |
| 1120 | 1123 | fn run( |
| 1121 | 1124 | allocator: Allocator, |
| 1122 | 1125 | io: Io, |
| 1123 | | env_map: *process.Environ.Map, |
| 1126 | env_map: *const process.Environ.Map, |
| 1124 | 1127 | cwd: []const u8, |
| 1125 | 1128 | args: []const []const u8, |
| 1126 | 1129 | ) !process.RunResult { |
| ... | ... | @@ -1138,6 +1141,11 @@ fn run( |
| 1138 | 1141 | return error.ChildExitError; |
| 1139 | 1142 | } |
| 1140 | 1143 | }, |
| 1144 | .signal => |sig| { |
| 1145 | std.debug.print("{s}\nThe following command terminated with signal {t}:\n", .{ result.stderr, sig }); |
| 1146 | dumpArgs(args); |
| 1147 | return error.ChildCrashed; |
| 1148 | }, |
| 1141 | 1149 | else => { |
| 1142 | 1150 | std.debug.print("{s}\nThe following command crashed:\n", .{result.stderr}); |
| 1143 | 1151 | dumpArgs(args); |