From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id gEh/ME+m414gNQAA0tVLHw (envelope-from ) for ; Fri, 12 Jun 2020 15:59:11 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 0OVKLE+m414ySwAAB5/wlQ (envelope-from ) for ; Fri, 12 Jun 2020 15:59:11 +0000 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 EA41A9408E7 for ; Fri, 12 Jun 2020 15:59:10 +0000 (UTC) Received: from localhost ([::1]:34490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjm5E-0003kG-W3 for larch@yhetil.org; Fri, 12 Jun 2020 11:59:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55118) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjm58-0003io-5w for guix-patches@gnu.org; Fri, 12 Jun 2020 11:59:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:57157) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jjm57-0007Hs-RI for guix-patches@gnu.org; Fri, 12 Jun 2020 11:59:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jjm57-00075F-PD for guix-patches@gnu.org; Fri, 12 Jun 2020 11:59:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#41253] [PATCH v4] guix repl: Add script execution. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 12 Jun 2020 15:59:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41253 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Konrad Hinsen Cc: 41253@debbugs.gnu.org Received: via spool by 41253-submit@debbugs.gnu.org id=B41253.159197752827210 (code B ref 41253); Fri, 12 Jun 2020 15:59:01 +0000 Received: (at 41253) by debbugs.gnu.org; 12 Jun 2020 15:58:48 +0000 Received: from localhost ([127.0.0.1]:40470 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jjm4t-00074o-Nu for submit@debbugs.gnu.org; Fri, 12 Jun 2020 11:58:47 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46924) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jjm4r-00074Y-Jv for 41253@debbugs.gnu.org; Fri, 12 Jun 2020 11:58:45 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:38091) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjm4m-0007EF-8H; Fri, 12 Jun 2020 11:58:40 -0400 Received: from [2a01:e0a:1d:7270:6a6c:dc17:fc02:cfda] (port=55052 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1jjm4l-00069I-5P; Fri, 12 Jun 2020 11:58:39 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= References: <20200514162537.29071-1-zimon.toutoune@gmail.com> Date: Fri, 12 Jun 2020 17:58:37 +0200 In-Reply-To: (Konrad Hinsen's message of "Sat, 06 Jun 2020 07:18:58 +0200") Message-ID: <87mu585l8y.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -3.3 (---) 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-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Spam-Score: -1.01 X-TUID: im41VnwvkJc8 Hi, and sorry for the delay! Konrad Hinsen skribis: > * guix/scripts/repl.scm: Add filename options for script execution. > * doc/guix.texi (Invoking guix repl): Document it. > * tests/guix-repl.sh: Test it. > * Makefile.am: (SH_TESTS): Add it. I have some comments regarding style and how to deal with multiple scripts, but I think we=E2=80=99re pretty much there. > +The general syntax is: > + > +@example > +guix repl @var{options} @var{file} @var{args} Should be: [@var{file} @var{args}@dots{}] The square brackets show it=E2=80=99s optional. > +When a @var{file} argument is provided, @var{file} is > +executed as a Guile scripts: =E2=80=9CWhen one or more @var{file} argument is provided, each @var{file} = is executed as a Guile program:=E2=80=9D > + (define script (reverse > + (map cdr > + (filter (lambda (opt) > + (eq? (car opt) 'script)) > + opts)))) To avoid car/cdr (info "(guix) Data Types and Pattern Matching"), I suggest something along these lines: (define scripts ;plural, no? (reverse (filter-map (match-lambda (('script . script) script) (_ #f)) opts))) > + (define script-file > + (let ((file (car script)) > + (directory (getcwd))) > + (canonicalize-path > + (cond ((string-prefix? "/" file) file) > + (else (string-append directory "/" file)))))) I think we can just use file names as they arrive, without attempting to canonicalize them or anything. > + (unless (null? script) > + ;; Run script > + (save-module-excursion > + (lambda () > + (set-program-arguments (cons script-file (cdr script))) > + (set-user-module) > + (load script-file)))) =3D> (for-each load scripts) =20=20=20=20 > +cat > "$tmpfile"< +#!/usr/bin/env -S guix repl -- Rather: #!$(type -P env) This will ensure it works even in Guix build environments. Could you send an updated patch? Thank you! Ludo=E2=80=99.