[PATCH] WIP guix: Add wrap-script.

  • Done
  • quality assurance status badge
Details
6 participants
  • Chris Marusich
  • Hartmut Goebel
  • Jelle Licht
  • Ludovic Courtès
  • Nils Gillmann
  • Ricardo Wurmus
Owner
unassigned
Submitted by
Ricardo Wurmus
Severity
important
R
R
Ricardo Wurmus wrote on 2 Jan 2018 21:44
(address . guix-patches@gnu.org)
20180102204434.2716-1-rekado@elephly.net
* guix/build/utils.scm (wrap-script): New procedure.
---
guix/build/utils.scm | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 101 insertions(+)

Toggle diff (128 lines)
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 © 2013 Andreas Enge <andreas@enge.fr>
;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
+;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -84,6 +85,7 @@
fold-port-matches
remove-store-references
wrap-program
+ wrap-script
invoke
locale-category->string))
@@ -1068,6 +1070,105 @@ with definitions for VARS."
(chmod prog-tmp #o755)
(rename-file prog-tmp prog))))
+(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[=:][[: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 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 interpreted
+as a comment in the script's language.
+
+Special encoding comments as supported by Python are recreated on the second
+line.
+
+Note that this procedure can only be used once per file as Guile scripts are
+not supported."
+ (define update-env
+ (match-lambda
+ ((var sep '= 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 '= 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=> (regexp-exec interpreter-regex (read-line p))
+ (lambda (m) (match:substring m 1))))
+ (false-if-exception
+ (and=> (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))))))))
+
;;;
;;; Locales.
--
2.15.0
H
H
Hartmut Goebel wrote on 3 Jan 2018 14:59
69141465-bdd7-4855-c5d0-a3750646273b@crazy-compilers.com
This code is over-changeling my scheme knowledge :-) Thus just a few
comments:


