diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-09-14 14:56:45 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-09-14 14:56:45 -0700 |
| commit | 85b10eb07c27d021804473ee54a0b5942e4784d5 (patch) | |
| tree | 1c3450ba81bed2e4125bf21e21ce2e03631ca53e /src/main.zig | |
| parent | 5523e2061b37de2b884c1c53fdcefb823755c7d0 (diff) | |
| download | zig-85b10eb07c27d021804473ee54a0b5942e4784d5.tar.gz zig-85b10eb07c27d021804473ee54a0b5942e4784d5.zip | |
ZIG_EXE envirnoment variable instead of testing build options
No longer introduce build options for tests. Instead, ZIG_EXE
environment variable is added to any invocation of `zig run` or `zig
test`.
The end result of this branch is the same: there is no longer a
mandatory positional command line argument when invoking zig test
binaries directly.
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/main.zig b/src/main.zig index a3b15c34af..4e24b3d789 100644 --- a/src/main.zig +++ b/src/main.zig @@ -3057,6 +3057,7 @@ fn buildOutputType( gpa, arena, test_exec_args.items, + self_exe_path, arg_mode, target_info, watch, @@ -3128,6 +3129,7 @@ fn buildOutputType( gpa, arena, test_exec_args.items, + self_exe_path, arg_mode, target_info, watch, @@ -3152,6 +3154,7 @@ fn buildOutputType( gpa, arena, test_exec_args.items, + self_exe_path, arg_mode, target_info, watch, @@ -3230,6 +3233,7 @@ fn runOrTest( gpa: Allocator, arena: Allocator, test_exec_args: []const ?[]const u8, + self_exe_path: []const u8, arg_mode: ArgMode, target_info: std.zig.system.NativeTargetInfo, watch: bool, @@ -3258,16 +3262,20 @@ fn runOrTest( if (runtime_args_start) |i| { try argv.appendSlice(all_args[i..]); } + var env_map = try std.process.getEnvMap(arena); + try env_map.put("ZIG_EXE", self_exe_path); + // We do not execve for tests because if the test fails we want to print // the error message and invocation below. if (std.process.can_execv and arg_mode == .run and !watch) { // execv releases the locks; no need to destroy the Compilation here. - const err = std.process.execv(gpa, argv.items); + const err = std.process.execve(gpa, argv.items, &env_map); try warnAboutForeignBinaries(arena, arg_mode, target_info, link_libc); 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) { var child = std.ChildProcess.init(argv.items, gpa); + child.env_map = &env_map; child.stdin_behavior = .Inherit; child.stdout_behavior = .Inherit; child.stderr_behavior = .Inherit; |
