Skip to content

Commit

Permalink
Add make module (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
undyamon authored Nov 29, 2023
1 parent cbd99ac commit f2cbe8f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down Expand Up @@ -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 `<target>` with `:Task start make <target>`.

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:
Expand Down
22 changes: 22 additions & 0 deletions lua/tasks/module/make.lua
Original file line number Diff line number Diff line change
@@ -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 `<task>`, calling `Task start make <task>`
-- will run `make <task>` (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,
}),
}

0 comments on commit f2cbe8f

Please sign in to comment.