Straight.el: Add a post-build hook

Created on 2 Jul 2020  Â·  16Comments  Â·  Source: raxod502/straight.el

For certain packages (like vterm), a few manual commands are required after each update. I couldn’t find it in the documentation: I would like to have an obvious way to perform commands after the build process.

Example:

(use-package vterm
  :straight t
  :ensure t
  ;; would be new:
  :post-build-hook (vterm-module-compile))

Something like that.

(If I accidentally failed to see an already existing option for that: Sorry!)

build system feature hook nonstandard packaging

Most helpful comment

I mean, the point of that comment isn't to document how to specify a custom recipe, it's just to point out that straight.el does not provide the features of use-package. And ideally with #549 specifying custom commands should not be a routine operation.

All 16 comments

Well, there is straight-use-package-pre-build-functions but indeed no straight-use-package-post-build-functions. And you are right that the most reasonable thing is not to have a hook but rather a new keyword in the recipe. Although it will be a straight.el keyword, not a use-package one like in your example code.

I think that you should take a look at https://github.com/raxod502/straight.el/pull/535, which will be about the right place for this functionality. (Not necessarily in that very pull request, but in the same part of the code.)

535 makes it possible to specify a recipe like so now:

(use-package vterm
  :straight t
  :ensure t
  :post-build (let ((vetrm-always-compile-module t))
                (require 'vterm)))

Awesome! I hope that it will be merged. :-)

@dertuxmalwieder support for the :build and :post-build keywords is now available on the develop branch.
The following works for me to set up vterm. Let me know if you have any trouble, questions or suggestions.

Test Case

(straight-bug-report
  :post-bootstrap 
  (straight-use-package
   '(vterm :post-build
           ((let
                ((vterm-always-compile-module t))
              (require 'vterm))))))

  • Test run at: 2020-10-23 21:03:17
  • system-type: gnu/linux
  • straight-version: prerelease (HEAD -> develop, origin/develop) cd42db6 2020-10-23
  • emacs-version: GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo version 1.17.3, Xaw3d scroll bars) of 2020-10-14

Output

Bootstrapping straight.el...
Bootstrapping straight.el...done
Rebuilding all packages due to build cache schema change
Looking for gnu-elpa-mirror recipe → Cloning melpa...
Looking for gnu-elpa-mirror recipe → Cloning melpa...done
Looking for emacsmirror-mirror recipe → Cloning gnu-elpa-mirror...
Looking for emacsmirror-mirror recipe → Cloning gnu-elpa-mirror...done
Looking for straight recipe → Cloning emacsmirror-mirror...
Looking for straight recipe → Cloning emacsmirror-mirror...done
Building straight...
Building straight...done

Test run with version: prerelease (HEAD -> develop, origin/develop) cd42db6 2020-10-23
Cloning emacs-libvterm (for vterm)...
Cloning emacs-libvterm (for vterm)...done
Building vterm...

Compilation of ‘emacs-libvterm’ module succeeded
Building vterm...done

Hmm. How can I update straight.el to the develop branch?

(setq straight-repository-branch "develop“)

Yet:

Error (use-package): Failed to parse package vterm: use-package: Unrecognized keyword: :post-build

Has straight been rebuilt? M-x straight-rebuild-package straight and, if necessary M-x straight-normalize-package straight

prerelease (HEAD -> develop, origin/develop) 75db2e0 %cs

Seems so. Still, after a restart (with a reload):

Error (use-package): Failed to parse package vterm: use-package: Unrecognized keyword: :post-build

Would you mind evaluating this in a buffer with lexical binding enabled?:

(straight-bug-report
  :post-bootstrap 
  (straight-use-package
   '(vterm :post-build
           ((let
                ((vterm-always-compile-module t))
              (require 'vterm))))))

And copying the resultant "straight-bug-report-process" buffer here?

This:

Error (use-package): Failed to parse package vterm: use-package: Unrecognized keyword: :post-build

Might also the be the result of a malformed use-package declaration. What is does your use-package declaration for vterm look like?

Output:

Bootstrapping straight.el...
Bootstrapping straight.el...done
Rebuilding all packages due to build cache schema change
Looking for gnu-elpa-mirror recipe → Cloning melpa...
Looking for gnu-elpa-mirror recipe → Cloning melpa...done
Looking for emacsmirror-mirror recipe → Cloning gnu-elpa-mirror...
Looking for emacsmirror-mirror recipe → Cloning gnu-elpa-mirror...done
Looking for straight recipe → Cloning emacsmirror-mirror...
Looking for straight recipe → Cloning emacsmirror-mirror...done
Building straight...
Building straight...done

Test run with version: prerelease (HEAD -> develop, origin/develop) 68dade0 %cs
Cloning emacs-libvterm (for vterm)...
Cloning emacs-libvterm (for vterm)...done
Building vterm...

Compilation of `emacs-libvterm' module succeeded
Debugger entered--Lisp error: (file-missing "Cannot open load file" "No such file or directory" "vterm-module")
  require(vterm-module)
  byte-code("\301\302\303\304#\204 \0\10\204\22\0\305\306!\203\34\0\307 \210\301\302!\210\202 \0\310\311!\210\301\312!\210\301\313!\210\301\314!\210\301\315!\210\301\316..." [vterm-always-compile-module require vterm-module nil t y-or-n-p "Vterm needs `vterm-module' to work.  Compile it no..." vterm-module-compile error "Vterm will not work until `vterm-module' is compil..." subr-x cl-lib term color compile face-remap custom-declare-variable vterm-shell funcall function #f(compiled-function () #<bytecode 0x1ffd79c2af65>) "The shell that gets run in the vterm." :type string :group vterm vterm-max-scrollback #f(compiled-function () #<bytecode 0x1ffd79c2af75>) "Maximum 'scrollback' value.\n\nThe maximum allowed i..." number vterm-min-window-width #f(compiled-function () #<bytecode 0x1ffd7ac03121>) "Minimum window width." vterm-kill-buffer-on-exit #f(compiled-function () #<bytecode 0x1ffd7ac03131>) "If not nil vterm buffers are killed when the attac..." boolean defvaralias vterm-clear-scrollback vterm-clear-scrollback-when-clearing (saved-value saved-variable-comment) put make-obsolete-variable "0.0.1" vterm-use-vterm-prompt vterm-use-vterm-prompt-detection-method #f(compiled-function () #<bytecode 0x1ffd7ac03141>) "If not nil `vterm-clear' clears both screen and sc..." vterm-keymap-exceptions #f(compiled-function () #<bytecode 0x1ffd7ac03151>) ...] 10)
  require(vterm)
  (let ((vterm-always-compile-module t)) (require 'vterm))
  eval((let ((vterm-always-compile-module t)) (require 'vterm)))
  straight--run-build-commands((:post-build ((let ((vterm-always-compile-module t)) (require 'vterm))) :files ("*" (:exclude ".dir-locals.el" ".gitignore" ".clang-format" ".travis.yml") "vterm-pkg.el") :flavor melpa :repo "akermu/emacs-libvterm" :host github :package "vterm" :type git :local-repo "emacs-libvterm") post)
  straight--build-package((:post-build ((let ((vterm-always-compile-module t)) (require 'vterm))) :files ("*" (:exclude ".dir-locals.el" ".gitignore" ".clang-format" ".travis.yml") "vterm-pkg.el") :flavor melpa :repo "akermu/emacs-libvterm" :host github :package "vterm" :type git :local-repo "emacs-libvterm") nil)
  #f(compiled-function () #<bytecode 0x1ffd7a029b8d>)()
  straight--transaction-exec(use-package-\(:post-build\ \(\(let\ \(\(vterm-always-compile-module\ t\)\)\ \(require\ \'vterm\)\)\)\ :files\ \(\"*\"\ \(:exclude\ \"\.dir-locals\.el\"\ \"\.gitignore\"\ \"\.clang-format\"\ \"\.travis\.yml\"\)\ \"vterm-pkg\.el\"\)\ :flavor\ melpa\ :repo\ \"akermu/emacs-libvterm\"\ :host\ github\ :package\ \"vterm\"\ :type\ git\ :local-repo\ \"emacs-libvterm\"\)-nil-nil :now #f(compiled-function () #<bytecode 0x1ffd7a029b8d>))
  straight-use-package((vterm :post-build ((let ((vterm-always-compile-module t)) (require 'vterm))) :files ("*" (:exclude ".dir-locals.el" ".gitignore" ".clang-format" ".travis.yml") "vterm-pkg.el") :flavor melpa :repo "akermu/emacs-libvterm" :host github))
  (let ((straight-bug-report-args '(:post-bootstrap (progn (straight-use-package '...)) :executable "/Applications/Emacs.app/Contents/MacOS/Emacs-x86_6..." :user-dir "/var/folders/tq/7ds0xd3d13lgzvj4qkdgknhh0000gn/T/s..."))) (setq user-emacs-directory "/var/folders/tq/7ds0xd3d13lgzvj4qkdgknhh0000gn/T/s...") (setq straight-repository-branch "develop") (setq debug-on-error t) (defvar bootstrap-version) (let ((bootstrap-file (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory)) (bootstrap-version 5)) (unless (file-exists-p bootstrap-file) (with-current-buffer (url-retrieve-synchronously (concat "https://raw.githubusercontent.com/" "raxod502/straight.el/develop/install.el") 'silent 'inhibit-cookies) (goto-char (point-max)) (eval-print-last-sexp))) (load bootstrap-file nil 'nomessage)) (condition-case nil (message "Test run with version: %s" (straight-version)) (error nil)) (straight-use-package '(vterm :post-build ((let ((vterm-always-compile-module t)) (require 'vterm))) :files ("*" (:exclude ".dir-locals.el" ".gitignore" ".clang-format" ".travis.yml") "vterm-pkg.el") :flavor melpa :repo "akermu/emacs-libvterm" :host github)))
  eval((let ((straight-bug-report-args '(:post-bootstrap (progn (straight-use-package ...)) :executable "/Applications/Emacs.app/Contents/MacOS/Emacs-x86_6..." :user-dir "/var/folders/tq/7ds0xd3d13lgzvj4qkdgknhh0000gn/T/s..."))) (setq user-emacs-directory "/var/folders/tq/7ds0xd3d13lgzvj4qkdgknhh0000gn/T/s...") (setq straight-repository-branch "develop") (setq debug-on-error t) (defvar bootstrap-version) (let ((bootstrap-file (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory)) (bootstrap-version 5)) (unless (file-exists-p bootstrap-file) (with-current-buffer (url-retrieve-synchronously (concat "https://raw.githubusercontent.com/" "raxod502/straight.el/develop/install.el") 'silent 'inhibit-cookies) (goto-char (point-max)) (eval-print-last-sexp))) (load bootstrap-file nil 'nomessage)) (condition-case nil (message "Test run with version: %s" (straight-version)) (error nil)) (straight-use-package '(vterm :post-build ((let (...) (require ...))) :files ("*" (:exclude ".dir-locals.el" ".gitignore" ".clang-format" ".travis.yml") "vterm-pkg.el") :flavor melpa :repo "akermu/emacs-libvterm" :host github))) t)
  command-line-1(("--eval" "(let\n    ((straight-bug-report-args\n      '(:post-..."))
  command-line()
  normal-top-level()

use-package:

(use-package vterm
  :ensure t
  ;; Update the module automatically:
  :post-build
  ((let
       ((vterm-always-compile-module t))
     (require 'vterm)))
  :config
  ;; Disable the highlighting of the current line
  ;; for the virtual terminal:
  (add-hook 'vterm-mode-hook (lambda () (setq-local global-hl-line-mode nil))))

Was that the entire buffer that was produced by straight-bug-report? It should include much more info, including system environment info.

The use-package form you're using is malformed. The first problem is that use-package's :ensure keyword uses package.el which conflicts with straight. The second is that the :post-build keyword must be part of the straight recipe.
Try this out:

(use-package vterm
  ;; Update the module automatically:
  :straight (:post-build ((let ((vterm-always-compile-module t))
                            (require 'vterm))))
  :config
  ;; Disable the highlighting of the current line
  ;; for the virtual terminal:
  (add-hook 'vterm-mode-hook (lambda () (setq-local global-hl-line-mode nil))))

Yes, that seems to be the entire buffer.

Ah, I see. Your code works!
I thought straight can basically absorb use-package.

I thought straight can basically absorb use-package.

The above commit adds a note about this point, since it's a common point of confusion. Let me know if you think of any way we could improve the communication about it.

Well, the note still doesn’t cover the few cases where the command needs to be altered...

Are there any specific cases that come to mind?

I mean, the point of that comment isn't to document how to specify a custom recipe, it's just to point out that straight.el does not provide the features of use-package. And ideally with #549 specifying custom commands should not be a routine operation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

raxod502 picture raxod502  Â·  3Comments

hlissner picture hlissner  Â·  3Comments

mclearc picture mclearc  Â·  4Comments

progfolio picture progfolio  Â·  3Comments

agsdot picture agsdot  Â·  4Comments