Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions lua/mason-core/installer/context/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -205,21 +205,34 @@ function InstallContext:write_exec_wrapper(new_executable_rel_path, target_execu
end
return self:write_shell_exec_wrapper(
new_executable_rel_path,
("%q"):format(path.concat {
self:get_install_path(),
target_executable_rel_path,
})
target_executable_rel_path
)
end

local BASH_TEMPLATE = _.dedent [[
#!/usr/bin/env bash
%s
exec %s "$@"
script_path=$0
pushd "$(dirname "$script_path")" > /dev/null || exit 1
script_path=$(basename "$script_path")
push_depth=1
while [ -L "$script_path" ]; do
script_path=$(readlink "$script_path")
pushd "$(dirname "$script_path")" > /dev/null || exit 1
script_path=$(basename "$script_path")
push_depth=$((push_depth + 1))
done
script_dir=$(pwd -P)
for _ in $(seq 1 "$push_depth"); do
popd > /dev/null || exit 1
done

exec "$script_dir/%s" "$@"
]]

local BATCH_TEMPLATE = _.dedent [[
@ECHO off
SET script_dir=%~dp0
%s
%s %%*
]]
Expand Down Expand Up @@ -250,6 +263,11 @@ function InstallContext:write_shell_exec_wrapper(new_executable_rel_path, comman
return ("SET %s=%s"):format(var, value)
end, _.to_pairs(env or {}))

command = ("%q"):format(path.concat {
"%script_dir%\\",
command,
})

self.fs:write_file(executable_file, BATCH_TEMPLATE:format(_.join("\n", formatted_envs), command))
return executable_file
end,
Expand Down