GNU bug report logs - #29951
[PATCH] WIP guix: Add wrap-script.

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: guix-patches; Severity: important; Reported by: Ricardo Wurmus <rekado@HIDDEN>; Keywords: patch; dated Tue, 2 Jan 2018 20:46:01 UTC; Maintainer for guix-patches is guix-patches@HIDDEN.
Severity set to 'important' from 'normal' Request was from ludo@HIDDEN (Ludovic Courtès) to control <at> debbugs.gnu.org. Full text available.

Message received at 29951 <at> debbugs.gnu.org:


Received: (at 29951) by debbugs.gnu.org; 12 Jan 2018 22:52:20 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Jan 12 17:52:20 2018
Received: from localhost ([127.0.0.1]:54278 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1ea8BP-0006eG-Qy
	for submit <at> debbugs.gnu.org; Fri, 12 Jan 2018 17:52:20 -0500
Received: from hera.aquilenet.fr ([185.233.100.1]:44964)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <ludo@HIDDEN>) id 1ea8BO-0006e8-4C
 for 29951 <at> debbugs.gnu.org; Fri, 12 Jan 2018 17:52:18 -0500
Received: from localhost (localhost [127.0.0.1])
 by hera.aquilenet.fr (Postfix) with ESMTP id 1809B10A22;
 Fri, 12 Jan 2018 23:52:17 +0100 (CET)
X-Virus-Scanned: Debian amavisd-new at aquilenet.fr
Received: from hera.aquilenet.fr ([127.0.0.1])
 by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id KDjc6FMHiQ5Z; Fri, 12 Jan 2018 23:52:16 +0100 (CET)
Received: from ribbon (unknown [IPv6:2a01:e0a:1d:7270:af76:b9b:ca24:c465])
 by hera.aquilenet.fr (Postfix) with ESMTPSA id A40A610880;
 Fri, 12 Jan 2018 23:52:15 +0100 (CET)
From: ludo@HIDDEN (Ludovic =?utf-8?Q?Court=C3=A8s?=)
To: Ricardo Wurmus <rekado@HIDDEN>
Subject: Re: [bug#29951] [PATCH] WIP guix: Add wrap-script.
References: <20180102204434.2716-1-rekado@HIDDEN>
Date: Fri, 12 Jan 2018 23:52:14 +0100
In-Reply-To: <20180102204434.2716-1-rekado@HIDDEN> (Ricardo Wurmus's
 message of "Tue, 2 Jan 2018 21:44:34 +0100")
Message-ID: <87373ar8pt.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: 1.0 (+)
X-Debbugs-Envelope-To: 29951
Cc: h.goebel@HIDDEN, 29951 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 1.0 (+)

Hi!

Ricardo Wurmus <rekado@HIDDEN> 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.




Information forwarded to guix-patches@HIDDEN:
bug#29951; Package guix-patches. Full text available.

Message received at 29951 <at> debbugs.gnu.org:


Received: (at 29951) by debbugs.gnu.org; 5 Jan 2018 10:06:40 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Jan 05 05:06:40 2018
Received: from localhost ([127.0.0.1]:36360 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1eXOtc-0001zM-6O
	for submit <at> debbugs.gnu.org; Fri, 05 Jan 2018 05:06:40 -0500
Received: from mail-out.m-online.net ([212.18.0.10]:47853)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <h.goebel@HIDDEN>) id 1eXOta-0001zE-Jc
 for 29951 <at> debbugs.gnu.org; Fri, 05 Jan 2018 05:06:39 -0500
Received: from frontend01.mail.m-online.net (unknown [192.168.8.182])
 by mail-out.m-online.net (Postfix) with ESMTP id 3zCgLP33R6z1qtGF;
 Fri,  5 Jan 2018 11:06:37 +0100 (CET)
Received: from localhost (dynscan1.mnet-online.de [192.168.6.70])
 by mail.m-online.net (Postfix) with ESMTP id 3zCgLP21tLz1qsvp;
 Fri,  5 Jan 2018 11:06:37 +0100 (CET)
X-Virus-Scanned: amavisd-new at mnet-online.de
Received: from mail.mnet-online.de ([192.168.8.182])
 by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new,
 port 10024)
 with ESMTP id doRVi3L7z0f1; Fri,  5 Jan 2018 11:06:36 +0100 (CET)
