Cache build targets
Follow up on a conversation on Mastodon.
Is it possible to have a smarter™ way of caching a target based on the contents rather than modification time?
For example:
_expensive-target-workhorse:
a bunch of expensive commands
expensive-target : _expensive-target-workhorse!cached
One idea for the implementation (non-PHONY targets) is to store the caches in PROJECT_ROOT/.bmakelib-caches & use checksums to identify if a target exists in the cache and retrieve the value. In the case of directories, the checksum of the tar'ed archive can be used.
I'm not sure how this would work. Could you outline what you mean?
Say you have a target named expensive.bin which does some expensive compiling and linking to produce, well, the executable expensive.bin.
You've also got one simple file which expensive.bin depends upon. For example, simple.foo.
- You make
expensive.binand do some tests. - You modify
simple.fooand makeexpensive.bin. - You're not happy w/ the results, so you undo your changes and make
expensive.binwhich makessimple.fooin the process too.
If there was a build cache, the "remaking in (3) could have been avoided b/c Make could tell that it had already made simple.foo and expensive.bin w/ the exact same contents in (2) and there's no need to remake things. In that case, could simply move the artefacts from the cache to the "build" directory and call it done.
Does that make sense?