diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-06-27 14:50:20 +0200 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-06-27 14:50:20 +0200 |
| commit | 8697555125c57ae64a0c9b78514b4aac4fd523de (patch) | |
| tree | a699df53a7c35a4425f30bca86982c4341f6de40 /content/posts/2023-05-31-re-inventing-task-runner-that-i-actually-used-daily.md | |
| parent | 33b2615a5038bc85036081e8b5e0da8584d88097 (diff) | |
| download | mitjafelicijan.com-8697555125c57ae64a0c9b78514b4aac4fd523de.tar.gz | |
Massive formatting and added figcaption
Diffstat (limited to 'content/posts/2023-05-31-re-inventing-task-runner-that-i-actually-used-daily.md')
| -rw-r--r-- | content/posts/2023-05-31-re-inventing-task-runner-that-i-actually-used-daily.md | 158 |
1 files changed, 74 insertions, 84 deletions
diff --git a/content/posts/2023-05-31-re-inventing-task-runner-that-i-actually-used-daily.md b/content/posts/2023-05-31-re-inventing-task-runner-that-i-actually-used-daily.md index 17fdaf6..1abfd1e 100644 --- a/content/posts/2023-05-31-re-inventing-task-runner-that-i-actually-used-daily.md +++ b/content/posts/2023-05-31-re-inventing-task-runner-that-i-actually-used-daily.md | |||
| @@ -5,55 +5,49 @@ date: 2023-05-31T12:21:10+02:00 | |||
| 5 | draft: false | 5 | draft: false |
| 6 | --- | 6 | --- |
| 7 | 7 | ||
| 8 | Couple of months ago I had this brilliant idea of re-inventing the wheel | 8 | Couple of months ago I had this brilliant idea of re-inventing the wheel by |
| 9 | by making an alternative for make. And so I went. Boldly into the | 9 | making an alternative for make. And so I went. Boldly into the battle. And to my |
| 10 | battle. And to my big surprise my attempt resulted in not a completely | 10 | big surprise my attempt resulted in not a completely useless piece of software. |
| 11 | useless piece of software. | 11 | |
| 12 | 12 | My initial requirements were quite simple but soon grow into something more | |
| 13 | My initial requirements were quite simple but soon grow into something | 13 | ambitious. And looking back I should have stuck to the simple version. My |
| 14 | more ambitious. And looking back I should have stuck to the simple | 14 | laziness was on my side this time though. Because I haven’t implemented some of |
| 15 | version. My laziness was on my side this time though. Because I haven’t | 15 | the features I now realise I really didn’t need them and they would bog the |
| 16 | implemented some of the features I now realise I really didn’t need them | 16 | whole program and make it be something it was never meant to be. |
| 17 | and they would bog the whole program and make it be something it was | ||
| 18 | never meant to be. | ||
| 19 | 17 | ||
| 20 | My basic requirements were following: | 18 | My basic requirements were following: |
| 21 | 19 | ||
| 22 | - Syntax should be a tiny bit inspired by Rake and Rakefiles. | 20 | - Syntax should be a tiny bit inspired by Rake and Rakefiles. |
| 23 | - Should borrow the overall feel of a unit test experience. | 21 | - Should borrow the overall feel of a unit test experience. |
| 24 | - Using something like Python would be a bit of an overkill. | 22 | - Using something like Python would be a bit of an overkill. |
| 25 | - The program must be statically compiled, so it can run on same | 23 | - The program must be statically compiled, so it can run on same architecture |
| 26 | architecture without libc, musl dependencies or things like that. | 24 | without libc, musl dependencies or things like that. |
| 27 | - Install ruby for rake is a bit overkill and can not be done | 25 | - Install ruby for rake is a bit overkill and can not be done with certain |
| 28 | with certain really lightweight distributions like Alpine | 26 | really lightweight distributions like Alpine Linux. This tool would be usable |
| 29 | Linux. This tool would be usable on such lightweight systems | 27 | on such lightweight systems for remote debugging. |
| 30 | for remote debugging. | 28 | - I want to use it for more than just compiling things. I want to use it as an |
| 31 | - I want to use it for more than just compiling things. I want to | 29 | entry-point into a project, and I want this to help me indirectly document the |
| 32 | use it as an entry-point into a project, and I want this to | 30 | project as well. |
| 33 | help me indirectly document the project as well. | 31 | - It should be an abstraction over bash shell or the default system shell. |
| 34 | - It should be an abstraction over bash shell or the default | ||
| 35 | system shell. | ||
| 36 | - Each task essentially becomes its own shell instance. | 32 | - Each task essentially becomes its own shell instance. |
| 37 | - Must work on Linux and macOS systems. | 33 | - Must work on Linux and macOS systems. |
| 38 | - By default, running `erd` list all the available tasks (when | 34 | - By default, running `erd` list all the available tasks (when I use make, I |
| 39 | I use make, I usually put a disclaimer that you should check | 35 | usually put a disclaimer that you should check Makefile to see all available |
| 40 | Makefile to see all available target). | 36 | target). |
| 41 | - Should support passing arguments when you run it from a shell. | 37 | - Should support passing arguments when you run it from a shell. |
| 42 | - Normal variable as the same as environmental variables. There | 38 | - Normal variable as the same as environmental variables. There is no |
| 43 | is no distinction. Every variable is also essentially an | 39 | distinction. Every variable is also essentially an environment variable and |
| 44 | environment variable and can be used by other programs. | 40 | can be used by other programs. |
| 45 | - State between tasks is not shared, and this makes this “pure” | 41 | - State between tasks is not shared, and this makes this “pure” shell instances. |
| 46 | shell instances. | 42 | - Should be single-threaded for the start and later expanded with `@spawn` |
| 47 | - Should be single-threaded for the start and later expanded | 43 | command. |
| 48 | with `@spawn` command. | ||
| 49 | - Variables behave like macros and are preprocessed before evaluation. | 44 | - Variables behave like macros and are preprocessed before evaluation. |
| 50 | - Should support something like `assure` that would check if | 45 | - Should support something like `assure` that would check if programs like C |
| 51 | programs like C compiler or Python (whatever the project | 46 | compiler or Python (whatever the project requires) are installed on a machine. |
| 52 | requires) are installed on a machine. | ||
| 53 | 47 | ||
| 54 | Quite a reasonable list of requirements. I do this things already in my | 48 | Quite a reasonable list of requirements. I do this things already in my |
| 55 | Makefiles or/and Bash scripts. But I would like to avoid repeating | 49 | Makefiles or/and Bash scripts. But I would like to avoid repeating myself every |
| 56 | myself every time I start working on something new. | 50 | time I start working on something new. |
| 57 | 51 | ||
| 58 | So I started with the following syntax. | 52 | So I started with the following syntax. |
| 59 | 53 | ||
| @@ -111,13 +105,12 @@ end | |||
| 111 | end | 105 | end |
| 112 | ``` | 106 | ``` |
| 113 | 107 | ||
| 114 | One thing that I really like about Errand. Yes, this is what it is | 108 | One thing that I really like about Errand. Yes, this is what it is called. And |
| 115 | called. And it is available at | 109 | it is available at https://git.mitjafelicijan.com/errand.git/about/. Moving |
| 116 | https://git.mitjafelicijan.com/errand.git/about/. Moving on. One thing | 110 | on. One thing that I really like is that a task is a persistent shell. By that I |
| 117 | that I really like is that a task is a persistent shell. By that I mean, | 111 | mean, that the whole task, even if it contains multiple command in one shell. |
| 118 | that the whole task, even if it contains multiple command in one shell. | 112 | In make each line in a target is that and you need to combine lines or add `\` |
| 119 | In make each line in a target is that and you need to combine lines or | 113 | at the end of the line. |
| 120 | add `\` at the end of the line. | ||
| 121 | 114 | ||
| 122 | ```bash | 115 | ```bash |
| 123 | # How you do this things in make. | 116 | # How you do this things in make. |
| @@ -126,43 +119,40 @@ target: | |||
| 126 | python script.py | 119 | python script.py |
| 127 | ``` | 120 | ``` |
| 128 | 121 | ||
| 129 | This solves this problem. Consider each task and what is being executed | 122 | This solves this problem. Consider each task and what is being executed in that |
| 130 | in that task a shell that will only close when all the tasks are | 123 | task a shell that will only close when all the tasks are completed. |
| 131 | completed. | 124 | |
| 132 | 125 | By self-documenting I mean that if you are in a directory with `Errandfile` in, | |
| 133 | By self-documenting I mean that if you are in a directory with | 126 | if you only type `erd` and press enter it should by default display all the |
| 134 | `Errandfile` in, if you only type `erd` and press enter it should by | 127 | possible targets. In make i was doing this by having a first target be something |
| 135 | default display all the possible targets. In make i was doing this by | 128 | like `default` that echos the message “Check Makefile for all available target.” |
| 136 | having a first target be something like `default` that echos the message | 129 | Because all of the tasks in Errand require a message I use that to display let’s |
| 137 | “Check Makefile for all available target.” Because all of the tasks in | 130 | call it table of contents. |
| 138 | Errand require a message I use that to display let’s call it table of | 131 | |
| 139 | contents. | 132 | Because I don’t use any external dependencies this whole thing can be statically |
| 140 | 133 | compiled. So that also checked one of the boxes. | |
| 141 | Because I don’t use any external dependencies this whole thing can be | 134 | |
| 142 | statically compiled. So that also checked one of the boxes. | 135 | It works on Linux and on a Mac so that’s also a bonus. I don’t believe this |
| 143 | 136 | would work on Windows machines because of the way that I use shell instances. By | |
| 144 | It works on Linux and on a Mac so that’s also a bonus. I don’t believe | 137 | you could use something like Windows Subsystem for Linux and run it in |
| 145 | this would work on Windows machines because of the way that I use shell | 138 | there. That is a valid option. |
| 146 | instances. By you could use something like Windows Subsystem for Linux | 139 | |
| 147 | and run it in there. That is a valid option. | 140 | To finish this essay off, how was it to use it in “real life”. I have to be |
| 148 | 141 | honest. Some of the missing features still bother me. `@dotenv` directive is | |
| 149 | To finish this essay off, how was it to use it in “real life”. I have to | 142 | still missing and I need to implement this ASAP. |
| 150 | be honest. Some of the missing features still bother me. `@dotenv` | 143 | |
| 151 | directive is still missing and I need to implement this ASAP. | 144 | Another thing that needs to happen is support for streaming output. Currently |
| 152 | 145 | commands like `docker-compose` that runs in foreground mode is not compatible | |
| 153 | Another thing that needs to happen is support for streaming output. | 146 | with Errand. So commands that stream output are an issue. I need to revisit how |
| 154 | Currently commands like `docker-compose` that runs in foreground mode is | 147 | I initiate shell and how I read stdout and stderr. But that shouldn’t be a |
| 155 | not compatible with Errand. So commands that stream output are an issue. | 148 | problem. |
| 156 | I need to revisit how I initiate shell and how I read stdout and stderr. | 149 | |
| 157 | But that shouldn’t be a problem. | 150 | I have been very satisfied with this thing. I am pleasantly surprised by how |
| 158 | 151 | useful it is. I really wanted to test this in the wild before I commit to it. I | |
| 159 | I have been very satisfied with this thing. I am pleasantly surprised by | 152 | have more abandoned project than Google and it’s bringing a massive shame to my |
| 160 | how useful it is. I really wanted to test this in the wild before I | 153 | family at this point. So I wanted to be sure that this is even useful. And it |
| 161 | commit to it. I have more abandoned project than Google and it’s | 154 | actually is. Quite surprised at myself. |
| 162 | bringing a massive shame to my family at this point. So I wanted to be | 155 | |
| 163 | sure that this is even useful. And it actually is. Quite surprised at | 156 | I really need to package this now and write proper docs. And maybe rewrite |
| 164 | myself. | 157 | tokeniser. Its atrocious right now. Site to behold! But that is an issue for |
| 165 | 158 | another time. | |
| 166 | I really need to package this now and write proper docs. And maybe | ||
| 167 | rewrite tokeniser. Its atrocious right now. Site to behold! But that is | ||
| 168 | an issue for another time. | ||