Received: from hermia.goebel-consult.de
 (ppp-83-171-156-105.dynamic.mnet-online.de [83.171.156.105])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (No client certificate requested)
 by mail.mnet-online.de (Postfix) with ESMTPS;
 Fri,  5 Jan 2018 11:06:36 +0100 (CET)
Received: from [192.168.110.2] (lenashee.goebel-consult.de [192.168.110.2])
 by hermia.goebel-consult.de (Postfix) with ESMTP id 497856002B;
 Fri,  5 Jan 2018 11:06:36 +0100 (CET)
Subject: Re: [PATCH] WIP guix: Add wrap-script.
To: Ricardo Wurmus <rekado@HIDDEN>
References: <20180102204434.2716-1-rekado@HIDDEN>
 <69141465-bdd7-4855-c5d0-a3750646273b@HIDDEN>
 <87o9m84t2n.fsf@HIDDEN>
From: Hartmut Goebel <h.goebel@HIDDEN>
Organization: crazy-compilers.com
Message-ID: <0b4f18c5-ff7d-f03f-e6c7-1866e28099e3@HIDDEN>
Date: Fri, 5 Jan 2018 11:06:35 +0100
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
 Thunderbird/52.5.2
MIME-Version: 1.0
In-Reply-To: <87o9m84t2n.fsf@HIDDEN>
Content-Type: multipart/alternative;
 boundary="------------37E86838AE7EDC0F9EB64E90"
Content-Language: en-US
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 29951
Cc: 29951 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.7 (/)

This is a multi-part message in MIME format.
--------------37E86838AE7EDC0F9EB64E90
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

Am 05.01.2018 um 09:19 schrieb Ricardo Wurmus:

Thanks for your reply.

>> Does this take care of proper quoting the string-values?
> What string values do you refer to?  We first generate an S-expression
> (where we don’t need to take care of escaping things anyway) and then
> format it as a string (with “format” and the “~s” format string), and
> then we print that S-expression-as-a-string into a file.

I mean the values of the environment variables to be set, whcih might
contain double-quotes or backslashes.

But I understand that these values are calculated within guile anyway
and ~s takes care of proper quoting. So this is fine. Thanks for
elaborating.

-- 
Regards
Hartmut Goebel

| Hartmut Goebel          | h.goebel@HIDDEN               |
| www.crazy-compilers.com | compilers which you thought are impossible |


--------------37E86838AE7EDC0F9EB64E90
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Am 05.01.2018 um 09:19 schrieb Ricardo
      Wurmus:<br>
      <br>
      Thanks for your reply.<br>
      <br>
    </div>
    <blockquote type="cite" cite="mid:87o9m84t2n.fsf@HIDDEN">
      <blockquote type="cite" style="color: #000000;">
        <pre wrap="">Does this take care of proper quoting the string-values?
</pre>
      </blockquote>
      <pre wrap="">What string values do you refer to?  We first generate an S-expression
(where we don’t need to take care of escaping things anyway) and then
format it as a string (with “format” and the “~s” format string), and
then we print that S-expression-as-a-string into a file.</pre>
    </blockquote>
    <p>I mean the values of the environment variables to be set, whcih
      might contain double-quotes or backslashes.</p>
    <p>But I understand that these values are calculated within guile
      anyway and ~s takes care of proper quoting. So this is fine.
      Thanks for elaborating.<br>
    </p>
    <pre class="moz-signature" cols="72">-- 
Regards
Hartmut Goebel

