Skip to content

Commit

Permalink
fix: CMakeRun should not change the current build target
Browse files Browse the repository at this point in the history
  • Loading branch information
Civitasv committed Dec 7, 2023
1 parent 5d8d0f7 commit b496e92
Showing 1 changed file with 46 additions and 42 deletions.
88 changes: 46 additions & 42 deletions lua/cmake-tools/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -638,40 +638,42 @@ function cmake.run(opt)
end), true
else -- if result_code == Types.SELECTED_LAUNCH_TARGET_NOT_BUILT
-- Build select launch target every time
config.build_target = config.launch_target
return cmake.build({ fargs = utils.deepcopy(opt.fargs) }, function()
result = config:get_launch_target()
local target_path = result.data

local launch_path = cmake.get_launch_path(cmake.get_launch_target())

if full_cmd ~= "" then
-- This jumps to the working directory, builds the target and then launches it inside the launch terminal
-- Hence, "cd ".. cwd .. " && ".. The \" is for path handling, specifically in win32
full_cmd = 'cd "'
.. config.cwd
.. '" && '
.. full_cmd
.. " && "
.. terminal.prepare_cmd_for_execute(
return cmake.build(
{ target = config.launch_target, fargs = utils.deepcopy(opt.fargs) },
function()
result = config:get_launch_target()
local target_path = result.data

local launch_path = cmake.get_launch_path(cmake.get_launch_target())

if full_cmd ~= "" then
-- This jumps to the working directory, builds the target and then launches it inside the launch terminal
-- Hence, "cd ".. cwd .. " && ".. The \" is for path handling, specifically in win32
full_cmd = 'cd "'
.. config.cwd
.. '" && '
.. full_cmd
.. " && "
.. terminal.prepare_cmd_for_execute(
target_path,
cmake:get_launch_args(),
launch_path,
opt.wrap_call,
environment.get_run_environment(config, config.launch_target, true)
)
else
full_cmd = terminal.prepare_cmd_for_execute(
target_path,
cmake:get_launch_args(),
launch_path,
opt.wrap_call,
environment.get_run_environment(config, config.launch_target, true)
)
else
full_cmd = terminal.prepare_cmd_for_execute(
target_path,
cmake:get_launch_args(),
launch_path,
opt.wrap_call,
environment.get_run_environment(config, config.launch_target, true)
)
end
utils.execute(target_path, full_cmd, config.terminal, config.executor)
full_cmd = ""
end
utils.execute(target_path, full_cmd, config.terminal, config.executor)
full_cmd = ""
end)
)
end
end
end
Expand Down Expand Up @@ -837,21 +839,23 @@ if has_nvim_dap then
true
else -- if result_code == Types.SELECTED_LAUNCH_TARGET_NOT_BUILT then
-- Build select launch target every time
config.build_target = config.launch_target
return cmake.build({ fargs = utils.deepcopy(opt.fargs) }, function()
result = config:get_launch_target()
local target_path = result.data
local dap_config = {
name = config.launch_target,
program = target_path,
cwd = cmake.get_launch_path(cmake.get_launch_target()),
args = cmake:get_launch_args(),
env = env,
}
-- close cmake console
cmake.close()
dap.run(vim.tbl_extend("force", dap_config, const.cmake_dap_configuration))
end)
return cmake.build(
{ target = config.launch_target, fargs = utils.deepcopy(opt.fargs) },
function()
result = config:get_launch_target()
local target_path = result.data
local dap_config = {
name = config.launch_target,
program = target_path,
cwd = cmake.get_launch_path(cmake.get_launch_target()),
args = cmake:get_launch_args(),
env = env,
}
-- close cmake console
cmake.close()
dap.run(vim.tbl_extend("force", dap_config, const.cmake_dap_configuration))
end
)
end
end
end
Expand Down

0 comments on commit b496e92

Please sign in to comment.