diff mbox series

[bug#49329,v2,4/5] gnu: renpy: Correct inputs.

Message ID 20210703092842.32189-4-leo.prikler@student.tugraz.at
State Accepted
Headers show
Series [bug#49329,v2,1/5] gnu: python2-renpy: Drop unused Ren'py sources. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Leo Prikler July 3, 2021, 9:28 a.m. UTC
* gnu/packages/game-development.scm (renpy)[#:modules]: Add SRFI-1.
[#:imported-modules]: Likewise.
[#:phases]<fix-commands>: Search for ‘python2’ and ‘xdg-open’ in inputs.
<start-xserver>: Search for ‘xorg-server’ in native-inputs.
<install>: Search for ‘python2’ in inputs.
<wrap>: Search for python dependencies in inputs.
[inputs]: Add python2, drop python2-pygame (already propagated by
python2-renpy). Move xorg-server from here…
[native-inputs]: … to here.
[propagated-inputs]: Empty.
---
 gnu/packages/game-development.scm | 54 +++++++++++++++++++++++--------
 1 file changed, 40 insertions(+), 14 deletions(-)

Comments

Christopher Marusich July 11, 2021, 4:37 a.m. UTC | #1
Leo Prikler <leo.prikler@student.tugraz.at> writes:

> diff --git a/gnu/packages/game-development.scm b/gnu/packages/game-development.scm
> [...]
>               #t))
>           (replace 'wrap
>             (lambda* (#:key inputs outputs #:allow-other-keys)
> -             (wrap-program (string-append (assoc-ref outputs "out")
> -                                          "/bin/renpy")
> -               `("PYTHONPATH" = (,(getenv "PYTHONPATH"))))
> -             #t)))))
> +             (let ((out (assoc-ref outputs "out"))
> +                   (site (string-append "/lib/python"
> +                                        (python-version
> +                                         (assoc-ref inputs "python"))
> +                                        "/site-packages")))
> +               (wrap-program (string-append out "/bin/renpy")
> +                 `("PYTHONPATH" =
> +                   (,@(delete-duplicates
> +                       (map
> +                        (lambda (store-path)
> +                          (string-append store-path site))
> +                        (cons (assoc-ref outputs "out")
> +                              (map cdr
> +                                   (filter
> +                                    (lambda (input)
> +                                      (string-prefix? "python2" (car input)))
> +                                    inputs))))))))
> +               #t))))))

What's the motivation for doing this?  It seems like the new version
deletes duplicates, but has the downside of being a little more
complicated and relying on the package names to determine what goes into
the PYTHONPATH.

Duplicate entries in the PYTHONPATH should not be a problem for
correctness or performance, right?  I feel like this section was perhaps
better the way it was originally.  Am I missing something?
Leo Prikler July 11, 2021, 6:58 a.m. UTC | #2
Am Samstag, den 10.07.2021, 21:37 -0700 schrieb Chris Marusich:
> Leo Prikler <leo.prikler@student.tugraz.at> writes:
> 
> > diff --git a/gnu/packages/game-development.scm b/gnu/packages/game-
> > development.scm
> > [...]
> >               #t))
> >           (replace 'wrap
> >             (lambda* (#:key inputs outputs #:allow-other-keys)
> > -             (wrap-program (string-append (assoc-ref outputs
> > "out")
> > -                                          "/bin/renpy")
> > -               `("PYTHONPATH" = (,(getenv "PYTHONPATH"))))
> > -             #t)))))
> > +             (let ((out (assoc-ref outputs "out"))
> > +                   (site (string-append "/lib/python"
> > +                                        (python-version
> > +                                         (assoc-ref inputs
> > "python"))
> > +                                        "/site-packages")))
> > +               (wrap-program (string-append out "/bin/renpy")
> > +                 `("PYTHONPATH" =
> > +                   (,@(delete-duplicates
> > +                       (map
> > +                        (lambda (store-path)
> > +                          (string-append store-path site))
> > +                        (cons (assoc-ref outputs "out")
> > +                              (map cdr
> > +                                   (filter
> > +                                    (lambda (input)
> > +                                      (string-prefix? "python2"
> > (car input)))
> > +                                    inputs))))))))
> > +               #t))))))
> 
> What's the motivation for doing this?  It seems like the new version
> deletes duplicates, but has the downside of being a little more
> complicated and relying on the package names to determine what goes
> into
> the PYTHONPATH.
> 
> Duplicate entries in the PYTHONPATH should not be a problem for
> correctness or performance, right?  I feel like this section was
> perhaps
> better the way it was originally.  Am I missing something?
The reason is that I want to avoid having native-inputs in PYTHONPATH
(which the naïve getenv-based solution will always return).  For native
builds these currently can't be avoided even with the above snippet,
but for cross-builds and maybe future native-builds which separate
inputs and native-inputs, this ought to do "the correct thing".

delete-duplicates is more of a style thing than anything else, in my
personal opinion the wrapper script is more readable with it.

Regards,
Leo
diff mbox series

Patch

diff --git a/gnu/packages/game-development.scm b/gnu/packages/game-development.scm
index 7c5d45c412..5d5fa5cf8b 100644
--- a/gnu/packages/game-development.scm
+++ b/gnu/packages/game-development.scm
@@ -1266,15 +1266,22 @@  are only used to bootstrap it.")
     (arguments
      `(#:tests? #f ; see python2-renpy
        #:python ,python-2
+       #:modules ((srfi srfi-1)
+                  (guix build python-build-system)
+                  (guix build utils))
+       #:imported-modules ((srfi srfi-1) ,@%python-build-system-modules)
        #:phases
        (modify-phases %standard-phases
          (add-after 'unpack 'fix-commands
-           (lambda* (#:key outputs #:allow-other-keys)
+           (lambda* (#:key inputs outputs #:allow-other-keys)
              (substitute* "launcher/game/choose_directory.rpy"
-               (("/usr/bin/python") (which "python2")))
+               (("/usr/bin/python")
+                (string-append (assoc-ref inputs "python2")
+                               "/bin/python2")))
              (substitute* "launcher/game/front_page.rpy"
                (("xdg-open")
-                (which "xdg-open")))
+                (string-append (assoc-ref inputs "xdg-utils")
+                               "/bin/xdg-open")))
              (substitute* "launcher/game/project.rpy"
                (("cmd = \\[ executable, \"-EO\", sys.argv\\[0\\] \\]")
                 (string-append "cmd = [ \"" (assoc-ref outputs "out")
@@ -1291,8 +1298,9 @@  are only used to bootstrap it.")
                ((", \"game\",") ","))
              #t))
          (add-before 'build 'start-xserver
-           (lambda* (#:key inputs #:allow-other-keys)
-             (let ((xorg-server (assoc-ref inputs "xorg-server")))
+           (lambda* (#:key inputs native-inputs #:allow-other-keys)
+             (let ((xorg-server (assoc-ref (or native-inputs inputs)
+                                           "xorg-server")))
                (setenv "HOME" (getcwd))
                (system (format #f "~a/bin/Xvfb :1 &" xorg-server))
                (setenv "DISPLAY" ":1")
@@ -1344,7 +1352,8 @@  are only used to bootstrap it.")
 
                (call-with-output-file bin/renpy
                  (lambda (port)
-                   (format port "#!~a~%" (which "python2"))
+                   (format port "#!~a/bin/python2~%"
+                           (assoc-ref inputs "python2"))
                    (format port "
 from __future__ import print_function
 
@@ -1433,15 +1442,32 @@  if __name__ == \"__main__\":
              #t))
          (replace 'wrap
            (lambda* (#:key inputs outputs #:allow-other-keys)
-             (wrap-program (string-append (assoc-ref outputs "out")
-                                          "/bin/renpy")
-               `("PYTHONPATH" = (,(getenv "PYTHONPATH"))))
-             #t)))))
+             (let ((out (assoc-ref outputs "out"))
+                   (site (string-append "/lib/python"
+                                        (python-version
+                                         (assoc-ref inputs "python"))
+                                        "/site-packages")))
+               (wrap-program (string-append out "/bin/renpy")
+                 `("PYTHONPATH" =
+                   (,@(delete-duplicates
+                       (map
+                        (lambda (store-path)
+                          (string-append store-path site))
+                        (cons (assoc-ref outputs "out")
+                              (map cdr
+                                   (filter
+                                    (lambda (input)
+                                      (string-prefix? "python2" (car input)))
+                                    inputs))))))))
+               #t))))))
     (inputs
-     `(("python2-tkinter" ,python-2 "tk")
-       ("python2-pygame" ,python2-pygame-sdl2)
-       ("python2-renpy" ,python2-renpy)
-       ("xorg-server" ,xorg-server)))
+     `(("python2-renpy" ,python2-renpy)
+       ("python2-tkinter" ,python-2 "tk")
+       ("python2" ,python-2) ; for ‘fix-commands’ and ‘wrap’
+       ("xdg-utils" ,xdg-utils)))
+    (propagated-inputs '())
+    (native-inputs
+     `(("xorg-server" ,xorg-server-for-tests)))
     (outputs
      (list "out" "tutorial" "the-question"))
     (home-page "https://www.renpy.org/")