| Hartmut Goebel          | <a class="moz-txt-link-abbreviated" href="mailto:h.goebel@HIDDEN">h.goebel@HIDDEN</a>               |
| <a class="moz-txt-link-abbreviated" href="http://www.crazy-compilers.com">www.crazy-compilers.com</a> | compilers which you thought are impossible |
</pre>
  </body>
</html>

--------------37E86838AE7EDC0F9EB64E90--




Information forwarded to guix-patches@HIDDEN:
bug#29951; Package guix-patches. Full text available.

Message received at 29951 <at> debbugs.gnu.org:


Received: (at 29951) by debbugs.gnu.org; 5 Jan 2018 08:19:30 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Jan 05 03:19:29 2018
Received: from localhost ([127.0.0.1]:36314 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1eXNDt-0007gi-Ko
	for submit <at> debbugs.gnu.org; Fri, 05 Jan 2018 03:19:29 -0500
Received: from sender-of-o51.zoho.com ([135.84.80.216]:21099)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <rekado@HIDDEN>) id 1eXNDr-0007gX-KH
 for 29951 <at> debbugs.gnu.org; Fri, 05 Jan 2018 03:19:28 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1515140343; 
 s=zoho; d=elephly.net; i=rekado@HIDDEN;
 h=References:From:To:Cc:Subject:In-reply-to:Date:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID;
 l=3864; bh=f5/D8RMsnJBqHbEL0yVntI1DoG9wqFchd5ueDwOa+C4=;
 b=X9gmhJiXFhFluqhUWHoIKZorsinwz14nTp8VU8PV81mk//hl3clAqXl8gjaahjtP
 bB/4M7vAYZaxFmVt5FVDCJXsxBELOpkmRWHSBwqUuuLJHv2qAP0YtesQe/Fi8Prd4oz
 82/Dh6B/m40ID1C/8IlnBRJy6mFuuIPKBsVoSZYs=
Received: from localhost (port-92-200-114-22.dynamic.qsc.de [92.200.114.22])
 by mx.zohomail.com with SMTPS id 1515140343614140.34013010982653;
 Fri, 5 Jan 2018 00:19:03 -0800 (PST)
References: <20180102204434.2716-1-rekado@HIDDEN>
 <69141465-bdd7-4855-c5d0-a3750646273b@HIDDEN>
User-agent: mu4e 1.0-alpha3; emacs 25.3.1
From: Ricardo Wurmus <rekado@HIDDEN>
To: Hartmut Goebel <h.goebel@HIDDEN>
Subject: Re: [PATCH] WIP guix: Add wrap-script.
In-reply-to: <69141465-bdd7-4855-c5d0-a3750646273b@HIDDEN>
X-URL: https://elephly.net
X-PGP-Key: https://elephly.net/rekado.pubkey
X-PGP-Fingerprint: BCA6 89B6 3655 3801 C3C6  2150 197A 5888 235F ACAC
Date: Fri, 05 Jan 2018 09:19:00 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Message-ID: <87o9m84t2n.fsf@HIDDEN>
X-ZohoMailClient: External
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 29951
Cc: 29951 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 0.0 (/)


Hi Hartmut,

>> +                                (false-if-exception
>> +                                 (and=3D> (regexp-exec coding-line-rege=
x (read-line p))
>> +                                        (lambda (m) (match:substring m =
0)))))))))
>
> When using emacs, this line can also contain other local variable
> definitions. What about keeping the whole line?

The purpose here was just to retain the coding comment, because it is
interpreted by Python itself to set the file encoding.  Other values are
not used by Python to make any such decisions.

Since these modified files are only generated in a build phase to modify
the *execution* environment (and the unchanged files are available via
=E2=80=9Cguix build -S=E2=80=9D), I think that it is reasonable to assume t=
hat users
won=E2=80=99t be interested in editing these files directly, so hints to th=
e
editor don=E2=80=99t need to be preserved.

I find it a little cleaner to keep this coding-line preservation as
restricted as possible, but maybe you are right and it would be safer to
just copy the whole line when the coding regex matches.

