From f2cbe8f4f5fbfc73ae8eb08521cd0080f536e626 Mon Sep 17 00:00:00 2001 From: undyamon <148129121+undyamon@users.noreply.github.com> Date: Wed, 29 Nov 2023 23:02:35 +0100 Subject: Add make module (#18) --- README.md | 26 ++++++++++++++++++++++++++ lua/tasks/module/make.lua | 22 ++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 lua/tasks/module/make.lua diff --git a/README.md b/README.md index 431c8fb..a03c2c1 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Tasks in this plugin are provided by modules that implement functionality for a - [CMake](https://cmake.org) via [cmake-file-api](https://cmake.org/cmake/help/latest/manual/cmake-file-api.7.html#codemodel-version-2). - [Cargo](https://doc.rust-lang.org/cargo). +- [GNU Make](https://www.gnu.org/software/make/) You can also write [your own module](#modules-creation-and-configuration). @@ -90,6 +91,31 @@ require('tasks').setup({ Cargo module doesn't have a `target` param which specific to CMake because `cargo run` automatically pick the binary. If there is multiple binaries, you can set which one you want to run using `--bin` or `--project` in step 2 as you do in CLI. +### GNU Make + +1. Open a Make project. +2. Run a Make target `` with `:Task start make `. + +To override targets or add custom `make` options, configure the appropriate task: + +```lua +require('tasks').setup({ + default_params = { + ... + make = { + cmd = 'make', + args = { + all = { '-j10', 'all' }, -- :Task start make all → make -j10 all + build = {}, -- :Task start make build → make + nuke = { 'clean' }, -- :Task start make nuke → make clean + }, + }, + ... + } +}) +``` + + ## Modules creation and configuration To create a module just put a lua file under `lua/tasks/modules` in your configuration or submit your module as a PR. In this module you need to return a table with the following fields: diff --git a/lua/tasks/module/make.lua b/lua/tasks/module/make.lua new file mode 100644 index 0000000..3d176c1 --- /dev/null +++ b/lua/tasks/module/make.lua @@ -0,0 +1,22 @@ +local Path = require('plenary.path') + +return { + params = { 'cmd' }, + condition = function() return Path:new('Makefile'):exists() end, + + -- This module supports dynamic tasks by using the `__index` metamethod. + -- By default, for any string ``, calling `Task start make ` + -- will run `make ` (i.e., dynamic tasks are mapped to make targets). + -- This behavior can be customized by overriding the task 'args' parameters + -- in the `default_params` provided on setup. + tasks = setmetatable({}, { + __index = function(_, target) + return function(module_config, _) + return { + cmd = module_config.cmd, + args = module_config.args and module_config.args[target] or { target }, + } + end + end, + }), +} -- cgit v1.2.3