A stupid simple make wrapper that makes my life easier
github.com
github.com
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?
Here is another alternative:
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 )
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.
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).
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-...
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-...
By depending on ${pysrc} which is set above with `pysrc = $(shell find ${pysrcdirs} -name *.py)` you ignore the possibility that a file may be removed. This would happen in a bisect for example or if someone were to manually delete a file. This will prevent tests from running.
I think the bigger issue with your makefile is that there's about 5 targets in total which actually make use of any of make's features, and a lot of targets which make incorrect assumptions about how make works.
Here's a list of targets which appear to not use any of make's features at all (and no, depending on ${app} being set up before they are ran does not constitute using make's features): audit, run_no_backend, run-frontend, run-nonlocal-frontend, app, run-worker, run-broker, testcase, test_integration, test_system, test_datasets, test_deterministic, test_mysql, test_postgres, clean, clean_virtualenv, mrproper, pip-sync, _mark_outdated, _commit_update, ${python} ${pip}.
Moreover, here's an example of a target with fundamental issues:
update_requirements: _mark_outdated requirements.txt requirements-dev.txt requirements-deploy.txt _commit_update
This is just plain wrong. You're treating make dependencies as some kind of sequential list of commands. That's not how make works. If I was running this with make -j or a gnu make implementation with by-default nondeterministic target build order choice this would just break.
I'm not saying your makefile saves zero purpose. There's a few targets there which you should keep. But it should really be 90% shorter with all the removed bits in a shell script so that you're not relying on nuances of your particular version of GNU make to make it work.
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.
I know what make is and I know how to use it, thanks.
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".
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.
In fact, nothing is stopping people from using make for some things and leaving the bulk of everything else to a separate shell script.
Give my Run tool a try:
Run: Easily manage and invoke small scripts and wrappers https://github.com/TekWizely/run
Pydoit is the sweet spot for most of my use cases:
- it scales up (graph of deps, file watcher, etc) but above all, it scales DOWN (simple stuff are dead simple)
- it promotes a declarative task definition
- it embraces the shell yet let you use python if you need to
- it gets out of your way and doesn't try to rule your project. It just runs what you want and disapear.
- the doc is nice
The biggest drawback is that you need to pip install it, which means non python devs will avoid it. I wish it was provided as an stand alone executable
which wholly abstracts "pip install this thing that has an entry_point without hating your life."
Still, make kinda sucks. I've yet to meet a build system that ticks these boxes: multi-language, simple, fast.
Even the fact it's using python to declare your tasks is not a problem: it's basically a function signature and a mapping, nothing you can't master in 5 minutes, and certainly simpler than make files DSL. Also easier to get right and debug.
The problem is the fact you need python to install it and run it, which non python dev will rightfully not care to do.
With that in mind, I toss my tool into the ring:
Run: Easily manage and invoke small scripts and wrappers - https://github.com/TekWizely/run