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