>> +        (when interpreter
>> +          (let* ((header (format #f "\
>> +#!~a --no-auto-compile
>> +#!#; ~a
>> +#\\-~s
>> +#\\-~s
>> +"
>> +                                 (which "guile")
>> +                                 (or coding-line "Guix wrapper")
>> +                                 (cons 'begin (map update-env vars))
>> +                                 `(apply execl ,interpreter
>> +                                         (car (command-line))
>> +                                         (command-line))))
>
> Does this take care of proper quoting the string-values?

What string values do you refer to?  We first generate an S-expression
(where we don=E2=80=99t need to take care of escaping things anyway) and th=
en
format it as a string (with =E2=80=9Cformat=E2=80=9D and the =E2=80=9C~s=E2=
=80=9D format string), and
then we print that S-expression-as-a-string into a file.

I ran this on an actual Python file in the store.  This is the original
file, which I copied to =E2=80=9C/tmp/test-python=E2=80=9D:

--8<---------------cut here---------------start------------->8---
#!/gnu/store/iyy9w0hcxv4dg9q92d4g023vvz50r5bq-python-3.5.3/bin/python3.5
import sys
from lib2to3.main import main

sys.exit(main("lib2to3.fixes"))
--8<---------------cut here---------------end--------------->8---

This is the code in the REPL:

--8<---------------cut here---------------start------------->8---
,use (guix build utils)
scheme@(guile-user)> (wrap-script "/tmp/test-python"
                                  '("PYTHONPATH" ":" prefix ("/foo/bar:what=
ever"))
                                  '("FOOBAR" ":" suffix ("/to/me")))
scheme@(guile-user)>
--8<---------------cut here---------------end--------------->8---

This is the result in =E2=80=9C/tmp/test-python=E2=80=9D:

--8<---------------cut here---------------start------------->8---
#!/home/rekado/.guix-profile/bin/guile --no-auto-compile
#!#; Guix wrapper
#\-(begin (let ((current (getenv "PYTHONPATH"))) (setenv "PYTHONPATH" (if c=
urrent (string-append "/foo/bar:whatever" ":" current) "/foo/bar:whatever")=
)) (let ((current (getenv "FOOBAR"))) (setenv "FOOBAR" (if current (string-=
append current ":" "/to/me") "/to/me"))))
#\-(apply execl "/gnu/store/iyy9w0hcxv4dg9q92d4g023vvz50r5bq-python-3.5.3/b=
in/python3.5" (car (command-line)) (command-line))
#!/gnu/store/iyy9w0hcxv4dg9q92d4g023vvz50r5bq-python-3.5.3/bin/python3.5
import sys
from lib2to3.main import main

sys.exit(main("lib2to3.fixes"))
--8<---------------cut here---------------end--------------->8---

>
>> +                (call-with-ascii-input-file prog
>
> Does this work if the file contains non-ascii characters, e.g. \xf0
> (assuming "ascii" means 0-127 only)?

=E2=80=9Ccall-with-ascii-input-file=E2=80=9D opens the file as a binary, so=
 it reads the
file as a series of bytes.  This seems fine when reading only the
shebang (which is ASCII only) and when trying to match the coding regex
on the second line.

--
Ricardo

GPG: BCA6 89B6 3655 3801 C3C6  2150 197A 5888 235F ACAC
https://elephly.net






Information forwarded to guix-patches@HIDDEN:
bug#29951; Package guix-patches. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 3 Jan 2018 13:59:44 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Jan 03 08:59:44 2018
Received: from localhost ([127.0.0.1]:33883 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1eWja3-0007SO-QU
	for submit <at> debbugs.gnu.org; Wed, 03 Jan 2018 08:59:44 -0500
Received: from eggs.gnu.org ([208.118.235.92]:59692)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <h.goebel@HIDDEN>) id 1eWja2-0007SC-6y
 for submit <at> debbugs.gnu.org; Wed, 03 Jan 2018 08:59:42 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <h.goebel@HIDDEN>) id 1eWjZw-0001tb-0K
 for submit <at> debbugs.gnu.org; Wed, 03 Jan 2018 08:59:36 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=disabled
 version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:51044)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <h.goebel@HIDDEN>)
 id 1eWjZv-0001tV-Sf
 for submit <at> debbugs.gnu.org; Wed, 03 Jan 2018 08:59:35 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:50661)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <h.goebel@HIDDEN>) id 1eWjZu-0002AZ-Rh
 for guix-patches@HIDDEN; Wed, 03 Jan 2018 08:59:35 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <h.goebel@HIDDEN>) id 1eWjZr-0001rB-QM
 for guix-patches@HIDDEN; Wed, 03 Jan 2018 08:59:34 -0500
Received: from mail-out.m-online.net ([212.18.0.9]:56446)
 by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <h.goebel@HIDDEN>)
 id 1eWjZr-0001qO-JZ
 for guix-patches@HIDDEN; Wed, 03 Jan 2018 08:59:31 -0500
Received: from frontend01.mail.m-online.net (unknown [192.168.8.182])
 by mail-out.m-online.net (Postfix) with ESMTP id 3zBXc10SnVz1qrjS;
 Wed,  3 Jan 2018 14:59:28 +0100 (CET)
Received: from localhost (dynscan1.mnet-online.de [192.168.6.70])
 by mail.m-online.net (Postfix) with ESMTP id 3zBXc05v2Vz26T2W;
 Wed,  3 Jan 2018 14:59:28 +0100 (CET)
X-Virus-Scanned: amavisd-new at mnet-online.de
Received: from mail.mnet-online.de ([192.168.8.182])
 by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new,
 port 10024)
 with ESMTP id TvadCGkKtVLA; Wed,  3 Jan 2018 14:59:28 +0100 (CET)
Received: from hermia.goebel-consult.de
 (ppp-212-114-230-52.dynamic.mnet-online.de [212.114.230.52])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (No client certificate requested)
 by mail.mnet-online.de (Postfix) with ESMTPS;
 Wed,  3 Jan 2018 14:59:28 +0100 (CET)
Received: from [192.168.110.2] (lenashee.goebel-consult.de [192.168.110.2])
 by hermia.goebel-consult.de (Postfix) with ESMTP id 8C9F8602E0;
 Wed,  3 Jan 2018 14:59:27 +0100 (CET)
Subject: Re: [PATCH] WIP guix: Add wrap-script.
To: Ricardo Wurmus <rekado@HIDDEN>, guix-patches@HIDDEN
References: <20180102204434.2716-1-rekado@HIDDEN>
From: Hartmut Goebel <h.goebel@HIDDEN>
Organization: crazy-compilers.com
Message-ID: <69141465-bdd7-4855-c5d0-a3750646273b@HIDDEN>
Date: Wed, 3 Jan 2018 14:59:27 +0100
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
 Thunderbird/52.5.2
MIME-Version: 1.0
In-Reply-To: <20180102204434.2716-1-rekado@HIDDEN>
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Content-Language: en-US
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
 [fuzzy]
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -5.0 (-----)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -5.0 (-----)

This code is over-changeling my scheme knowledge :-) Thus just a few
comments:


> +                                (false-if-exception
> +                                 (and=> (regexp-exec coding-line-regex (read-line p))
> +                                        (lambda (m) (match:substring m 0)))))))))

When using emacs, this line can also contain other local variable
definitions. What about keeping the whole line?

> +        (when interpreter
> +          (let* ((header (format #f "\
> +#!~a --no-auto-compile
> +#!#; ~a
> +#\\-~s
> +#\\-~s
> +"
> +                                 (which "guile")
> +                                 (or coding-line "Guix wrapper")
> +                                 (cons 'begin (map update-env vars))
> +                                 `(apply execl ,interpreter
> +                                         (car (command-line))
> +                                         (command-line))))

Does this take care of proper quoting the string-values?

> +                (call-with-ascii-input-file prog

Does this work if the file contains non-ascii characters, e.g. \xf0
(assuming "ascii" means 0-127 only)?


-- 
Regards
Hartmut Goebel

| Hartmut Goebel          | h.goebel@HIDDEN               |
| www.crazy-compilers.com | compilers which you thought are impossible |





Information forwarded to guix-patches@HIDDEN:
bug#29951; Package guix-patches. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 2 Jan 2018 20:45:09 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Jan 02 15:45:08 2018
Received: from localhost ([127.0.0.1]:33515 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1eWTQl-00078p-G6
	for submit <at> debbugs.gnu.org; Tue, 02 Jan 2018 15:45:08 -0500
Received: from eggs.gnu.org ([208.118.235.92]:51186)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <rekado@HIDDEN>) id 1eWTQj-000784-4K
 for submit <at> debbugs.gnu.org; Tue, 02 Jan 2018 15:45:01 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <rekado@HIDDEN>) id 1eWTQc-0005FN-RE
 for submit <at> debbugs.gnu.org; Tue, 02 Jan 2018 15:44:55 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_40,T_DKIM_INVALID
 autolearn=disabled version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:56643)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <rekado@HIDDEN>) id 1eWTQc-0005FF-NW
 for submit <at> debbugs.gnu.org; Tue, 02 Jan 2018 15:44:54 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:42110)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <rekado@HIDDEN>) id 1eWTQZ-0001FO-FZ
 for guix-patches@HIDDEN; Tue, 02 Jan 2018 15:44:54 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <rekado@HIDDEN>) id 1eWTQV-0005C7-Cl
 for guix-patches@HIDDEN; Tue, 02 Jan 2018 15:44:51 -0500
