diff --git a/lua/compiler/bau/cmake.lua b/lua/compiler/bau/cmake.lua index f111351d..18403d7e 100644 --- a/lua/compiler/bau/cmake.lua +++ b/lua/compiler/bau/cmake.lua @@ -1,4 +1,5 @@ --- CMakeLists.txt bau actions +local utils = require "compiler.utils" local M = {} @@ -7,6 +8,8 @@ function M.action(option) local overseer = require("overseer") local final_message = "--task finished--" + local rm, mkdir, ignore_err = utils.get_commands() + -- Global: CMAKE_BUILD_DIR local success, build_dir = pcall(vim.api.nvim_get_var, 'CMAKE_BUILD_DIR') if not success or build_dir == "" then build_dir = './build' end @@ -27,10 +30,10 @@ function M.action(option) name = "- CMake interpreter", strategy = { "orchestrator", tasks = {{ name = "- Run CMake → " .. option, - cmd = "mkdir -p \"" .. build_dir .. "\"" .. + cmd = mkdir .. "\"" .. build_dir .. "\" " .. ignore_err .. " && " .. cmd_build .. -- Build to 'build' directory. " && " .. cmd_target .. -- Build target from the 'build' directory. - " && echo '" .. cmd_build .. " && " .. cmd_target .. "'" .. -- echo + " && echo \"" .. cmd_build .. " && " .. cmd_target .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } },},},}) diff --git a/lua/compiler/bau/meson.lua b/lua/compiler/bau/meson.lua index 0fb33f72..c5a8cfe9 100644 --- a/lua/compiler/bau/meson.lua +++ b/lua/compiler/bau/meson.lua @@ -1,4 +1,5 @@ --- meson.build bau actions +local utils = require "compiler.utils" local M = {} @@ -7,6 +8,8 @@ function M.action(option) local overseer = require("overseer") local final_message = "--task finished--" + local rm, mkdir, ignore_err = utils.get_commands() + -- Global: MESON_BUILD_DIR local success, build_dir = pcall(vim.api.nvim_get_var, 'MESON_BUILD_DIR') if not success or build_dir == "" then build_dir = './build' end @@ -29,7 +32,7 @@ function M.action(option) name = "- Meson interpreter", strategy = { "orchestrator", tasks = {{ name = "- Run Meson → " .. option, - cmd = "mkdir -p \"" .. build_dir .. "\"" .. + cmd = mkdir .. "\"" .. build_dir .. "\"" .. ignore_err .. " && " .. cmd_setup .. -- Setup " && " .. cmd_build .. -- Build target from the 'build' directory. --" && " .. cmd_target .. -- Run target diff --git a/lua/compiler/bau/msbuild.lua b/lua/compiler/bau/msbuild.lua new file mode 100644 index 00000000..3fbeab38 --- /dev/null +++ b/lua/compiler/bau/msbuild.lua @@ -0,0 +1,21 @@ +--- Makefile bau actions + +local M = {} + +-- Backend - overseer tasks performed on option selected +function M.action(option) + local overseer = require("overseer") + local final_message = "--task finished--" + local task = overseer.new_task({ + name = "- MSBuild interpreter", + strategy = { "orchestrator", + tasks = {{ name = "- Run MSBuild → MSBuild.exe " .. option, + cmd = "MSBuild.exe ".. option .. -- run + " && echo MSBuild.exe " .. option .. -- echo + " && echo \"" .. final_message .. "\"", + components = { "default_extended" } + },},},}) + task:start() +end + +return M diff --git a/lua/compiler/languages/asm.lua b/lua/compiler/languages/asm.lua index a6c244af..a69c928a 100644 --- a/lua/compiler/languages/asm.lua +++ b/lua/compiler/languages/asm.lua @@ -14,46 +14,50 @@ M.options = { function M.action(selected_option) local utils = require("compiler.utils") local overseer = require("overseer") - local entry_point = utils.os_path(vim.fn.getcwd() .. "/main.asm") -- working_directory/main.asm - local entry_point_dir = vim.fn.fnamemodify(entry_point, ":h") -- working_directory/ - local files = utils.find_files(entry_point_dir, "*.asm") -- *.asm files under entry_point_dir (recursively) - local output_dir = utils.os_path(vim.fn.getcwd() .. "/bin/") -- working_directory/bin/ - local output = utils.os_path(vim.fn.getcwd() .. "/bin/program") -- working_directory/bin/program - local arguments = "-g" -- arguments can be overriden in .solution + local entry_point = utils.os_path(vim.fn.getcwd() .. "/main.asm") -- working_directory/main.asm + local entry_point_dir = vim.fn.fnamemodify(entry_point, ":h") -- working_directory/ + local files = utils.find_files(entry_point_dir, "*.asm") -- *.asm files under entry_point_dir (recursively) + local output_dir = utils.os_path(vim.fn.getcwd() .. "/bin/", true) -- working_directory/bin/ + local output = utils.os_path(vim.fn.getcwd() .. "/bin/program", true, true) -- working_directory/bin/program + local arguments = "-g" -- arguments can be overriden in .solution local final_message = "--task finished--" + entry_point = utils.os_path(entry_point) -- surround "" + + local rm, mkdir, ignore_err = utils.get_commands() + if selected_option == "option1" then -- Build .asm files in parallel local tasks_compile = {} for _, file in pairs(files) do local filename = vim.fn.fnamemodify(file, ":t") - local output_o = output_dir .. filename .. ".o" + local output_o = utils.os_path(output_dir .. filename .. ".o", true) file = utils.os_path(file, true) - local task = { name = "- Build program → " .. file, - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && nasm -f elf64 " .. file .. " -o \"" .. output_o .. "\" ".. arguments .. -- compile - " && echo " .. file .. -- echo - " && echo \"" .. final_message .. "\"", - components = { "default_extended" } + local task = { "shell", name = "- Build program → " .. file, + cmd = rm .. output .. ignore_err .. -- clean + " && " .. mkdir .. output_dir .. ignore_err .. -- mkdir + " && nasm -f elf64 " .. file .. " -o " .. output_o .. " ".. arguments .. -- compile + " && echo " .. file .. -- echo + " && echo '" .. final_message .. "'", + components = { "default_extended" } } files[_] = utils.os_path(output_dir .. filename .. ".o", true) -- prepare for linker table.insert(tasks_compile, task) end -- Link .o files files = table.concat(files ," ") -- table to string - local task_link = { name = "- Link program → \"" .. entry_point .."\"" , - cmd = "ld " .. files .. " -o \"" .. output .. "\"" .. -- link - " && rm -f " .. files .. " || true" .. -- clean - " && \"" .. output .. "\"" .. -- run - " && echo && echo \"" .. entry_point .. "\"" .. -- echo + local task_link = { "shell", name = "- Link program → \"" .. entry_point .. "\"", + cmd = "ld " .. files .. " -o " .. output .. -- link + " && " .. rm .. files .. ignore_err .. -- clean + " && " .. output .. -- run + " && echo && echo \"" .. entry_point .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } } -- Run program - local task_run = { name = "- Run program → \"" .. output .. "\"", - cmd = utils.os_path(output, true) .. -- run - " && echo && echo \"" .. output .. "\"" .. -- echo + local task_run = { name = "- Run program → " .. output, + cmd = output .. -- run + " && echo && echo " .. output .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } } @@ -72,25 +76,25 @@ function M.action(selected_option) local tasks_compile = {} for _, file in pairs(files) do local filename = vim.fn.fnamemodify(file, ":t") - local output_o = output_dir .. filename .. ".o" + local output_o = utils.os_path(output_dir .. filename .. ".o", true) file = utils.os_path(file, true) - local task = { name = "- Build program → " .. file, - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && nasm -f elf64 " .. file .. " -o \"" .. output_o .. "\" " .. arguments .. -- compile - " && echo " .. file .. -- echo + local task = { "shell", name = "- Build program → " .. file, + cmd = rm .. output .. ignore_err .. -- clean + " && " .. mkdir .. output_dir .. ignore_err .. -- mkdir + " && nasm -f elf64 " .. file .. " -o " .. output_o .. " " .. arguments .. -- compile + " && echo " .. file .. -- echo " && echo \"" .. final_message .. "\"", - components = { "default_extended" } + components = { "default_extended" } } files[_] = utils.os_path(output_dir .. filename .. ".o", true) -- prepare for linker table.insert(tasks_compile, task) end -- Link .o files files = table.concat(files ," ") -- table to string - local task_link = { name = "- Link program → \"" .. entry_point .. "\"", - cmd = "ld " .. files .. " -o \"" .. output .. "\"" .. -- link - " && rm -f " .. files .. " || true" .. -- clean - " && echo \"" .. entry_point .. "\"" .. -- echo + local task_link = { "shell", name = "- Link program → \"" .. entry_point .. "\"", + cmd = "ld " .. files .. " -o " .. output .. -- link + " && " .. rm .. files .. ignore_err .. -- clean + " && echo \"" .. entry_point .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } } @@ -106,9 +110,9 @@ function M.action(selected_option) local task = overseer.new_task({ name = "- Assembly compiler", strategy = { "orchestrator", - tasks = {{ name = "- Run program → \"" .. output .. "\"", - cmd = "\"" .. output .. "\"" .. -- run - " && echo && echo \"" .. output .. "\"" .. -- echo + tasks = {{ name = "- Run program → " .. output, + cmd = output .. -- run + " && echo && echo " .. output .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } },},},}) @@ -129,7 +133,7 @@ function M.action(selected_option) entry_point = utils.os_path(variables.entry_point) entry_point_dir = vim.fn.fnamemodify(entry_point, ":h") files = utils.find_files(entry_point_dir, "*.asm") - output = utils.os_path(variables.output) -- entry_point/bin/program + output = utils.os_path(variables.output, true, true) -- entry_point/bin/program output_dir = utils.os_path(output:match("^(.-[/\\])[^/\\]*$")) -- entry_point/bin arguments = variables.arguments or arguments -- optional @@ -137,13 +141,13 @@ function M.action(selected_option) local tasks_compile = {} for _, file in pairs(files) do local filename = vim.fn.fnamemodify(file, ":t") - local output_o = output_dir .. filename .. ".o" + local output_o = utils.os_path(output_dir .. filename .. ".o", true) file = utils.os_path(file, true) - local task = { name = "- Build program → " .. file, - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && nasm -f elf64 " .. file .. " -o \"" .. output_o .. "\" " .. arguments .. -- compile - " && echo " .. file .. -- echo + local task = { "shell", name = "- Build program → " .. file, + cmd = rm .. output .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir + " && nasm -f elf64 " .. file .. " -o " .. output_o .. " " .. arguments .. -- compile + " && echo " .. file .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } } @@ -152,10 +156,10 @@ function M.action(selected_option) end -- Link .o files files = table.concat(files ," ") -- table to string - local task_link = { name = "- Link program → " .. entry_point, - cmd = "ld " .. files .. " -o \"" .. output .. "\"" .. -- link - " && rm -f " .. files .. " || true" .. -- clean - " && echo \"" .. entry_point .. "\"" .. -- echo + local task_link = { "shell", name = "- Link program → " .. entry_point, + cmd = "ld " .. files .. " -o " .. output .. -- link + " && " .. rm .. files .. ignore_err .. -- clean + " && echo \"" .. entry_point .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } } @@ -167,7 +171,7 @@ function M.action(selected_option) local solution_executables = config["executables"] if solution_executables then for entry, executable in pairs(solution_executables) do - utils.os_path(executable, true) + executable = utils.os_path(executable, true, true) task = { name = "- Run program → " .. executable, cmd = executable .. -- run " && echo && echo " .. executable .. -- echo @@ -196,20 +200,20 @@ function M.action(selected_option) entry_point = utils.os_path(entry_point) entry_point_dir = vim.fn.fnamemodify(entry_point, ":h") files = utils.find_files(entry_point_dir, "*.asm") - output_dir = utils.os_path(entry_point:match("^(.-[/\\])[^/\\]*$") .. "bin") -- entry_point/bin - output = utils.os_path(output_dir .. "/program") -- entry_point/bin/program + output_dir = utils.os_path(entry_point:match("^(.-[/\\])[^/\\]*$") .. "bin", true) -- entry_point/bin + output = utils.os_path(output_dir .. "/program", true, true) -- entry_point/bin/program -- Build .asm files in parallel local tasks_compile = {} for _, file in pairs(files) do local filename = vim.fn.fnamemodify(file, ":t") - local output_o = output_dir .. filename .. ".o" + local output_o = utils.os_path(output_dir .. filename .. ".o", true) file = utils.os_path(file, true) - local task = { name = "- Build program → " .. file, - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && nasm -f elf64 " .. file .. " -o \"" .. output_o .. "\" " .. arguments .. -- compile - " && echo " .. file .. -- echo + local task = { "shell", name = "- Build program → " .. file, + cmd = rm .. output .. ignore_err .. -- clean + " && " .. mkdir .. output_dir .. ignore_err .. -- mkdir + " && nasm -f elf64 " .. file .. " -o " .. output_o .. " " .. arguments .. -- compile + " && echo " .. file .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } } @@ -217,11 +221,11 @@ function M.action(selected_option) table.insert(tasks_compile, task) end -- Link .o files - files = table.concat(files ," ") -- table to string - local task_link = { name = "- Link program → \"" .. entry_point .. "\"", - cmd = "ld " .. files .. " -o \"" .. output .. "\"" .. -- link - " && rm -f " .. files .. " || true" .. -- clean - " && echo \"" .. entry_point .. "\"" .. -- echo + files = table.concat(files, " ") -- table to string + local task_link = { "shell", name = "- Link program → \"" .. entry_point .. "\"", + cmd = "ld " .. files .. " -o " .. output .. -- link + " && " .. rm .. files .. ignore_err .. -- clean + " && echo \"" .. entry_point .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } } diff --git a/lua/compiler/languages/c.lua b/lua/compiler/languages/c.lua index 1ae4bab8..f97b2e6a 100644 --- a/lua/compiler/languages/c.lua +++ b/lua/compiler/languages/c.lua @@ -22,17 +22,19 @@ function M.action(selected_option) local final_message = "--task finished--" + local rm, mkdir, ignore_error = utils.get_commands() + if selected_option == "option1" then local task = overseer.new_task({ name = "- C compiler", strategy = { "orchestrator", tasks = {{ name = "- Build & run program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && gcc " .. files .. " -o \"" .. output .. "\" " .. arguments .. -- compile - " && \"" .. output .. "\"" .. -- run - " && echo \"" .. entry_point .. "\"" .. -- echo - " && echo \"" .. final_message .. "\"", + cmd = rm .. "\"" .. output .. "\"" .. ignore_error .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_error .. -- mkdir + " && gcc " .. files .. " -o \"" .. output .. "\" " .. arguments .. -- compile + " && \"" .. output .. "\"" .. -- run + " && echo \"" .. entry_point .. "\"" .. -- echo + " && echo \"" .. final_message .. "\"", components = { "default_extended" } },},},}) task:start() @@ -41,11 +43,11 @@ function M.action(selected_option) name = "- C compiler", strategy = { "orchestrator", tasks = {{ name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && gcc " .. files .. " -o \"" .. output .. "\" " .. arguments .. -- compile - " && echo \"" .. entry_point .. "\"" .. -- echo - " && echo \"" .. final_message .. "\"", + cmd = rm .. "\"" .. output .. "\"" .. ignore_error .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_error .. -- mkdir + " && gcc " .. files .. " -o \"" .. output .. "\" " .. arguments .. -- compile + " && echo \"" .. entry_point .. "\"" .. -- echo + " && echo \"" .. final_message .. "\"", components = { "default_extended" } },},},}) task:start() @@ -78,13 +80,13 @@ function M.action(selected_option) output = utils.os_path(variables.output) output_dir = utils.os_path(output:match("^(.-[/\\])[^/\\]*$")) arguments = variables.arguments or arguments -- optional + task = { name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && gcc " .. files .. " -o \"" .. output .. "\" " .. arguments .. -- compile - " && echo \"" .. entry_point .. "\"" .. -- echo - " && echo \"" .. final_message .. "\"", - components = { "default_extended" } + cmd = rm .. "\"" .. output .. "\"" .. ignore_error .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_error .. -- mkdir + " && gcc " .. files .. " -o \"" .. output .. "\" " .. arguments .. -- compile + " && echo \"" .. entry_point .. "\"" .. -- echo + " && echo \"" .. final_message .. "\"" } table.insert(tasks, task) -- store all the tasks we've created ::continue:: @@ -121,12 +123,13 @@ function M.action(selected_option) files = utils.find_files_to_compile(entry_point, "*.c") output_dir = utils.os_path(entry_point:match("^(.-[/\\])[^/\\]*$") .. "bin") -- entry_point/bin output = utils.os_path(output_dir .. "/program") -- entry_point/bin/program + task = { name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && gcc " .. files .. " -o \"" .. output .. "\" " .. arguments .. -- compile - " && echo \"" .. entry_point .. "\"" .. -- echo - " && echo \"" .. final_message .. "\"", + cmd = rm .. "\"" .. output .. "\"" .. ignore_error .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_error .. -- mkdir + " && gcc " .. files .. " -o \"" .. output .. "\" " .. arguments .. -- compile + " && echo \"" .. entry_point .. "\"" .. -- echo + " && echo \"" .. final_message .. "\"", components = { "default_extended" } } table.insert(tasks, task) -- store all the tasks we've created diff --git a/lua/compiler/languages/cpp.lua b/lua/compiler/languages/cpp.lua index 694c8f59..616ff907 100644 --- a/lua/compiler/languages/cpp.lua +++ b/lua/compiler/languages/cpp.lua @@ -22,17 +22,19 @@ function M.action(selected_option) local final_message = "--task finished--" + local rm, mkdir, ignore_err = utils.get_commands() + if selected_option == "option1" then local task = overseer.new_task({ name = "- C++ compiler", strategy = { "orchestrator", tasks = {{ name = "- Build & run program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && g++ " .. files .. " -o \"" .. output .. "\" " .. arguments .. -- compile - " && \"" .. output .. "\"" .. -- run - " && echo \"" .. entry_point .. "\"" .. -- echo - " && echo \"" .. final_message .. "\"", + cmd = rm .. "\"" .. output .. "\"" .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir + " && g++ " .. files .. " -o \"" .. output .. "\" " .. arguments .. -- compile + " && \"" .. output .. "\"" .. -- run + " && echo \"" .. entry_point .. "\"" .. -- echo + " && echo \"" .. final_message .. "\"", components = { "default_extended" } },},},}) task:start() @@ -41,11 +43,11 @@ function M.action(selected_option) name = "- C++ compiler", strategy = { "orchestrator", tasks = {{ name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && g++ " .. files .. " -o \"" .. output .. "\" " .. arguments .. -- compile - " && echo \"" .. entry_point .. "\"" .. -- echo - " && echo \"" .. final_message .. "\"", + cmd = rm .. "\"" .. output .. "\"" .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir + " && g++ " .. files .. " -o \"" .. output .. "\" " .. arguments .. -- compile + " && echo \"" .. entry_point .. "\"" .. -- echo + " && echo \"" .. final_message .. "\"", components = { "default_extended" } },},},}) task:start() @@ -78,12 +80,13 @@ function M.action(selected_option) output = utils.os_path(variables.output) output_dir = utils.os_path(output:match("^(.-[/\\])[^/\\]*$")) arguments = variables.arguments or arguments -- optional + task = { name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && g++ " .. files .. " -o \"" .. output .. "\" " .. arguments .. -- compile - " && echo \"" .. entry_point .. "\"" .. -- echo - " && echo \"" .. final_message .. "\"", + cmd = rm .. "\"" .. output .. "\"" .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir + " && g++ " .. files .. " -o \"" .. output .. "\" " .. arguments .. -- compile + " && echo \"" .. entry_point .. "\"" .. -- echo + " && echo \"" .. final_message .. "\"", components = { "default_extended" } } table.insert(tasks, task) -- store all the tasks we've created @@ -121,12 +124,13 @@ function M.action(selected_option) files = utils.find_files_to_compile(entry_point, "*.cpp") output_dir = utils.os_path(entry_point:match("^(.-[/\\])[^/\\]*$") .. "bin") -- entry_point/bin output = utils.os_path(output_dir .. "/program") -- entry_point/bin/program + task = { name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && g++ " .. files .. " -o \"" .. output .. "\" " .. arguments .. -- compile - " && echo \"" .. entry_point .. "\"" .. -- echo - " && echo \"" .. final_message .. "\"", + cmd = rm .. "\"" .. output .. "\"" .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir + " && g++ " .. files .. " -o \"" .. output .. "\" " .. arguments .. -- compile + " && echo \"" .. entry_point .. "\"" .. -- echo + " && echo \"" .. final_message .. "\"", components = { "default_extended" } } table.insert(tasks, task) -- store all the tasks we've created diff --git a/lua/compiler/languages/cs.lua b/lua/compiler/languages/cs.lua index 325af7b5..27077d30 100644 --- a/lua/compiler/languages/cs.lua +++ b/lua/compiler/languages/cs.lua @@ -22,20 +22,22 @@ function M.action(selected_option) local files = utils.find_files_to_compile(entry_point, "*.cs") -- *.cs files under entry_point_dir (recursively) local output_dir = utils.os_path(vim.fn.getcwd() .. "/bin/") -- working_directory/bin/ local output = utils.os_path(vim.fn.getcwd() .. "/bin/Program.exe") -- working_directory/bin/program - local arguments = "-warn:4 /debug" -- arguments can be overriden in .solution + local arguments = "-warn:4 /debug" -- arguments can be overriden in .solution local final_message = "--task finished--" + local rm, mkdir, ignore_error = utils.get_commands() + if selected_option == "option1" then local task = overseer.new_task({ name = "- C# compiler", strategy = { "orchestrator", tasks = {{ name = "- Build & run program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && csc " .. files .. " -out:\"" .. output .. "\" " .. arguments .. -- compile bytecode - " && mono \"" .. output .. "\"" .. -- run - " ; echo \"" .. entry_point .. "\"" .. -- echo - " ; echo \"" .. final_message .. "\"", + cmd = rm .. "\"" .. output .. "\"" .. ignore_error .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_error .. -- mkdir + " && csc " .. files .. " -out:\"" .. output .. "\" " .. arguments .. -- compile bytecode + " && mono \"" .. output .. "\"" .. -- run + " && echo \"" .. entry_point .. "\"" .. -- echo + " && echo \"" .. final_message .. "\"", components = { "default_extended" } },},},}) task:start() @@ -44,11 +46,11 @@ function M.action(selected_option) name = "- C# compiler", strategy = { "orchestrator", tasks = {{ name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && csc " .. files .. " -out:\"" .. output .. "\" " .. arguments .. -- compile bytecode - " && echo \"" .. entry_point .. "\"" .. -- echo - " && echo \"" .. final_message .. "\"", + cmd = rm .. "\"" .. output .. "\"" .. ignore_error .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_error .. -- mkdir + " && csc " .. files .. " -out:\"" .. output .. "\" " .. arguments .. -- compile bytecode + " && echo \"" .. entry_point .. "\"" .. -- echo + " && echo \"" .. final_message .. "\"", components = { "default_extended" } },},},}) task:start() @@ -58,8 +60,8 @@ function M.action(selected_option) strategy = { "orchestrator", tasks = {{ name = "- Run program → \"" .. entry_point .. "\"", cmd = "mono \"" .. output .. "\"" .. -- run - " ; echo \"" .. entry_point .. "\"" .. -- echo - " ; echo \"" .. final_message .. "\"", + " && echo \"" .. entry_point .. "\"" .. -- echo + " && echo \"" .. final_message .. "\"", components = { "default_extended" } },},},}) task:start() @@ -81,12 +83,13 @@ function M.action(selected_option) output = utils.os_path(variables.output) output_dir = utils.os_path(output:match("^(.-[/\\])[^/\\]*$")) arguments = variables.arguments or arguments -- optional + task = { name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && csc " .. files .. " -out:\"" .. output .. "\" " .. arguments .. -- compile bytecode - " && echo \"" .. entry_point .. "\"" .. -- echo - " && echo \"" .. final_message .. "\"", + cmd = rm .. "\"" .. output .. "\"" .. ignore_error .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_error .. -- mkdir + " && csc " .. files .. " -out:\"" .. output .. "\" " .. arguments .. -- compile bytecode + " && echo \"" .. entry_point .. "\"" .. -- echo + " && echo \"" .. final_message .. "\"", components = { "default_extended" } } table.insert(tasks, task) -- store all the tasks we've created @@ -124,12 +127,13 @@ function M.action(selected_option) files = utils.find_files_to_compile(entry_point, "*.cs") output_dir = utils.os_path(entry_point:match("^(.-[/\\])[^/\\]*$") .. "bin") -- entry_point/bin output = utils.os_path(output_dir .. "/program") -- entry_point/bin/program + task = { name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && csc " .. files .. " -out:\"" .. output .. "\" " .. arguments .. -- compile - " && echo \"" .. entry_point .. "\"" .. -- echo - " && echo \"" .. final_message .. "\"", + cmd = rm .. "\"" .. output .. "\"" .. ignore_error .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_error .. -- mkdir + " && csc " .. files .. " -out:\"" .. output .. "\" " .. arguments .. -- compile bytecode + " && echo \"" .. entry_point .. "\"" .. -- echo + " && echo \"" .. final_message .. "\"", components = { "default_extended" } } table.insert(tasks, task) -- store all the tasks we've created diff --git a/lua/compiler/languages/dart.lua b/lua/compiler/languages/dart.lua index 8e6fc69d..273bfe9e 100644 --- a/lua/compiler/languages/dart.lua +++ b/lua/compiler/languages/dart.lua @@ -29,9 +29,10 @@ function M.action(selected_option) local current_file = utils.os_path(vim.fn.expand('%:p'), true) -- current file local entry_point = utils.os_path(vim.fn.getcwd() .. "/lib/main.dart", true) -- working_directory/lib/main.dart local output_dir = utils.os_path(vim.fn.getcwd() .. "/bin/") -- working_directory/bin/ - local output = utils.os_path(vim.fn.getcwd() .. "/bin/main") -- working_directory/bin/main + local output = utils.os_path(vim.fn.getcwd() .. "/bin/main", false, true) -- working_directory/bin/main local final_message = "--task finished--" + local rm, mkdir, ignore_err = utils.get_commands() --=========================== INTERPRETED =================================-- if selected_option == "option1" then @@ -142,11 +143,11 @@ function M.action(selected_option) name = "- Dart compiler", strategy = { "orchestrator", tasks = {{ name = "- Build & run program → " .. entry_point, - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm .. "\"" .. output .. "\"" .. ignore_err .. -- clean + " && ".. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && dart compile exe " .. entry_point .. " -o \"" .. output .. "\" " .. arguments .. -- compile - " && \"" .. output .. "\"" .. -- run - " && echo \"" .. entry_point .. "\"" .. -- echo + " && \"" .. output .. "\"" .. -- run + " && echo " .. entry_point .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } },},},}) @@ -157,10 +158,10 @@ function M.action(selected_option) name = "- Dart compiler", strategy = { "orchestrator", tasks = {{ name = "- Build program → " .. entry_point, - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm .. "\"" .. output .. "\"" .. ignore_err .. -- clean + " && ".. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && dart compile exe " .. entry_point .. " -o \"" .. output .. "\" " .. arguments .. -- compile - " && echo \"" .. entry_point .. "\"" .. -- echo + " && echo " .. entry_point .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } },},},}) @@ -171,8 +172,8 @@ function M.action(selected_option) name = "- Dart compiler", strategy = { "orchestrator", tasks = {{ name = "- Run program → \"" .. output .. "\"", - cmd = "\"" .. output .. "\"" .. -- run - " && echo \"" .. entry_point .. "\"" .. -- echo + cmd = "\"" .. output .. "\"" .. -- run + " && echo " .. entry_point .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } },},},}) @@ -195,10 +196,10 @@ function M.action(selected_option) output_dir = utils.os_path(output:match("^(.-[/\\])[^/\\]*$")) local arguments = variables.arguments or "" -- optional task = { name = "- Run program → " .. entry_point, - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p " .. output_dir .. -- mkdir + cmd = rm .. "\"" .. output .. "\"" .. ignore_err .. -- clean + " && ".. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && dart compile exe " .. entry_point .. " -o \"" .. output .. "\" " .. arguments .. -- compile - " && echo " .. entry_point .. -- echo + " && echo " .. entry_point .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } } @@ -237,8 +238,8 @@ function M.action(selected_option) output_dir = utils.os_path(entry_point:match("^(.-[/\\])[^/\\]*$") .. "../bin") -- entry_point/../bin output = utils.os_path(output_dir .. "/main") -- entry_point/bin/main task = { name = "- Build program → \"" .. entry_point .. "\"", - cmd ="rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm .. "\"" .. output .. "\"" .. ignore_err .. -- clean + " && ".. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && dart compile exe \"" .. entry_point .. "\" -o \"" .. output .. "\" " .. arguments .. -- compile " && echo \"" .. entry_point .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", diff --git a/lua/compiler/languages/fortran.lua b/lua/compiler/languages/fortran.lua index 3cf70440..4ee04184 100644 --- a/lua/compiler/languages/fortran.lua +++ b/lua/compiler/languages/fortran.lua @@ -16,20 +16,22 @@ function M.action(selected_option) local overseer = require("overseer") local current_file = utils.os_path(vim.fn.expand('%:p'), true) -- current file local output_dir = utils.os_path(vim.fn.stdpath("cache") .. "/compiler/fortran/") -- working_directory/bin/ - local output = output_dir .. "program" -- working_directory/bin/program + local output = utils.os_path(output_dir .. "program", true, true) -- working_directory/bin/program local arguments = "" -- arguments can be overriden in .solution local final_message = "--task finished--" + local rm, mkdir, ignore_err = utils.get_commands() + if selected_option == "option1" then local task = overseer.new_task({ name = "- Fortran compiler", strategy = { "orchestrator", tasks = {{ name = "- Run this file → " .. current_file, - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm .. output .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && gfortran " .. current_file .. " -o \"" .. output .. "\" " .. arguments .. -- compile - " && " .. output .. -- run - " && echo " .. current_file .. -- echo + " && " .. output .. -- run + " && echo " .. current_file .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } },},},}) diff --git a/lua/compiler/languages/go.lua b/lua/compiler/languages/go.lua index 3c2b4214..8f2edfc3 100644 --- a/lua/compiler/languages/go.lua +++ b/lua/compiler/languages/go.lua @@ -14,21 +14,22 @@ M.options = { function M.action(selected_option) local utils = require("compiler.utils") local overseer = require("overseer") - local entry_point = utils.os_path(vim.fn.getcwd() .. "/main.go", true) -- working_directory/main.go - local files = utils.find_files_to_compile(entry_point, "*.go") -- *.go files under entry_point_dir (recursively) - local output_dir = utils.os_path(vim.fn.getcwd() .. "/bin/", true) -- working_directory/bin/ - local output = utils.os_path(vim.fn.getcwd() .. "/bin/program", true) -- working_directory/bin/program - local arguments = "-a -gcflags='-N -l'" -- arguments can be overriden in .solution + local entry_point = utils.os_path(vim.fn.getcwd() .. "/main.go", true) -- working_directory/main.go + local files = utils.find_files_to_compile(entry_point, "*.go") -- *.go files under entry_point_dir (recursively) + local output_dir = utils.os_path(vim.fn.getcwd() .. "/bin/", true) -- working_directory/bin/ + local output = utils.os_path(vim.fn.getcwd() .. "/bin/program", true, true) -- working_directory/bin/program + local arguments = "-a -gcflags=\"-N -l\"" -- arguments can be overriden in .solution local final_message = "--task finished--" + local rm, mkdir, ignore_err = utils.get_commands() if selected_option == "option1" then local task = overseer.new_task({ name = "- Go compiler", strategy = { "orchestrator", tasks = {{ name = "- Build & run program → " .. entry_point, - cmd = "rm -f " .. output .. -- clean - " && mkdir -p " .. output_dir .. -- mkdir + cmd = rm .. output .. ignore_err .. -- clean + " && " .. mkdir .. output_dir .. ignore_err .. -- mkdir " && go build " .. arguments .. " -o " .. output .. " " .. files .. -- compile " && " .. output .. -- run " && echo " .. entry_point .. -- echo @@ -41,8 +42,8 @@ function M.action(selected_option) name = "- Go compiler", strategy = { "orchestrator", tasks = {{ name = "- Build program → " .. entry_point, - cmd = "rm -f " .. output .. -- clean - " && mkdir -p " .. output_dir .. -- mkdir + cmd = rm .. output .. ignore_err .. -- clean + " && " .. mkdir .. output_dir .. ignore_err .. -- mkdir " && go build " .. arguments .. " -o " .. output .. " " .. files .. -- compile " && echo " .. entry_point .. -- echo " && echo \"" .. final_message .. "\"", @@ -74,15 +75,16 @@ function M.action(selected_option) for entry, variables in pairs(config) do if entry == "executables" then goto continue end entry_point = utils.os_path(variables.entry_point) - files = utils.find_files_to_compile(entry_point, "*.go") - output = utils.os_path(variables.output) - output_dir = utils.os_path(output:match("^(.-[/\\])[^/\\]*$")) + files = utils.find_files_to_compile(entry_point, "*.go", true) + entry_point = utils.os_path(variables.entry_point, true) + output = utils.os_path(variables.output, true, true) + output_dir = utils.os_path(output:match("^(.-[/\\])[^/\\]*$"), true) arguments = variables.arguments or arguments -- optional - task = { name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\"" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && go build " .. arguments .. " -o \"" .. output .. "\" " .. files .. -- compile - " && echo \"" .. entry_point .. "\"" .. -- echo + task = { name = "- Build program → " .. entry_point, + cmd = rm .. output .. ignore_err .. -- clean + " && " .. mkdir .. output_dir .. ignore_err .. -- mkdir + " && go build " .. arguments .. " -o " .. output .. " " .. files .. -- compile + " && echo " .. entry_point .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } } @@ -93,7 +95,7 @@ function M.action(selected_option) local solution_executables = config["executables"] if solution_executables then for entry, executable in pairs(solution_executables) do - executable = utils.os_path(executable, true) + executable = utils.os_path(executable, true, true) task = { name = "- Run program → " .. executable, cmd = executable .. -- run " && echo " .. executable .. -- echo @@ -119,13 +121,14 @@ function M.action(selected_option) for _, entry_point in ipairs(entry_points) do entry_point = utils.os_path(entry_point) files = utils.find_files_to_compile(entry_point, "*.go") - output_dir = utils.os_path(entry_point:match("^(.-[/\\])[^/\\]*$") .. "bin") -- entry_point/bin - output = utils.os_path(output_dir .. "/program") -- entry_point/bin/program - task = { name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\"" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && go build " .. arguments .. " -o \"" .. output .. "\" " .. files .. -- compile - " && echo \"" .. entry_point .. "\"" .. -- echo + entry_point = utils.os_path(entry_point,true) + output_dir = utils.os_path(entry_point:match("^(.-[/\\])[^/\\]*$") .. "bin", true) -- entry_point/bin + output = utils.os_path(output_dir .. "/program", true, true) -- entry_point/bin/program + task = { name = "- Build program → " .. entry_point, + cmd = rm .. output .. ignore_err .. -- clean + " && " .. mkdir .. output_dir .. ignore_err .. -- mkdir + " && go build " .. arguments .. " -o " .. output .. " " .. files .. -- compile + " && echo " .. entry_point .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } } diff --git a/lua/compiler/languages/java.lua b/lua/compiler/languages/java.lua index 5225fce9..e9e168f2 100644 --- a/lua/compiler/languages/java.lua +++ b/lua/compiler/languages/java.lua @@ -21,22 +21,29 @@ M.options = { function M.action(selected_option) local utils = require("compiler.utils") local overseer = require("overseer") - local entry_point = utils.os_path(vim.fn.getcwd() .. "/Main.java") -- working_directory/Main.java - local files = utils.find_files_to_compile(entry_point, "*.java") -- *.java files under entry_point_dir (recursively) - local output_dir = utils.os_path(vim.fn.getcwd() .. "/bin/") -- working_directory/bin/ - local output = utils.os_path(vim.fn.getcwd() .. "/bin/Main") -- working_directory/bin/Main.class - local output_filename = "Main" -- working_directory/bin/Main - local arguments = "-Xlint:all" -- arguments can be overriden in .solution + local entry_point = utils.os_path(vim.fn.getcwd() .. "/Main.java") -- working_directory/Main.java + local files = utils.find_files_to_compile(entry_point, "*.java") -- *.java files under entry_point_dir (recursively) + local output_dir = utils.os_path(vim.fn.getcwd() .. "/bin/") -- working_directory/bin/ + local output = utils.os_path(vim.fn.getcwd() .. "/bin/Main") -- working_directory/bin/Main.class + local output_filename = "Main" -- working_directory/bin/Main + local arguments = "-Xlint:all" -- arguments can be overriden in .solution local final_message = "--task finished--" + -- HACK: I don't know why, but javac has problems backslashes '\' as path seperators, so we convert to '/' + output_dir = output_dir:gsub("\\", "/") + output = output:gsub("\\", "/") + files = files:gsub("\\", "/") + + local rm_file, mkdir, ignore_err = utils.get_commands() + --========================== Build as class ===============================-- if selected_option == "option1" then local task = overseer.new_task({ name = "- Java compiler", strategy = { "orchestrator", tasks = {{ name = "- Build & run program (class) → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output_dir .. "*.class\"" .. " || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm_file .. "\"" .. output_dir .. "*.class\"" .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && javac -d \"" .. output_dir .. "\" " .. arguments .. " " .. files .. -- compile bytecode (.class) " && java -cp \"" .. output_dir .. "\" " .. output_filename .. -- run " && echo \"" .. entry_point .. "\"" .. -- echo @@ -49,8 +56,8 @@ function M.action(selected_option) name = "- Java compiler", strategy = { "orchestrator", tasks = {{ name = "- Build program (class) → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output_dir .. "/*.class\"" .. " || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm_file .. "\"" .. output_dir .. "*.class\"" .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && javac -d \"" .. output_dir .. "\" " .. arguments .. " " .. files .. -- compile bytecode (.class) " && echo \"" .. entry_point .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", @@ -83,12 +90,14 @@ function M.action(selected_option) if entry == "executables" then goto continue end entry_point = utils.os_path(variables.entry_point) files = utils.find_files_to_compile(entry_point, "*.java") + files = files:gsub("\\", "/") output = utils.os_path(variables.output) output_dir = utils.os_path(output:match("^(.-[/\\])[^/\\]*$")) + output_dir = output_dir:gsub("\\", "/") arguments = variables.arguments or arguments -- optiona task = { name = "- Build program (class) → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output_dir .. "/*.class\"" .. " || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm_file .. "\"" .. output_dir .. "*.class\"" .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && javac -d \"" .. output_dir .. "\" " .. arguments .. " " .. files .. -- compile bytecode " && echo \"" .. entry_point .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", @@ -102,6 +111,7 @@ function M.action(selected_option) if solution_executables then for entry, executable in pairs(solution_executables) do output_dir = utils.os_path(executable:match("^(.-[/\\])[^/\\]*$")) + output_dir = output_dir:gsub("\\", "/") output_filename = vim.fn.fnamemodify(executable, ':t:r') task = { name = "- Run program (class) → \"" .. executable .. "\"", cmd = "java -cp \"" .. output_dir .. "\" " .. output_filename .. -- run @@ -128,10 +138,12 @@ function M.action(selected_option) for _, entry_point in ipairs(entry_points) do entry_point = utils.os_path(entry_point) files = utils.find_files_to_compile(entry_point, "*.java") + files = files:gsub("\\", "/") output_dir = utils.os_path(entry_point:match("^(.-[/\\])[^/\\]*$") .. "bin") -- entry_point/bin + output_dir = output_dir:gsub("\\", "/") task = { name = "- Build program (class) → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output_dir .. "/*.class\"" .. " || true" .. -- clean - " && mkdir -p \"" .. output_dir .."\"" .. -- mkdir + cmd = rm_file .. "\"" .. output_dir .. "*.class\"" .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .."\"" .. ignore_err .. -- mkdir " && javac -d \"" .. output_dir .. "\" " .. arguments .. " " .. files .. -- compile bytecode " && echo \"" .. entry_point .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", @@ -159,8 +171,8 @@ function M.action(selected_option) name = "- Java compiler", strategy = { "orchestrator", tasks = {{ name = "- Build & run program (jar) → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. ".jar\"" .. " || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm_file .. "\"" .. output .. ".jar\"" .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && jar cfe \"" .. output .. ".jar\" " .. output_filename .. " -C \"" .. output_dir .. "\" . " .. -- compile bytecode (.jar) " && java -jar \"" .. output .. ".jar\"" .. -- run " && echo \"" .. entry_point .. "\"" .. -- echo @@ -173,8 +185,8 @@ function M.action(selected_option) name = "- Java compiler", strategy = { "orchestrator", tasks = {{ name = "- Build program (jar) → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. ".jar\"" .. " || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm_file .. "\"" .. output .. ".jar\"" .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && jar cfe \"" .. output .. ".jar\" " .. output_filename .. " -C \"" .. output_dir .. "\" . " .. -- compile bytecode (.jar) " && echo \"" .. entry_point .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", @@ -206,16 +218,20 @@ function M.action(selected_option) for entry, variables in pairs(config) do if entry == "executables" then goto continue end entry_point = utils.os_path(variables.entry_point) + entry_point = entry_point:gsub("\\", "/") files = utils.find_files_to_compile(entry_point, "*.java") + files = files:gsub("\\", "/") output = utils.os_path(variables.output) + output = output:gsub("\\", "/") output_dir = utils.os_path(output:match("^(.-[/\\])[^/\\]*$")) + output_dir = output_dir:gsub("\\", "/") output_filename = vim.fn.fnamemodify(output, ':t:r') arguments = variables.arguments or arguments -- optional task = { name = "- Build program (jar) → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm_file .. "\"" .. output .. "\"" .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && jar cfe \"" .. output .. "\" " .. output_filename .. " -C \"" .. output_dir .. "\" . " .. -- compile bytecode (jar) - " && echo \"" .. entry_point .. "\"" .. -- echo + " && echo \"" .. entry_point .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } } @@ -254,10 +270,10 @@ function M.action(selected_option) output_dir = utils.os_path(entry_point:match("^(.-[/\\])[^/\\]*$") .. "bin") -- entry_point/bin output = utils.os_path(output_dir .. "/Main") -- entry_point/bin/Main.jar task = { name = "- Build program (jar) → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. ".jar\" " .. " || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm_file .. "\"" .. output .. ".jar\" " .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && jar cfe \"" .. output .. ".jar\" " .. output_filename .. " -C \"" .. output_dir .. "\" . " .. -- compile bytecode (jar) - " && echo \"" .. entry_point .. "\"" .. -- echo + " && echo \"" .. entry_point .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } } diff --git a/lua/compiler/languages/kotlin.lua b/lua/compiler/languages/kotlin.lua index c7c546e0..ceca8ca0 100644 --- a/lua/compiler/languages/kotlin.lua +++ b/lua/compiler/languages/kotlin.lua @@ -29,14 +29,21 @@ function M.action(selected_option) local arguments = "" -- arguments can be overriden in .solution local final_message = "--task finished--" + local rm_file, mkdir, ignore_err = utils.get_commands() + + -- HACK: I don't know why, but javac has problems backslashes '\' as path seperators, so we convert to '/' + output_dir = output_dir:gsub("\\", "/") + output = output:gsub("\\", "/") + files = files:gsub("\\", "/") + --========================== Build as class ===============================-- if selected_option == "option1" then local task = overseer.new_task({ name = "- Kotlin compiler", strategy = { "orchestrator", tasks = {{ name = "- Build & run program (class) → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output_dir .. "/*.class\" " .. " || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm_file .. "\"" .. output_dir .. "*.class\" " .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && kotlinc " .. files .. " -d \"" .. output_dir .. "\" " .. arguments .. -- compile bytecode " && java -cp \"" .. output_dir .. "\" " .. output_filename .. -- run " && echo \"" .. entry_point .. "\"" .. -- echo @@ -49,8 +56,8 @@ function M.action(selected_option) name = "- Kotlin compiler", strategy = { "orchestrator", tasks = {{ name = "- Build program (class) → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output_dir .. "/*.class\" " .. " || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm_file .. "\"" .. output_dir .. "*.class\" " .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && kotlinc " .. files .. " -d \"" .. output_dir .. "\" " .. arguments .. -- compile bytecode " && echo \"" .. entry_point .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", @@ -83,12 +90,14 @@ function M.action(selected_option) if entry == "executables" then goto continue end entry_point = utils.os_path(variables.entry_point) files = utils.find_files_to_compile(entry_point, "*.kt") + files = files:gsub("\\", "/") output = utils.os_path(variables.output) output_dir = utils.os_path(output:match("^(.-[/\\])[^/\\]*$")) + output_dir = output_dir:gsub("\\", "/") arguments = variables.arguments or arguments -- optional task = { name = "- Build program (class) → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output_dir .. "/*.class\"" .. " || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm_file .. "\"" .. output_dir .. "*.class\" " .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && kotlinc " .. files .. " -d \"" .. output_dir .. "\" " .. arguments .. " " .. -- compile bytecode " && echo \"" .. entry_point .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", @@ -102,6 +111,7 @@ function M.action(selected_option) if solution_executables then for entry, executable in pairs(solution_executables) do output_dir = utils.os_path(executable:match("^(.-[/\\])[^/\\]*$")) + output_dir = output_dir:gsub("\\", "/") output_filename = vim.fn.fnamemodify(executable, ":t:r") task = { name = "- Run program (class) → \"" .. executable .. "\"", cmd = "java -cp \"" .. output_dir .. "\" " .. output_filename .. -- run @@ -130,8 +140,8 @@ function M.action(selected_option) files = utils.find_files_to_compile(entry_point, "*.kt") output_dir = utils.os_path(entry_point:match("^(.-[/\\])[^/\\]*$") .. "bin") -- entry_point/bin task = { name = "- Build program (class) → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output_dir .. "/*.class\"" .. " || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm_file .. "\"" .. output_dir .. "*.class\" " .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && kotlinc " .. files .. " -d \"" .. output_dir .. "\" " .. arguments .. -- compile bytecode " && echo \"" .. entry_point .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", @@ -159,8 +169,8 @@ function M.action(selected_option) name = "- Kotlin compiler", strategy = { "orchestrator", tasks = {{ name = "- Build & run program (jar) → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true " .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm_file .. "\"" .. output .. "*.class\" " .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && kotlinc " .. files .. " -include-runtime -d \"" .. output .. ".jar\" " .. arguments .. -- compile bytecode (jar) " && java -jar \"" .. output .. ".jar\"" .. -- run " && echo \"" .. entry_point .. "\"" .. -- echo @@ -173,8 +183,8 @@ function M.action(selected_option) name = "- Kotlin compiler", strategy = { "orchestrator", tasks = {{ name = "- Build program (jar) → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true " .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm_file .. "\"" .. output .. "*.class\" " .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && kotlinc " .. files .. " -include-runtime -d \"" .. output .. ".jar\" " .. arguments .. -- compile bytecode (jar) " && echo \"" .. entry_point .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", @@ -211,8 +221,8 @@ function M.action(selected_option) output_dir = utils.os_path(output:match("^(.-[/\\])[^/\\]*$")) arguments = variables.arguments or arguments -- optional task = { name = "- Build program (jar) → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true " .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm_file .. "\"" .. output .. "*.class\" " .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && kotlinc " .. files .. " -include-runtime -d \"" .. output .. "\" " .. arguments .. -- compile bytecode (jar) " && echo \"" .. entry_point .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", @@ -254,8 +264,8 @@ function M.action(selected_option) output_dir = utils.os_path(entry_point:match("^(.-[/\\])[^/\\]*$") .. "bin") -- entry_point/bin output = utils.os_path(output_dir .. "/Main") -- entry_point/bin/MainKt.jar task = { name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true " .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm_file .. "\"" .. output .. "*.class\" " .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && kotlinc " .. files .. " -include-runtime -d \"" .. output .. ".jar\" " .. arguments .. -- compile bytecode (jar) " && echo \"" .. entry_point .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", diff --git a/lua/compiler/languages/python.lua b/lua/compiler/languages/python.lua index 88d51098..7beb1cf8 100644 --- a/lua/compiler/languages/python.lua +++ b/lua/compiler/languages/python.lua @@ -29,15 +29,16 @@ M.options = { function M.action(selected_option) local utils = require("compiler.utils") local overseer = require("overseer") - local current_file = utils.os_path(vim.fn.expand('%:p'), true) -- current file - local entry_point = utils.os_path(vim.fn.getcwd() .. "/main.py") -- working_directory/main.py - local files = utils.find_files_to_compile(entry_point, "*.py") -- *.py files under entry_point_dir (recursively) - local output_dir = utils.os_path(vim.fn.getcwd() .. "/bin/") -- working_directory/bin/ - local output = utils.os_path(vim.fn.getcwd() .. "/bin/program") -- working_directory/bin/program + local current_file = utils.os_path(vim.fn.expand('%:p'), true) -- current file + local entry_point = utils.os_path(vim.fn.getcwd() .. "/main.py") -- working_directory/main.py + local files = utils.find_files_to_compile(entry_point, "*.py") -- *.py files under entry_point_dir (recursively) + local output_dir = utils.os_path(vim.fn.getcwd() .. "/bin/") -- working_directory/bin/ + local output = utils.os_path(vim.fn.getcwd() .. "/bin/program", false, true) -- working_directory/bin/program local final_message = "--task finished--" -- For python, arguments are not globally defined, -- as we have 3 different ways to run the code. + local rm, mkdir, ignore_err = utils.get_commands() --=========================== INTERPRETED =================================-- if selected_option == "option1" then @@ -148,8 +149,8 @@ function M.action(selected_option) name = "- Python machine code compiler", strategy = { "orchestrator", tasks = {{ name = "- Build & run program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm .. "\"" .. output .. "\"" .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && nuitka --no-pyi-file --remove-output --follow-imports" .. -- compile to machine code " --output-filename=\"" .. output .. "\"" .. " " .. arguments .. " " .. "\"" .. entry_point .. "\"" .. @@ -165,8 +166,8 @@ function M.action(selected_option) name = "- Python machine code compiler", strategy = { "orchestrator", tasks = {{ name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm .. "\"" .. output .. "\"" .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && nuitka --no-pyi-file --remove-output --follow-imports" .. -- compile to machine code " --output-filename=\"" .. output .. "\"" .. " " .. arguments .. " \"" .. entry_point .. "\"" .. @@ -204,8 +205,8 @@ function M.action(selected_option) output_dir = utils.os_path(output:match("^(.-[/\\])[^/\\]*$")) local arguments = variables.arguments or "--warn-implicit-exceptions --warn-unusual-code" -- optional task = { name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm .. "\"" .. output .. "\"" .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && nuitka --no-pyi-file --remove-output --follow-imports" .. -- compile to machine code " --output-filename=\"" .. output .. "\"" .. " " .. arguments .. " \"" .. entry_point .. "\"" .. @@ -249,8 +250,8 @@ function M.action(selected_option) output = utils.os_path(output_dir .. "/program") -- entry_point/bin/program local arguments = "--warn-implicit-exceptions --warn-unusual-code" -- optional task = { name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm .. "\"" .. output .. "\"" .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir " && nuitka --no-pyi-file --remove-output --follow-imports" .. -- compile to machine code " --output-filename=\"" .. output .. "\"" .. " " .. arguments .. " \"" .. entry_point .. "\"" .. @@ -281,15 +282,18 @@ function M.action(selected_option) --============================ BYTECODE ===================================-- elseif selected_option == "option8" then local cache_dir = utils.os_path(vim.fn.stdpath "cache" .. "/compiler/pyinstall/") + -- HACK: cache and output dir need to have forward slashes, or else pyinstaller errors + cache_dir = cache_dir:gsub("\\", "/") + output_dir = output_dir:gsub("\\", "/") local output_filename = vim.fn.fnamemodify(output, ":t") local arguments = "--log-level WARN --python-option W" -- optional local task = overseer.new_task({ name = "- Python bytecode compiler", strategy = { "orchestrator", tasks = {{ name = "- Build & run program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && mkdir -p \"" .. cache_dir .. "\"" .. + cmd = rm .. "\"" .. output .. "\"" .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir + " && " .. mkdir .. "\"" .. cache_dir .. "\"" .. ignore_err .. " && pyinstaller " .. files .. -- compile to bytecode " --name " .. output_filename .. " --workpath \"" .. cache_dir .. "\"" .. @@ -303,15 +307,18 @@ function M.action(selected_option) task:start() elseif selected_option == "option9" then local cache_dir = utils.os_path(vim.fn.stdpath "cache" .. "/compiler/pyinstall/") + -- HACK: cache and output dir need to have forward slashes, or else pyinstaller errors + cache_dir = cache_dir:gsub("\\", "/") + output_dir = output_dir:gsub("\\", "/") local output_filename = vim.fn.fnamemodify(output, ":t") local arguments = "--log-level WARN --python-option W" -- optional local task = overseer.new_task({ name = "- Python bytecode compiler", strategy = { "orchestrator", tasks = {{ name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && mkdir -p \"" .. cache_dir .. "\"" .. + cmd = rm .. "\"" .. output .. "\"" .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir + " && " .. mkdir .. "\"" .. cache_dir .. "\"" .. ignore_err .. " && pyinstaller " .. files .. -- compile to bytecode " --name " .. output_filename .. " --workpath \"" .. cache_dir .. "\"" .. @@ -352,11 +359,14 @@ function M.action(selected_option) output = utils.os_path(variables.output) local output_filename = vim.fn.fnamemodify(output, ":t") output_dir = utils.os_path(output:match("^(.-[/\\])[^/\\]*$")) + -- HACK: cache and output dir need to have forward slashes, or else pyinstaller errors + cache_dir = cache_dir:gsub("\\", "/") + output_dir = output_dir:gsub("\\", "/") local arguments = variables.arguments or "--log-level WARN --python-option W" -- optional task = { name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && mkdir -p \"" .. cache_dir .. "\"" .. + cmd = rm .. "\"" .. output .. "\"" .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir + " && " .. mkdir .. "\"" .. cache_dir .. "\"" .. ignore_err .. " && pyinstaller " .. files .. -- compile to bytecode " --name " .. output_filename .. " --workpath \"" .. cache_dir .. "\"" .. @@ -402,11 +412,14 @@ function M.action(selected_option) output_dir = utils.os_path(entry_point:match("^(.-[/\\])[^/\\]*$") .. "bin") -- entry_point/bin output = utils.os_path(output_dir .. "/program") -- entry_point/bin/program local cache_dir = utils.os_path(vim.fn.stdpath "cache" .. "/compiler/pyinstall/") + -- HACK: cache and output dir need to have forward slashes, or else pyinstaller errors + cache_dir = cache_dir:gsub("\\", "/") + output_dir = output_dir:gsub("\\", "/") local output_filename = vim.fn.fnamemodify(output, ":t") local arguments = "--log-level WARN --python-option W" -- optional task = { name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. cache_dir .. "\"" .. -- mkdir + cmd = rm .. "\"" .. output .. "\"" .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. cache_dir .. "\"" .. ignore_err .. -- mkdir " && pyinstaller " .. files .. -- compile to bytecode " --name " .. output_filename .. " --workpath \"" .. cache_dir .. "\"" .. diff --git a/lua/compiler/languages/rust.lua b/lua/compiler/languages/rust.lua index c60b351e..da8a33be 100644 --- a/lua/compiler/languages/rust.lua +++ b/lua/compiler/languages/rust.lua @@ -21,19 +21,21 @@ M.options = { function M.action(selected_option) local utils = require("compiler.utils") local overseer = require("overseer") - local entry_point = utils.os_path(vim.fn.getcwd() .. "/main.rs", true) -- working_directory/main.rs - local output_dir = utils.os_path(vim.fn.getcwd() .. "/bin/", true) -- working_directory/bin/ - local output = utils.os_path(vim.fn.getcwd() .. "/bin/program", true) -- working_directory/bin/program - local arguments = "-D warnings -g" -- arguments can be overriden in .solution + local entry_point = utils.os_path(vim.fn.getcwd() .. "/main.rs", true) -- working_directory/main.rs + local output_dir = utils.os_path(vim.fn.getcwd() .. "/bin/", true) -- working_directory/bin/ + local output = utils.os_path(vim.fn.getcwd() .. "/bin/program", true, true) -- working_directory/bin/program + local arguments = "-D warnings -g" -- arguments can be overriden in .solution local final_message = "--task finished--" + local rm, mkdir, ignore_err = utils.get_commands() + if selected_option == "option1" then local task = overseer.new_task({ name = "- Rust compiler", strategy = { "orchestrator", tasks = {{ name = "- Build & run program → " .. entry_point, - cmd = "rm -f " .. output .. " || true" .. -- clean - " && mkdir -p " .. output_dir .. -- mkdir + cmd = rm .. output .. ignore_err .. -- clean + " && " .. mkdir .. output_dir .. ignore_err .. -- mkdir " && rustc " .. entry_point .. " -o " .. output .. " " .. arguments .. -- compile " && " .. output .. -- run " && echo " .. entry_point .. -- echo @@ -46,8 +48,8 @@ function M.action(selected_option) name = "- Rust compiler", strategy = { "orchestrator", tasks = {{ name = "- Build program → " .. entry_point, - cmd = "rm -f " .. output .. " || true" .. -- clean - " && mkdir -p " .. output_dir .. -- mkdir + cmd = rm .. output .. ignore_err .. -- clean + " && " .. mkdir .. output_dir .. ignore_err .. -- mkdir " && rustc " .. entry_point .. " -o " .. output .. " " .. arguments .. -- compile " && echo " .. entry_point .. -- echo " && echo \"" .. final_message .. "\"", @@ -79,12 +81,12 @@ function M.action(selected_option) for entry, variables in pairs(config) do if entry == "executables" then goto continue end entry_point = utils.os_path(variables.entry_point) - output = utils.os_path(variables.output) + output = utils.os_path(variables.output, false, true) output_dir = utils.os_path(output:match("^(.-[/\\])[^/\\]*$")) arguments = variables.arguments or arguments -- optional task = { name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir + cmd = rm .. output .. ignore_err .. -- clean + " && " .. mkdir .. output_dir .. ignore_err .. -- mkdir " && rustc \"" .. entry_point .. "\" -o \"" .. output .. "\" " .. arguments .. -- compile " && echo \"" .. entry_point .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", @@ -97,7 +99,7 @@ function M.action(selected_option) local solution_executables = config["executables"] if solution_executables then for entry, executable in pairs(solution_executables) do - executable = utils.os_path(executable, true) + executable = utils.os_path(executable, true, true) task = { name = "- Run program → " .. executable, cmd = executable .. -- run " && echo " .. executable .. -- echo @@ -121,14 +123,14 @@ function M.action(selected_option) entry_points = utils.find_files(vim.fn.getcwd(), "main.rs") for _, entry_point in ipairs(entry_points) do - entry_point = utils.os_path(entry_point) - output_dir = utils.os_path(entry_point:match("^(.-[/\\])[^/\\]*$") .. "bin") -- entry_point/bin - output = utils.os_path(output_dir .. "/program") -- entry_point/bin/program - task = { name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && rustc \"" .. entry_point .. "\" -o \"" .. output .. "\" " .. arguments .. -- compile - " && echo \"" .. entry_point .. "\"" .. -- echo + entry_point = utils.os_path(entry_point, true) + output_dir = utils.os_path(entry_point:match("^(.-[/\\])[^/\\]*$") .. "bin", true) -- entry_point/bin + output = utils.os_path(output_dir .. "/program", true, true) -- entry_point/bin/program + task = { name = "- Build program → " .. entry_point, + cmd = rm .. output .. ignore_err .. -- clean + " && " .. mkdir .. output_dir .. ignore_err .. -- mkdir + " && rustc " .. entry_point .. " -o " .. output .. " " .. arguments .. -- compile + " && echo " .. entry_point .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } } diff --git a/lua/compiler/languages/swift.lua b/lua/compiler/languages/swift.lua index c8d016c0..3927f3f3 100644 --- a/lua/compiler/languages/swift.lua +++ b/lua/compiler/languages/swift.lua @@ -20,24 +20,25 @@ M.options = { function M.action(selected_option) local utils = require("compiler.utils") local overseer = require("overseer") - local entry_point = utils.os_path(vim.fn.getcwd() .. "/main.swift") -- working_directory/main.swift - local files = utils.find_files_to_compile(entry_point, "*.swift") -- *.swift files under entry_point_dir (recursively) - local output_dir = utils.os_path(vim.fn.getcwd() .. "/bin/") -- working_directory/bin/ - local output = utils.os_path(vim.fn.getcwd() .. "/bin/program") -- working_directory/bin/program - local arguments = "-warn-swift3-objc-inference-minimal -g" -- arguments can be overriden in .solution + local entry_point = utils.os_path(vim.fn.getcwd() .. "/main.swift") -- working_directory/main.swift + local files = utils.find_files_to_compile(entry_point, "*.swift") -- *.swift files under entry_point_dir (recursively) + local output_dir = utils.os_path(vim.fn.getcwd() .. "/bin/") -- working_directory/bin/ + local output = utils.os_path(vim.fn.getcwd() .. "/bin/program", true, true) -- working_directory/bin/program + local arguments = "-warn-swift3-objc-inference-minimal -g" -- arguments can be overriden in .solution local final_message = "--task finished--" + local rm, mkdir, ignore_err = utils.get_commands() if selected_option == "option1" then local task = overseer.new_task({ name = "- Swift compiler", strategy = { "orchestrator", tasks = {{ name = "- Build & run program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && swiftc " .. files .. " -o \"" .. output .. "\" " .. arguments .. -- compile - " && \"" .. output .. "\"" .. -- run - " && echo \"" .. entry_point .. "\"" .. -- echo + cmd = rm .. output .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir + " && swiftc " .. files .. " -o " .. output .. " " .. arguments .. -- compile + " && " .. output .. -- run + " && echo \"" .. entry_point .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } },},},}) @@ -47,10 +48,10 @@ function M.action(selected_option) name = "- Swift compiler", strategy = { "orchestrator", tasks = {{ name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && swiftc " .. files .. " -o \"" .. output .. "\" " .. arguments .. -- compile - " && echo \"" .. entry_point .. "\"" .. -- echo + cmd = rm .. output .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir + " && swiftc " .. files .. " -o " .. output .. " " .. arguments .. -- compile + " && echo \"" .. entry_point .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } },},},}) @@ -59,9 +60,9 @@ function M.action(selected_option) local task = overseer.new_task({ name = "- Swift compiler", strategy = { "orchestrator", - tasks = {{ name = "- Run program → \"" .. output .. "\"", - cmd = "\"" .. output .. "\"" .. -- run - " && echo \"" .. output .. "\"" .. -- echo + tasks = {{ name = "- Run program → " .. output, + cmd = output .. -- run + " && echo " .. output .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } },},},}) @@ -81,14 +82,14 @@ function M.action(selected_option) if entry == "executables" then goto continue end entry_point = utils.os_path(variables.entry_point) files = utils.find_files_to_compile(entry_point, "*.swift") - output = utils.os_path(variables.output) + output = utils.os_path(variables.output, true, true) output_dir = utils.os_path(output:match("^(.-[/\\])[^/\\]*$")) arguments = variables.arguments or arguments -- optional task = { name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && swiftc " .. files .. " -o \"" .. output .. "\" " .. arguments .. -- compile - " && echo \"" .. entry_point .. "\"" .. -- echo + cmd = rm .. output .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir + " && swiftc " .. files .. " -o " .. output .. " " .. arguments .. -- compile + " && echo \"" .. entry_point .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } } @@ -99,7 +100,7 @@ function M.action(selected_option) local solution_executables = config["executables"] if solution_executables then for entry, executable in pairs(solution_executables) do - executable = utils.os_path(executable, true) + executable = utils.os_path(executable, true, true) task = { name = "- Run program → " .. executable, cmd = executable .. -- run " && echo " .. executable .. -- echo @@ -126,11 +127,11 @@ function M.action(selected_option) entry_point = utils.os_path(entry_point) files = utils.find_files_to_compile(entry_point, "*.swift") output_dir = utils.os_path(entry_point:match("^(.-[/\\])[^/\\]*$") .. "bin") -- entry_point/bin - output = utils.os_path(output_dir .. "/program") -- entry_point/bin/program + output = utils.os_path(output_dir .. "/program", true, true) -- entry_point/bin/program task = { name = "- Build program → \"" .. entry_point .. "\"", - cmd = "rm -f \"" .. output .. "\" || true" .. -- clean - " && mkdir -p \"" .. output_dir .. "\"" .. -- mkdir - " && swiftc " .. files .. " -o \"" .. output .. "\" " .. arguments .. -- compile + cmd = rm .. output .. ignore_err .. -- clean + " && " .. mkdir .. "\"" .. output_dir .. "\"" .. ignore_err .. -- mkdir + " && swiftc " .. files .. " -o " .. output .. " " .. arguments .. -- compile " && echo \"" .. entry_point .. "\"" .. -- echo " && echo \"" .. final_message .. "\"", components = { "default_extended" } diff --git a/lua/compiler/utils-bau.lua b/lua/compiler/utils-bau.lua index 195ec188..b4c32d6e 100644 --- a/lua/compiler/utils-bau.lua +++ b/lua/compiler/utils-bau.lua @@ -8,7 +8,6 @@ local M = {} local utils = require("compiler.utils") - -- PARSERS -- Private functions to parse bau files. -- ============================================================================ @@ -30,7 +29,7 @@ local function get_makefile_opts(path) -- Iterate through each line in the Makefile for line in file:lines() do -- Check for lines starting with a target rule (e.g., "target: dependencies") - local target = line:match "^(.-):" + local target = line:match("^(.-):") if target then in_target = true -- Exclude the ":" and add the option to the list with text and value fields @@ -117,6 +116,110 @@ local function get_meson_opts(path) return options end +---Given an MSBuild sln file, +---find all build targets and return them as a table. +---@param paths table Table of file paths, like this: { "./a.sln", "./b.sln" } +---@return table options A table like: +--- { { text: "MSBuild Build (Debug)", value="-t:Build -p:Configuration=Debug", bau = "msbuild"}, { text: "MSBuild Clean (Release)", value="-t:Build -p:Configuration=Release", bau = "msbuild" } ...} +function M.get_msbuild_opts(paths) + local options = {} + + local multiple_sln = #paths > 1 + + -- find configurations in each sln and build the output table + for _, path in pairs(paths) do + -- open the sln for reading + local file = io.open(path, "r") + + if file then + local in_configs = false + local configs = {} + + -- iterate through each line in the sln + for line in file:lines() do + -- check if we are in the configuration section + if line:match("^\tGlobalSection%(SolutionConfigurationPlatforms%).*") then + -- check if we've exited the section containing the configurations + in_configs = true + goto nextline + elseif line:match("^\tEndGlobalSection$") then + -- we've read all configurations + in_configs = false + goto finish + end + + -- stop if we aren't reading configurations + if not in_configs then + goto nextline + end + + -- get the configuration name from the current line + local config = line:gsub("^\t\t([a-zA-Z]+).*$", "%1") + + -- add to configs in a way that deduplicates the results + configs[config] = 1 + + ::nextline:: + end + ::finish:: + -- close the sln + file:close() + + -- copy out the keys from the table, we don't care about the values (they're all 1) + configs = vim.tbl_keys(configs) + + ---returns an entry table, given the parameters to generate it + ---@param projname string A string (needs to be surrounded by spaces) + ---@param target table A table of strings that are the target names (eg. { "Build", "Run" }) + ---@param config string The name of the configuration to build + ---@return table option An entry in an options table + local format_entry = function (projname, target, config) + local targetflags = '-t:' .. target[1] + local targetname = target[1] + -- handle multiple targets + for i = 2, #target do + local t = target[i] + targetflags = targetflags .. ' -t:' .. t + targetname = targetname .. ' and ' .. t + end + + return { + text = "MSBuild: " .. targetname .. projname .. "(" .. config .. ")", + value = targetflags .. " -p:Configuration=" .. config, + bau = "msbuild", + } + end + + -- remove release configs if there are others + if #configs > 1 then + for idx, config in pairs(configs) do + if config == "Release" then + table.remove(configs, idx) + end + end + end + + -- include project name if there are multiple sln files + local projname = ' ' + if multiple_sln then + projname = " " .. vim.fs.basename(path):gsub("%.sln$", "") .. " " + end + + -- Every MSBuild project gets these targets automatically + local targets = { { "Build" }, { "Run" }, { "Build", "Run" }, { "Clean" } } + + -- Append each option to the table + for _,config in pairs(configs) do + for _,target in pairs(targets) do + table.insert(options, format_entry(projname, target, config)) + end + end + end + end + + return options +end + ---If a gradle.build.kts or gradle.build file exists, ---parse the result of the command `gradle tasks`. --- @@ -128,13 +231,18 @@ end local function get_gradle_cmd_opts(path) -- guard clause local gradle_kts_file_exists = vim.fn.filereadable(path) == 1 - local gradle_file_exists = vim.fn.filereadable(vim.fn.fnamemodify(path, ':t:r')) == 1 + local gradle_file_exists = vim.fn.filereadable( + vim.fn.fnamemodify(path, ":t:r") + ) == 1 if not gradle_kts_file_exists and not gradle_file_exists then return {} end -- parse local GRADLE_CMD = "gradle tasks" - local UNIX_CMD = GRADLE_CMD .. " | awk '/Application tasks/,/^$/{if (!/^$/) print}' | awk 'NR > 2' | awk '!/--/ && NF {gsub(/ .*/, \"\", $0); print}' | sed '/^$/d'" - local WINDOWS_CMD = "powershell -c \"" .. GRADLE_CMD .. [[ | Out-String | Select-String -Pattern '(?sm)Application tasks(.*?)(?:\r?\n){2}' | ForEach-Object { $_.Matches.Groups[1].Value -split '\r?\n' | ForEach-Object -Begin { $skip = $true } { if (-not $skip) { ($_ -split '\s+', 2)[0] } $skip = $false } | Where-Object { $_ -notmatch '--' -and $_.Trim() -ne '' } }"]] + local UNIX_CMD = GRADLE_CMD + .. " | awk '/Application tasks/,/^$/{if (!/^$/) print}' | awk 'NR > 2' | awk '!/--/ && NF {gsub(/ .*/, \"\", $0); print}' | sed '/^$/d'" + local WINDOWS_CMD = 'powershell -c "' + .. GRADLE_CMD + .. [[ | Out-String | Select-String -Pattern '(?sm)Application tasks(.*?)(?:\r?\n){2}' | ForEach-Object { $_.Matches.Groups[1].Value -split '\r?\n' | ForEach-Object -Begin { $skip = $true } { if (-not $skip) { ($_ -split '\s+', 2)[0] } $skip = $false } | Where-Object { $_ -notmatch '--' -and $_.Trim() -ne '' } }"]] local options = {} local cmd_output = "" local is_windows = os.getenv("OS") == "Windows_NT" @@ -158,7 +266,6 @@ local function get_gradle_cmd_opts(path) return options end - ---Given a build.gradle.kts file, parse all the tasks, ---and return them as a table. --- @@ -203,10 +310,11 @@ local function get_gradle_opts(path) if task_match then in_task = true task_name = task_match - table.insert( - options, - { text = "Gradle " .. task_name, value = task_name, bau = "gradle" } - ) + table.insert(options, { + text = "Gradle " .. task_name, + value = task_name, + bau = "gradle", + }) elseif in_task then local task_end = line:match("}") if task_end then @@ -236,7 +344,7 @@ local function get_nodejs_opts(path) local file = io.open(path, "r") if file then - local content = file:read "*all" + local content = file:read("*all") file:close() -- parse package.json @@ -252,30 +360,24 @@ local function get_nodejs_opts(path) -- Global: NODEJS_PACKAGE_MANAGER local success, package_manager = - pcall(vim.api.nvim_get_var, "NODEJS_PACKAGE_MANAGER") + pcall(vim.api.nvim_get_var, "NODEJS_PACKAGE_MANAGER") if not success or package_manager == "" then package_manager = "npm" end -- Add parsed options to table "options" local scripts = package_json.scripts if scripts then -- Hardcode install/uninstall scripts - table.insert( - options, - { - text = package_manager:upper() .. " install", - value = package_manager .. " install", - bau = "nodejs", - } - ) + table.insert(options, { + text = package_manager:upper() .. " install", + value = package_manager .. " install", + bau = "nodejs", + }) if package_manager == "npm" then - table.insert( - options, - { - text = package_manager:upper() .. " uninstall *", - value = package_manager .. " uninstall *", - bau = "nodejs", - } - ) + table.insert(options, { + text = package_manager:upper() .. " uninstall *", + value = package_manager .. " uninstall *", + bau = "nodejs", + }) end -- Afterwards, add the scripts from package.json @@ -292,7 +394,6 @@ local function get_nodejs_opts(path) return options end - -- FRONTEND -- Public functions to call from the frontend. -- ============================================================================ @@ -320,6 +421,11 @@ function M.get_bau_opts() working_dir .. utils.os_path("/meson.build") )) + -- msbuild + vim.list_extend(options, M.get_msbuild_opts( + vim.fn.globpath(working_dir, "*.sln", true, true, true) + )) + -- gradle vim.list_extend(options, get_gradle_cmd_opts( working_dir .. utils.os_path("/build.gradle.kts") @@ -343,14 +449,15 @@ end function M.require_bau(bau) local local_path = debug.getinfo(1, "S").source:sub(2) local local_path_dir = local_path:match("(.*[/\\])") - local module_file_path = utils.os_path(local_path_dir .. "bau/" .. bau .. ".lua") + local module_file_path = + utils.os_path(local_path_dir .. "bau/" .. bau .. ".lua") local success, bau = pcall(dofile, module_file_path) if success then return bau else -- local error = "Build automation utilities \"" .. bau .. "\" not supported by the compiler." - -- vim.notify(error, vim.log.levels.INFO, { title = "Build automation utilities unsupported" }) + -- vim.notify(error, vim.log.levels.INFO, title = "Build automation utilities unsupported" ) return nil end end diff --git a/lua/compiler/utils.lua b/lua/compiler/utils.lua index 03afd0b8..70a0629e 100644 --- a/lua/compiler/utils.lua +++ b/lua/compiler/utils.lua @@ -18,7 +18,7 @@ function M.find_files(start_dir, file_name, surround) -- Create the find command with appropriate flags for recursive searching local find_command if string.sub(package.config, 1, 1) == "\\" then -- Windows - find_command = string.format('powershell.exe -Command "Get-ChildItem -Path \\"%s\\" -Recurse -Filter \\"%s\\" -File -Exclude \\".git\\" -ErrorAction SilentlyContinue"', start_dir, file_name) + find_command = string.format('powershell.exe -Command "Get-ChildItem -Path \\"%s\\" -Recurse -Filter \\"%s\\" -File -Exclude \\".git\\" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName"', start_dir, file_name, start_dir) else -- UNIX-like systems find_command = string.format('find "%s" -type d -name ".git" -prune -o -type f -name "%s" -print 2>/dev/null', start_dir, file_name) end @@ -150,13 +150,23 @@ end ---This way the shell will be able to detect spaces in the path. ---@param path string A path string. ---@param surround boolean|nil If true, surround path by "". False by default. +---@param exe boolean|nil If true, add .exe to path when on windows ---@return string|nil,nil path A path string formatted for the current OS. -function M.os_path(path, surround) +function M.os_path(path, surround, exe) if path == nil then return nil end if surround == nil then surround = false end + if exe == nil then exe = false end + + path = path:gsub("\"", "") -- Remove all " local separator = string.sub(package.config, 1, 1) + if exe and string.sub(package.config, 1, 1) == "\\" then -- Windows + if path:sub(-4) ~= ".exe" then + path = path .. ".exe" + end + end + if surround then path = '"' .. path .. '"' end @@ -172,4 +182,27 @@ function M.get_tests_dir(path_to_append) return M.os_path(plugin_dir .. "/tests/" .. path_to_append) end +---Gives you the correct commands for `rm`, `mkdir` and ignoring errors (`|| true` on unix) +---for the current OS. +---@usage local rm, mkdir, ignore_error = get_commands() +---@return string rm_file A command equivalent to `rm -f` for files +---@return string mkdir A command equivalent to `mkdir -p` +---@return string ignore_error The construct to ignore an error from the previous command +function M.get_commands() + local commands = {} + -- Unix versions + commands.rm = "rm -f " + commands.mkdir = "mkdir -p " + commands.ignore_error = " || true" + + if string.sub(package.config, 1, 1) == "\\" then -- Windows + commands.rm = "erase /f /q " + -- commands.rm_dir = "rd /s /q " + commands.mkdir = "mkdir " + commands.ignore_error = " > nul 2> nul & cd." -- rd and mkdir print errors, which we redirect to nul, so they don't show up and with '& cd.' we always get a success return code + end + + return commands.rm, commands.mkdir, commands.ignore_error +end + return M