[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 1/2] packages: Support for full Guix specification

From: Ricardo Wurmus
Subject: Re: [PATCH v2 1/2] packages: Support for full Guix specification
Date: Tue, 26 Apr 2022 22:30:21 +0200
User-agent: mu4e 1.6.10; emacs 28.0.50

Hi again,

Olivier Dion <> writes:

>>> +          ((first . rest) first)
>>> +          (_ (raise (condition
>>> +                     (&gwl-package-error
>>> +                      (package-spec (string-append name+version 
>>> output)))))))
>>> +        output))
>> I’d prefer to have this return multiple values instead of a compound
>> value.
> With (values ...)?  That's what (gnu packages) does I think.

I think I missed how you intended for this to work.  IIUC you’re letting
LOOKUP-PACKAGE return a list of a package and an output because that
will end up as an argument to PACKAGES->MANIFEST (in (@ (gwl processes)

PACKAGES->MANIFEST has this docstring:

 "Return a list of manifest entries, one for each item listed in PACKAGES.
Elements of PACKAGES can be either package objects or package/string tuples
denoting a specific output of a package."

So that’s why you’re making it return a tuple of package/string tuples –
for compatibility with that procedure.

My comment about returning multiple values or a record value totally
misses your intent.  Sorry!  Now I get it.

> I do think it would be better to wait for (guix inferior) to support
> selecting outputs.  However, I do need selection of outputs for my use
> case right now!  Specificaly, I need to have debug symbols of many
> packages.  The quick hack above does the work for me but I understand
> that it would be preferable if (guix inferior) has support for outputs
> instead.

I understand.

So … I think we can figure something out that won’t be far removed from
what you proposed.  I’d probably split it into smaller procedures,
though, to make it a bit more obvious what’s going on.

Let’s see the diff again…

> -(define (lookup-package specification)
> +(define (%lookup-package name+version output)
> +  (list (match (apply lookup-inferior-packages
> +                      (cons (current-guix) (string-split name+version #\@)))
> +          ((first . rest) first)
> +          (_ (raise (condition
> +                     (&gwl-package-error
> +                      (package-spec (string-append name+version output)))))))
> +        output))
> +(define* (lookup-package specification #:optional (output "out"))
>    (log-event 'guix (G_ "Looking up package `~a'~%") specification)
> -  (match (lookup-inferior-packages (current-guix) specification)
> -    ((first . rest) first)
> -    (_ (raise (condition
> -               (&gwl-package-error
> -                (package-spec specification)))))))
> +  (match (string-split specification #\:)
> +    ((name+version sub-drv) (%lookup-package name+version sub-drv))
> +    ((name+version) (simple-package (%lookup-package name+version output)))))

I’m struggling to figure out a cleaner way to do this…
Why are we processing the specification *and* accept an optional OUTPUT
argument?  It seems to me that SUB-DRV and OUTPUT *should* be the same,
but it’s possible to call LOOKUP-PACKAGE in a way that they differ,
which doesn’t make much sense to me.

Another thing that bothers me a bit is all that string splitting; once
for version, again for the output.  The (guix ui) module has
task.  It returns multiple values; let’s use LET* from SRFI-71.  What do
you think of this?

--8<---------------cut here---------------start------------->8---
(import (srfi srfi-71)
(define (lookup-package specification)
  "Look up SPECIFICATION in an inferior and return a matching package.  If the
specification declares a specific output return a tuple consisting of the
package value and the output.  If no matching package is found, raise a
   (log-event 'guix (G_ "Looking up package `~a'~%") specification)
   (let* ((name version output (package-specification->name+version+output 
            (match (lookup-inferior-packages (current-guix) name version)
              ((first . rest) first)
              (_ (raise (condition
                          (package-spec specification))))))))
     (if output
         (list package output)
--8<---------------cut here---------------end--------------->8---

What do you think of that?

>  (define (valid-package? val)
> -  (or (package? val)
> -      (inferior-package? val)))
> +  (or
> +   (and (list? val)
> +        (valid-package? (car val))
> +        (string? (cadr val)))
> +   (package? val)
> +   (inferior-package? val)))
> +

I suggest rewriting this whole thing with MATCH so that the structure of
VAL becomes apparent.  Perhaps something like this?

     ((maybe-package (? string? output))
      (valid-package? maybe-package))
      (or (package? val)
          (inferior-package? val))))

> +(define (simple-package pkg)
> +  (if (list? pkg) (car pkg) pkg))

I still don’t like this :)  Not only the implementation but the fact
that it appears to be needed.  At least implementation-wise I’d prefer
something like this:

(define (just-package maybe-package+output)
  (match maybe-package+output
    (((? package? package) (? string? output)) package)
    ((? package? package) package)
    (_ (error "what is this?"))))

There are a few places where we need to be careful that we’re dealing
with the right type and that we handle both cases equally well: when a
tuple is encountered and when a plain package value is encountered.

Ideally we’d also have tests for this.

What do you think of all this?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]