From 43cc1f2254018839a3933a2d91cf8589876a9164 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 27 Apr 2025 20:20:05 -0700 Subject: build: new utility for caching build configs. * config-cache-hook.tl: New file. If this is is installed as a git post-checkout hook, it will save and restore the configuration materials, associated with commit hash, under a directory called .config-cache. A cache of configs covering a wide range of commits helps with git bisecting. --- config-cache-hook.tl | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 config-cache-hook.tl diff --git a/config-cache-hook.tl b/config-cache-hook.tl new file mode 100755 index 00000000..73b7e30b --- /dev/null +++ b/config-cache-hook.tl @@ -0,0 +1,34 @@ +#!txr --lisp + +;; +;; This program is intended to be installed as .git/hooks/post-checkout. +;; It caches the build configuration for the current commit, and restores +;; it for the new commit, if possible. +;; + +;; People have git hook directories which are shared among different +;; repos; we only want to fire for txr. +(unless (ends-with "txr" (pwd)) + (exit)) + +(defvarl %files% '#"reconfigure config.h config.make") +(defvarl %cachedir% ".config-cache") + +(defun try-save-current-config (sha) + (when [all %files% path-exists-p] + (let ((dir (path-cat %cachedir% sha))) + (ensure-dir dir) + (copy-files %files% dir)))) + +(defun try-restore-new-config (sha) + (let* ((dir (path-cat %cachedir% sha)) + (files [map (op path-cat dir) %files%])) + (when [all files path-exists-p] + (copy-files files ".") + (put-line `restored cached configuration for @sha`)))) + +(match-case *args* + (@(require (@prevsha @newsha @nil) + (nequal prevsha newsha)) + (try-save-current-config prevsha) + (try-restore-new-config newsha))) -- cgit v1.2.3