[PATCH] [core-updates-frozen] Wrap meson with python code

  • Done
  • quality assurance status badge
Details
2 participants
  • Ludovic Courtès
  • Vivien Kraus
Owner
unassigned
Submitted by
Vivien Kraus
Severity
normal

Debbugs page

Vivien Kraus wrote 3 years ago
[PATCH] Meson needs proper wrapping
(address . guix-patches@gnu.org)
87r1bda6ff.fsf@planete-kraus.eu
Dear guix,

Meson needs to be wrapped, but the wrapping must not execute a new
process, if I understand correctly. I could use wrap-script, but I think
it’s more pythonic to set the path through sys.path rather than setting
an environment variable.

Now, this will create a world rebuild… What do you think?

Vivien
From 08845844e8e1a18232bf54f9f3f0b71d5e0c71ef Mon Sep 17 00:00:00 2001
From: Vivien Kraus <vivien@planete-kraus.eu>
Date: Thu, 18 Nov 2021 15:17:52 +0100
Subject: [PATCH] gnu: meson: Extend the python path in the installed program.

* gnu/packages/build-tools.scm (meson) [phase wrap]: Wrap the python path as
python code.
---
gnu/packages/build-tools.scm | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

Toggle diff (29 lines)
diff --git a/gnu/packages/build-tools.scm b/gnu/packages/build-tools.scm
index 849101c2a4..ef5aa4bd35 100644
--- a/gnu/packages/build-tools.scm
+++ b/gnu/packages/build-tools.scm
@@ -283,7 +283,21 @@ (define-public meson
#:phases (modify-phases %standard-phases
;; Meson calls the various executables in out/bin through the
;; Python interpreter, so we cannot use the shell wrapper.
- (delete 'wrap))))
+ (replace 'wrap
+ (lambda* (#:key outputs #:allow-other-keys)
+ (let ((path (string-split (getenv "GUIX_PYTHONPATH") #\:)))
+ (substitute* (string-append (assoc-ref outputs "out") "/bin/meson")
+ (("# EASY-INSTALL-ENTRY-SCRIPT")
+ (format #f "\
+import sys
+~a
+# EASY-INSTALL-ENTRY-SCRIPT"
+ (string-join
+ (map (lambda (path)
+ (format #f "sys.path.insert(0, '~a')"
+ path))
+ (reverse path))
+ "\n"))))))))))
(inputs `(("ninja" ,ninja)))
(propagated-inputs `(("python" ,python)))
(home-page "https://mesonbuild.com/")
--
2.34.0
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCAAdFiEEq4yIHjMvkliPpwQnO7C8EjLYuCwFAmGWYfQACgkQO7C8EjLY
uCx6RQv/dAim25a86h4Ob7Kxzu7VW8Zh5JCzGt8xEjPyerTsLw6hLxNpNRZz2V9k
giTdkcGVgnrdT5vx6IceoC0yQRE2L6AteWhI9k9toxZB1AEKr0i+C2BV668ydNUk
LSRAkD50gwKk+MAbgfqA0g5+hnjxQIPGyMvUX11uhKWzirEwfG+MukLOaO8BmPV2
s6HLZ9O0riXP+CZNrIcJYhk/YfVX5wFT754ps2UU4ptFwZetPSuSq1Mk0vIjeONH
XCLVfu8vpxf7SnLW0Y5TclMdjtKJCP0eS2OsAyN5vfjuq+zElZXmek2eby85M0BR
df5J8I+wEM6kWDiwQ6vK/MnO5mSu1LgH3RgRfR+t36wjpNUuSryeuufbQ4GGCAS3
IZcE9QlxvM55N6hj7SCUwXBASoeOkdn3YY9FeOSiVai5WikjQuMfxiWwntP/+R+L
AcH+eFRf3nIqzDX6UaRR/c9Js80msPHRAJo40Lz5WAkaJFRCPiSU3aycYVlDpepO
U//xlRs7
=9sky
-----END PGP SIGNATURE-----

Vivien Kraus wrote 3 years ago
Re: bug#51948: Acknowledgement ([PATCH] Meson needs proper wrapping)
(address . 51948@debbugs.gnu.org)
87mtm1a1wx.fsf@planete-kraus.eu
If I put the code in a new variable, we avoid a world rebuild, is it
better?

Vivien
From f25082c0a695734aaada2d286ef1770de5f99c2b Mon Sep 17 00:00:00 2001
From: Vivien Kraus <vivien@planete-kraus.eu>
Date: Thu, 18 Nov 2021 15:17:52 +0100
Subject: [PATCH] gnu: meson: Extend the python path in the installed program.

* gnu/packages/build-tools.scm (meson-wrapped): New variable.
---
gnu/packages/build-tools.scm | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)

Toggle diff (38 lines)
diff --git a/gnu/packages/build-tools.scm b/gnu/packages/build-tools.scm
index 849101c2a4..646e28e0c6 100644
--- a/gnu/packages/build-tools.scm
+++ b/gnu/packages/build-tools.scm
@@ -297,6 +297,31 @@ (define-public meson
resembles Python.")
(license license:asl2.0)))
+(define-public meson-wrapped
+ (package/inherit meson
+ (arguments
+ `(;; FIXME: Tests require many additional inputs and patching many
+ ;; hard-coded file system locations in "run_unittests.py".
+ #:tests? #f
+ #:phases (modify-phases %standard-phases
+ ;; Meson calls the various executables in out/bin through the
+ ;; Python interpreter, so we cannot use the shell wrapper.
+ (replace 'wrap
+ (lambda* (#:key outputs #:allow-other-keys)
+ (let ((path (string-split (getenv "GUIX_PYTHONPATH") #\:)))
+ (substitute* (string-append (assoc-ref outputs "out") "/bin/meson")
+ (("# EASY-INSTALL-ENTRY-SCRIPT")
+ (format #f "\
+import sys
+~a
+# EASY-INSTALL-ENTRY-SCRIPT"
+ (string-join
+ (map (lambda (path)
+ (format #f "sys.path.insert(0, '~a')"
+ path))
+ (reverse path))
+ "\n"))))))))))))
+
;;; This older Meson variant is kept for now for gtkmm and others that may
;;; have problems with 0.60.
(define-public meson-0.59
--
2.34.0
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCAAdFiEEq4yIHjMvkliPpwQnO7C8EjLYuCwFAmGWeM4ACgkQO7C8EjLY
uCz6QQv9ER6cXQI3BJCKRQ5NMgKBEyU+hUhNW5lVz0eX/6gKDMKHqsGWWZegVxZf
t7ExjXPfVZcdJxdgMgpaadK1vckCkyYnjUrmu2T4pcVQux2ZNiL0ZPEZbLXvafWs
NrT7sScExpcgleoMHulgNfq4EO6tHzg+CQY7PfROS7qp44VOnvQ6Q2JMmi9nQP+1
ZQtip+SLrwPfJX0/YWBfseC7KYy7x/51OyyFSgl53bty35YXiVPbhrVMMR6mENL8
jGbBqQ4V+ZlOKGru9jb6t7bdlC5DXl6svDkkwQVpRnRvvlWo4LEtNelXg2PKTwI3
FCvXNrpLB/yrb5fe1/QH9jFUCJBrWGaLhMitfLaake0RvWUHsSW424D7UAjsPhfv
7ZE3mztxaUG95z1/MgEQ3gAjPWsXlILOPzuA5Lc2VwcC5z2LejXQm9tICz3tIb95
Z/O7U36chM1NWNikvh3Z39DjK7vcQFBPAsES74V1XFQUEUm4jibBG/DqsEZNVibJ
8pv3+RtQ
=16yN
-----END PGP SIGNATURE-----

Ludovic Courtès wrote 3 years ago
Re: bug#51948: [PATCH] Meson needs proper wrapping
(name . Vivien Kraus)(address . vivien@planete-kraus.eu)(address . 51948@debbugs.gnu.org)
8735nsmgqc.fsf@gnu.org
Hi!

Vivien Kraus <vivien@planete-kraus.eu> skribis:

Toggle quote (5 lines)
> Meson needs to be wrapped, but the wrapping must not execute a new
> process, if I understand correctly. I could use wrap-script, but I think
> it’s more pythonic to set the path through sys.path rather than setting
> an environment variable.

Isn’t that what ‘wrap-script’ does?

Toggle quote (2 lines)
> Now, this will create a world rebuild… What do you think?

Not good! :-)

This Meson issue is not a regression compared to master, is it?

How about providing a user-facing ‘meson’ package that incorporates this
fix, while keeping the other ‘meson’ packages unchanged, to avoid
rebuilding too much? This can be achieved by marking the other packages
as hidden.

Toggle quote (25 lines)
> From 08845844e8e1a18232bf54f9f3f0b71d5e0c71ef Mon Sep 17 00:00:00 2001
> From: Vivien Kraus <vivien@planete-kraus.eu>
> Date: Thu, 18 Nov 2021 15:17:52 +0100
> Subject: [PATCH] gnu: meson: Extend the python path in the installed program.
>
> * gnu/packages/build-tools.scm (meson) [phase wrap]: Wrap the python path as
> python code.
> ---
> gnu/packages/build-tools.scm | 16 +++++++++++++++-
> 1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/gnu/packages/build-tools.scm b/gnu/packages/build-tools.scm
> index 849101c2a4..ef5aa4bd35 100644
> --- a/gnu/packages/build-tools.scm
> +++ b/gnu/packages/build-tools.scm
> @@ -283,7 +283,21 @@ (define-public meson
> #:phases (modify-phases %standard-phases
> ;; Meson calls the various executables in out/bin through the
> ;; Python interpreter, so we cannot use the shell wrapper.
> - (delete 'wrap))))
> + (replace 'wrap
> + (lambda* (#:key outputs #:allow-other-keys)
> + (let ((path (string-split (getenv "GUIX_PYTHONPATH") #\:)))
> + (substitute* (string-append (assoc-ref outputs "out") "/bin/meson")

Could you check ‘guix gc --references meson’ to make sure it does not
capture too much? (GUIX_PYTHONPATH might contain references to
build-time dependencies.)

I suppose GUIX_PYTHONPATH contains the package’s “out”, right?

Thanks!

Ludo’.
Vivien Kraus wrote 3 years ago
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 51948@debbugs.gnu.org)
877dd49rnn.fsf@planete-kraus.eu
Ludovic Courtès <ludo@gnu.org> writes:
Toggle quote (7 lines)
> Vivien Kraus <vivien@planete-kraus.eu> skribis:
>> Meson needs to be wrapped, but the wrapping must not execute a new
>> process, if I understand correctly. I could use wrap-script, but I think
>> it’s more pythonic to set the path through sys.path rather than setting
>> an environment variable.
>
> Isn’t that what ‘wrap-script’ does?
I think wrap-script converts the python script to a guile script that
happens to be the same file as the python script. I realize it won’t
even insert python code in the final program, so the wrapping code won’t
be executed when the python module is loaded by the python interpreter.

Toggle quote (4 lines)
> How about providing a user-facing ‘meson’ package that incorporates this
> fix, while keeping the other ‘meson’ packages unchanged, to avoid
> rebuilding too much? This can be achieved by marking the other packages
> as hidden.
I pushed an update that does precisely that. Is the name "meson-wrapped"
OK? Also, how can I influence guix to rather install the wrapped version
when the user invokes "guix install meson"?

Toggle quote (4 lines)
> Could you check ‘guix gc --references meson’ to make sure it does not
> capture too much? (GUIX_PYTHONPATH might contain references to
> build-time dependencies.)

I see, the only thing to wrap is just the "out" output in fact.
From dcb7114ada82da073adbbfbeef929a9daa558ccb Mon Sep 17 00:00:00 2001
From: Vivien Kraus <vivien@planete-kraus.eu>
Date: Thu, 18 Nov 2021 15:17:52 +0100
Subject: [PATCH] gnu: meson: Extend the python path in the installed program.

* gnu/packages/build-tools.scm (meson-wrapped): New variable.
---
gnu/packages/build-tools.scm | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)

Toggle diff (35 lines)
diff --git a/gnu/packages/build-tools.scm b/gnu/packages/build-tools.scm
index 849101c2a4..f323b6a388 100644
--- a/gnu/packages/build-tools.scm
+++ b/gnu/packages/build-tools.scm
@@ -297,6 +297,28 @@ (define-public meson
resembles Python.")
(license license:asl2.0)))
+(define-public meson-wrapped
+ (package/inherit meson
+ (arguments
+ `(;; FIXME: Tests require many additional inputs and patching many
+ ;; hard-coded file system locations in "run_unittests.py".
+ #:tests? #f
+ #:phases (modify-phases %standard-phases
+ ;; Meson calls the various executables in out/bin through the
+ ;; Python interpreter, so we cannot use the shell wrapper.
+ (replace 'wrap
+ (lambda* (#:key outputs inputs #:allow-other-keys)
+ (let ((python-version
+ (python-version (assoc-ref inputs "python")))
+ (output (assoc-ref outputs "out")))
+ (substitute* (string-append output "/bin/meson")
+ (("# EASY-INSTALL-ENTRY-SCRIPT")
+ (format #f "\
+import sys
+sys.path.insert(0, '~a/lib/python~a/site-packages')
+# EASY-INSTALL-ENTRY-SCRIPT"
+ output python-version)))))))))))
+
;;; This older Meson variant is kept for now for gtkmm and others that may
;;; have problems with 0.60.
(define-public meson-0.59
--
2.34.0
Vivien
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCAAdFiEEq4yIHjMvkliPpwQnO7C8EjLYuCwFAmGXrLwACgkQO7C8EjLY
uCwttwwAzrisBLi5jmz63/N7N6gzDA4BqZt4i6VHwzPtHHJ5zswesO2ostFbbgg1
dMygZLx/lloGDJ0UoxM4PC/LgVLZlwDRHi5NBP5/TFhVH7q8lEeylwKJSe+qXp0v
d4dTgYQ/MstrTL98xHTZuDEM9QOJfAIH68tIhhd+fDJMQk0iGY+hI+IHhvBtWzwb
ei5T+uUtD6i1EaykPUXO2Cs3AIsYMRLOQ0TvfDUE99JnpDVWu82YLHlcaASj+B+t
zO3aXdWeGj3FrIlr10R3AMKACZr6VyMjfNpUlEOLDqWxM/pg4L2O2LPnNZYxSN5t
eNOSXXKaTy8UMPnJn/mEo5FtOihizexbo3jd6EFkIln0/wBzFdEJB2+7QKG5dy9Y
P22k0u9SsmyUS0PVZ+3563lgMlb1daIWRLe0jdwEDXX4Bv0+k87dcc5K/n8IbLOL
/ZbJShUvhz3q0hHIDntTVLehyfiSpk5w4XkyHxAKLWxRRFVJNely6BNvN4I53CQq
jWHFeQYg
=Xyoa
-----END PGP SIGNATURE-----

Ludovic Courtès wrote 3 years ago
(name . Vivien Kraus)(address . vivien@planete-kraus.eu)(address . 51948@debbugs.gnu.org)
87zgpzhjta.fsf@gnu.org
Hi,

Vivien Kraus <vivien@planete-kraus.eu> skribis:

Toggle quote (8 lines)
>> How about providing a user-facing ‘meson’ package that incorporates this
>> fix, while keeping the other ‘meson’ packages unchanged, to avoid
>> rebuilding too much? This can be achieved by marking the other packages
>> as hidden.
> I pushed an update that does precisely that. Is the name "meson-wrapped"
> OK? Also, how can I influence guix to rather install the wrapped version
> when the user invokes "guix install meson"?

I you just add another meson@0.60 package like this patch does, the UI
will complain that “meson@0.60” is ambiguous, that there are two of them.

To work around it, I’d mark the unwrapped meson@0.60 as hidden (using
the ‘properties’ field) while keeping the other one visible.

That way “guix install meson” will install the wrapped one.

Does that make sense?

TIA,
Ludo’.
Vivien Kraus wrote 3 years ago
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 51948@debbugs.gnu.org)
8735nrahwc.fsf@planete-kraus.eu
Ludovic Courtès <ludo@gnu.org> writes:
Toggle quote (12 lines)
>> I pushed an update that does precisely that. Is the name "meson-wrapped"
>> OK? Also, how can I influence guix to rather install the wrapped version
>> when the user invokes "guix install meson"?
>
> I you just add another meson@0.60 package like this patch does, the UI
> will complain that “meson@0.60” is ambiguous, that there are two of them.
>
> To work around it, I’d mark the unwrapped meson@0.60 as hidden (using
> the ‘properties’ field) while keeping the other one visible.
>
> That way “guix install meson” will install the wrapped one.

I think that’s good: I build it with guix shell meson or guix build
meson, and I can run its absolute file name in a guix shell --pure
gcc. However, it does not seem to cause a world rebuild.

Vivien
From 3f77d8d5c652725411a21434443cbf2a2d135575 Mon Sep 17 00:00:00 2001
From: Vivien Kraus <vivien@planete-kraus.eu>
Date: Thu, 18 Nov 2021 15:17:52 +0100
Subject: [PATCH] gnu: meson: Extend the python path in the installed program.

* gnu/packages/build-tools.scm (meson-wrapped): New variable.
---
gnu/packages/build-tools.scm | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)

