aboutsummaryrefslogtreecommitdiffstats
path: root/lua/mason-core/installer
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-07-31 00:45:17 +0200
committerGitHub <noreply@github.com>2022-07-31 00:45:17 +0200
commit116a825929fa3066f32afc77f7459630419bc347 (patch)
treea695ae708b67b420d750f2dbc3bb76b0eb713735 /lua/mason-core/installer
parentfeat(taplo): use prebuilt binary if available (#201) (diff)
downloadmason-116a825929fa3066f32afc77f7459630419bc347.tar
mason-116a825929fa3066f32afc77f7459630419bc347.tar.gz
mason-116a825929fa3066f32afc77f7459630419bc347.tar.bz2
mason-116a825929fa3066f32afc77f7459630419bc347.tar.lz
mason-116a825929fa3066f32afc77f7459630419bc347.tar.xz
mason-116a825929fa3066f32afc77f7459630419bc347.tar.zst
mason-116a825929fa3066f32afc77f7459630419bc347.zip
fix(gem): write shim executables that enhance GEM_PATH appropriately (#202)
Diffstat (limited to 'lua/mason-core/installer')
-rw-r--r--lua/mason-core/installer/context.lua35
1 files changed, 16 insertions, 19 deletions
diff --git a/lua/mason-core/installer/context.lua b/lua/mason-core/installer/context.lua
index a3577cfa..93d45a8a 100644
--- a/lua/mason-core/installer/context.lua
+++ b/lua/mason-core/installer/context.lua
@@ -226,29 +226,42 @@ end
---@param new_executable_rel_path string: Relative path to the executable file to create.
---@param command string: The shell command to run.
+---@param env table<string, string>?
---@return string: The created executable filename.
-function InstallContext:write_shell_exec_wrapper(new_executable_rel_path, command)
+function InstallContext:write_shell_exec_wrapper(new_executable_rel_path, command, env)
return platform.when {
unix = function()
local std = require "mason-core.managers.std"
+ local formatted_envs = _.map(function(pair)
+ local var, value = pair[1], pair[2]
+ return ("export %s=%q"):format(var, value)
+ end, _.to_pairs(env or {}))
+
self.fs:write_file(
new_executable_rel_path,
_.dedent(([[
#!/bin/bash
+ %s
exec %s "$@"
- ]]):format(command))
+ ]]):format(_.join("\n", formatted_envs), command))
)
std.chmod("+x", { new_executable_rel_path })
return new_executable_rel_path
end,
win = function()
local executable_file = ("%s.cmd"):format(new_executable_rel_path)
+ local formatted_envs = _.map(function(pair)
+ local var, value = pair[1], pair[2]
+ return ("SET %s=%s"):format(var, value)
+ end, _.to_pairs(env or {}))
+
self.fs:write_file(
executable_file,
_.dedent(([[
@ECHO off
+ %s
%s %%*
- ]]):format(command))
+ ]]):format(_.join("\n", formatted_envs), command))
)
return executable_file
end,
@@ -259,20 +272,4 @@ function InstallContext:link_bin(executable, rel_path)
self.receipt:with_link("bin", executable, rel_path)
end
----@param patches string[]
-function InstallContext:apply_patches(patches)
- for _, patch in ipairs(patches) do
- self.spawn.patch {
- "-g",
- "0",
- "-f",
- on_spawn = function(_, stdio)
- local stdin = stdio[1]
- stdin:write(patch)
- stdin:close()
- end,
- }
- end
-end
-
return InstallContext