From 1cbf1af6a626bda28dda3d5075a96bd8ebbc4213 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 28 Apr 2025 06:54:46 -0700 Subject: 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. --- config-cache-hook.tl | 20 +++++++++++++++++--- 1 file 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))) -- cgit v1.2.3