diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2025-04-28 06:54:46 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2025-04-28 06:54:46 -0700 |
commit | 1cbf1af6a626bda28dda3d5075a96bd8ebbc4213 (patch) | |
tree | 863e216de58fb5958517ccb4c3dc0440d890c2c6 | |
parent | ba70e0a9fcc9f7415445da71b15c9844570bf0e7 (diff) | |
download | txr-1cbf1af6a626bda28dda3d5075a96bd8ebbc4213.tar.gz txr-1cbf1af6a626bda28dda3d5075a96bd8ebbc4213.tar.bz2 txr-1cbf1af6a626bda28dda3d5075a96bd8ebbc4213.zip |
build: config cache: use hash of config inputs as cache keys
* config-cache-hook.tl (hash-config-inputs): New function.
Hashes the configure script and the configure-related portions
at the end of the Makefile, starting with the conftest: targets.
We use git cat-file to get the correct versions of these files
at the specified git hash.
(try-save-current-config, try-restore-new-config): Convert
the incoming sha to a cache key.
(toplevel): Add debugging hash command.
-rwxr-xr-x | config-cache-hook.tl | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/config-cache-hook.tl b/config-cache-hook.tl index 7355c3f6..e092bac5 100755 --- a/config-cache-hook.tl +++ b/config-cache-hook.tl @@ -14,21 +14,35 @@ (defvarl %files% '#"reconfigure config.h config.make") (defvarl %cachedir% ".config-cache") +(defun hash-config-inputs (sha) + (let ((s (sha256-begin)) + (makefile-conftest-parts (flow `git cat-file -p @sha:Makefile` + command-get-lines + (member-if (op starts-with "conftest:")) + (join-with "\n")))) + (sha256-hash s (command-get-string `git cat-file -p @sha:configure`)) + (sha256-hash s makefile-conftest-parts) + (tostringp (sha256-end s)))) + (defun try-save-current-config (sha) (when [all %files% path-exists-p] - (let ((dir (path-cat %cachedir% sha))) + (let* ((key (hash-config-inputs sha)) + (dir (path-cat %cachedir% key))) (ensure-dir dir) (copy-files %files% dir t)))) (defun try-restore-new-config (sha) - (let* ((dir (path-cat %cachedir% sha)) + (let* ((key (hash-config-inputs sha)) + (dir (path-cat %cachedir% key)) (files [map (op path-cat dir) %files%])) (when [all files path-exists-p] (copy-files files "." t) (put-line `restored cached configuration for @sha`)))) (match-case *args* - (@(require (@prevsha @newsha @nil) + (("hash" @sha) + (flow sha hash-config-inputs put-line)) + (@(require (@prevsha @newsha @nil) (nequal prevsha newsha)) (try-save-current-config prevsha) (try-restore-new-config newsha))) |