emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 5ac08768aa0 1/2: Support side-effects while building VC packages


From: Philip Kaludercic
Subject: master 5ac08768aa0 1/2: Support side-effects while building VC packages
Date: Tue, 16 May 2023 15:22:27 -0400 (EDT)

branch: master
commit 5ac08768aa04b0a707eb421db78b7c18ec27b55a
Author: Joseph Turner <joseph@breatheoutbreathe.in>
Commit: Philip Kaludercic <philipk@posteo.net>

    Support side-effects while building VC packages
    
    * doc/emacs/package.texi (Specifying Package Sources): Document new
    specification attributes.
    * lisp/emacs-lisp/package-vc.el (package-vc-allow-side-effects): Add
    new user option.
    (package-vc--make): Add handler for processing :make and
    :shell-command.
    (package-vc--unpack-1): Check 'package-vc-allow-side-effects' and
    invoke 'package-vc--make'.
    * etc/NEWS: Mention change.  (Bug#63336)
---
 doc/emacs/package.texi        |  9 +++++++++
 etc/NEWS                      |  5 +++++
 lisp/emacs-lisp/package-vc.el | 40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+)

diff --git a/doc/emacs/package.texi b/doc/emacs/package.texi
index 6722185cb20..4f606b22e54 100644
--- a/doc/emacs/package.texi
+++ b/doc/emacs/package.texi
@@ -682,6 +682,15 @@ A string providing the repository-relative name of the 
documentation
 file from which to build an Info file.  This can be a Texinfo file or
 an Org file.
 
+@item :make
+A string or list of strings providing the target or targets defined in
+the repository Makefile which should run before building the Info
+file. Only takes effect when package-vc-allow-side-effects is non-nil.
+
+@item :shell-command
+A string providing the shell command to run before building the Info
+file. Only takes effect when package-vc-allow-side-effects is non-nil.
+
 @item :vc-backend
 A symbol naming the VC backend to use for downloading a copy of the
 package's repository (@pxref{Version Control Systems,,,emacs, The GNU
diff --git a/etc/NEWS b/etc/NEWS
index b4846eb11b0..8c4af51b312 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -294,6 +294,11 @@ When non-nil, it will automatically register every package 
as a
 project, that you can quickly select using 'project-switch-project'
 ('C-x p p').
 
+---
+*** New user option 'package-vc-allow-side-effects'.
+When non-nil, package specifications with side-effects for building
+software will used when building a package.
+
 ** Flymake
 
 +++
diff --git a/lisp/emacs-lisp/package-vc.el b/lisp/emacs-lisp/package-vc.el
index beca0bd00e2..35acd493b36 100644
--- a/lisp/emacs-lisp/package-vc.el
+++ b/lisp/emacs-lisp/package-vc.el
@@ -344,6 +344,40 @@ asynchronously."
         "\n")
        nil pkg-file nil 'silent))))
 
+(defcustom package-vc-allow-side-effects nil
+  "Whether to process :make and :shell-command spec arguments.
+
+It may be necessary to run :make and :shell-command arguments in
+order to initialize a package or build its documentation, but
+please be careful when changing this option, as installing and
+updating a package can run potentially harmful code.
+
+When set to a list of symbols (packages), run commands for only
+packages in the list.  When nil, never run commands.  Otherwise
+when non-nil, run commands for any package with :make or
+:shell-command specified.
+
+Package specs are loaded from trusted package archives."
+  :type '(choice (const :tag "Run for all packages" t)
+                 (repeat :tag "Run only for selected packages" (symbol :tag 
"Package name"))
+                 (const :tag "Never run" nil))
+  :version "30.1")
+
+(defun package-vc--make (pkg-spec pkg-desc)
+  "Process :make and :shell-command in PKG-SPEC.
+PKG-DESC is the package descriptor for the package that is being
+prepared."
+  (let ((target (plist-get pkg-spec :make))
+        (cmd (plist-get pkg-spec :shell-command))
+        (buf (format " *package-vc make %s*" (package-desc-name pkg-desc))))
+    (when (or cmd target)
+      (with-current-buffer (get-buffer-create buf)
+        (erase-buffer)
+        (when (and cmd (/= 0 (call-process shell-file-name nil t nil 
shell-command-switch cmd)))
+          (warn "Failed to run %s, see buffer %S" cmd (buffer-name)))
+        (when (and target (/= 0 (apply #'call-process "make" nil t nil (if 
(consp target) target (list target)))))
+          (warn "Failed to make %s, see buffer %S" target (buffer-name)))))))
+
 (declare-function org-export-to-file "ox" (backend file))
 
 (defun package-vc--build-documentation (pkg-desc file)
@@ -486,6 +520,12 @@ documentation and marking the package as installed."
       ;; Generate package file
       (package-vc--generate-description-file pkg-desc pkg-file)
 
+      ;; Process :make and :shell-command arguments before building 
documentation
+      (when (or (eq package-vc-allow-side-effects t)
+                (memq (package-desc-name pkg-desc)
+                      package-vc-allow-side-effects))
+        (package-vc--make pkg-spec pkg-desc))
+
       ;; Detect a manual
       (when (executable-find "install-info")
         (dolist (doc-file (ensure-list (plist-get pkg-spec :doc)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]