Skip to content

Commit

Permalink
feat(linker): use relative targets for symlinks
Browse files Browse the repository at this point in the history
Closes #1156.
  • Loading branch information
williamboman committed Oct 13, 2023
1 parent 239052c commit 4a54480
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lua/mason-core/installer/linker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ end
---@async
---@param context InstallContext
---@param link_context LinkContext
---@param link_fn async fun(new_abs_path: string, target_abs_path: string): Result
---@param link_fn async fun(new_abs_path: string, target_abs_path: string, target_rel_path: string): Result
local function link(context, link_context, link_fn)
log.trace("Linking", context.package, link_context.type, context.links[link_context.type])
return Result.try(function(try)
Expand All @@ -83,6 +83,7 @@ local function link(context, link_context, link_fn)
end
local new_abs_path = link_context.prefix(name, context.location)
local target_abs_path = vim.fs.joinpath(context.package:get_install_path(), rel_path)
local target_rel_path = path.relative(new_abs_path, target_abs_path)

do
-- 1. Ensure destination directory exists
Expand All @@ -109,7 +110,7 @@ local function link(context, link_context, link_fn)
end

-- 3. Execute link.
try(link_fn(new_abs_path, target_abs_path))
try(link_fn(new_abs_path, target_abs_path, target_rel_path))
context.receipt:with_link(link_context.type, name, rel_path)
end
end)
Expand All @@ -118,8 +119,8 @@ end
---@param context InstallContext
---@param link_context LinkContext
local function symlink(context, link_context)
return link(context, link_context, function(new_abs_path, target_abs_path)
return Result.pcall(fs.async.symlink, target_abs_path, new_abs_path)
return link(context, link_context, function(new_abs_path, _, target_rel_path)
return Result.pcall(fs.async.symlink, target_rel_path, new_abs_path)
end)
end

Expand All @@ -133,7 +134,8 @@ end

---@param context InstallContext
local function win_bin_wrapper(context)
return link(context, LinkContext.BIN, function(new_abs_path, target_abs_path)
return link(context, LinkContext.BIN, function(new_abs_path, target_rel_path)
local windows_target_rel_path = target_rel_path:gsub("/", "\\")
return Result.pcall(
fs.async.write_file,
new_abs_path,
Expand All @@ -148,7 +150,7 @@ local function win_bin_wrapper(context)
CALL :find_dp0
endLocal & goto #_undefined_# 2>NUL || title %%COMSPEC%% & "%s" %%*
]]):format(target_abs_path))
]]):format(windows_target_rel_path))
)
end)
end
Expand Down

0 comments on commit 4a54480

Please sign in to comment.