Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 3 additions & 5 deletions lua/cmake-tools/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ function cmake.generate(opt, callback)

local args = {
"-B",
utils.transform_path(config:build_directory_path(), config.executor.name == "quickfix"),
config:build_directory_path(),
"-S",
".",
}
Expand Down Expand Up @@ -298,9 +298,7 @@ function cmake.clean(callback)
return
end

local path = Path:new(
utils.transform_path(config:build_directory_path(), config.executor.name == "quickfix")
)
local path = Path:new(config:build_directory_path())
if not (path / "CMakeCache.txt"):exists() then
-- no need to clean up as we do not have a cache
return
Expand Down Expand Up @@ -407,7 +405,7 @@ function cmake.build(opt, callback)
else
args = {
"--build",
utils.transform_path(config:build_directory_path(), config.executor.name == "quickfix"),
config:build_directory_path(),
}
end

Expand Down
4 changes: 2 additions & 2 deletions lua/cmake-tools/terminal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -602,14 +602,14 @@ function _terminal.run(cmd, env_script, env, args, cwd, opts, on_exit, on_output
if osys.iswin32 and not is_windows_shell() then
cwd = cwd:gsub("\\", "/")
end
cwd = utils.transform_path(cwd)
cwd = utils.shell_quote(cwd)
local envTbl = {}
local fmtStr = osys.iswin32 and "set %s=%s" or "%s=%s"
for k, v in pairs(env) do
table.insert(envTbl, string.format(fmtStr, k, v))
end
env = table.concat(envTbl, " ")
args = table.concat(args, " ")
args = table.concat(vim.tbl_map(utils.shell_quote, args), " ")

return cmd, env, args, cwd
end
Expand Down
2 changes: 1 addition & 1 deletion lua/cmake-tools/test/ctest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function ctest.run(ctest_command, env, config, opt)
if opt.preset then
vim.list_extend(args, { "--preset", opt.preset })
else
vim.list_extend(args, { "--test-dir", utils.transform_path(opt.build_dir) })
vim.list_extend(args, { "--test-dir", opt.build_dir })
end

if opt.label then
Expand Down
6 changes: 3 additions & 3 deletions lua/cmake-tools/toggleterm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function _toggleterm.run(cmd, env_script, env, args, cwd, opts, on_exit, on_outp
local full_cmd = ""

-- Launch form executable's build directory by default
full_cmd = "cd " .. utils.transform_path(cwd) .. " &&"
full_cmd = "cd " .. utils.shell_quote(cwd) .. " &&"

if osys.iswin32 then
for k, v in pairs(env) do
Expand All @@ -40,15 +40,15 @@ function _toggleterm.run(cmd, env_script, env, args, cwd, opts, on_exit, on_outp
end
end

full_cmd = full_cmd .. " " .. utils.transform_path(cmd)
full_cmd = full_cmd .. " " .. utils.shell_quote(cmd)

if osys.islinux or osys.iswsl or osys.ismac then
full_cmd = " " .. full_cmd -- adding a space in front of the command prevents bash from recording the command in the history (if configured)
end

-- Add args to the cmd
for _, arg in ipairs(args) do
full_cmd = full_cmd .. " " .. arg
full_cmd = full_cmd .. " " .. utils.shell_quote(arg)
end

_toggleterm.cmd = full_cmd
Expand Down
19 changes: 8 additions & 11 deletions lua/cmake-tools/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ function utils.copyfile(src, target)
-- if we don't always use terminal
local cmd = "exec "
.. "'!cmake -E copy "
.. utils.transform_path(src)
.. utils.shell_quote(src)
.. " "
.. utils.transform_path(target)
.. utils.shell_quote(target)
.. "'"
vim.cmd(cmd)
end
Expand All @@ -101,22 +101,19 @@ function utils.softlink(src, target)
-- if we don't always use terminal
local cmd = "exec "
.. "'!cmake -E create_symlink "
.. utils.transform_path(src)
.. utils.shell_quote(src)
.. " "
.. utils.transform_path(target)
.. utils.shell_quote(target)
.. "'"
vim.cmd(cmd)
end
end

function utils.transform_path(path, keep)
if keep then
return path
end
if path[1] ~= '"' and string.find(path, " ") then
return '"' .. path .. '"'
function utils.shell_quote(str)
if str[1] ~= '"' and string.find(str, " ") then
return '"' .. str .. '"'
else
return path
return str
end
end

Expand Down
6 changes: 3 additions & 3 deletions lua/cmake-tools/vimux.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function _vimux.prepare_cmd_for_run(cmd, env, args, cwd)
local full_cmd = ""

-- Launch form executable's build directory by default
full_cmd = "cd " .. utils.transform_path(cwd) .. " &&"
full_cmd = "cd " .. utils.shell_quote(cwd) .. " &&"

if osys.iswin32 then
for k, v in pairs(env) do
Expand All @@ -55,15 +55,15 @@ function _vimux.prepare_cmd_for_run(cmd, env, args, cwd)
end
end

full_cmd = full_cmd .. " " .. utils.transform_path(cmd)
full_cmd = full_cmd .. " " .. utils.shell_quote(cmd)

if osys.islinux or osys.iswsl or osys.ismac then
full_cmd = " " .. full_cmd -- adding a space in front of the command prevents bash from recording the command in the history (if configured)
end

-- Add args to the cmd
for _, arg in ipairs(args) do
full_cmd = full_cmd .. " " .. arg
full_cmd = full_cmd .. " " .. utils.shell_quote(arg)
end

if osys.iswin32 then -- wrap in sub process to prevent env vars from being persited
Expand Down
Loading