Skip to content

Rebuild targets only if Makefile content changes

Patrick Steinhardt requested to merge pks-makefile-hash into master

As changes to our Makefile may require a rebuild of dependencies, e.g. because of a version change, those targets need to depend on the Makefile itself. Naturally, this is a heuristic that's going to be wrong often, but it's better than using stale artifacts for our build. Unfortunately, this breaks the caching mechanism used in CI as timestamps of files won't be preserved across differnt jobs. As a result, the build cache is going to be invalidated all the time.

Let's improve the situation by not depending on filestamps anymore, but instead on the Makefile's contents. It's quite easy to achieve by depending on a generated Makefile.sha256 file instead of the real Makefile. This file is being generated by a rule that's always executing, but the target will only get updated in case the hash of the source file actually changed. Like this, only real content changes will cause the timestamp of that file to get updated.

In order to make use of this in our CI, this commit also puts the generated Makefile.sha256 into our cache.


I'm splitting out uncontroversial parts of my MRs which I think can get merged pre-v13.3.0 withuot causing issues in order to unblock myself on other parts of the system I'm working on. This here is pulled out of my libgit2 MR and is also required for my generic Git target.

Edited by Patrick Steinhardt

Merge request reports