all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#72266: this-package-input for multiple outputs package
@ 2024-07-24  0:41 Simon Tournier
  0 siblings, 0 replies; only message in thread
From: Simon Tournier @ 2024-07-24  0:41 UTC (permalink / raw)
  To: 72266; +Cc: ludo

Hi,

For the good or the bad, we have package with multiple outputs.  For
instance, see ’git’ with ’git:send-email’ and others.

However, it’s not always easy to work with them using the “new style”.

For a concrete example: <https://issues.guix.gnu.org/66704#4>.


A minimal example.

--8<---------------cut here---------------start------------->8---
$ cat /tmp/pkgs/pkgs.scm
(define-module (pkgs)
  #:use-module (guix packages)
  #:use-module (gnu packages base)
  #:use-module (gnu packages version-control))

(define-public salut
  (package
    (inherit hello)
    (name "bye")
    (inputs
     (list git
           `(,git "send-email")))))
--8<---------------cut here---------------end--------------->8---

Then, it’s possible to add phases, e.g.,

--8<---------------cut here---------------start------------->8---
                (wrap-program (string-append #$output "/bin/hello")
                  `("STUFF" ":" prefix
                    (,(string-append #$(this-package-input "git") "/bin")))
--8<---------------cut here---------------end--------------->8---

All fine!

However, from my understanding, it does not seem possible to access
using this “new style” way to other outputs than “out”.  Because, the
inputs reads,

--8<---------------cut here---------------start------------->8---
$ guix repl -q -L /tmp/pkgs
GNU Guile 3.0.9
Copyright (C) 1995-2023 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guix-user)> ,use(guix packages)
scheme@(guix-user)> ,use(pkgs)
scheme@(guix-user)> ,pp (package-inputs salut)
$1 = (("git"
  #<package git@2.45.2 gnu/packages/version-control.scm:243 73a06a652580>)
 ("git"
  #<package git@2.45.2 gnu/packages/version-control.scm:243 73a06a652580>
  "send-email"))
--8<---------------cut here---------------end--------------->8---

Other said, both outputs have the same label – here “git”.

Then, the procedure ’this-package-input’ – under the hood via
lookup-package-input and then lookup-input from (guix packages) – calls:

    (assoc-ref (package-inputs some-package) some-string)

Therefore, since “some-string” is the same here, bang!


A first proposal for fixing the issue.

It’s easy to tweak how ’sanitize-inputs’ works.  For instance using this
patch:

--8<---------------cut here---------------start------------->8---
1 file changed, 1 insertion(+), 1 deletion(-)
guix/packages.scm | 2 +-

modified   guix/packages.scm
@@ -667,7 +667,7 @@ (define (add-input-label input)
     ((? package? package)
      (list (package-name package) package))
     (((? package? package) output)                ;XXX: ugly?
-     (list (package-name package) package output))
+     (list (string-append (package-name package) ":" output) package output))
     ((? gexp-input?)       ;XXX: misplaced because 'native?' field is ignored?
      (let ((obj    (gexp-input-thing input))
            (output (gexp-input-output input)))
--8<---------------cut here---------------end--------------->8---

Now we get different labels,

--8<---------------cut here---------------start------------->8---
scheme@(guix-user)> ,pp (package-inputs salut)
$1 = (("git"
  #<package git@2.45.2 gnu/packages/version-control.scm:243 72f31b35de70>)
 ("git:send-email"
  #<package git@2.45.2 gnu/packages/version-control.scm:243 72f31b35de70>
  "send-email"))
--8<---------------cut here---------------end--------------->8---

So far, so good!  Please note that some packages then need some
adjustment; e.g., see below.


Next, let add to the package definition this snippet for more wrapping,

--8<---------------cut here---------------start------------->8---
                    (,(string-append #$(this-package-input "git:send-email") "/bin")))
--8<---------------cut here---------------end--------------->8---

Because of the procedure ’lookup-input’ from (guix packages), the
package is correctly identified but the output is still discarded.
Hence this modification:

--8<---------------cut here---------------start------------->8---
1 file changed, 1 insertion(+)
guix/packages.scm | 1 +

modified   guix/packages.scm
@@ -1213,6 +1213,7 @@ (define (lookup-input inputs name)
   ;; check package names.
   (match (assoc-ref inputs name)
     ((obj) obj)
+    ((obj (? string? out)) (cons obj out))
     ((obj _) obj)
     (#f #f)))
 --8<---------------cut here---------------end--------------->8---

But then it is still incorrect.  For instance, we check using
’package-arguments’ and the interesting part reads:

--8<---------------cut here---------------start------------->8---
(unquote (string-append #<gexp-input (#<package git@2.45.2 gnu/packages/version-control.scm:243 7b7573de1b00> . "send-email"):out> "/bin"))
--8<---------------cut here---------------end--------------->8---

Ok, this is incorrect and it will error when trying to build.  Well, the
G-exp compiler needs to be updated in agreement with ’lookup-input’ as
above.  What I would expect is something like:

    #<gexp-input #<package git@2.45.2 gnu/packages/version-control.scm:243 7b7573de1b00>:send-email>


All in all, I am a bit lost inside the module (guix gexp). :-)  To be continued…

Cheers,
simon


Some adjustments here or there:

--8<---------------cut here---------------start------------->8---
1 file changed, 1 insertion(+), 1 deletion(-)
gnu/packages/backup.scm | 2 +-

modified   gnu/packages/backup.scm
@@ -318,7 +318,7 @@ (define-public libarchive
                      (libxml2 (assoc-ref inputs "libxml2"))
                      (xz      (assoc-ref inputs "xz"))
                      (zlib    (assoc-ref inputs "zlib"))
-                     (zstd    (assoc-ref inputs "zstd"))
+                     (zstd    (assoc-ref inputs "zstd:lib"))
                      (bzip2   (assoc-ref inputs "bzip2")))
                 ;; Embed absolute references to these inputs to avoid propagation.
                 (substitute* (list (string-append lib "/pkgconfig/libarchive.pc")
--8<---------------cut here---------------end--------------->8---

And thus improving the situation for packages with multiple outputs and
“new style” probably means a world rebuild.




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-07-24  6:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-24  0:41 bug#72266: this-package-input for multiple outputs package Simon Tournier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.