From 5ff30bcb99a8a7f293dca5c9005bcb3f7ec2cce4 Mon Sep 17 00:00:00 2001 From: Gaweringo <40121865+Gaweringo@users.noreply.github.com> Date: Wed, 12 Jun 2024 11:49:10 +0200 Subject: [PATCH 01/17] feat: make commands windows compatible --- lua/compiler/utils.lua | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lua/compiler/utils.lua b/lua/compiler/utils.lua index 03afd0b8..dfb9b032 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 @@ -157,6 +157,12 @@ function M.os_path(path, surround) 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 +178,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 From 8f98f48647507d8487e0bcefbddd4976b0fbd4ec Mon Sep 17 00:00:00 2001 From: Gaweringo <40121865+Gaweringo@users.noreply.github.com> Date: Sun, 22 Sep 2024 18:25:52 +0200 Subject: [PATCH 02/17] feat: add ability to automatically add .exe to os_path on windows --- lua/compiler/utils.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lua/compiler/utils.lua b/lua/compiler/utils.lua index dfb9b032..70a0629e 100644 --- a/lua/compiler/utils.lua +++ b/lua/compiler/utils.lua @@ -150,10 +150,14 @@ 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) From ff47ef448c025895c17c7a6ecd3d93140e15daa5 Mon Sep 17 00:00:00 2001 From: Gaweringo <40121865+Gaweringo@users.noreply.github.com> Date: Mon, 16 Sep 2024 04:33:44 +0200 Subject: [PATCH 03/17] feat(asm): add windows support to asm --- lua/compiler/languages/asm.lua | 122 +++++++++++++++++---------------- 1 file changed, 63 insertions(+), 59 deletions(-) diff --git a/lua/compiler/languages/asm.lua b/lua/compiler/languages/asm.lua index a6c244af..cf090252 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 @@ -197,7 +201,7 @@ function M.action(selected_option) 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 = utils.os_path(output_dir .. "/program", true, true) -- entry_point/bin/program -- Build .asm files in parallel local tasks_compile = {} @@ -205,11 +209,11 @@ function M.action(selected_option) local filename = vim.fn.fnamemodify(file, ":t") local output_o = output_dir .. filename .. ".o" 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" } } From 27c73cf3af4b07f8f185e900af075773a40b2f1e Mon Sep 17 00:00:00 2001 From: Gaweringo <40121865+Gaweringo@users.noreply.github.com> Date: Mon, 16 Sep 2024 04:34:23 +0200 Subject: [PATCH 04/17] feat(c): add windows support to c --- lua/compiler/languages/c.lua | 47 +++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 22 deletions(-) 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 From 5d68358bee1789cf7fdbeeff7ef52076f1a05b9a Mon Sep 17 00:00:00 2001 From: Gaweringo <40121865+Gaweringo@users.noreply.github.com> Date: Mon, 16 Sep 2024 04:34:41 +0200 Subject: [PATCH 05/17] feat(cpp): add windows support to cpp --- lua/compiler/languages/cpp.lua | 46 ++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 21 deletions(-) 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 From f50eb609f7c442d499500c5827e2b1d746525776 Mon Sep 17 00:00:00 2001 From: Gaweringo <40121865+Gaweringo@users.noreply.github.com> Date: Mon, 16 Sep 2024 04:35:01 +0200 Subject: [PATCH 06/17] feat(cs): add windows support to cs --- lua/compiler/languages/cs.lua | 52 +++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 24 deletions(-) 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 From e25603a7f7e5b27ec827f80c9a9bd0037c60a280 Mon Sep 17 00:00:00 2001 From: Gaweringo <40121865+Gaweringo@users.noreply.github.com> Date: Tue, 17 Sep 2024 00:52:12 +0200 Subject: [PATCH 07/17] feat(dart): add windows support to dart --- lua/compiler/languages/dart.lua | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) 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 .. "\"", From 15cc4cc5de56750a414aa361039560c145c5186f Mon Sep 17 00:00:00 2001 From: Gaweringo <40121865+Gaweringo@users.noreply.github.com> Date: Sun, 22 Sep 2024 18:35:48 +0200 Subject: [PATCH 08/17] feat(go): add windows support to go --- lua/compiler/languages/go.lua | 53 ++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 25 deletions(-) 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" } } From 518302156ed473c4dda078f86522344845babe39 Mon Sep 17 00:00:00 2001 From: Gaweringo <40121865+Gaweringo@users.noreply.github.com> Date: Mon, 23 Sep 2024 02:51:15 +0200 Subject: [PATCH 09/17] feat(java): add windows support to java --- lua/compiler/languages/java.lua | 64 ++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 24 deletions(-) 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" } } From cc73b6e98cf69fbfb846b804f92b9ff59c85eae3 Mon Sep 17 00:00:00 2001 From: Gaweringo <40121865+Gaweringo@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:33:35 +0200 Subject: [PATCH 10/17] feat(kotlin): add windows support to kotlin --- lua/compiler/languages/kotlin.lua | 42 +++++++++++++++++++------------ 1 file changed, 26 insertions(+), 16 deletions(-) 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 .. "\"", From 4a5713242d0b023659f1d82beb2d215d752017a9 Mon Sep 17 00:00:00 2001 From: Gaweringo <40121865+Gaweringo@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:08:35 +0200 Subject: [PATCH 11/17] feat(python): add windows support to python --- lua/compiler/languages/python.lua | 61 +++++++++++++++++++------------ 1 file changed, 37 insertions(+), 24 deletions(-) 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 .. "\"" .. From 206d135996cda7d0b3170fc2871c8101a6a6c5a2 Mon Sep 17 00:00:00 2001 From: Gaweringo <40121865+Gaweringo@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:34:06 +0200 Subject: [PATCH 12/17] feat(rust): add windows support to rust --- lua/compiler/languages/rust.lua | 42 +++++++++++++++++---------------- 1 file changed, 22 insertions(+), 20 deletions(-) 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" } } From 2aaeaa79e7abd0be4c6d3f13374e578393589ccc Mon Sep 17 00:00:00 2001 From: Gaweringo <40121865+Gaweringo@users.noreply.github.com> Date: Mon, 23 Sep 2024 20:29:33 +0200 Subject: [PATCH 13/17] feat(swift): add windows support to swift --- lua/compiler/languages/swift.lua | 55 ++++++++++++++++---------------- 1 file changed, 28 insertions(+), 27 deletions(-) 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" } From e1900481f8ad2335d0a20d14c9c6f93056e4ecfe Mon Sep 17 00:00:00 2001 From: Gaweringo <40121865+Gaweringo@users.noreply.github.com> Date: Mon, 23 Sep 2024 21:12:34 +0200 Subject: [PATCH 14/17] feat(cmake): add windows support to cmake --- lua/compiler/bau/cmake.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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" } },},},}) From 2db0b4a49b92530c0fd941e874efc15a06b00956 Mon Sep 17 00:00:00 2001 From: Gaweringo <40121865+Gaweringo@users.noreply.github.com> Date: Mon, 23 Sep 2024 21:12:51 +0200 Subject: [PATCH 15/17] feat(meson): add windows support to meson --- lua/compiler/bau/meson.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 From 8a6328b2b9a30403bccf7cf9679f744c1ba17954 Mon Sep 17 00:00:00 2001 From: Gaweringo <40121865+Gaweringo@users.noreply.github.com> Date: Mon, 23 Sep 2024 22:39:08 +0200 Subject: [PATCH 16/17] feat(fortran): add windows support to fortran --- lua/compiler/languages/fortran.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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" } },},},}) From 22da8fd5b0daf99ce4ceabd3c5ee7d541fc2ce65 Mon Sep 17 00:00:00 2001 From: Gaweringo <40121865+Gaweringo@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:49:23 +0200 Subject: [PATCH 17/17] fixup! feat(asm): add windows support to asm --- lua/compiler/languages/asm.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lua/compiler/languages/asm.lua b/lua/compiler/languages/asm.lua index cf090252..a69c928a 100644 --- a/lua/compiler/languages/asm.lua +++ b/lua/compiler/languages/asm.lua @@ -79,10 +79,10 @@ function M.action(selected_option) local output_o = utils.os_path(output_dir .. filename .. ".o", true) file = utils.os_path(file, true) 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 + 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" } } @@ -200,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", true, true) -- 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 = { "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 + 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" } }