From d981ddf12814c85e01208feecd159598820aab49 Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Sun, 15 Dec 2024 14:47:30 -0500 Subject: [PATCH] macos: add our application bundle to XDG_DATA_DIRS We're packaging more and more application-specific data directories in our application bundle. It's helpful to add that path to XDG_DATA_DIRS so those applications (that support XDG_DATA_DIRS) can locate their data directories without additional user-level configuration. This also fixes a typo ("MATHPATH") in the nearby MANPATH-building code. --- src/termio/Exec.zig | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 41f86958e..ea476e08c 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -794,26 +794,42 @@ const Subprocess = struct { } } - // Add the man pages from our application bundle to MANPATH. - if (comptime builtin.target.isDarwin()) { - if (cfg.resources_dir) |resources_dir| man: { - var buf: [std.fs.max_path_bytes]u8 = undefined; - const dir = std.fmt.bufPrint(&buf, "{s}/../man", .{resources_dir}) catch |err| { - log.warn("error building manpath, man pages may not be available err={}", .{err}); - break :man; - }; + // On macOS, export additional data directories from our + // application bundle. + if (comptime builtin.target.isDarwin()) darwin: { + const resources_dir = cfg.resources_dir orelse break :darwin; + var buf: [std.fs.max_path_bytes]u8 = undefined; + + const xdg_data_dir_key = "XDG_DATA_DIRS"; + if (std.fmt.bufPrint(&buf, "{s}/..", .{resources_dir})) |data_dir| { + try env.put( + xdg_data_dir_key, + try internal_os.appendEnv( + alloc, + env.get(xdg_data_dir_key) orelse "/usr/local/share:/usr/share", + data_dir, + ), + ); + } else |err| { + log.warn("error building {s}; err={}", .{ xdg_data_dir_key, err }); + } + + const manpath_key = "MANPATH"; + if (std.fmt.bufPrint(&buf, "{s}/../man", .{resources_dir})) |man_dir| { // Always append with colon in front, as it mean that if // `MANPATH` is empty, then it should be treated as an extra // path instead of overriding all paths set by OS. try env.put( - "MANPATH", + manpath_key, try internal_os.appendEnvAlways( alloc, - env.get("MATHPATH") orelse "", - dir, + env.get(manpath_key) orelse "", + man_dir, ), ); + } else |err| { + log.warn("error building {s}; man pages may not be available; err={}", .{ manpath_key, err }); } }