Received: from sender-of-o51.zoho.com ([135.84.80.216]:21088)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <rekado@HIDDEN>) id 1eWTQV-0005Bl-4D
 for guix-patches@HIDDEN; Tue, 02 Jan 2018 15:44:47 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1514925879; 
 s=zoho; d=elephly.net; i=rekado@HIDDEN;
 h=From:To:Cc:Subject:Date:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID;
 l=3895; bh=C58YzEZHqqwJSFrk+d/9KKnYxnbCpcUNkAI/Ful/EJU=;
 b=LOBB+d6dUtOUIDqYwrKgZpYfVneWjsd0pxwYb/PoRu9/qp26+3/yQjrNd+X1g9Qm
 gq3kiJ4OpyxOsrkzaVaipCiue8uOmPO6ntf/qQ9QYzxLMhb7UXxA+86ZHAAkHET3Pj5
 puo2gBP5q1l/WzjXXh7Ld9D0dVnW4VZrspEvOcC4=
Received: from localhost (port-92-200-194-49.dynamic.qsc.de [92.200.194.49])
 by mx.zohomail.com with SMTPS id 1514925879695415.46803452792415;
 Tue, 2 Jan 2018 12:44:39 -0800 (PST)
From: Ricardo Wurmus <rekado@HIDDEN>
To: guix-patches@HIDDEN
Subject: [PATCH] WIP guix: Add wrap-script.
Date: Tue,  2 Jan 2018 21:44:34 +0100
X-Mailer: git-send-email 2.15.0
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Message-ID: <20180102204434.2716-1-rekado@HIDDEN>
X-ZohoMailClient: External
X-ZohoMail: Z_26063301 SPT_1 Z_26062608 SPT_0
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
 [fuzzy]
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -4.0 (----)
X-Debbugs-Envelope-To: submit
Cc: Ricardo Wurmus <rekado@HIDDEN>, h.goebel@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -4.0 (----)

