From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id SNl8IN/2m2IfsgAAbAwnHQ (envelope-from ) for ; Sun, 05 Jun 2022 02:20:47 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id 2JGEIN/2m2KWmgAA9RJhRA (envelope-from ) for ; Sun, 05 Jun 2022 02:20:47 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 076482651D for ; Sun, 5 Jun 2022 02:20:46 +0200 (CEST) Received: from localhost ([::1]:46606 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxe0b-0007YT-Qw for larch@yhetil.org; Sat, 04 Jun 2022 20:20:45 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1654388447; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=UTQ5LSpedemaGjnxCBY385JV3NQm/erQ1hA+xqcWnmk=; b=pKDx+xg8GEF4exFzXS8w+p5NtCKWWgM0046sxlW7H1RCjmKsa/0lk/zeHMXdkB5RicYsUQ 8jW3DRPKZl09giAdTrdCzQowlulRPcgj8BJoqd2NcSFdBxQhgu3P5wvP0dz786OEckzjbi PDiFDr+ErF45HmObnHVyNqPykccySDwavu5iYyugFWbqiBuj0FaO9duhklf5oyIZVvARNp aF3WmVD94qITmdiG5G4+4TEf/6ghQxEhHQc6JyjqaJ5RCXIDPF/U3vjTRRN2UxcqVKfNL9 zZShe+Lg3QRtCvy8ZHe2fXuK3tDHPqu7szkMDf6VXCWx7M9Bu332qB+pt1cCDQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1654388447; a=rsa-sha256; cv=none; b=RaGXCRYg6M0mAhKwjuZQD1cA/kXRKbqij9AnwT8yEPpQAsH1oybpX0SHJGab4qltwkC5P0 Xfss/fxpVIxz/my5xmqgFXiFmljPqUotMpjEiYb+teGVzSwneH50sD1bf+o1xKLG+Xq6hD S4sBXYtGFjEySTQj8FJrLFqMmPVq4yHehjBz8T2BLU5T1NKlS+4oYKeLkzNjwQ8HYIKZuI N5HUE4loCyOL3imo2HEkrEpizdUPml4b7eP/KdQN3J59+dVpBtOMF32khv4sFikufwrvLq AtXJ2B/newVqJt5bozrKvTsdz9YEWUWa81BDyY79VP4Yz+aXItuRTsjRjyGlmw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=posteo.net header.s=2017 header.b=I9sYRWmt; dmarc=fail reason="SPF not aligned (strict)" header.from=posteo.net (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 7.98 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=posteo.net header.s=2017 header.b=I9sYRWmt; dmarc=fail reason="SPF not aligned (strict)" header.from=posteo.net (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 076482651D X-Spam-Score: 7.98 X-Migadu-Scanner: scn0.migadu.com X-TUID: JDXlZqEqUmlP * 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 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") base-commit: 271736117e3f09b616a2dbd5d74c9595926c9297 -- 2.36.1