From 15cd12091e46410d486c482aafcae3cdc281189a Mon Sep 17 00:00:00 2001 From: Zeioth Date: Tue, 22 Aug 2023 06:09:54 +0200 Subject: [PATCH] feat(.solution.toml): Now accept multiple ocurrences of `executable`. --- lua/compiler/languages/asm.lua | 33 +++++------ lua/compiler/languages/c.lua | 35 ++++++------ lua/compiler/languages/cpp.lua | 31 +++++------ lua/compiler/languages/cs.lua | 31 +++++------ lua/compiler/languages/go.lua | 31 +++++------ lua/compiler/languages/java.lua | 33 +++++------ lua/compiler/languages/lua.lua | 20 ++++++- lua/compiler/languages/perl.lua | 20 ++++++- lua/compiler/languages/python.lua | 92 ++++++++++++++++++------------- lua/compiler/languages/ruby.lua | 20 ++++++- lua/compiler/languages/rust.lua | 37 ++++++------- lua/compiler/languages/sh.lua | 44 ++++++++++----- 12 files changed, 249 insertions(+), 178 deletions(-) diff --git a/lua/compiler/languages/asm.lua b/lua/compiler/languages/asm.lua index 5a0fe9e..1540843 100644 --- a/lua/compiler/languages/asm.lua +++ b/lua/compiler/languages/asm.lua @@ -109,20 +109,17 @@ function M.action(selected_option) vim.cmd("OverseerOpen") elseif selected_option == "option4" then local entry_points + local task = {} local tasks = {} - local task + local executables = {} -- if .solution file exists in working dir local solution_file = utils.get_solution_file() if solution_file then local config = utils.parse_solution_file(solution_file) - local executable for entry, variables in pairs(config) do - if variables.executable then - executable = utils.os_path(variables.executable) - goto continue - end + if entry == "executables" then goto continue end 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") @@ -157,20 +154,24 @@ function M.action(selected_option) ::continue:: end - if executable then - task = { "shell", name = "- Run program → " .. executable, - cmd = executable .. -- run - " && echo && echo " .. executable .. -- echo - " && echo '" .. final_message .. "'" - } - table.insert(tasks, task) - else - task = {} + local solution_executables = config["executables"] + if solution_executables then + for entry, executable in pairs(solution_executables) do + task = { "shell", name = "- Run program → " .. executable, + cmd = executable .. -- run + " && echo " .. executable .. -- echo + " && echo '" .. final_message .. "'" + } + table.insert(executables, task) -- store all the executables we've created + table.insert(tasks, executables) + end end task = overseer.new_task({ name = "- Assembly compiler", strategy = { "orchestrator", - tasks = tasks + tasks = tasks -- Build all the programs in the solution in parallel + -- Link all the programs in the solution in parallel +-- -- Then run the solution executable(s) }}) task:start() vim.cmd("OverseerOpen") diff --git a/lua/compiler/languages/c.lua b/lua/compiler/languages/c.lua index ecfc600..ce90644 100644 --- a/lua/compiler/languages/c.lua +++ b/lua/compiler/languages/c.lua @@ -55,28 +55,25 @@ function M.action(selected_option) name = "- C compiler", strategy = { "orchestrator", tasks = {{ "shell", name = "- Run program → " .. entry_point, - cmd = output .. -- run - " && echo " .. output .. -- echo + cmd = output .. -- run + " && echo " .. output .. -- echo " && echo '" .. final_message .. "'" },},},}) task:start() vim.cmd("OverseerOpen") elseif selected_option == "option4" then local entry_points + local task = {} local tasks = {} - local task + local executables = {} -- if .solution file exists in working dir local solution_file = utils.get_solution_file() if solution_file then local config = utils.parse_solution_file(solution_file) - local executable for entry, variables in pairs(config) do - if variables.executable then - executable = utils.os_path(variables.executable) - goto continue - end + if entry == "executables" then goto continue end entry_point = utils.os_path(variables.entry_point) files = utils.find_files_to_compile(entry_point, "*.c") output = utils.os_path(variables.output) @@ -93,21 +90,23 @@ function M.action(selected_option) ::continue:: end - if executable then - task = { "shell", name = "- Run program → " .. executable, - cmd = executable .. -- run - " && echo " .. executable .. -- echo - " && echo '" .. final_message .. "'" - } - else - task = {} + local solution_executables = config["executables"] + if solution_executables then + for entry, executable in pairs(solution_executables) do + task = { "shell", name = "- Run program → " .. executable, + cmd = executable .. -- run + " && echo " .. executable .. -- echo + " && echo '" .. final_message .. "'" + } + table.insert(executables, task) -- store all the executables we've created + end end task = overseer.new_task({ name = "- C compiler", strategy = { "orchestrator", tasks = { - tasks, -- Build all the programs in the solution in parallel - task -- Then run the solution executable + tasks, -- Build all the programs in the solution in parallel + executables -- Then run the solution executable(s) }}}) task:start() vim.cmd("OverseerOpen") diff --git a/lua/compiler/languages/cpp.lua b/lua/compiler/languages/cpp.lua index 6846b2f..55bf349 100644 --- a/lua/compiler/languages/cpp.lua +++ b/lua/compiler/languages/cpp.lua @@ -63,19 +63,16 @@ function M.action(selected_option) elseif selected_option == "option4" then local entry_points local tasks = {} - local task + local task = {} + local executables = {} -- if .solution file exists in working dir local solution_file = utils.get_solution_file() if solution_file then local config = utils.parse_solution_file(solution_file) - local executable for entry, variables in pairs(config) do - if variables.executable then - executable = utils.os_path(variables.executable) - goto continue - end + if entry == "executables" then goto continue end entry_point = utils.os_path(variables.entry_point) files = utils.find_files_to_compile(entry_point, "*.cpp") output = utils.os_path(variables.output) @@ -92,21 +89,23 @@ function M.action(selected_option) ::continue:: end - if executable then - task = { "shell", name = "- Run program → " .. executable, - cmd = executable .. -- run - " && echo " .. executable .. -- echo - " && echo '" .. final_message .. "'" - } - else - task = {} + local solution_executables = config["executables"] + if solution_executables then + for entry, executable in pairs(solution_executables) do + task = { "shell", name = "- Run program → " .. executable, + cmd = executable .. -- run + " && echo " .. executable .. -- echo + " && echo '" .. final_message .. "'" + } + table.insert(executables, task) -- store all the executables we've created + end end task = overseer.new_task({ name = "- C++ compiler", strategy = { "orchestrator", tasks = { - tasks, -- Build all the programs in the solution in parallel - task -- Then run the solution executable + tasks, -- Build all the programs in the solution in parallel + executables -- Then run the solution executable(s) }}}) task:start() vim.cmd("OverseerOpen") diff --git a/lua/compiler/languages/cs.lua b/lua/compiler/languages/cs.lua index b9fc8e1..9c810cc 100644 --- a/lua/compiler/languages/cs.lua +++ b/lua/compiler/languages/cs.lua @@ -66,20 +66,17 @@ function M.action(selected_option) vim.cmd("OverseerOpen") elseif selected_option == "option4" then local entry_points + local task = {} local tasks = {} - local task + local executables = {} -- if .solution file exists in working dir local solution_file = utils.get_solution_file() if solution_file then local config = utils.parse_solution_file(solution_file) - local executable for entry, variables in pairs(config) do - if variables.executable then - executable = utils.os_path(variables.executable) - goto continue - end + if entry == "executables" then goto continue end entry_point = utils.os_path(variables.entry_point) files = utils.find_files_to_compile(entry_point, "*.cs") output = utils.os_path(variables.output) @@ -96,21 +93,23 @@ function M.action(selected_option) ::continue:: end - if executable then - task = { "shell", name = "- Run program → " .. executable, - cmd = "mono " .. executable .. -- run - " && echo " .. executable .. -- echo - " && echo '" .. final_message .. "'" - } - else - task = {} + local solution_executables = config["executables"] + if solution_executables then + for entry, executable in pairs(solution_executables) do + task = { "shell", name = "- Run program → " .. executable, + cmd = "mono " .. executable .. -- run + " && echo " .. executable .. -- echo + " && echo '" .. final_message .. "'" + } + table.insert(executables, task) -- store all the executables we've created + end end task = overseer.new_task({ name = "- C# compiler", strategy = { "orchestrator", tasks = { - tasks, -- Build all the programs in the solution in parallel - task -- Then run the solution executable + tasks, -- Build all the programs in the solution in parallel + executables -- Then run the solution executable(s) }}}) task:start() vim.cmd("OverseerOpen") diff --git a/lua/compiler/languages/go.lua b/lua/compiler/languages/go.lua index 3e5315f..415320d 100644 --- a/lua/compiler/languages/go.lua +++ b/lua/compiler/languages/go.lua @@ -63,20 +63,17 @@ function M.action(selected_option) vim.cmd("OverseerOpen") elseif selected_option == "option4" then local entry_points + local task = {} local tasks = {} - local task + local executables = {} -- if .solution file exists in working dir local solution_file = utils.get_solution_file() if solution_file then local config = utils.parse_solution_file(solution_file) - local executable for entry, variables in pairs(config) do - if variables.executable then - executable = utils.os_path(variables.executable) - goto continue - end + 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) @@ -93,21 +90,23 @@ function M.action(selected_option) ::continue:: end - if executable then - task = { "shell", name = "- Run program → " .. executable, - cmd = executable .. -- run - " && echo " .. executable .. -- echo - " && echo '" .. final_message .. "'" - } - else - task = {} + local solution_executables = config["executables"] + if solution_executables then + for entry, executable in pairs(solution_executables) do + task = { "shell", name = "- Run program → " .. executable, + cmd = executable .. -- run + " && echo " .. executable .. -- echo + " && echo '" .. final_message .. "'" + } + table.insert(executables, task) -- store all the executables we've created + end end task = overseer.new_task({ name = "- Go compiler", strategy = { "orchestrator", tasks = { - tasks, -- Build all the programs in the solution in parallel - task -- Then run the solution executable + tasks, -- Build all the programs in the solution in parallel + executables -- Then run the solution executable(s) }}}) task:start() vim.cmd("OverseerOpen") diff --git a/lua/compiler/languages/java.lua b/lua/compiler/languages/java.lua index c92bb67..d06a1f2 100644 --- a/lua/compiler/languages/java.lua +++ b/lua/compiler/languages/java.lua @@ -63,20 +63,17 @@ function M.action(selected_option) vim.cmd("OverseerOpen") elseif selected_option == "option4" then local entry_points + local task = {} local tasks = {} - local task + local executables = {} -- if .solution file exists in working dir local solution_file = utils.get_solution_file() if solution_file then local config = utils.parse_solution_file(solution_file) - local executable for entry, variables in pairs(config) do - if variables.executable then - executable = utils.os_path(variables.executable) - goto continue - end + if entry == "executables" then goto continue end entry_point = utils.os_path(variables.entry_point) files = utils.find_files_to_compile(entry_point, "*.java") output = utils.os_path(variables.output) @@ -93,23 +90,23 @@ function M.action(selected_option) ::continue:: end - if executable then - output_dir = vim.fn.fnamemodify(executable, ":h") - output_filename = vim.fn.fnamemodify(executable, ":t:r") - task = { "shell", name = "- Run program → " .. executable, - cmd = "java -cp " .. output_dir .. " " .. output_filename .. -- run - " && echo " .. executable .. -- echo - " && echo '" .. final_message .. "'" - } - else - task = {} + local solution_executables = config["executables"] + if solution_executables then + for entry, executable in pairs(solution_executables) do + task = { "shell", name = "- Run program → " .. executable, + cmd = "java -cp " .. output_dir .. " " .. output_filename .. -- run + " && echo " .. executable .. -- echo + " && echo '" .. final_message .. "'" + } + table.insert(executables, task) -- store all the executables we've created + end end task = overseer.new_task({ name = "- Java compiler", strategy = { "orchestrator", tasks = { - tasks, -- Build all the programs in the solution in parallel - task -- Then run the solution executable + tasks, -- Build all the programs in the solution in parallel + executables -- Then run the solution executable(s) }}}) task:start() vim.cmd("OverseerOpen") diff --git a/lua/compiler/languages/lua.lua b/lua/compiler/languages/lua.lua index 22b0b53..f4f8888 100644 --- a/lua/compiler/languages/lua.lua +++ b/lua/compiler/languages/lua.lua @@ -42,8 +42,9 @@ function M.action(selected_option) vim.cmd("OverseerOpen") elseif selected_option == "option3" then local entry_points + local task = {} local tasks = {} - local task + local executables = {} -- if .solution file exists in working dir local solution_file = utils.get_solution_file() @@ -51,6 +52,7 @@ function M.action(selected_option) local config = utils.parse_solution_file(solution_file) for entry, variables in pairs(config) do + if entry == "executables" then goto continue end entry_point = utils.os_path(variables.entry_point) arguments = variables.arguments or "" -- optional task = { "shell", name = "- Run program → " .. entry_point, @@ -59,12 +61,26 @@ function M.action(selected_option) " && echo '" .. final_message .. "'" } table.insert(tasks, task) -- store all the tasks we've created + ::continue:: + end + + local solution_executables = config["executables"] + if solution_executables then + for entry, executable in pairs(solution_executables) do + task = { "shell", name = "- Run program → " .. executable, + cmd = executable .. -- run + " && echo " .. executable .. -- echo + " && echo '" .. final_message .. "'" + } + table.insert(executables, task) -- store all the executables we've created + end end task = overseer.new_task({ name = "- Lua interpreter", strategy = { "orchestrator", tasks = { - tasks, -- Run all the programs in the solution in parallel + tasks, -- Build all the programs in the solution in parallel + executables -- Then run the solution executable(s) }}}) task:start() vim.cmd("OverseerOpen") diff --git a/lua/compiler/languages/perl.lua b/lua/compiler/languages/perl.lua index 363c341..c2cb97b 100644 --- a/lua/compiler/languages/perl.lua +++ b/lua/compiler/languages/perl.lua @@ -42,8 +42,9 @@ function M.action(selected_option) vim.cmd("OverseerOpen") elseif selected_option == "option3" then local entry_points + local task = {} local tasks = {} - local task + local executables = {} -- if .solution file exists in working dir local solution_file = utils.get_solution_file() @@ -51,6 +52,7 @@ function M.action(selected_option) local config = utils.parse_solution_file(solution_file) for entry, variables in pairs(config) do + if entry == "executables" then goto continue end entry_point = utils.os_path(variables.entry_point) arguments = variables.arguments or "" -- optional task = { "shell", name = "- Run program → " .. entry_point, @@ -59,12 +61,26 @@ function M.action(selected_option) " && echo '" .. final_message .. "'" } table.insert(tasks, task) -- store all the tasks we've created + ::continue:: + end + + local solution_executables = config["executables"] + if solution_executables then + for entry, executable in pairs(solution_executables) do + task = { "shell", name = "- Run program → " .. executable, + cmd = executable .. -- run + " && echo " .. executable .. -- echo + " && echo '" .. final_message .. "'" + } + table.insert(executables, task) -- store all the executables we've created + end end task = overseer.new_task({ name = "- Perl interpreter", strategy = { "orchestrator", tasks = { - tasks, -- Run all the programs in the solution in parallel + tasks, -- Build all the programs in the solution in parallel + executables -- Then run the solution executable(s) }}}) task:start() vim.cmd("OverseerOpen") diff --git a/lua/compiler/languages/python.lua b/lua/compiler/languages/python.lua index c6f4a21..18e91f5 100644 --- a/lua/compiler/languages/python.lua +++ b/lua/compiler/languages/python.lua @@ -29,11 +29,11 @@ M.options = { function M.action(selected_option) local utils = require("compiler.utils") local overseer = require("overseer") - local current_file = vim.fn.expand('%:p') -- 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 = vim.fn.expand('%:p') -- 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 final_message = "--task finished--" -- For python, arguments are not globally defined, -- as we have 3 different ways to run the code. @@ -64,8 +64,9 @@ function M.action(selected_option) vim.cmd("OverseerOpen") elseif selected_option == "option3" then local entry_points + local task = {} local tasks = {} - local task + local executables = {} -- if .solution file exists in working dir local solution_file = utils.get_solution_file() @@ -73,6 +74,7 @@ function M.action(selected_option) local config = utils.parse_solution_file(solution_file) for entry, variables in pairs(config) do + if entry == "executables" then goto continue end local entry_point = utils.os_path(variables.entry_point) local arguments = variables.arguments or "" -- optional task = { "shell", name = "- Run program → " .. entry_point, @@ -81,12 +83,26 @@ function M.action(selected_option) " && echo '" .. final_message .. "'" } table.insert(tasks, task) -- store all the tasks we've created + ::continue:: + end + + local solution_executables = config["executables"] + if solution_executables then + for entry, executable in pairs(solution_executables) do + task = { "shell", name = "- Run program → " .. executable, + cmd = executable .. -- run + " && echo " .. executable .. -- echo + " && echo '" .. final_message .. "'" + } + table.insert(executables, task) -- store all the executables we've created + end end task = overseer.new_task({ name = "- Python interpreter", strategy = { "orchestrator", tasks = { - tasks, -- Run all the programs in the solution in parallel + tasks, -- Build all the programs in the solution in parallel + executables -- Then run the solution executable(s) }}}) task:start() vim.cmd("OverseerOpen") @@ -171,19 +187,16 @@ function M.action(selected_option) elseif selected_option == "option7" then local entry_points local tasks = {} - local task + local task = {} + local executables = {} -- if .solution file exists in working dir local solution_file = utils.get_solution_file() if solution_file then local config = utils.parse_solution_file(solution_file) - local executable for entry, variables in pairs(config) do - if variables.executable then - executable = utils.os_path(variables.executable) - goto continue - end + if entry == "executables" then goto continue end entry_point = utils.os_path(variables.entry_point) output = utils.os_path(variables.output) output_dir = utils.os_path(output:match("^(.-[/\\])[^/\\]*$")) @@ -201,21 +214,23 @@ function M.action(selected_option) ::continue:: end - if executable then - task = { "shell", name = "- Python machine code compiler", - cmd = executable .. -- run - " && echo " .. executable .. -- echo - " && echo '" .. final_message .. "'" - } - else - task = {} + local solution_executables = config["executables"] + if solution_executables then + for entry, executable in pairs(solution_executables) do + task = { "shell", name = "- Run program → " .. executable, + cmd = executable .. -- run + " && echo " .. executable .. -- echo + " && echo '" .. final_message .. "'" + } + table.insert(executables, task) -- store all the executables we've created + end end task = overseer.new_task({ name = "- Build program → " .. entry_point, strategy = { "orchestrator", tasks = { - tasks, -- Build all the programs in the solution in parallel - task -- Then run the solution executable + tasks, -- Build all the programs in the solution in parallel + executables -- Then run the solution executable(s) }}}) task:start() vim.cmd("OverseerOpen") @@ -317,19 +332,16 @@ function M.action(selected_option) elseif selected_option == "option11" then local entry_points local tasks = {} - local task + local task = {} + local executables = {} -- if .solution file exists in working dir local solution_file = utils.get_solution_file() if solution_file then local config = utils.parse_solution_file(solution_file) - local executable for entry, variables in pairs(config) do - if variables.executable then - executable = utils.os_path(variables.executable) - goto continue - end + if entry == "executables" then goto continue end local cache_dir = utils.os_path(vim.fn.stdpath "cache" .. "/compiler/pyinstall/") entry_point = utils.os_path(variables.entry_point) files = utils.find_files_to_compile(entry_point, "*.py") @@ -353,21 +365,23 @@ function M.action(selected_option) ::continue:: end - if executable then - task = { "shell", name = "- Python bytecode compiler", - cmd = executable .. -- run - " && echo " .. executable .. -- echo - " && echo '" .. final_message .. "'" - } - else - task = {} + local solution_executables = config["executables"] + if solution_executables then + for entry, executable in pairs(solution_executables) do + task = { "shell", name = "- Run program → " .. executable, + cmd = executable .. -- run + " && echo " .. executable .. -- echo + " && echo '" .. final_message .. "'" + } + table.insert(executables, task) -- store all the executables we've created + end end task = overseer.new_task({ name = "- Build program → " .. entry_point, strategy = { "orchestrator", tasks = { - tasks, -- Build all the programs in the solution in parallel - task -- Then run the solution executable + tasks, -- Build all the programs in the solution in parallel + executables -- Then run the solution executable(s) }}}) task:start() vim.cmd("OverseerOpen") diff --git a/lua/compiler/languages/ruby.lua b/lua/compiler/languages/ruby.lua index 4a48e7f..36faf33 100644 --- a/lua/compiler/languages/ruby.lua +++ b/lua/compiler/languages/ruby.lua @@ -42,8 +42,9 @@ function M.action(selected_option) vim.cmd("OverseerOpen") elseif selected_option == "option3" then local entry_points + local task = {} local tasks = {} - local task + local executables = {} -- if .solution file exists in working dir local solution_file = utils.get_solution_file() @@ -51,6 +52,7 @@ function M.action(selected_option) local config = utils.parse_solution_file(solution_file) for entry, variables in pairs(config) do + if entry == "executables" then goto continue end entry_point = utils.os_path(variables.entry_point) arguments = variables.arguments or "" -- optional task = { "shell", name = "- Run program → " .. entry_point, @@ -59,12 +61,26 @@ function M.action(selected_option) " && echo '" .. final_message .. "'" } table.insert(tasks, task) -- store all the tasks we've created + ::continue:: + end + + local solution_executables = config["executables"] + if solution_executables then + for entry, executable in pairs(solution_executables) do + task = { "shell", name = "- Run program → " .. executable, + cmd = executable .. -- run + " && echo " .. executable .. -- echo + " && echo '" .. final_message .. "'" + } + table.insert(executables, task) -- store all the executables we've created + end end task = overseer.new_task({ name = "- Ruby interpreter", strategy = { "orchestrator", tasks = { - tasks, -- Run all the programs in the solution in parallel + tasks, -- Build all the programs in the solution in parallel + executables -- Then run the solution executable(s) }}}) task:start() vim.cmd("OverseerOpen") diff --git a/lua/compiler/languages/rust.lua b/lua/compiler/languages/rust.lua index b2c7475..45ca843 100644 --- a/lua/compiler/languages/rust.lua +++ b/lua/compiler/languages/rust.lua @@ -23,9 +23,9 @@ 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") -- working_directory/main.rs - 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 entry_point = utils.os_path(vim.fn.getcwd() .. "/main.rs") -- working_directory/main.rs + 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 = "-D warnings -g" -- arguments can be overriden in .solution local final_message = "--task finished--" @@ -69,20 +69,17 @@ function M.action(selected_option) vim.cmd("OverseerOpen") elseif selected_option == "option4" then local entry_points + local task = {} local tasks = {} - local task + local executables = {} -- if .solution file exists in working dir local solution_file = utils.get_solution_file() if solution_file then local config = utils.parse_solution_file(solution_file) - local executable for entry, variables in pairs(config) do - if variables.executable then - executable = utils.os_path(variables.executable) - goto continue - end + if entry == "executables" then goto continue end entry_point = utils.os_path(variables.entry_point) output = utils.os_path(variables.output) output_dir = utils.os_path(output:match("^(.-[/\\])[^/\\]*$")) @@ -98,21 +95,23 @@ function M.action(selected_option) ::continue:: end - if executable then - task = { "shell", name = "- Run program → " .. executable, - cmd = executable .. -- run - " && echo " .. executable .. -- echo - " && echo '" .. final_message .. "'" - } - else - task = {} + local solution_executables = config["executables"] + if solution_executables then + for entry, executable in pairs(solution_executables) do + task = { "shell", name = "- Run program → " .. executable, + cmd = executable .. -- run + " && echo " .. executable .. -- echo + " && echo '" .. final_message .. "'" + } + table.insert(executables, task) -- store all the executables we've created + end end task = overseer.new_task({ name = "- Rust compiler", strategy = { "orchestrator", tasks = { - tasks, -- Build all the programs in the solution in parallel - task -- Then run the solution executable + tasks, -- Build all the programs in the solution in parallel + executables -- Then run the solution executable(s) }}}) task:start() vim.cmd("OverseerOpen") diff --git a/lua/compiler/languages/sh.lua b/lua/compiler/languages/sh.lua index 2a6a6e1..4cf0bd0 100644 --- a/lua/compiler/languages/sh.lua +++ b/lua/compiler/languages/sh.lua @@ -16,8 +16,8 @@ M.options = { function M.action(selected_option) local utils = require("compiler.utils") local overseer = require("overseer") - local entry_point = vim.fn.expand('%:p') -- current buffer - local arguments = "" -- arguments can be overriden in .solution + local entry_point = vim.fn.expand('%:p') -- current buffer + local arguments = "" -- arguments can be overriden in .solution local final_message = "--task finished--" @@ -26,16 +26,17 @@ function M.action(selected_option) name = "- Shell interpreter", strategy = { "orchestrator", tasks = {{ "shell", name = "- Run program → " .. entry_point, - cmd = entry_point .. -- run - " && echo " .. entry_point .. -- echo - " && echo '" .. final_message .. "'" -- echo + cmd = entry_point .. -- run + " && echo " .. entry_point .. -- echo + " && echo '" .. final_message .. "'" -- echo },},},}) task:start() vim.cmd("OverseerOpen") elseif selected_option == "option2" then local entry_points + local task = {} local tasks = {} - local task + local executables = {} -- if .solution file exists in working dir local solution_file = utils.get_solution_file() @@ -43,20 +44,35 @@ function M.action(selected_option) local config = utils.parse_solution_file(solution_file) for entry, variables in pairs(config) do + if entry == "executables" then goto continue end entry_point = utils.os_path(variables.entry_point) arguments = variables.arguments or "" -- optional task = { "shell", name = "- Run program → " .. entry_point, - cmd = arguments .. arguments == "" or " " .. entry_point .. -- run - " && echo " .. entry_point .. -- echo - " && echo '" .. final_message .. "'" -- echo + cmd = (arguments == "" and "" or arguments .. " ") .. entry_point .. -- run + " && echo " .. entry_point .. -- echo + " && echo '" .. final_message .. "'" -- echo } table.insert(tasks, task) -- store all the tasks we've created + ::continue:: + end + + local solution_executables = config["executables"] + if solution_executables then + for entry, executable in pairs(solution_executables) do + task = { "shell", name = "- Run program → " .. executable, + cmd = executable .. -- run + " && echo " .. executable .. -- echo + " && echo '" .. final_message .. "'" + } + table.insert(executables, task) -- store all the executables we've created + end end task = overseer.new_task({ name = "- Shell interpreter", strategy = { "orchestrator", tasks = { - tasks, -- Run all the programs in the solution in parallel + tasks, -- Build all the programs in the solution in parallel + executables -- Then run the solution executable(s) }}}) task:start() vim.cmd("OverseerOpen") @@ -68,9 +84,9 @@ function M.action(selected_option) for _, entry_point in ipairs(entry_points) do entry_point = utils.os_path(entry_point) task = { "shell", name = "- Run program → " .. entry_point, - cmd = entry_point .. -- run - " && echo " .. entry_point .. -- echo - " && echo '" .. final_message .. "'" -- echo + cmd = entry_point .. -- run + " && echo " .. entry_point .. -- echo + " && echo '" .. final_message .. "'" -- echo } table.insert(tasks, task) -- store all the tasks we've created end @@ -83,7 +99,7 @@ function M.action(selected_option) vim.cmd("OverseerOpen") end elseif selected_option == "option3" then - require("compiler.languages.make").run_makefile() -- run + require("compiler.languages.make").run_makefile() -- run end end