authorgravatar for johnnymarler@gmail.comJonathan Marler <johnnymarler@gmail.com> 2022-02-06 23:52:08-07:00
committergravatar for johnnymarler@gmail.comJonathan Marler <johnnymarler@gmail.com> 2022-05-11 18:40:53-06:00
log9e89000ffc92fd881ccb59d2571debe003a2f7b1
tree0ada26a5978e82567dfe8f21fded83758142dbfd
parent15d5988e692c182892a118115fd7025048e06c29

Update usages of `process.getEnvMap` and change BufMap -> EnvMap where applicable

# Conflicts: # lib/std/build/RunStep.zig

5 files changed, 27 insertions(+), 38 deletions(-)

doc/docgen.zig+2-2
......@@ -1708,7 +1708,7 @@ fn genHtml(
17081708 }
17091709}
17101710
1711fn exec(allocator: Allocator, env_map: *std.BufMap, args: []const []const u8) !ChildProcess.ExecResult {
1711fn exec(allocator: Allocator, env_map: *process.EnvMap, args: []const []const u8) !ChildProcess.ExecResult {
17121712 const result = try ChildProcess.exec(.{
17131713 .allocator = allocator,
17141714 .argv = args,
......@@ -1732,7 +1732,7 @@ fn exec(allocator: Allocator, env_map: *std.BufMap, args: []const []const u8) !C
17321732 return result;
17331733}
17341734
1735fn getBuiltinCode(allocator: Allocator, env_map: *std.BufMap, zig_exe: []const u8) ![]const u8 {
1735fn getBuiltinCode(allocator: Allocator, env_map: *process.EnvMap, zig_exe: []const u8) ![]const u8 {
17361736 const result = try exec(allocator, env_map, &[_][]const u8{ zig_exe, "build-obj", "--show-builtin" });
17371737 return result.stdout;
17381738}
lib/std/build.zig+4-4
......@@ -12,7 +12,7 @@ const StringHashMap = std.StringHashMap;
1212const Allocator = mem.Allocator;
1313const process = std.process;
1414const BufSet = std.BufSet;
15const BufMap = std.BufMap;
15const EnvMap = std.process.EnvMap;
1616const fmt_lib = std.fmt;
1717const File = std.fs.File;
1818const CrossTarget = std.zig.CrossTarget;
......@@ -48,7 +48,7 @@ pub const Builder = struct {
4848 invalid_user_input: bool,
4949 zig_exe: []const u8,
5050 default_step: *Step,
51 env_map: *BufMap,
51 env_map: *EnvMap,
5252 top_level_steps: ArrayList(*TopLevelStep),
5353 install_prefix: []const u8,
5454 dest_dir: ?[]const u8,
......@@ -167,7 +167,7 @@ pub const Builder = struct {
167167 cache_root: []const u8,
168168 global_cache_root: []const u8,
169169 ) !*Builder {
170 const env_map = try allocator.create(BufMap);
170 const env_map = try allocator.create(EnvMap);
171171 env_map.* = try process.getEnvMap(allocator);
172172
173173 const host = try NativeTargetInfo.detect(allocator, .{});
......@@ -963,7 +963,7 @@ pub const Builder = struct {
963963 warn("\n", .{});
964964 }
965965
966 pub fn spawnChildEnvMap(self: *Builder, cwd: ?[]const u8, env_map: *const BufMap, argv: []const []const u8) !void {
966 pub fn spawnChildEnvMap(self: *Builder, cwd: ?[]const u8, env_map: *const EnvMap, argv: []const []const u8) !void {
967967 if (self.verbose) {
968968 printCmd(cwd, argv);
969969 }
lib/std/build/RunStep.zig+7-18
......@@ -9,7 +9,7 @@ const fs = std.fs;
99const mem = std.mem;
1010const process = std.process;
1111const ArrayList = std.ArrayList;
12const BufMap = std.BufMap;
12const EnvMap = process.EnvMap;
1313const Allocator = mem.Allocator;
1414const ExecError = build.Builder.ExecError;
1515
......@@ -29,7 +29,7 @@ argv: ArrayList(Arg),
2929cwd: ?[]const u8,
3030
3131/// Override this field to modify the environment, or use setEnvironmentVariable
32env_map: ?*BufMap,
32env_map: ?*EnvMap,
3333
3434stdout_action: StdIoAction = .inherit,
3535stderr_action: StdIoAction = .inherit,
......@@ -91,8 +91,8 @@ pub fn addArgs(self: *RunStep, args: []const []const u8) void {
9191}
9292
9393pub fn clearEnvironment(self: *RunStep) void {
94 const new_env_map = self.builder.allocator.create(BufMap) catch unreachable;
95 new_env_map.* = BufMap.init(self.builder.allocator);
94 const new_env_map = self.builder.allocator.create(EnvMap) catch unreachable;
95 new_env_map.* = EnvMap.init(self.builder.allocator);
9696 self.env_map = new_env_map;
9797}
9898
......@@ -100,18 +100,7 @@ pub fn addPathDir(self: *RunStep, search_path: []const u8) void {
100100 const env_map = self.getEnvMap();
101101
102102 var key: []const u8 = undefined;
103 var prev_path: ?[]const u8 = undefined;
104 if (builtin.os.tag == .windows) {
105 key = "Path";
106 prev_path = env_map.get(key);
107 if (prev_path == null) {
108 key = "PATH";
109 prev_path = env_map.get(key);
110 }
111 } else {
112 key = "PATH";
113 prev_path = env_map.get(key);
114 }
103 var prev_path = env_map.get("PATH");
115104
116105 if (prev_path) |pp| {
117106 const new_path = self.builder.fmt("{s}" ++ [1]u8{fs.path.delimiter} ++ "{s}", .{ pp, search_path });
......@@ -121,9 +110,9 @@ pub fn addPathDir(self: *RunStep, search_path: []const u8) void {
121110 }
122111}
123112
124pub fn getEnvMap(self: *RunStep) *BufMap {
113pub fn getEnvMap(self: *RunStep) *EnvMap {
125114 return self.env_map orelse {
126 const env_map = self.builder.allocator.create(BufMap) catch unreachable;
115 const env_map = self.builder.allocator.create(EnvMap) catch unreachable;
127116 env_map.* = process.getEnvMap(self.builder.allocator) catch unreachable;
128117 self.env_map = env_map;
129118 return env_map;
lib/std/child_process.zig+13-13
......@@ -12,7 +12,7 @@ const linux = os.linux;
1212const mem = std.mem;
1313const math = std.math;
1414const debug = std.debug;
15const BufMap = std.BufMap;
15const EnvMap = process.EnvMap;
1616const Os = std.builtin.Os;
1717const TailQueue = std.TailQueue;
1818const maxInt = std.math.maxInt;
......@@ -34,7 +34,7 @@ pub const ChildProcess = struct {
3434 argv: []const []const u8,
3535
3636 /// Leave as null to use the current env map using the supplied allocator.
37 env_map: ?*const BufMap,
37 env_map: ?*const EnvMap,
3838
3939 stdin_behavior: StdIo,
4040 stdout_behavior: StdIo,
......@@ -375,7 +375,7 @@ pub const ChildProcess = struct {
375375 argv: []const []const u8,
376376 cwd: ?[]const u8 = null,
377377 cwd_dir: ?fs.Dir = null,
378 env_map: ?*const BufMap = null,
378 env_map: ?*const EnvMap = null,
379379 max_output_bytes: usize = 50 * 1024,
380380 expand_arg0: Arg0Expand = .no_expand,
381381 }) !ExecResult {
......@@ -1237,7 +1237,7 @@ fn readIntFd(fd: i32) !ErrInt {
12371237}
12381238
12391239/// Caller must free result.
1240pub fn createWindowsEnvBlock(allocator: mem.Allocator, env_map: *const BufMap) ![]u16 {
1240pub fn createWindowsEnvBlock(allocator: mem.Allocator, env_map: *const EnvMap) ![]u16 {
12411241 // count bytes needed
12421242 const max_chars_needed = x: {
12431243 var max_chars_needed: usize = 4; // 4 for the final 4 null bytes
......@@ -1245,7 +1245,7 @@ pub fn createWindowsEnvBlock(allocator: mem.Allocator, env_map: *const BufMap) !
12451245 while (it.next()) |pair| {
12461246 // +1 for '='
12471247 // +1 for null byte
1248 max_chars_needed += pair.key_ptr.len + pair.value_ptr.len + 2;
1248 max_chars_needed += pair.name.len + pair.value.len + 2;
12491249 }
12501250 break :x max_chars_needed;
12511251 };
......@@ -1255,10 +1255,10 @@ pub fn createWindowsEnvBlock(allocator: mem.Allocator, env_map: *const BufMap) !
12551255 var it = env_map.iterator();
12561256 var i: usize = 0;
12571257 while (it.next()) |pair| {
1258 i += try unicode.utf8ToUtf16Le(result[i..], pair.key_ptr.*);
1258 i += try unicode.utf8ToUtf16Le(result[i..], pair.name);
12591259 result[i] = '=';
12601260 i += 1;
1261 i += try unicode.utf8ToUtf16Le(result[i..], pair.value_ptr.*);
1261 i += try unicode.utf8ToUtf16Le(result[i..], pair.value);
12621262 result[i] = 0;
12631263 i += 1;
12641264 }
......@@ -1273,17 +1273,17 @@ pub fn createWindowsEnvBlock(allocator: mem.Allocator, env_map: *const BufMap) !
12731273 return allocator.shrink(result, i);
12741274}
12751275
1276pub fn createNullDelimitedEnvMap(arena: mem.Allocator, env_map: *const std.BufMap) ![:null]?[*:0]u8 {
1276pub fn createNullDelimitedEnvMap(arena: mem.Allocator, env_map: *const EnvMap) ![:null]?[*:0]u8 {
12771277 const envp_count = env_map.count();
12781278 const envp_buf = try arena.allocSentinel(?[*:0]u8, envp_count, null);
12791279 {
12801280 var it = env_map.iterator();
12811281 var i: usize = 0;
12821282 while (it.next()) |pair| : (i += 1) {
1283 const env_buf = try arena.allocSentinel(u8, pair.key_ptr.len + pair.value_ptr.len + 1, 0);
1284 mem.copy(u8, env_buf, pair.key_ptr.*);
1285 env_buf[pair.key_ptr.len] = '=';
1286 mem.copy(u8, env_buf[pair.key_ptr.len + 1 ..], pair.value_ptr.*);
1283 const env_buf = try arena.allocSentinel(u8, pair.name.len + pair.value.len + 1, 0);
1284 mem.copy(u8, env_buf, pair.name);
1285 env_buf[pair.name.len] = '=';
1286 mem.copy(u8, env_buf[pair.name.len + 1 ..], pair.value);
12871287 envp_buf[i] = env_buf.ptr;
12881288 }
12891289 assert(i == envp_count);
......@@ -1294,7 +1294,7 @@ pub fn createNullDelimitedEnvMap(arena: mem.Allocator, env_map: *const std.BufMa
12941294test "createNullDelimitedEnvMap" {
12951295 const testing = std.testing;
12961296 const allocator = testing.allocator;
1297 var envmap = BufMap.init(allocator);
1297 var envmap = EnvMap.init(allocator);
12981298 defer envmap.deinit();
12991299
13001300 try envmap.put("HOME", "/home/ifreund");
lib/std/process.zig+1-1
......@@ -1364,7 +1364,7 @@ pub fn execv(allocator: mem.Allocator, argv: []const []const u8) ExecvError {
13641364pub fn execve(
13651365 allocator: mem.Allocator,
13661366 argv: []const []const u8,
1367 env_map: ?*const std.BufMap,
1367 env_map: ?*const EnvMap,
13681368) ExecvError {
13691369 if (!can_execv) @compileError("The target OS does not support execv");
13701370