* guix/build/utils.scm (wrap-script): New procedure.
---
 guix/build/utils.scm | 101 +++++++++++++++++++++++++++++++++++++++++++++++=
++++
 1 file changed, 101 insertions(+)

diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index 7391307c8..a2efcb31c 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -3,6 +3,7 @@
 ;;; Copyright =C2=A9 2013 Andreas Enge <andreas@HIDDEN>
 ;;; Copyright =C2=A9 2013 Nikita Karetnikov <nikita@HIDDEN>
 ;;; Copyright =C2=A9 2015 Mark H Weaver <mhw@HIDDEN>
+;;; Copyright =C2=A9 2018 Ricardo Wurmus <rekado@HIDDEN>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -84,6 +85,7 @@
             fold-port-matches
             remove-store-references
             wrap-program
+            wrap-script
             invoke
=20
             locale-category->string))
@@ -1068,6 +1070,105 @@ with definitions for VARS."
         (chmod prog-tmp #o755)
         (rename-file prog-tmp prog))))
=20
+(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 V=
ARS
+is the same as in the WRAP-PROGRAM procedure.  This procedure differs from
+WRAP-PROGRAM in that it does not create a separate shell script.  Instead,
+PROG is modified directly by prepending a Guile script, which is interpret=
ed
+as a comment in the script's language.
+
+Special encoding comments as supported by Python are recreated on the seco=
nd
+line.
+
+Note that this procedure can only be used once per file as Guile scripts a=
re
+not supported."
+      (define update-env
+        (match-lambda
+          ((var sep '=3D rest)
+           `(setenv ,var ,(string-join rest sep)))
+          ((var sep 'prefix rest)
+           `(let ((current (getenv ,var)))
+              (setenv ,var (if current
+                               (string-append ,(string-join rest sep)
+                                              ,sep current)
+                               ,(string-join rest sep)))))
+          ((var sep 'suffix rest)
+           `(let ((current (getenv ,var)))
+              (setenv ,var (if current
+                               (string-append current ,sep
+                                              ,(string-join rest sep))
+                               ,(string-join rest sep)))))
+          ((var '=3D rest)
+           `(setenv ,var ,(string-join rest ":")))
+          ((var 'prefix rest)
+           `(let ((current (getenv ,var)))
+              (setenv ,var (if current
+                               (string-append ,(string-join rest ":")
+                                              ":" current)
+                               ,(string-join rest ":")))))
+          ((var 'suffix rest)
+           `(let ((current (getenv ,var)))
+              (setenv ,var (if current
+                               (string-append current ":"
+                                              ,(string-join rest ":"))
+                               ,(string-join rest ":")))))))
+      (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))=
)))))))
+        (when interpreter
+          (let* ((header (format #f "\
+#!~a --no-auto-compile
+#!#; ~a
+#\\-~s
+#\\-~s
+"
+                                 (which "guile")
+                                 (or coding-line "Guix wrapper")
+                                 (cons 'begin (map update-env vars))
+                                 `(apply execl ,interpreter
+                                         (car (command-line))
+                                         (command-line))))
+                 (template (string-append prog ".XXXXXX"))
+                 (out      (mkstemp! template))
+                 (st       (stat prog))
+                 (mode     (stat:mode st)))
+            (with-throw-handler #t
+              (lambda ()
+                (call-with-ascii-input-file prog
+                  (lambda (p)
+                    (format out header)
+                    (dump-port p out)
+                    (close out)
+                    (chmod template mode)
+                    (rename-file template prog)
+                    (set-file-time prog st))))
+              (lambda (key . args)
+                (format (current-error-port)
+                        "wrap-script: ~a: error: ~a ~s~%"
+                        prog key args)
+                (false-if-exception (delete-file template))
+                #f))))))))
+
 =0C
 ;;;
 ;;; Locales.
--=20
2.15.0







Acknowledgement sent to Ricardo Wurmus <rekado@HIDDEN>:
New bug report received and forwarded. Copy sent to guix-patches@HIDDEN. Full text available.
Report forwarded to guix-patches@HIDDEN:
bug#29951; Package guix-patches. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sun, 14 Jan 2018 22:15:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.