diff options
| -rw-r--r-- | README.md | 26 | ||||
| -rw-r--r-- | lua/tasks/module/make.lua | 22 |
2 files changed, 48 insertions, 0 deletions
| @@ -26,6 +26,7 @@ Tasks in this plugin are provided by modules that implement functionality for a | |||
| 26 | 26 | ||
| 27 | - [CMake](https://cmake.org) via [cmake-file-api](https://cmake.org/cmake/help/latest/manual/cmake-file-api.7.html#codemodel-version-2). | 27 | - [CMake](https://cmake.org) via [cmake-file-api](https://cmake.org/cmake/help/latest/manual/cmake-file-api.7.html#codemodel-version-2). |
| 28 | - [Cargo](https://doc.rust-lang.org/cargo). | 28 | - [Cargo](https://doc.rust-lang.org/cargo). |
| 29 | - [GNU Make](https://www.gnu.org/software/make/) | ||
| 29 | 30 | ||
| 30 | You can also write [your own module](#modules-creation-and-configuration). | 31 | You can also write [your own module](#modules-creation-and-configuration). |
| 31 | 32 | ||
| @@ -90,6 +91,31 @@ require('tasks').setup({ | |||
| 90 | 91 | ||
| 91 | 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. | 92 | 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. |
| 92 | 93 | ||
| 94 | ### GNU Make | ||
| 95 | |||
| 96 | 1. Open a Make project. | ||
| 97 | 2. Run a Make target `<target>` with `:Task start make <target>`. | ||
| 98 | |||
| 99 | To override targets or add custom `make` options, configure the appropriate task: | ||
| 100 | |||
| 101 | ```lua | ||
| 102 | require('tasks').setup({ | ||
| 103 | default_params = { | ||
| 104 | ... | ||
| 105 | make = { | ||
| 106 | cmd = 'make', | ||
| 107 | args = { | ||
| 108 | all = { '-j10', 'all' }, -- :Task start make all → make -j10 all | ||
| 109 | build = {}, -- :Task start make build → make | ||
| 110 | nuke = { 'clean' }, -- :Task start make nuke → make clean | ||
| 111 | }, | ||
| 112 | }, | ||
| 113 | ... | ||
| 114 | } | ||
| 115 | }) | ||
| 116 | ``` | ||
| 117 | |||
| 118 | |||
| 93 | ## Modules creation and configuration | 119 | ## Modules creation and configuration |
| 94 | 120 | ||
| 95 | 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: | 121 | 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 @@ | |||
| 1 | local Path = require('plenary.path') | ||
| 2 | |||
| 3 | return { | ||
| 4 | params = { 'cmd' }, | ||
| 5 | condition = function() return Path:new('Makefile'):exists() end, | ||
| 6 | |||
| 7 | -- This module supports dynamic tasks by using the `__index` metamethod. | ||
| 8 | -- By default, for any string `<task>`, calling `Task start make <task>` | ||
| 9 | -- will run `make <task>` (i.e., dynamic tasks are mapped to make targets). | ||
| 10 | -- This behavior can be customized by overriding the task 'args' parameters | ||
| 11 | -- in the `default_params` provided on setup. | ||
| 12 | tasks = setmetatable({}, { | ||
| 13 | __index = function(_, target) | ||
| 14 | return function(module_config, _) | ||
| 15 | return { | ||
| 16 | cmd = module_config.cmd, | ||
| 17 | args = module_config.args and module_config.args[target] or { target }, | ||
| 18 | } | ||
| 19 | end | ||
| 20 | end, | ||
| 21 | }), | ||
| 22 | } | ||
