diff options
| author | Aotrix <[email protected]> | 2025-12-27 02:06:43 +0100 |
|---|---|---|
| committer | Aotrix <[email protected]> | 2025-12-27 02:06:43 +0100 |
| commit | 62a6f04e21e637a330a9c9c6649f821ca48be621 (patch) | |
| tree | 08902546577195bdb849f59b5d2c77ded7cc1e7b /lua/aotrix/compile.lua | |
| parent | eb811c4f0f223720ec72e120812cb51495c60c5e (diff) | |
allow exit if an error occurs during build
Diffstat (limited to 'lua/aotrix/compile.lua')
| -rw-r--r-- | lua/aotrix/compile.lua | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/lua/aotrix/compile.lua b/lua/aotrix/compile.lua index 3fcb54c..9227e6c 100644 --- a/lua/aotrix/compile.lua +++ b/lua/aotrix/compile.lua @@ -62,7 +62,7 @@ function executeCommandInTerminal(command) -- 'clear' is used to hide the command local exit_message = "\nPress enter to exit..." vim.api.nvim_chan_send(channel, - "clear && " .. command .. " && echo '" .. exit_message .. "' && read -s && exit" .. "\n") + "clear && " .. command .. "; echo '" .. exit_message .. "' && read -s && exit" .. "\n") end ---Compiles a target @@ -72,8 +72,20 @@ function compileTarget() function compile(pTarget) if not (pTarget == nil) and string.len(pTarget) > 0 then createFloatingTerminal() - local command = "cmake --build build --target " .. pTarget .. " && ./build/" .. pTarget - executeCommandInTerminal(command) + local build_dir = "build" + local commandTable = { "if [ ! -d " .. build_dir .. " ]; then mkdir " .. build_dir, + "cmake -S . -B " .. build_dir .. "; fi", + "cmake --build " .. build_dir .. " --target " .. pTarget, + build_dir .. "/" .. pTarget + } + local commandConcatenation = "" + for i, command in ipairs(commandTable) do + commandConcatenation = commandConcatenation .. command + if i < #commandTable then + commandConcatenation = commandConcatenation .. " && " + end + end + executeCommandInTerminal(commandConcatenation) end end |