Toggle quote (4 lines)
> + (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?

Toggle quote (14 lines)
> + (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?

Toggle quote (2 lines)
> + (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@crazy-compilers.com |
| www.crazy-compilers.com | compilers which you thought are impossible |
R
R
Ricardo Wurmus wrote on 5 Jan 2018 09:19
(name . Hartmut Goebel)(address . h.goebel@crazy-compilers.com)(address . 29951@debbugs.gnu.org)
87o9m84t2n.fsf@elephly.net
Hi Hartmut,

Toggle quote (7 lines)
>> + (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?

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
“guix build -S”), I think that it is reasonable to assume that users
won’t be interested in editing these files directly, so hints to the
editor don’t 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.

Toggle quote (16 lines)
>> + (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’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 ran this on an actual Python file in the store. This is the original
file, which I copied to “/tmp/test-python”:

Toggle snippet (7 lines)
#!/gnu/store/iyy9w0hcxv4dg9q92d4g023vvz50r5bq-python-3.5.3/bin/python3.5
import sys
from lib2to3.main import main

sys.exit(main("lib2to3.fixes"))

This is the code in the REPL:

Toggle snippet (7 lines)
,use (guix build utils)
scheme@(guile-user)> (wrap-script "/tmp/test-python"
'("PYTHONPATH" ":" prefix ("/foo/bar:whatever"))
'("FOOBAR" ":" suffix ("/to/me")))
scheme@(guile-user)>

This is the result in “/tmp/test-python”:

Toggle snippet (11 lines)
#!/home/rekado/.guix-profile/bin/guile --no-auto-compile
#!#; Guix wrapper
#\-(begin (let ((current (getenv "PYTHONPATH"))) (setenv "PYTHONPATH" (if current (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/bin/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"))

Toggle quote (6 lines)
>
>> + (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)?

“call-with-ascii-input-file” 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
H
H
Hartmut Goebel wrote on 5 Jan 2018 11:06
(name . Ricardo Wurmus)(address . rekado@elephly.net)(address . 29951@debbugs.gnu.org)
0b4f18c5-ff7d-f03f-e6c7-1866e28099e3@crazy-compilers.com
Am 05.01.2018 um 09:19 schrieb Ricardo Wurmus:

Thanks for your reply.

Toggle quote (6 lines)
>> 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@crazy-compilers.com |
| www.crazy-compilers.com | compilers which you thought are impossible |
Attachment: file
L
L
Ludovic Courtès wrote on 12 Jan 2018 23:52
Re: [bug#29951] [PATCH] WIP guix: Add wrap-script.
(name . Ricardo Wurmus)(address . rekado@elephly.net)
87373ar8pt.fsf@gnu.org
Hi!

Ricardo Wurmus <rekado@elephly.net> skribis:

Toggle quote (2 lines)
> * guix/build/utils.scm (wrap-script): New procedure.

[...]

Toggle quote (27 lines)
> +(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[=:][[: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 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 interpreted
> +as a comment in the script's language.
> +
> +Special encoding comments as supported by Python are recreated on the second
> +line.
> +
> +Note that this procedure can only be used once per file as Guile scripts are
> +not supported."

Nice!

Toggle quote (10 lines)
> + (let-values (((interpreter coding-line)
> + (call-with-ascii-input-file prog
> + (lambda (p)
> + (values (false-if-exception
> + (and=> (regexp-exec interpreter-regex (read-line p))
> + (lambda (m) (match:substring m 1))))
> + (false-if-exception
> + (and=> (regexp-exec coding-line-regex (read-line p))
> + (lambda (m) (match:substring m 0)))))))))

‘false-if-exception’ is problematic because it can hide errors. 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?

Toggle quote (2 lines)
> + (when interpreter

Should it return #t on success and #f on failure? Or just thrown an
exception on failure?

Toggle quote (2 lines)
> + (which "guile")

Let’s add #:guile defaulting to (which "guile").

I wonder if ‘wrap-program’ could automatically call ‘wrap-script’ when
appropriate so that users don’t have to choose by themselves. WDYT?

Thanks!

Ludo’.
L
L
Ludovic Courtès wrote on 14 Jan 2018 22:59
control message for bug #29951
(address . control@debbugs.gnu.org)
87d12cje4j.fsf@gnu.org
severity 29951 important
C
C
Chris Marusich wrote on 2 Aug 2018 08:26
Re: [bug#29951] [PATCH] WIP guix: Add wrap-script.
(name . Ricardo Wurmus)(address . rekado@elephly.net)
87sh3xcmib.fsf@gmail.com
Ricardo Wurmus <rekado@elephly.net> writes:

Toggle quote (12 lines)
> This is the result in “/tmp/test-python”:
>
> #!/home/rekado/.guix-profile/bin/guile --no-auto-compile
> #!#; Guix wrapper
> #\-(begin (let ((current (getenv "PYTHONPATH"))) (setenv "PYTHONPATH" (if current (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/bin/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"))

I understand that the part beginning with #! and ending with !# are a
block comment in scheme, so they will be ignored by Guile, and that
"Guix wrapper" shows up after a ;, so it will also be considered a
comment by Guile, but I don't understand why the lines following that
need to begin with #\-. I also don't understand why Guile doesn't
complain about it. Why do the lines begin with #\-?

--
Chris
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEy/WXVcvn5+/vGD+x3UCaFdgiRp0FAltipAwACgkQ3UCaFdgi
Rp2ruxAArb+xtJfkF5amVlQQCwGGkwgJOrZWSNL7KSkXISrDWNWQ6+JEIQJWYnj8
SBVArYEGwW9uk1Psw6UxEJ9grAwMpTCPbjTMSuNb5YdVczqVakTsD0zAskqpdGtr
m7Ig+SF6t8sqCwfDF9yY1pM+quYlU49kwj/KnEaMakJczM1CvD8CHhV9YA9QvBfe
ERCAYzam2xItlUHOWG7lTtpSCv7KCvFxYMEtiVDTKLeW3Gv3EM1vzBtLRmjqIJLS
lvH4/MJy9VttiPfx+zm+Dlt6dfXscZj78e5sm9U8PtbfAhHAYmhmSRmTo3Gm4gGr
CCgeMhEXaETHVkpDi4A7D5mD/3oj7ar749o8OWN5an2+VlL21k7Yy4+qoatO1Z6v
M0l0bwDsrUKCYXB4bI/gdCkccs19gn7Hub/pP6LozXyyIcYkacTvrhO24QHOrQsz
AwI1bPlj916jVyXWxAuvg3WGqiuO0XwCi3orxWRGsycMvEkJrrFfsvrvm3Xvni+H
sMSu6KmDKirEH+QZCuROWXP2Bz229L9yHebODLRXzeiYtRJsciOglLEIvAg9h2s/
GsVrfkt17J77UDlo+V7bfIlTpzJBrFFe0tONW+Lch+PPCoVymJnjgPNY9lpJCddC
a34wwxtNxI/2dJYGKjbHH0HWvyd8M2AWMAPC8d/fqDVj1UTBDEs=
=eN44
-----END PGP SIGNATURE-----

R
R
Ricardo Wurmus wrote on 2 Aug 2018 09:23
(name . Chris Marusich)(address . cmmarusich@gmail.com)
87600ts04b.fsf@elephly.net
Hi Chris,

Toggle quote (21 lines)
> Ricardo Wurmus <rekado@elephly.net> writes:
>
>> This is the result in “/tmp/test-python”:
>>
>> #!/home/rekado/.guix-profile/bin/guile --no-auto-compile
>> #!#; Guix wrapper
>> #\-(begin (let ((current (getenv "PYTHONPATH"))) (setenv "PYTHONPATH" (if current (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/bin/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"))
>
> I understand that the part beginning with #! and ending with !# are a
> block comment in scheme, so they will be ignored by Guile, and that
> "Guix wrapper" shows up after a ;, so it will also be considered a
> comment by Guile, but I don't understand why the lines following that
> need to begin with #\-. I also don't understand why Guile doesn't
> complain about it. Why do the lines begin with #\-?

#\- is Guile syntax for the character “-”. To ensure that the target
language ignores these lines they must start with “#”. In Guile,
however, we cannot just use “#” on its own. The “#” in Guile is the
start of a reader macro. We don’t really want a reader macro at the
beginning of each line, though – we just want to move on and get to the
expression.

So we use “#\-”, which evaluates to the character “-”. It is valid in
Scheme to write code that evaluates to something and then ignore that
value. Here’s an example:

10
23
#\a
#\b
5
(display "hello")

Guile would evaluate the numbers and characters one after the other, and
none of them would have any effect on the final expression that displays
“hello”.

In the wrapper we do the same kind of thing. This line:

#\-(begin (let …) …)

is really just two Scheme values: a single arbitrary character and the
S-expression that we care about. We only care about the side-effects of
evaluating the S-expression.

A language that uses “#” to mark comments, on the other hand, would
simply ignore the whole line. The result is that we can use Guile to
set environment variables and then hand over execution to the target
language interpreter, which would run in the new environment.

The advantage of this approach is: we don’t have to rename wrapped
scripts any more (“.foo-real”), which makes for prettier usage messages
(“Usage: foo -v” instead of “Usage: .foo-real -v”) and avoids problems
when an application checks its own name to determine what actions it
should take.

--
Ricardo
J
J
Jelle Licht wrote on 2 Aug 2018 10:18
(name . Ricardo Wurmus)(address . rekado@elephly.net)
CAPsKtfJDw=ba=8a3CUHnif9PkruQ-B0ui5nTY1C+1gQSXfRiGg@mail.gmail.com
2018-01-02 21:44 GMT+01:00 Ricardo Wurmus <rekado@elephly.net>:

Toggle quote (30 lines)
> * 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 © 2013 Andreas Enge <andreas@enge.fr>
> ;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
> ;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
> +;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
> ;;;
> ;;; This file is part of GNU Guix.
> ;;;
> @@ -84,6 +85,7 @@
> fold-port-matches
> remove-store-references
> wrap-program
> + wrap-script
> invoke
>
> locale-category->string))
> @@ -1068,6 +1070,105 @@ with definitions for VARS."
> (chmod prog-tmp #o755)
>

[...]

Toggle quote (8 lines)
> (rename-file prog-tmp prog))))
>
> +(define wrap-script
> + (let ((interpreter-regex
> + (make-regexp
> + (string-append "^#! ?(/bin/sh|/gnu/store/[^/]+/bin/("
>

Won't this be an issue for people using a customized store location?

[snipped]
Toggle quote (1 lines)
>
Attachment: file
C
C
Chris Marusich wrote on 2 Aug 2018 10:37
(name . Ricardo Wurmus)(address . rekado@elephly.net)
87y3dpb1uo.fsf@gmail.com
Hi Ricardo,

Thank you for taking the time to explain it!

Ricardo Wurmus <rekado@elephly.net> writes:

Toggle quote (8 lines)
> [...] This line:
>
> #\-(begin (let …) …)
>
> is really just two Scheme values: a single arbitrary character and the
> S-expression that we care about. We only care about the side-effects of
> evaluating the S-expression.

I understand now. We're reading the hyphen symbol, and not doing
anything with it. Got it!

Toggle quote (6 lines)
> The advantage of this approach is: we don’t have to rename wrapped
> scripts any more (“.foo-real”), which makes for prettier usage messages
> (“Usage: foo -v” instead of “Usage: .foo-real -v”) and avoids problems
> when an application checks its own name to determine what actions it
> should take.

Sounds great!

--
Chris
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEy/WXVcvn5+/vGD+x3UCaFdgiRp0FAltiwt8ACgkQ3UCaFdgi
Rp1tRg//evUOIouFt5oLR9joAfp953f/PZv4GovdueN4Hq6BoVFAH52ggSJw9G0O
u0g9IKcrtWqiYa5ao1RqROPLqTqca3i1TgBUY0tsc67AammqCg9ntC4Kuku4Lb+4
B9bczuVOiVSJBQuNMejaefC4Nc1skkkPtZFQqN8nkPvfVXzcYK+4ei0vMUb1U8hz
zR2TNQNI9zSjoym/psfKjqpKAyDBw7ZhbsIqJ6Zltd1qKd7deGthrE8GKySW+ze1
4G4E4HF8pkQ/owtKIHxwhcC84YjekoaanFK2DC06AGJ1mZBtHBs6vkRZay1ldggV
lr/U/+VzeuugB0yLgV33mtL+cjHdUyZmetTHqr7iBxYZDiIcQx70/pAUWUjZqe3I
KobgZfz6HKGke6CLiaVqdOvtQjVfDGfmwgmsFcSfMuT11Gzy/XxcMVPpxdzpomw3
QCMKC+Xy9rtnIyqXo9/lPEBOFUFCs2Ant+b/xC35YvK9aHbSTdGgqXu7baWJMxkm
cC4J60zp4I6ybT5RBwD/HlF6BMIVCrbUW78fh0mCjJKNNIoeL5XA0Zwtequ3a92r
nLhqAZ4PNncqaonu81/iyJKz9a6u+wJBlrFvEa7qv83Xv8/1OZyg0BEi4+D/Opp+
sgxx90H9PAvCk7gANylyRiC9yvcj28BsvwZTZ0hW+D9j2eYWfAs=
=lswz
-----END PGP SIGNATURE-----

N
N
Nils Gillmann wrote on 2 Aug 2018 11:22
(name . Jelle Licht)(address . jlicht@fsfe.org)
20180802092255.hmdu5p3a5y7wbm37@abyayala
Jelle Licht transcribed 4.1K bytes:
Toggle quote (44 lines)
> 2018-01-02 21:44 GMT+01:00 Ricardo Wurmus <rekado@elephly.net>:
>
> > * 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 © 2013 Andreas Enge <andreas@enge.fr>
> > ;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
> > ;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
> > +;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
> > ;;;
> > ;;; This file is part of GNU Guix.
> > ;;;
> > @@ -84,6 +85,7 @@
> > fold-port-matches
> > remove-store-references
> > wrap-program
> > + wrap-script
> > invoke
> >
> > locale-category->string))
> > @@ -1068,6 +1070,105 @@ with definitions for VARS."
> > (chmod prog-tmp #o755)
> >
>
> [...]
>
> > (rename-file prog-tmp prog))))
> >
> > +(define wrap-script
> > + (let ((interpreter-regex
> > + (make-regexp
> > + (string-append "^#! ?(/bin/sh|/gnu/store/[^/]+/bin/("
> >
>
> Won't this be an issue for people using a customized store location?

Can't we make this substitutable at configure time?

Toggle quote (2 lines)
> [snipped]
> >
R
R
Ricardo Wurmus wrote on 2 Aug 2018 10:37
(name . Jelle Licht)(address . jlicht@fsfe.org)
87o9elp3jt.fsf@elephly.net
Jelle Licht <jlicht@fsfe.org> writes:

Toggle quote (4 lines)
> 2018-01-02 21:44 GMT+01:00 Ricardo Wurmus <rekado@elephly.net>:
>
>> * guix/build/utils.scm (wrap-script): New procedure.
>> ---
[…]
Toggle quote (9 lines)
>>
>> +(define wrap-script
>> + (let ((interpreter-regex
>> + (make-regexp
>> + (string-append "^#! ?(/bin/sh|/gnu/store/[^/]+/bin/("
>>
>
> Won't this be an issue for people using a customized store location?

Yes. I suppose we could change this to use the actual store prefix.

--
Ricardo
R
R
Ricardo Wurmus wrote on 4 Feb 2019 08:50
Re: bug#26752: Ansible & others' problems with wrapped '.ansible-real' scripts
(name . Ludovic Courtès)(address . ludo@gnu.org)
87tvhkhu15.fsf@elephly.net
ludo@gnu.org (Ludovic Courtès) writes:
Toggle quote (11 lines)
> Jelle Licht <jlicht@fsfe.org> skribis:
>
>> The current ansible package is still brokenin the same way.
>>
>> Is there already an acceptable way of working around this problem?
>> Otherwise I could send my (extremely hacky) workaround that adds a specific
>> condition in the ansible source code to check for .ansible-real.
>
> For now I think we have to go with the hack. Make sure to add a comment
> linking to this bug report.

There is a way to get around this. It’s presented in #29951:


Open issues with this include a hard-coded store prefix, but it’s no big
obstacle. Should we give this a try on core-updates?
R
R
Ricardo Wurmus wrote on 4 Feb 2019 09:03
control message for bug #29951
(address . control@debbugs.gnu.org)
168b78834d7.67d54665800973180.6444581326634091821@zoho.com
block 29951 by 26752
R
R
Ricardo Wurmus wrote on 4 Feb 2019 09:34
control message for bug #29824
(address . control@debbugs.gnu.org)
168b7a530bf.6c123492-1929141092.-7906724368339708670@zoho.com
block 29824 by 29951
R
R
Ricardo Wurmus wrote on 4 Feb 2019 09:02
control message for bug #29951
(address . control@debbugs.gnu.org)
168b78764c2.7307dec41255821358.-6686512393397758191@zoho.com
block 29951 by 29824
R
R
Ricardo Wurmus wrote on 4 Feb 2019 11:29
control message for bug #29824
(address . control@debbugs.gnu.org)
168b80f4d46.4e38f3fb-540430156.7945528783842604060@zoho.com
unblock 29824 by 29951
R
R
Ricardo Wurmus wrote on 4 Feb 2019 11:31
control message for bug #26752
(address . control@debbugs.gnu.org)
168b80ff826.23c94323855229521.-827146741371564246@zoho.com
block 26752 by 29951
R
R
Ricardo Wurmus wrote on 4 Feb 2019 11:31
control message for bug #29951
(address . control@debbugs.gnu.org)
168b8107ef7.213235a9311363538.-800503255172129691@zoho.com
unblock 29951 by 29824
R
R
Ricardo Wurmus wrote on 4 Feb 2019 11:32
(address . control@debbugs.gnu.org)
168b810eaf2.6b84c6c5-1274999762.-8695646092044213478@zoho.com
unblock 29951 by 26752
R
R
Ricardo Wurmus wrote on 4 Feb 2019 11:31
control message for bug #29824
(address . control@debbugs.gnu.org)
168b8104fcb.745c4eff1000524141.2903290622000671690@zoho.com
block 29824 by 29951
L
L
Ludovic Courtès wrote on 4 Feb 2019 19:05
Re: bug#26752: Ansible & others' problems with wrapped '.ansible-real' scripts
(name . Ricardo Wurmus)(address . rekado@elephly.net)
8736p3sa2s.fsf@gnu.org
Hi,

Ricardo Wurmus <rekado@elephly.net> skribis:

Toggle quote (19 lines)
> ludo@gnu.org (Ludovic Courtès) writes:
>> Jelle Licht <jlicht@fsfe.org> skribis:
>>
>>> The current ansible package is still brokenin the same way.
>>>
>>> Is there already an acceptable way of working around this problem?
>>> Otherwise I could send my (extremely hacky) workaround that adds a specific
>>> condition in the ansible source code to check for .ansible-real.
>>
>> For now I think we have to go with the hack. Make sure to add a comment
>> linking to this bug report.
>
> There is a way to get around this. It’s presented in #29951:
>
> https://issues.guix.info/issue/29951
>
> Open issues with this include a hard-coded store prefix, but it’s no big
> obstacle. Should we give this a try on core-updates?

Definitely, please do!

Thanks,
Ludo’.
L
L
Ludovic Courtès wrote on 6 Feb 2019 23:14
(name . Ricardo Wurmus)(address . rekado@elephly.net)
87lg2s5zv7.fsf@gnu.org
Ricardo Wurmus <rekado@elephly.net> skribis:

Toggle quote (16 lines)
> ludo@gnu.org (Ludovic Courtès) writes:
>> Jelle Licht <jlicht@fsfe.org> skribis:
>>
>>> The current ansible package is still brokenin the same way.
>>>
>>> Is there already an acceptable way of working around this problem?
>>> Otherwise I could send my (extremely hacky) workaround that adds a specific
>>> condition in the ansible source code to check for .ansible-real.
>>
>> For now I think we have to go with the hack. Make sure to add a comment
>> linking to this bug report.
>
> There is a way to get around this. It’s presented in #29951:
>
> https://issues.guix.info/issue/29951

BTW, there’s also this patch series on this topic:


What to do?

Ludo’.
R
R
Ricardo Wurmus wrote on 7 Feb 2019 00:10
[PATCH]: guix: Add wrap-script.
(address . 29951@debbugs.gnu.org)
87d0o4fr7q.fsf@elephly.net
Here’s a new version which raises a condition on errors, handles
all shebangs (including those with arguments or with custom store
prefix), and which allows the value for “guile” to be overridden.

It comes with tests.

It doesn’t apply automatically when “wrap-program” is used. It might be
a good idea to call it automatically and fall back to “wrap-program” if
the target is not a supported script.

Comments are very welcome!

--
Ricardo
R
R
Ricardo Wurmus wrote on 8 Feb 2019 11:10
(address . 29951-done@debbugs.gnu.org)
87h8demvz3.fsf@elephly.net
Ricardo Wurmus <rekado@elephly.net> writes:

Toggle quote (6 lines)
> Here’s a new version which raises a condition on errors, handles
> all shebangs (including those with arguments or with custom store
> prefix), and which allows the value for “guile” to be overridden.
>
> It comes with tests.

I have pushed this to core-updates with commit
0fb9a8df429a7b9f40610ff15baaff0d8e31e8cf

Toggle quote (4 lines)
> It doesn’t apply automatically when “wrap-program” is used. It might be
> a good idea to call it automatically and fall back to “wrap-program” if
> the target is not a supported script.

It still doesn’t do this. To use it you have to opt in and use
“wrap-script” instead of “wrap-program”.

Comments are still welcome!

--
Ricardo
Closed
?