From patchwork Sun Jun 5 19:51:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Fredrik Salomonsson X-Patchwork-Id: 39751 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 8CBE427BBE9; Sun, 5 Jun 2022 20:53:31 +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 5697627BBEA for ; Sun, 5 Jun 2022 20:53:30 +0100 (BST) Received: from localhost ([::1]:51966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxwJV-0003pN-Dc for patchwork@mira.cbaines.net; Sun, 05 Jun 2022 15:53:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41684) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxwJ4-0003nz-JR for guix-patches@gnu.org; Sun, 05 Jun 2022 15:53:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:39668) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxwJ4-0003n2-An for guix-patches@gnu.org; Sun, 05 Jun 2022 15:53:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nxwJ4-0007Lm-8W for guix-patches@gnu.org; Sun, 05 Jun 2022 15:53:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#55420] [PATCH v3 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 19:53: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.165445872528172 (code B ref 55420); Sun, 05 Jun 2022 19:53:02 +0000 Received: (at 55420) by debbugs.gnu.org; 5 Jun 2022 19:52:05 +0000 Received: from localhost ([127.0.0.1]:33561 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nxwI7-0007KJ-8u for submit@debbugs.gnu.org; Sun, 05 Jun 2022 15:52:05 -0400 Received: from mout01.posteo.de ([185.67.36.65]:50677) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nxwI2-0007Jj-6O for 55420@debbugs.gnu.org; Sun, 05 Jun 2022 15:52:02 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 8D4E7240027 for <55420@debbugs.gnu.org>; Sun, 5 Jun 2022 21:51:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1654458711; bh=3QmFu7NTbkRC0nhbTFW4Cy0FkgYDp/1ICvDnLzYelCg=; h=From:To:Cc:Subject:Date:From; b=gkiac1D4K2K+G4eTlMVpTHl2NwWB0vzh9Unv2cMo29VQar5g2Y9royAvt1R/TCoP1 U2Cs9cwq3XdFVVThpVWSwQL3pIBYS3VxOWgh9TYBjpbWwU/mEqRODOhs7zJ52MLO++ XSqlnRKhmYgESif+zwmMziK6YCIxOWwbYW+CFIVeOvzuHkCZXT0YD8vambaEPNVMGY KKJeWHvnn40vXjKMiTcIwzLW3S9nhiv1iOseun3EYoUSlLcO7rAsS3CqG5XmD4JkVy sBvNH7DHMUu7dvf4jZd9uBbZKQT4Sn0QGqfarY/vw0dVc+2NC73WkbWR99Y9zGYmYi o1LiKlPJWoypQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4LGS1f3b6Gz6tmp; Sun, 5 Jun 2022 21:51:50 +0200 (CEST) From: Fredrik Salomonsson Date: Sun, 5 Jun 2022 19:51:42 +0000 Message-Id: <20220605195143.23591-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 | 43 +++++++++++++++++++++++++++++++++++++ 3 files changed, 74 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..27cff46c38 --- /dev/null +++ b/tests/build-emacs-utils.scm @@ -0,0 +1,43 @@ +;;; 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") +;; Only run the following tests if emacs is present. +(test-skip (if (which "emacs") 0 2)) + +(test-equal "emacs-batch-script: 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")