8 ms·
"The Makefile is the single source of truth for dev commands" This feels like when you set up a club for a hobby you enjoy, let's say it's beer pong, and you g
by Arch-TK 5y ago
"The Makefile is the single source of truth for dev commands"
This feels like when you set up a club for a hobby you enjoy, let's say it's beer pong, and you go on holiday for a month, you come back to find that your beer pong club is now full of people just chugging lots of beer and completely ignoring the game.
Please, make is a sophisticated tool with lots of good features. It is NOT a repository for "dev commands" whatever the hell that means. Make is a tool which takes targets, dependencies and recipes and turns them into a DAG which it then executes based on a set of criteria. If you want a glorified shell script which runs commands, why not just do a bash script with a switch in it? It's certainly going to behave a lot more like you expect. Why call it cake when it has almost nothing to do with make?
- ataylor32 5y ago> why not just do a bash script with a switch in it? Here is another alternative: https://github.com/TekWizely/run https://github.com/TekWizely/run
- TekWizely 5y agoHey thanks for the bump ! I sometimes chime in on posts where OP makes a tool in the same domain as Run. When I hit this article yesterday, the bash script convo hadn't started yet and I saw the OPs creation as not being in the same realm as Run, so didn't chime in. But now that its been mentioned :) Anyway I got a few extra subs from your call out, so thanks again for that! (actually I just spent the last 30 mins reviewing 24 hours of HN posts to see where the call out might have come from, and finally found it :) -- Surprisingly google hasn't indexed this post yet so didn't show up in my saved search )
- aequitas 5y ago> It is NOT a repository for "dev commands" whatever the hell that means. What it means is that it doesn't matter if I run `make test`, my coworker runs `make test` or the CI system runs `make test`, we all end up with the same result. Namely that the test suite will be run, after all stuff is done that is needed to setup the dev environment. Basically you codify all actions you as a developer would need, to setup, verify or use a project and all the dependencies between them. This makes your projects portable and when you have multiple projects (in different languages), getting it setup and running the test suite is the same for each one of them. Why not use a bash script? That's how I started off but once a coworker introduced me to Make I never looked back. Bash scales really badly in terms of readability and maintainability.
- Arch-TK 5y agoRight, I wasn't asking what "single source of truth is" I was asking what a "dev command" is. If you have commands and you want to store them so that multiple people can run them then the solution is NOT make, using make to execute commands is really quite like using machine gun to turn your TV on. Make is a very big and complex tool with lots of nuance and lots of different and not-cross-compatible versions. Moreover, it doesn't always use the same shell on every machine you run it on so using it to store bash scripts (for example) isn't really portable either. I'm sorry to be the one to tell you this but neither you nor your coworker know what make is if all you think it is is a way to store subcommands. If you want shell scripts write shell scripts. If you want them all to stem from one command (as subcommands), use a switch statement. These solutions will actually likely be far more reliable and portable (if you know what you're doing, I would imagine it's easier with portable shell than portable shell in make since even most of the programmers I know who use make for the purpose it was designed for don't seem to understand it very well).
- aequitas 5y agoTake a look at one of my Makefiles[0]. It uses most features Make has to offer (to much so). It doesn't matter what state you start from, fresh clones repo or outdated virtualenv. Running `make run` will do everything needed to run the application instance, `make test` will run the testsuite. Each command is it's own "functional" block of shell script with it's inputs (prerequisites) and outputs (target). All recipies will run in Bash on all system btw, see the first line of the Makefile. Still, a Makefile with only targets, no prerequisites is less cruft than a Bash script with a switch statement. But eventually your (team) needs will grow and you start to introduce more logic and dependencies. This is where Make shines for me. [0] https://gitlab.com/internet-cleanup-foundation/web-security-map/-/blob/master/Makefile https://gitlab.com/internet-cleanup-foundation/web-security-...
- Arch-TK 5y ago"Dependencies" in your makefile are literally just functions. This can literally all be done with a bash script and 100% less backslashes to make things run in one shell. I really seriously think that this would be much cleared if written in bash. That being said, while perusing the original makefile I found multiple issues. The one which stands out the most is that running make with a -j flag (which is entirely likely if your end user aliases that in their bashrc, I know multiple people that do). I am pretty sure fix and test can't run concurrently, at least I can't imagine how in-place fixing of files while running tests would work reliably. There's probably more cases where this would break things. Another issue is using `echo -e` and other bashisms, except that it's not guaranteed make will be running bash. I really don't understand why your makefile keeps creating files, if it didn't create most of those files it would behave basically identically except for not needing to periodically run clean. In fact, by not providing a full DAG your makefile is just annoying in that there really isn't any option other than deleting random files or redoing all the steps. I don't see how having to delete .make.test and running make test is any better than having ./run-testsuite or ./run testsuite just run the testsuite every time. Edit: I noticed your makefile sets SHELL. But this will in turn break this line: https://gitlab.com/internet-cleanup-foundation/web-security-map/-/blob/master/Makefile#L60 https://gitlab.com/internet-cleanup-foundation/web-security-...
- vimax 5y agoYour shell file with a switch isn't going to do incremental parallel builds. If you understand make, your makefile will behave as you expect it to. If you try to read a makefile as a shell script you'll constantly be surprised.
- Arch-TK 5y agoThe people this tool is aimed for don't use make to do incremental parallel builds. They use it to as a glorified shell wrapper which produces sub commands. That's what the use-case for this tool seems to be at least. I know what make is and I know how to use it, thanks.
- wurosh 5y agoAnd you have concluded this how? Again, in what way is this arcane power of make that you describe subdued by this tool?
- Arch-TK 5y agoI've concluded this buy looking at some of the makefiles that people are referring to and the way the description of the tool is worded. Calling makefiles a "single source of truth" for "dev commands" sounds to me like a glorified shell script aggregator. That's not what make is. All in all I have two issues: 1. The naming of this tool. It's not make specific, you could literally make this tool run anything else and it would still work identically. But in this case it seems to be encouraging misuses of make. 2. The concept described by the tool's documentation that makefiles are "a single source of truth for dev commands".
- wurosh 5y agoFair enough, but this wrapper does not take any power away from make. How much of that power ends up being used is up to the developer. It can literally anything a regular instance of make can do - it just supplies the dependencies. In what way does that have nothing to do with make? If you think there is a better way of phrasing it, I'd be more than happy to adopt it.
- wurosh 5y agoChanged from "dev commands" to "the build process". Hopefully that makes the intent of the tool clearer.
- bassdropvroom 5y ago> why not just do a bash script with a switch in it? Because with bash scripts you'd be re-inventing the wheel when it comes to dependencies, among other things. Make certainly might not be the right tool for having a bunch of "dev commands" that aren't targets/recipes, but bash isn't it either. There is plenty of task runners that allow you to have a single source of truth for dev commands.
- Arch-TK 5y agoMost "dependencies" in the makefiles I see which are like this are just other phony targets. In bash you can do this with functions, and if you're worried they'll get ran more than once you can write another 1 line function which only runs a function if it hasn't been ran yet during that execution of the script. In fact, nothing is stopping people from using make for some things and leaving the bulk of everything else to a separate shell script.
- TekWizely 5y ago> If you want a glorified shell script which runs commands Give my Run tool a try: Run: Easily manage and invoke small scripts and wrappers https://github.com/TekWizely/run https://github.com/TekWizely/run