Toggle diff (44 lines)
diff --git a/gnu/packages/build-tools.scm b/gnu/packages/build-tools.scm
index 849101c2a4..6a8a9c6f66 100644
--- a/gnu/packages/build-tools.scm
+++ b/gnu/packages/build-tools.scm
@@ -287,6 +287,7 @@ (define-public meson
(inputs `(("ninja" ,ninja)))
(propagated-inputs `(("python" ,python)))
(home-page "https://mesonbuild.com/")
+ (properties '((hidden? . #t)))
(synopsis "Build system designed to be fast and user-friendly")
(description
"The Meson build system is focused on user-friendliness and speed.
@@ -297,6 +298,29 @@ (define-public meson
resembles Python.")
(license license:asl2.0)))
+(define-public meson-wrapped
+ (package/inherit meson
+ (arguments
+ `(;; FIXME: Tests require many additional inputs and patching many
+ ;; hard-coded file system locations in "run_unittests.py".
+ #:tests? #f
+ #:phases (modify-phases %standard-phases
+ ;; Meson calls the various executables in out/bin through the
+ ;; Python interpreter, so we cannot use the shell wrapper.
+ (replace 'wrap
+ (lambda* (#:key outputs inputs #:allow-other-keys)
+ (let ((python-version
+ (python-version (assoc-ref inputs "python")))
+ (output (assoc-ref outputs "out")))
+ (substitute* (string-append output "/bin/meson")
+ (("# EASY-INSTALL-ENTRY-SCRIPT")
+ (format #f "\
+import sys
+sys.path.insert(0, '~a/lib/python~a/site-packages')
+# EASY-INSTALL-ENTRY-SCRIPT"
+ output python-version)))))))))
+ (properties '())))
+
;;; This older Meson variant is kept for now for gtkmm and others that may
;;; have problems with 0.60.
(define-public meson-0.59
--
2.34.0
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCAAdFiEEq4yIHjMvkliPpwQnO7C8EjLYuCwFAmGYJ+MACgkQO7C8EjLY
uCxKbwv8DT8JsMpOEENYRVL5YMNfEjoXTzCE3EVLlznDcanCeh/KmixaaaiWdvsl
ewKUdsxwds0Hod9NL8U/bG8sSeT24cFz2Q/lTqIzekOK78NmhcKHvjatwLKPSgBo
W9yeDQ/HPK1puCTd1bGK9Aq9YGfKQmFX6ggoOb5oNWX+eFRfOLZ9hygui7+Lhl+v
Ayx3EzzcLR9nK10cA5DczWyh4PwWGBOzmN+BEJSywkCQrFMKYBxLE04LY4pT1CJc
OgWUEO+rVK8Viap/N6KvOdfqA5V9T5L9QL28UOr+xhiKevYBnPS7JRC47iRZoU36
DFYh7zRW0GNUhtogShc/dUU63N+a7Y6BiCen8PSFmMAEBLDJzGPeL3+FM59OO0Gf
5WUZ/iTnpajvA8i33NCccIxcOVQUtfOjMrNTM5LZse9cw5u8dLQAv2mvSBkbWRXU
ZXs8zz7uWRE5KvTq0lNSgDvKXQqEFJNlr7p20c9zBqqs4jcZbhfkukUownWyb/oI
rpCRvUme
=OJg8
-----END PGP SIGNATURE-----

Vivien Kraus wrote 3 years ago
[PATCH] [core-updates-frozen] Wrap meson with python code
(address . control@debbugs.gnu.org)
874k84ksqo.fsf@planete-kraus.eu
retitle 51948 [PATCH] [core-updates-frozen] Wrap meson with python code
Ludovic Courtès wrote 3 years ago
(name . Vivien Kraus)(address . vivien@planete-kraus.eu)(address . 51948-done@debbugs.gnu.org)
87czmrn9vu.fsf_-_@gnu.org
Hi,

Vivien Kraus <vivien@planete-kraus.eu> skribis:

Toggle quote (7 lines)
> From 3f77d8d5c652725411a21434443cbf2a2d135575 Mon Sep 17 00:00:00 2001
> From: Vivien Kraus <vivien@planete-kraus.eu>
> Date: Thu, 18 Nov 2021 15:17:52 +0100
> Subject: [PATCH] gnu: meson: Extend the python path in the installed program.
>
> * gnu/packages/build-tools.scm (meson-wrapped): New variable.

Applied, thanks!

As discussed on IRC, I followed up with a patch that moves Python from
‘propagated-inputs’ (!) to ‘inputs’ in ‘meson-wrapped’. Most likely
Python was propagated just for the sake of setting GUIX_PYTHONPATH, but
it’s bad style as it forces it into user profiles.

Ludo’.
Closed
?
Your comment

This issue is archived.

To comment on this conversation send an email to 51948@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 51948
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch
You may also tag this issue. See list of standard tags. For example, to set the confirmed and easy tags
mumi command -t +confirmed -t +easy
Or, remove the moreinfo tag and set the help tag
mumi command -t -moreinfo -t +help