Skip to content

Automatic Rebuilding of Packages on Restart

Nicholas Vollmer edited this page Oct 21, 2024 · 3 revisions

In order to automatically rebuild packages which are housed in the elpaca-repos-directory a custom build function can be added to a package's recipe:

  (defun +elpaca/build-if-new (e)
    (setf (elpaca<-build-steps e)
          (if-let ((default-directory (elpaca<-build-dir e))
                   (main (ignore-errors (elpaca--main-file e)))
                   (compiled (expand-file-name (concat (file-name-base main) ".elc")))
                   ((file-newer-than-file-p main compiled)))
              (progn (elpaca--signal e "Rebuilding due to source changes")
                     (cl-set-difference elpaca-build-steps
                                        '(elpaca--clone elpaca--configure-remotes elpaca--checkout-ref)))
            (elpaca--build-steps nil (file-exists-p (elpaca<-build-dir e))
                                 (file-exists-p (elpaca<-repo-dir e)))))
    (elpaca--continue-build e))

e.g.

(elpaca (doct :host github :repo "progfolio/doct" :build (+elpaca/build-if-new)))

The package will be rebuilt when Emacs is started and the source code is newer than the compiled elisp.