@@ -10,6 +10,7 @@ const log = std.log.scoped(.config);
1010pub const Manager = struct {
1111 io : std.Io ,
1212 allocator : std.mem.Allocator ,
13+ environ_map : * const std.process.Environ.Map ,
1314 config : Config ,
1415 zig_exe : ? struct {
1516 /// Same as `Manager.config.zig_exe_path.?`
@@ -41,10 +42,11 @@ pub const Manager = struct {
4142 arena : std.heap.ArenaAllocator.State ,
4243 },
4344
44- pub fn init (io : std.Io , allocator : std.mem.Allocator ) error {OutOfMemory }! Manager {
45+ pub fn init (io : std.Io , allocator : std.mem.Allocator , environ_map : * const std.process.Environ.Map ) error {OutOfMemory }! Manager {
4546 return .{
4647 .io = io ,
4748 .allocator = allocator ,
49+ .environ_map = environ_map ,
4850 .zig_exe = null ,
4951 .zig_lib_dir = null ,
5052 .global_cache_dir = null ,
@@ -169,7 +171,7 @@ pub const Manager = struct {
169171
170172 if (config .zig_exe_path == null ) blk : {
171173 if (! std .process .can_spawn ) break :blk ;
172- const zig_exe_path = try findZig (io , manager .allocator ) orelse break :blk ;
174+ const zig_exe_path = try findZig (io , manager .allocator , manager . environ_map ) orelse break :blk ;
173175 defer manager .allocator .free (zig_exe_path );
174176 config .zig_exe_path = try arena .dupe (u8 , zig_exe_path );
175177 }
@@ -320,7 +322,7 @@ pub const Manager = struct {
320322 "--show-builtin" ,
321323 };
322324
323- const run_result = std .process .Child . run (
325+ const run_result = std .process .run (
324326 manager .allocator ,
325327 io ,
326328 .{
@@ -565,7 +567,7 @@ pub fn getZigEnv(
565567 result_arena : std.mem.Allocator ,
566568 zig_exe_path : []const u8 ,
567569) error {OutOfMemory }! ? Env {
568- const zig_env_result = std .process .Child . run (
570+ const zig_env_result = std .process .run (
569571 allocator ,
570572 io ,
571573 .{ .argv = &.{ zig_exe_path , "env" } },
@@ -580,7 +582,7 @@ pub fn getZigEnv(
580582 }
581583
582584 switch (zig_env_result .term ) {
583- .Exited = > | code | {
585+ .exited = > | code | {
584586 if (code != 0 ) {
585587 log .err ("zig env command exited with error code {d}." , .{code });
586588 if (zig_env_result .stderr .len != 0 ) {
@@ -589,7 +591,7 @@ pub fn getZigEnv(
589591 return null ;
590592 }
591593 },
592- .Signal , .Stopped , .Unknown = > {
594+ .signal , .stopped , .unknown = > {
593595 log .err ("zig env command terminated unexpectedly." , .{});
594596 if (zig_env_result .stderr .len != 0 ) {
595597 log .err ("stderr: {s}" , .{zig_env_result .stderr });
@@ -685,29 +687,15 @@ pub const DidConfigChange = @Struct(
685687 &@splat (.{ .default_value_ptr = & false }),
686688);
687689
688- pub fn findZig (io : std.Io , allocator : std.mem.Allocator ) error {OutOfMemory }! ? []const u8 {
690+ pub fn findZig (
691+ io : std.Io ,
692+ allocator : std.mem.Allocator ,
693+ environ_map : * const std.process.Environ.Map ,
694+ ) error {OutOfMemory }! ? []const u8 {
689695 const is_windows = builtin .target .os .tag == .windows ;
690696
691- const env_path = std .process .getEnvVarOwned (allocator , "PATH" ) catch | err | switch (err ) {
692- error .EnvironmentVariableNotFound = > return null ,
693- error .OutOfMemory = > | e | return e ,
694- error .InvalidWtf8 = > | e | {
695- log .err ("failed to load 'PATH' environment variable: {}" , .{e });
696- return null ;
697- },
698- };
699- defer allocator .free (env_path );
700-
701- const env_path_ext = if (is_windows )
702- std .process .getEnvVarOwned (allocator , "PATHEXT" ) catch | err | switch (err ) {
703- error .EnvironmentVariableNotFound = > return null ,
704- error .OutOfMemory = > | e | return e ,
705- error .InvalidWtf8 = > | e | {
706- log .err ("failed to load 'PATH' environment variable: {}" , .{e });
707- return null ;
708- },
709- };
710- defer if (is_windows ) allocator .free (env_path_ext );
697+ const env_path = environ_map .get ("PATH" ) orelse return null ;
698+ const env_path_ext = if (is_windows ) environ_map .get ("PATHEXT" ) orelse return null ;
711699
712700 var filename_buffer : std .ArrayList (u8 ) = .empty ;
713701 defer filename_buffer .deinit (allocator );
0 commit comments