diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2025-04-27 20:20:05 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2025-04-27 20:20:05 -0700 |
commit | 43cc1f2254018839a3933a2d91cf8589876a9164 (patch) | |
tree | 483d33806b66016c8bf458716066bddb3233e1a8 | |
parent | 46268ca86d9666069056db627a2e5c85045ae570 (diff) | |
download | txr-43cc1f2254018839a3933a2d91cf8589876a9164.tar.gz txr-43cc1f2254018839a3933a2d91cf8589876a9164.tar.bz2 txr-43cc1f2254018839a3933a2d91cf8589876a9164.zip |
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.
-rwxr-xr-x | config-cache-hook.tl | 34 |
1 files changed, 34 insertions, 0 deletions
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))) |