From patchwork Sun Jun 5 00:19:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Fredrik Salomonsson X-Patchwork-Id: 39745 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id DF9EF27BBEA; Sun, 5 Jun 2022 01:20:45 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 5075727BBE9 for ; Sun, 5 Jun 2022 01:20:45 +0100 (BST) Received: from localhost ([::1]:46606 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxe0a-0007YT-G8 for patchwork@mira.cbaines.net; Sat, 04 Jun 2022 20:20:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxdzv-0007YC-7A for guix-patches@gnu.org; Sat, 04 Jun 2022 20:20:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:37667) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxdzu-0005At-IV for guix-patches@gnu.org; Sat, 04 Jun 2022 20:20:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nxdzu-0001KO-Ei for guix-patches@gnu.org; Sat, 04 Jun 2022 20:20:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#55420] [PATCH v2 1/2] guix: emacs-utils: Add emacs-batch-script. References: <20220514230017.27372-1-plattfot@posteo.net> In-Reply-To: <20220514230017.27372-1-plattfot@posteo.net> Resent-From: Fredrik Salomonsson Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 05 Jun 2022 00:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55420 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 55420@debbugs.gnu.org Cc: Fredrik Salomonsson Received: via spool by 55420-submit@debbugs.gnu.org id=B55420.16543883835057 (code B ref 55420); Sun, 05 Jun 2022 00:20:02 +0000 Received: (at 55420) by debbugs.gnu.org; 5 Jun 2022 00:19:43 +0000 Received: from localhost ([127.0.0.1]:59795 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nxdza-0001JQ-GH for submit@debbugs.gnu.org; Sat, 04 Jun 2022 20:19:42 -0400 Received: from mout01.posteo.de ([185.67.36.65]:47597) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nxdzV-0001J7-OX for 55420@debbugs.gnu.org; Sat, 04 Jun 2022 20:19:40 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id CAD8E240027 for <55420@debbugs.gnu.org>; Sun, 5 Jun 2022 02:19:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1654388371; bh=L9Hf9VdwkFnH1hhGyJxqo7noBPJKkpHZbofQS8q/MJA=; h=From:To:Cc:Subject:Date:From; b=I9sYRWmtgNVFGopgRa/yYQ2N0fgfKxozzvIziVLRXeQEMxTfOWqE0DXPUfpsgLfWv wC/03KG3l5nKryLJ/iw3QbjFbUGOUfQoVrzKV/I1X4PvW1L181g75jNMlsC2T8EitK 6xArn2C7tEu9lPLac8B1jTsrdkWfrrb4D1ZcFGgGZhoO7Z9y6ak5fZLkxDUi/Hm+mG uTCkrVpXSSCR+xI1c4FR12CMx/mddFQb4cf1AJu0UUJr6JAKx0BQdhqXsT0elZQ6et ksjPpDQHMGCAEfeKvujghH8YFdxNMhwybaEqQHXJMI19Jty6CooztKaMrmGHD5IN4p n8T+FMG45UlIQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4LFy0y58n8z6tmM; Sun, 5 Jun 2022 02:19:30 +0200 (CEST) From: Fredrik Salomonsson Date: Sun, 5 Jun 2022 00:19:23 +0000 Message-Id: <20220605001924.184934-1-plattfot@posteo.net> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/build/emacs-utils.scm (emacs-batch-script): New procedure. * tests/build-emacs-utils.scm: New file. * Makefile.am (TESTS): Add `tests/build-emacs-utils.scm'. --- Makefile.am | 1 + guix/build/emacs-utils.scm | 30 +++++++++++++++++++++++++++ tests/build-emacs-utils.scm | 41 +++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 tests/build-emacs-utils.scm base-commit: 271736117e3f09b616a2dbd5d74c9595926c9297 diff --git a/Makefile.am b/Makefile.am index e8d4b7ef8a..4a8514ea3a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -469,6 +469,7 @@ SCM_TESTS = \ tests/boot-parameters.scm \ tests/bournish.scm \ tests/builders.scm \ + tests/build-emacs-utils.scm \ tests/build-utils.scm \ tests/cache.scm \ tests/challenge.scm \ diff --git a/guix/build/emacs-utils.scm b/guix/build/emacs-utils.scm index 60a754b9e9..1684bf3262 100644 --- a/guix/build/emacs-utils.scm +++ b/guix/build/emacs-utils.scm @@ -3,6 +3,7 @@ ;;; Copyright © 2014 Alex Kost ;;; Copyright © 2018, 2020, 2022 Maxim Cournoyer ;;; Copyright © 2019 Liliana Marie Prikler +;;; Copyright © 2022 Fredrik Salomonsson ;;; ;;; This file is part of GNU Guix. ;;; @@ -22,10 +23,19 @@ (define-module (guix build emacs-utils) #:use-module (guix build utils) #:use-module (ice-9 format) + #:use-module (ice-9 popen) + #:use-module (ice-9 rdelim) + #:use-module (srfi srfi-34) + #:use-module (srfi srfi-35) #:export (%emacs emacs-batch-eval emacs-batch-edit-file emacs-batch-disable-compilation + emacs-batch-script + + emacs-batch-error? + emacs-batch-error-message + emacs-generate-autoloads emacs-byte-compile-directory @@ -69,6 +79,26 @@ (define (emacs-batch-disable-compilation file) (add-file-local-variable 'no-byte-compile t) (basic-save-buffer)))) +(define-condition-type &emacs-batch-error &error + emacs-batch-error? + (message emacs-batch-error-message)) + +(define (emacs-batch-script expr) + "Execute the Elisp code EXPR in Emacs batch mode and return output." + (let* ((error-pipe (pipe)) + (port (parameterize ((current-error-port (cdr error-pipe))) + (open-pipe* + OPEN_READ + (%emacs) "--quick" "--batch" + (string-append "--eval=" (expr->string expr))))) + (output (read-string port)) + (status (close-pipe port))) + (close-port (cdr error-pipe)) + (unless (zero? status) + (raise (condition (&emacs-batch-error + (message (read-string (car error-pipe))))))) + output)) + (define (emacs-generate-autoloads name directory) "Generate autoloads for Emacs package NAME placed in DIRECTORY." (let* ((file (string-append directory "/" name "-autoloads.el")) diff --git a/tests/build-emacs-utils.scm b/tests/build-emacs-utils.scm new file mode 100644 index 0000000000..03b73b1fed --- /dev/null +++ b/tests/build-emacs-utils.scm @@ -0,0 +1,41 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2022 Fredrik Salomonsson +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + + +(define-module (test build-emacs-utils) + #:use-module (guix tests) + #:use-module (guix build emacs-utils) + #:use-module (guix build utils) + #:use-module ((guix utils) + #:select (call-with-temporary-directory)) + #:use-module (srfi srfi-34) + #:use-module (srfi srfi-64)) + +(test-begin "build-emacs-utils") + +(test-equal "print foo from emacs" + "foo" + (emacs-batch-script '(princ "foo"))) + +(test-assert "emacs-batch-script: raise &emacs-batch-error on failure" + (guard (c ((emacs-batch-error? c) + (string-contains (emacs-batch-error-message c) + "Lisp error: (wrong-type-argument numberp \"three\")"))) + (emacs-batch-script '(mapcar 'number-to-string (list 1 2 "three"))))) + +(test-end "build-emacs-utils") From patchwork Sun Jun 5 00:19:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fredrik Salomonsson X-Patchwork-Id: 39746 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id C9A3027BBEA; Sun, 5 Jun 2022 01:20:46 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 79EE527BBE9 for ; Sun, 5 Jun 2022 01:20:46 +0100 (BST) Received: from localhost ([::1]:46622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxe0b-0007ZT-Lx for patchwork@mira.cbaines.net; Sat, 04 Jun 2022 20:20:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55034) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxdzv-0007YD-DV for guix-patches@gnu.org; Sat, 04 Jun 2022 20:20:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:37668) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxdzv-0005C7-4v for guix-patches@gnu.org; Sat, 04 Jun 2022 20:20:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nxdzv-0001KX-0K for guix-patches@gnu.org; Sat, 04 Jun 2022 20:20:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#55420] [PATCH v2 2/2] guix: emacs-utils: Add emacs-header-parse. Resent-From: Fredrik Salomonsson Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 05 Jun 2022 00:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55420 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 55420@debbugs.gnu.org Cc: Fredrik Salomonsson Received: via spool by 55420-submit@debbugs.gnu.org id=B55420.16543883845065 (code B ref 55420); Sun, 05 Jun 2022 00:20:02 +0000 Received: (at 55420) by debbugs.gnu.org; 5 Jun 2022 00:19:44 +0000 Received: from localhost ([127.0.0.1]:59797 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nxdzb-0001Jd-VB for submit@debbugs.gnu.org; Sat, 04 Jun 2022 20:19:44 -0400 Received: from mout02.posteo.de ([185.67.36.66]:49005) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nxdzZ-0001JD-KH for 55420@debbugs.gnu.org; Sat, 04 Jun 2022 20:19:42 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id B3E59240107 for <55420@debbugs.gnu.org>; Sun, 5 Jun 2022 02:19:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1654388375; bh=Tz4lxpV5l2GYe6LS5apP0+3x+FwL/ndP77P/hweNnjE=; h=From:To:Cc:Subject:Date:From; b=Ws5FC8i4N3KLDevmzQe9ZvtUVPQFZLdcGNaT4SvQ48C0b3AIYmEJDgbX9dc1qSygH GJmdfZacomQEsSWYmrJgESY3/RKNwusa9L+DWex/FYVaeZE7BKnB6LDt3FbE7eR4g4 qjyImUeZQQJhnLbZoxVrDHyT6xemZiTb6ofH6dX7duvhS328dU+G+cb+4onASOPqxI /M1ewSa1eG4XHjkM+Z6X5aGr+V8TwPMy4PEU7xWwMUHsg5rGMQ3tF7EQqNMBuGLwIt +HeArf2HxWO9i4tviNWsFcdrvpPrA+P2d0xgHDfisDUNue8+Lakll/y99HZAy60EOP dReqCNm2jV/VQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4LFy125kPpz6tmM; Sun, 5 Jun 2022 02:19:34 +0200 (CEST) From: Fredrik Salomonsson Date: Sun, 5 Jun 2022 00:19:24 +0000 Message-Id: <20220605001924.184934-2-plattfot@posteo.net> In-Reply-To: <20220605001924.184934-1-plattfot@posteo.net> References: <20220605001924.184934-1-plattfot@posteo.net> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/build/emacs-utils.scm (emacs-header-parse): New procedure. * tests/build-emacs-utils.scm ("emacs-header-parse: fetch version", "emacs-header-parse: fetch keywords", "emacs-header-parse: fetch nonexistent author"): New tests. --- guix/build/emacs-utils.scm | 9 +++++++++ tests/build-emacs-utils.scm | 30 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/guix/build/emacs-utils.scm b/guix/build/emacs-utils.scm index 1684bf3262..8ee547f2b3 100644 --- a/guix/build/emacs-utils.scm +++ b/guix/build/emacs-utils.scm @@ -38,6 +38,7 @@ (define-module (guix build emacs-utils) emacs-generate-autoloads emacs-byte-compile-directory + emacs-header-parse as-display emacs-substitute-sexps @@ -114,6 +115,14 @@ (define* (emacs-byte-compile-directory dir) (byte-recompile-directory (file-name-as-directory ,dir) 0 1)))) (emacs-batch-eval expr))) +(define (emacs-header-parse section file) + "Parse the header SECTION in FILE and return it as a string." + (emacs-batch-script + `(progn + (require 'lisp-mnt) + (find-file ,file) + (princ (lm-header ,section))))) + (define as-display ;syntactic keyword for 'emacs-substitute-sexps' '(as display)) diff --git a/tests/build-emacs-utils.scm b/tests/build-emacs-utils.scm index 03b73b1fed..57647caaa2 100644 --- a/tests/build-emacs-utils.scm +++ b/tests/build-emacs-utils.scm @@ -38,4 +38,34 @@ (define-module (test build-emacs-utils) "Lisp error: (wrong-type-argument numberp \"three\")"))) (emacs-batch-script '(mapcar 'number-to-string (list 1 2 "three"))))) +(define (test-emacs-header-parse section) + (call-with-temporary-directory + (lambda (directory) + (let ((mock-elisp-file (string-append directory "/foo.el"))) + (call-with-output-file mock-elisp-file + (lambda (port) + (display ";;; foo --- mock emacs package -*- lexical-binding: t -*- + +;; Created: 4 Jun 2022 +;; Keywords: lisp test +;; Version: 1.0.0 +;;; Commentary: +;;; Code: +;;; foo.el ends here +" + port))) + (emacs-header-parse section mock-elisp-file))))) + +(test-equal "emacs-header-parse: fetch version" + "1.0.0" + (test-emacs-header-parse "version")) + +(test-equal "emacs-header-parse: fetch keywords" + "lisp test" + (test-emacs-header-parse "keywords")) + +(test-equal "emacs-header-parse: fetch nonexistent author" + "nil" + (test-emacs-header-parse "author")) + (test-end "build-emacs-utils")