From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42756) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eXNEW-0004Wu-EW for guix-patches@gnu.org; Fri, 05 Jan 2018 03:20:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eXNEQ-0005yC-7u for guix-patches@gnu.org; Fri, 05 Jan 2018 03:20:08 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:55866) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eXNEP-0005xO-Vu for guix-patches@gnu.org; Fri, 05 Jan 2018 03:20:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eXNEP-0007hh-PH for guix-patches@gnu.org; Fri, 05 Jan 2018 03:20:01 -0500 Subject: [bug#29951] [PATCH] WIP guix: Add wrap-script. Resent-Message-ID: References: <20180102204434.2716-1-rekado@elephly.net> <69141465-bdd7-4855-c5d0-a3750646273b@crazy-compilers.com> From: Ricardo Wurmus In-reply-to: <69141465-bdd7-4855-c5d0-a3750646273b@crazy-compilers.com> 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@elephly.net> 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: Hartmut Goebel Cc: 29951@debbugs.gnu.org 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