diff options
-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))) |