From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35458) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ea8CB-0005MS-Q6 for guix-patches@gnu.org; Fri, 12 Jan 2018 17:53:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ea8C7-0002XS-3g for guix-patches@gnu.org; Fri, 12 Jan 2018 17:53:07 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:46381) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ea8C7-0002XL-09 for guix-patches@gnu.org; Fri, 12 Jan 2018 17:53:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ea8C6-0006f9-Hz for guix-patches@gnu.org; Fri, 12 Jan 2018 17:53:02 -0500 Subject: [bug#29951] [PATCH] WIP guix: Add wrap-script. Resent-Message-ID: From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) References: <20180102204434.2716-1-rekado@elephly.net> Date: Fri, 12 Jan 2018 23:52:14 +0100 In-Reply-To: <20180102204434.2716-1-rekado@elephly.net> (Ricardo Wurmus's message of "Tue, 2 Jan 2018 21:44:34 +0100") Message-ID: <87373ar8pt.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: Ricardo Wurmus Cc: h.goebel@crazy-compilers.com, 29951@debbugs.gnu.org Hi! Ricardo Wurmus skribis: > * guix/build/utils.scm (wrap-script): New procedure. [...] > +(define wrap-script > + (let ((interpreter-regex > + (make-regexp > + (string-append "^#! ?(/bin/sh|/gnu/store/[^/]+/bin/(" > + (string-join '("python[^ ]*" > + "Rscript" > + "perl" > + "ruby" > + "bash" > + "sh") "|") > + ") ?.*)"))) > + (coding-line-regex > + (make-regexp > + ".*#.*coding[=3D:][[:space:]]*([-[a-zA-Z_0-9].]+)"))) > + (lambda* (prog #:rest vars) > + "Wrap the script PROG such that VARS are set first. The format of= VARS > +is the same as in the WRAP-PROGRAM procedure. This procedure differs fr= om > +WRAP-PROGRAM in that it does not create a separate shell script. Instea= d, > +PROG is modified directly by prepending a Guile script, which is interpr= eted > +as a comment in the script's language. > + > +Special encoding comments as supported by Python are recreated on the se= cond > +line. > + > +Note that this procedure can only be used once per file as Guile scripts= are > +not supported." Nice! > + (let-values (((interpreter coding-line) > + (call-with-ascii-input-file prog > + (lambda (p) > + (values (false-if-exception > + (and=3D> (regexp-exec interpreter-regex= (read-line p)) > + (lambda (m) (match:substring m 1= )))) > + (false-if-exception > + (and=3D> (regexp-exec coding-line-regex= (read-line p)) > + (lambda (m) (match:substring m 0= ))))))))) =E2=80=98false-if-exception=E2=80=99 is problematic because it can hide err= ors. Could you narrow that down to the exception type of interest? Or is there a risk of random decoding errors and the likes when passed a binary file? > + (when interpreter Should it return #t on success and #f on failure? Or just thrown an exception on failure? > + (which "guile") Let=E2=80=99s add #:guile defaulting to (which "guile"). I wonder if =E2=80=98wrap-program=E2=80=99 could automatically call =E2=80= =98wrap-script=E2=80=99 when appropriate so that users don=E2=80=99t have to choose by themselves. WDYT? Thanks! Ludo=E2=80=99.