From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#63336: [PATCH] package-vc: Process :make and :shell-command spec args Date: Sun, 14 May 2023 01:08:29 -0700 Message-ID: <87cz33parh.fsf@breatheoutbreathe.in> References: <874joprxmx.fsf@breatheoutbreathe.in> <87jzxkecnk.fsf@posteo.net> <87pm7b7up0.fsf@breatheoutbreathe.in> <877ctghey0.fsf@posteo.net> <873540rqkm.fsf@breatheoutbreathe.in> <87ilcvichb.fsf@posteo.net> Reply-To: Joseph Turner Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34301"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 63336@debbugs.gnu.org To: Philip Kaludercic Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun May 14 10:40:26 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1py7HG-0008k3-L7 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 14 May 2023 10:40:26 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1py7Gv-0007fj-AF; Sun, 14 May 2023 04:40:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1py7Gt-0007du-6s for bug-gnu-emacs@gnu.org; Sun, 14 May 2023 04:40:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1py7Gs-0004er-U5 for bug-gnu-emacs@gnu.org; Sun, 14 May 2023 04:40:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1py7Gs-0000PY-Fh for bug-gnu-emacs@gnu.org; Sun, 14 May 2023 04:40:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Joseph Turner Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 14 May 2023 08:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63336 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 63336-submit@debbugs.gnu.org id=B63336.16840535801543 (code B ref 63336); Sun, 14 May 2023 08:40:02 +0000 Original-Received: (at 63336) by debbugs.gnu.org; 14 May 2023 08:39:40 +0000 Original-Received: from localhost ([127.0.0.1]:40271 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1py7GV-0000Oo-Lo for submit@debbugs.gnu.org; Sun, 14 May 2023 04:39:40 -0400 Original-Received: from out-37.mta0.migadu.com ([91.218.175.37]:30319) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1py7GS-0000Oe-Fu for 63336@debbugs.gnu.org; Sun, 14 May 2023 04:39:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=breatheoutbreathe.in; s=key1; t=1684053574; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=MFMg82/aSxEpmnbBOjPAp8+wLCFZXaJUaQr+35FzTGE=; b=Dej9W7Z8k916qO8WA7trraTsQ+0yuynCwWue1ewotXuOGZ+wANJU0XJa2r3+LP4SCtsDGj NW/3yN3MzLi/uMxeECY6sj36VAZEVa0NG5m5UFN2pwIhhHDuLMMY9Dfx76gmBc7Ovs23e1 dfa5gC8rann5n0ZXypsCVnjVZ7Rl544= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-reply-to: <87ilcvichb.fsf@posteo.net> X-Migadu-Flow: FLOW_OUT X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:261711 Archived-At: --=-=-= Content-Type: text/plain Philip Kaludercic writes: > Joseph Turner writes: > >> Philip Kaludercic writes: >> >>> Joseph Turner writes: >> From b27724197acd4ee72f9d336843f0e6ed9fcee87b Mon Sep 17 00:00:00 2001 >> From: Joseph Turner >> Date: Sat, 13 May 2023 10:05:04 -0700 >> Subject: [PATCH] package-vc: Process :make and :shell-command spec args >> >> --- >> lisp/emacs-lisp/package-vc.el | 37 +++++++++++++++++++++++++++++++++++ >> 1 file changed, 37 insertions(+) >> >> diff --git a/lisp/emacs-lisp/package-vc.el b/lisp/emacs-lisp/package-vc.el >> index beca0bd00e2..8529d1dad5c 100644 >> --- a/lisp/emacs-lisp/package-vc.el >> +++ b/lisp/emacs-lisp/package-vc.el >> @@ -344,6 +344,33 @@ asynchronously." >> "\n") >> nil pkg-file nil 'silent)))) >> >> +(defcustom package-vc-process-make nil > > Have we discussed the name of this user option? I feel it is too > immediate, and therefore not intuitively obvious what purpose it serves. > I would imagine something along the lines of > "package-vc-allow-side-effects" or "package-vc-permit-building" could be > better? WDYT? I like "package-vc-allow-side-effects". Changed in attached patch. >> + "Whether to process :make and :shell-command spec arguments. > > I guess here too an explanation would be warranted (and in the manual). > Explaining what the issue is, and why one might be wary to enable the option. Does my addition suffice? We also might want to add another option for package-vc-allow-side-effects like 'user-defined, which only runs :make and :shell-command args which were specified by the user (as opposed to those which were downloaded from elpa). WDYT? To update the manual, shall I edit doc/emacs/package.texi directly or is there another file to edit? >> +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 PKG-SPEC arguments for PKG-DESC." >> + (let ((target (plist-get pkg-spec :make)) >> + (cmd (plist-get pkg-spec :shell-command))) >> + (when (or cmd target) >> + (with-current-buffer (get-buffer-create > > I'd format the buffer name in the top let to prevent this line-break here. Done. >> + (format " *package-vc make %s*" (package-desc-name pkg-desc))) >> + (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))))))) > > If :shell-command fails, do we really want to proceed to :make? Up to you! I was following the lead of elpa-admin.el. >> (declare-function org-export-to-file "ox" (backend file)) >> >> (defun package-vc--build-documentation (pkg-desc file) >> @@ -486,6 +513,16 @@ 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 >> + (pcase package-vc-process-make >> + ((pred consp) ; When non-`nil' list, check if package is on the list. >> + (when (memq (package-desc-name pkg-desc) package-vc-process-make) >> + (package-vc--make pkg-spec pkg-desc))) >> + ('nil ; When `nil', do nothing. >> + nil) > > Perhaps swap the two conditions, first checking nil then listp which I > think reads more natural. Then again, is pcase actually serving > anything here? I switched the first two cases. I think pcase is readable here, especially if we add an 'user-defined option. What would you use instead? >> + (_ ; When otherwise non-`nil', run commands. >> + (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))) --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-package-vc-Process-make-and-shell-command-spec-args.patch >From 3e7084e8e3e3ba142f383e90bfa656f59f3cc1ad Mon Sep 17 00:00:00 2001 From: Joseph Turner Date: Sat, 13 May 2023 10:05:04 -0700 Subject: [PATCH] package-vc: Process :make and :shell-command spec args --- lisp/emacs-lisp/package-vc.el | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lisp/emacs-lisp/package-vc.el b/lisp/emacs-lisp/package-vc.el index beca0bd00e2..8403add364c 100644 --- a/lisp/emacs-lisp/package-vc.el +++ b/lisp/emacs-lisp/package-vc.el @@ -344,6 +344,36 @@ asynchronously." "\n") nil pkg-file nil 'silent)))) +(defcustom package-vc-allow-side-effects nil + "Whether to process :make and :shell-command spec arguments. + +Be careful when changing this option as processing :make and +:shell-command will 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 PKG-SPEC arguments for PKG-DESC." + (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 +516,16 @@ 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 + (pcase package-vc-allow-side-effects + ('nil ; When `nil', do nothing. + nil) + ((pred consp) ; When non-`nil' list, check if package is on the list. + (when (memq (package-desc-name pkg-desc) package-vc-allow-side-effects) + (package-vc--make pkg-spec pkg-desc))) + (_ ; When otherwise non-`nil', run commands. + (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))) -- 2.40.1 --=-=-=--