From 62a6f04e21e637a330a9c9c6649f821ca48be621 Mon Sep 17 00:00:00 2001 From: Aotrix <9aotrix@protonmail.com> Date: Sat, 27 Dec 2025 02:06:43 +0100 Subject: allow exit if an error occurs during build --- lua/aotrix/compile.lua | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'lua/aotrix') 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 -- cgit v1.2.3