Skip to content

Commit

Permalink
fix: change back to build root if luarocks changes to subdirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Jul 20, 2024
1 parent d32ff32 commit 8d9140b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/luarocks/build/treesitter-parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ local function execute(...)
return fs.execute(...)
end

-- HACK: if a rock depends on another rock that has the same source, but in a subdirectory,
-- luarocks will not change back to the project root.
-- This is the case for some tree-sitter parsers, e.g. tree-sitter-markdown and
-- tree-sitter-markdown_inline.
-- As a workaround, we save the build root dir between builds and cd back to it if set.
local build_root_dir

---@param rockspec table
---@param no_install boolean
function treesitter_parser.run(rockspec, no_install)
Expand All @@ -64,7 +71,14 @@ function treesitter_parser.run(rockspec, no_install)
("'%s' is not installed.\n%s requires %s to build."):format(js_runtime, rockspec.name, js_runtime_name)
end
end
local cwd = fs.absolute_name(dir.path("."))
if build_root_dir and cwd:match("^" .. build_root_dir) then
-- cwd is a subdirectory of build_root_dir.
util.printout("Changing to directory: " .. build_root_dir)
fs.change_dir(build_root_dir)
end
if build.location then
build_root_dir = fs.absolute_name(dir.path("."))
util.printout("Changing to directory: " .. build.location)
fs.change_dir(build.location)
end
Expand Down

0 comments on commit 8d9140b

Please sign in to comment.