aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.zig25
-rw-r--r--src/test.zig9
2 files changed, 13 insertions, 21 deletions
diff --git a/src/main.zig b/src/main.zig
index d5a3bce82d..4e24b3d789 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -3253,40 +3253,29 @@ fn runOrTest(
defer argv.deinit();
if (test_exec_args.len == 0) {
- // when testing pass the zig_exe_path to argv
- if (arg_mode == .zig_test)
- try argv.appendSlice(&[_][]const u8{
- exe_path, self_exe_path,
- })
- // when running just pass the current exe
- else
- try argv.appendSlice(&[_][]const u8{
- exe_path,
- });
+ try argv.append(exe_path);
} else {
for (test_exec_args) |arg| {
- if (arg) |a| {
- try argv.append(a);
- } else {
- try argv.appendSlice(&[_][]const u8{
- exe_path, self_exe_path,
- });
- }
+ try argv.append(arg orelse exe_path);
}
}
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;
diff --git a/src/test.zig b/src/test.zig
index f26c65f3f8..b95a66c11f 100644
--- a/src/test.zig
+++ b/src/test.zig
@@ -1214,6 +1214,7 @@ pub const TestContext = struct {
fn run(self: *TestContext) !void {
const host = try std.zig.system.NativeTargetInfo.detect(.{});
+ const zig_exe_path = try std.process.getEnvVarOwned(self.arena, "ZIG_EXE");
var progress = std.Progress{};
const root_node = progress.start("compiler", self.cases.items.len);
@@ -1272,6 +1273,7 @@ pub const TestContext = struct {
&prg_node,
case.*,
zig_lib_directory,
+ zig_exe_path,
&aux_thread_pool,
global_cache_directory,
host,
@@ -1298,6 +1300,7 @@ pub const TestContext = struct {
root_node: *std.Progress.Node,
case: Case,
zig_lib_directory: Compilation.Directory,
+ zig_exe_path: []const u8,
thread_pool: *ThreadPool,
global_cache_directory: Compilation.Directory,
host: std.zig.system.NativeTargetInfo,
@@ -1351,7 +1354,7 @@ pub const TestContext = struct {
try tmp.dir.writeFile(tmp_src_path, update.src);
var zig_args = std.ArrayList([]const u8).init(arena);
- try zig_args.append(std.testing.zig_exe_path);
+ try zig_args.append(zig_exe_path);
if (case.is_test) {
try zig_args.append("test");
@@ -1545,7 +1548,7 @@ pub const TestContext = struct {
.link_libc = case.link_libc,
.use_llvm = use_llvm,
.use_stage1 = null, // We already handled stage1 tests
- .self_exe_path = std.testing.zig_exe_path,
+ .self_exe_path = zig_exe_path,
// TODO instead of turning off color, pass in a std.Progress.Node
.color = .off,
// TODO: force self-hosted linkers with stage2 backend to avoid LLD creeping in
@@ -1795,7 +1798,7 @@ pub const TestContext = struct {
continue :update; // Pass test.
}
try argv.appendSlice(&[_][]const u8{
- std.testing.zig_exe_path,
+ zig_exe_path,
"run",
"-cflags",
"-std=c99",