all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [bug#65062] [PATCH core-updates 0/1] Specify output in input label when it's not "out".
@ 2023-08-05  2:50 Hilton Chain via Guix-patches via
  2023-08-05  2:53 ` [bug#65062] [PATCH core-updates 1/1] packages: " Hilton Chain via Guix-patches via
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Hilton Chain via Guix-patches via @ 2023-08-05  2:50 UTC (permalink / raw)
  To: 65062
  Cc: Hilton Chain, Christopher Baines, Josselin Poiret,
	Ludovic Courtès, Mathieu Othacehe, Ricardo Wurmus,
	Simon Tournier, Tobias Geerinckx-Rice

Hello Guix,

Recently I found it not possible to find `(,gcc "lib") in inputs with
`this-package-input' since it has the label "gcc" and there're other "gcc"s
in the build environment.

As we should avoid direct use on input labels, I think the solution is to
modify `add-input-label', hence the patch.

Taking `aide' from (gnu packages admin) as an example, the current behavior is
that both `pcre:static' and `pcre' have the label "pcre", this affects
`this-package-input' and `modify-inputs':
--8<---------------cut here---------------start------------->8---
scheme@(guix-user)> ,use (guix packages)
scheme@(guix-user)> ,use (gnu packages admin)
scheme@(guix-user)> ((@@ (guix packages) add-input-label) (package-inputs aide))
$1 = ("_" ([...]
           ("pcre" #<package pcre@8.45 gnu/packages/pcre.scm:41 7f59cd759bb0> "static")
           ("pcre" #<package pcre@8.45 gnu/packages/pcre.scm:41 7f59cd759bb0>)
           ("zlib" #<package zlib@1.2.13 gnu/packages/compression.scm:106 7f59c130bd10> "static")
           ("zlib" #<package zlib@1.2.13 gnu/packages/compression.scm:106 7f59c130bd10>)))
--8<---------------cut here---------------end--------------->8---

With the patch appiled, `pcre:static' has the label "pcre:static", while
`pcre' stays "pcre":
--8<---------------cut here---------------start------------->8---
scheme@(guix-user)> ,use (guix packages)
scheme@(guix-user)> ,use (gnu packages admin)
scheme@(guix-user)> ((@@ (guix packages) add-input-label) (package-inputs aide))
$1 = ("_" ([...]
           ("pcre:static" #<package pcre@8.45 gnu/packages/pcre.scm:41 7f6fe32efe70> "static")
           ("pcre" #<package pcre@8.45 gnu/packages/pcre.scm:41 7f6fe32efe70>)
           ("zlib:static" #<package zlib@1.2.13 gnu/packages/compression.scm:106 7f6fd244a000> "static")
           ("zlib" #<package zlib@1.2.13 gnu/packages/compression.scm:106 7f6fd244a000>)))
--8<---------------cut here---------------end--------------->8---

Thanks

Hilton Chain (1):
  packages: Specify output in input label when it's not "out".

 guix/packages.scm | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)


base-commit: 8852e6bb5521edca099d6f346efc92db3244584c
--
2.41.0




^ permalink raw reply	[flat|nested] 13+ messages in thread

* [bug#65062] [PATCH core-updates 1/1] packages: Specify output in input label when it's not "out".
  2023-08-05  2:50 [bug#65062] [PATCH core-updates 0/1] Specify output in input label when it's not "out" Hilton Chain via Guix-patches via
@ 2023-08-05  2:53 ` Hilton Chain via Guix-patches via
  2023-08-22 16:00   ` Ludovic Courtès
  2023-08-05  3:01 ` [bug#65062] [PATCH core-updates 0/1] " Hilton Chain via Guix-patches via
  2023-10-03  9:15 ` [bug#65062] [PATCH v2 core-updates 0/2] packages: Lookup inputs by specification Hilton Chain via Guix-patches via
  2 siblings, 1 reply; 13+ messages in thread
From: Hilton Chain via Guix-patches via @ 2023-08-05  2:53 UTC (permalink / raw)
  To: 65062
  Cc: Hilton Chain, Christopher Baines, Josselin Poiret,
	Ludovic Courtès, Mathieu Othacehe, Ricardo Wurmus,
	Simon Tournier, Tobias Geerinckx-Rice

* guix/packages.scm (add-input-label): Specify output when it's not "out".
---
 guix/packages.scm | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/guix/packages.scm b/guix/packages.scm
index ba98bb0fb4..d0e6e16cbb 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -626,7 +626,13 @@ (define (add-input-label input)
     ((? package? package)
      (list (package-name package) package))
     (((? package? package) output)                ;XXX: ugly?
-     (list (package-name package) package output))
+     (if (string=? output "out")
+         ;; (package "out") => ("package" package "out")
+         (list (package-name package) package output)
+         ;; (package "output") => ("package:output" 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)))
-- 
2.41.0





^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [bug#65062] [PATCH core-updates 0/1] Specify output in input label when it's not "out".
  2023-08-05  2:50 [bug#65062] [PATCH core-updates 0/1] Specify output in input label when it's not "out" Hilton Chain via Guix-patches via
  2023-08-05  2:53 ` [bug#65062] [PATCH core-updates 1/1] packages: " Hilton Chain via Guix-patches via
@ 2023-08-05  3:01 ` Hilton Chain via Guix-patches via
  2023-08-05  3:19   ` Hilton Chain via Guix-patches via
  2023-10-03  9:15 ` [bug#65062] [PATCH v2 core-updates 0/2] packages: Lookup inputs by specification Hilton Chain via Guix-patches via
  2 siblings, 1 reply; 13+ messages in thread
From: Hilton Chain via Guix-patches via @ 2023-08-05  3:01 UTC (permalink / raw)
  To: 65062

On Sat, 05 Aug 2023 10:50:32 +0800,
Hilton Chain wrote:
> 
> Hello Guix,
> 
> Recently I found it not possible to find `(,gcc "lib") in inputs with
> `this-package-input' since it has the label "gcc" and there're other "gcc"s
> in the build environment.
> 
> As we should avoid direct use on input labels, I think the solution is to
> modify `add-input-label', hence the patch.
> 
> Taking `aide' from (gnu packages admin) as an example, the current behavior is
> that both `pcre:static' and `pcre' have the label "pcre", this affects
> `this-package-input' and `modify-inputs':

Ahh sorry, I haven't checked `lookup-input', it seems that it doesn't
use input labels, so this patch only applies to `modify-inputs'.




^ permalink raw reply	[flat|nested] 13+ messages in thread

* [bug#65062] [PATCH core-updates 0/1] Specify output in input label when it's not "out".
  2023-08-05  3:01 ` [bug#65062] [PATCH core-updates 0/1] " Hilton Chain via Guix-patches via
@ 2023-08-05  3:19   ` Hilton Chain via Guix-patches via
  0 siblings, 0 replies; 13+ messages in thread
From: Hilton Chain via Guix-patches via @ 2023-08-05  3:19 UTC (permalink / raw)
  To: control, 65062

tags 65062 moreinfo
thanks

On Sat, 05 Aug 2023 11:01:40 +0800,
Hilton Chain wrote:
> Ahh sorry, I haven't checked `lookup-input', it seems that it doesn't
> use input labels, so this patch only applies to `modify-inputs'.

Sorry for the noise, I have checked `lookup-input' and it uses labels,
but returns unwanted result with this patch (searching for "gcc:lib"
returns a "gcc").

I'll check that out.




^ permalink raw reply	[flat|nested] 13+ messages in thread

* [bug#65062] [PATCH core-updates 1/1] packages: Specify output in input label when it's not "out".
  2023-08-05  2:53 ` [bug#65062] [PATCH core-updates 1/1] packages: " Hilton Chain via Guix-patches via
@ 2023-08-22 16:00   ` Ludovic Courtès
  2023-08-24  3:42     ` Hilton Chain via Guix-patches via
  0 siblings, 1 reply; 13+ messages in thread
From: Ludovic Courtès @ 2023-08-22 16:00 UTC (permalink / raw)
  To: Hilton Chain
  Cc: Josselin Poiret, Simon Tournier, Mathieu Othacehe,
	Tobias Geerinckx-Rice, Ricardo Wurmus, 65062, Christopher Baines

Hi,

Hilton Chain <hako@ultrarare.space> skribis:

> * guix/packages.scm (add-input-label): Specify output when it's not "out".

[...]

> +         (list (string-append (package-name package) ":" output)
> +               package
> +               output)))

The Grand Plan¹ is to eventually get rid of labels entirely (or almost:
there’d still be input alists on the build side).  As such, I thought we
shouldn’t worry too much about what the actual label is.  But perhaps
you stumbled upon situations where this is a problem?  Could you
describe them?

Thanks,
Ludo’.

¹ https://guix.gnu.org/en/blog/2021/the-big-change/




^ permalink raw reply	[flat|nested] 13+ messages in thread

* [bug#65062] [PATCH core-updates 1/1] packages: Specify output in input label when it's not "out".
  2023-08-22 16:00   ` Ludovic Courtès
@ 2023-08-24  3:42     ` Hilton Chain via Guix-patches via
  2023-08-25 11:10       ` Josselin Poiret via Guix-patches via
  2023-09-08 22:03       ` Ludovic Courtès
  0 siblings, 2 replies; 13+ messages in thread
From: Hilton Chain via Guix-patches via @ 2023-08-24  3:42 UTC (permalink / raw)
  To: Ludovic Courtès
  Cc: Josselin Poiret, Simon Tournier, Mathieu Othacehe,
	Tobias Geerinckx-Rice, Ricardo Wurmus, 65062, Christopher Baines

Hi Ludo,

On Wed, 23 Aug 2023 00:00:00 +0800,
Ludovic Courtès wrote:
>
> Hi,
>
> Hilton Chain <hako@ultrarare.space> skribis:
>
> > * guix/packages.scm (add-input-label): Specify output when it's not "out".
>
> [...]
>
> > +         (list (string-append (package-name package) ":" output)
> > +               package
> > +               output)))
>
> The Grand Plan¹ is to eventually get rid of labels entirely (or almost:
> there’d still be input alists on the build side).  As such, I thought we
> shouldn’t worry too much about what the actual label is.  But perhaps
> you stumbled upon situations where this is a problem?  Could you
> describe them?
>
> Thanks,
> Ludo’.
>
> ¹ https://guix.gnu.org/en/blog/2021/the-big-change/

My main concern is that currently modify-inputs, this-package-input
and this-package-native-input operate on input labels and there would
be duplicated labels if adding multiple outputs of a package.

For modify-inputs, I think there's no approach to solve this without
also specifying labels in inputs.

Although this-package-* can be replaced by search-input-*, I'd like to
avoid (dirname (dirname (search-input-file inputs "/lib/..."))) when
(this-package-input "...") is available.


For current this-package-* vs. search-input-*, I have other points:

1. In the context of build system arguments, like #:configure-flags,
inputs and native-inputs as variables aren't available, one may need
to use %build-inputs, %build-host-inputs and %build-target-inputs for
search-input-*, which is inconsistent with other parts.

2. It might be a bit confusing when, for example, adding
tzdata-for-test to native-inputs, and referencing it with proper
cross-compilation support:
--8<---------------cut here---------------start------------->8---
(setenv "TZDIR"
        (search-input-directory
         (if #$(%current-target-system) native-inputs inputs)
         "/share/zoneinfo"))
--8<---------------cut here---------------end--------------->8---

In such cases I may prefer this-package-*, but it would be unreliable
when there're duplicated labels.


There's also issue referencing a package when multiple versions of it
under a same name are added to the inputs, which may not fall under
this "Subject:".


Thanks




^ permalink raw reply	[flat|nested] 13+ messages in thread

* [bug#65062] [PATCH core-updates 1/1] packages: Specify output in input label when it's not "out".
  2023-08-24  3:42     ` Hilton Chain via Guix-patches via
@ 2023-08-25 11:10       ` Josselin Poiret via Guix-patches via
  2023-09-08 22:03       ` Ludovic Courtès
  1 sibling, 0 replies; 13+ messages in thread
From: Josselin Poiret via Guix-patches via @ 2023-08-25 11:10 UTC (permalink / raw)
  To: Hilton Chain, Ludovic Courtès
  Cc: Simon Tournier, Mathieu Othacehe, Tobias Geerinckx-Rice,
	Ricardo Wurmus, 65062, Christopher Baines

[-- Attachment #1: Type: text/plain, Size: 634 bytes --]

Hi everyone,

Hilton Chain <hako@ultrarare.space> writes:

> 2. It might be a bit confusing when, for example, adding
> tzdata-for-test to native-inputs, and referencing it with proper
> cross-compilation support:
> --8<---------------cut here---------------start------------->8---
> (setenv "TZDIR"
>         (search-input-directory
>          (if #$(%current-target-system) native-inputs inputs)
>          "/share/zoneinfo"))
> --8<---------------cut here---------------end--------------->8---

FWIW, the idiomatic way in Guix is to use `(or native-inputs inputs)`
instead of that if.

HTH,
-- 
Josselin Poiret

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 682 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [bug#65062] [PATCH core-updates 1/1] packages: Specify output in input label when it's not "out".
  2023-08-24  3:42     ` Hilton Chain via Guix-patches via
  2023-08-25 11:10       ` Josselin Poiret via Guix-patches via
@ 2023-09-08 22:03       ` Ludovic Courtès
  2023-10-03  9:13         ` Hilton Chain via Guix-patches via
  1 sibling, 1 reply; 13+ messages in thread
From: Ludovic Courtès @ 2023-09-08 22:03 UTC (permalink / raw)
  To: Hilton Chain
  Cc: Josselin Poiret, Simon Tournier, Mathieu Othacehe,
	Tobias Geerinckx-Rice, Ricardo Wurmus, 65062, Christopher Baines

Hi,

Hilton Chain <hako@ultrarare.space> skribis:

>> Hilton Chain <hako@ultrarare.space> skribis:
>>
>> > * guix/packages.scm (add-input-label): Specify output when it's not "out".
>>
>> [...]
>>
>> > +         (list (string-append (package-name package) ":" output)
>> > +               package
>> > +               output)))
>>
>> The Grand Plan¹ is to eventually get rid of labels entirely (or almost:
>> there’d still be input alists on the build side).  As such, I thought we
>> shouldn’t worry too much about what the actual label is.  But perhaps
>> you stumbled upon situations where this is a problem?  Could you
>> describe them?

[...]

> My main concern is that currently modify-inputs, this-package-input
> and this-package-native-input operate on input labels and there would
> be duplicated labels if adding multiple outputs of a package.
>
> For modify-inputs, I think there's no approach to solve this without
> also specifying labels in inputs.

Yes, good point.

Another, more radical approach, would be to change semantics, whereby
(inputs (list p)) would mean that all the outputs of ‘p’, not just
“out”, are taken as inputs.  That’d simplify inputs at the expense of
precision, and (this-package-input NAME) would always be unambiguous.

But maybe that’s too radical and uncertain.

So all things considered, I guess you’re right and we should do what you
propose.

Minor issues:

> --- a/guix/packages.scm
> +++ b/guix/packages.scm
> @@ -626,7 +626,13 @@ (define (add-input-label input)
>      ((? package? package)
>       (list (package-name package) package))
>      (((? package? package) output)                ;XXX: ugly?
> -     (list (package-name package) package output))
> +     (if (string=? output "out")
> +         ;; (package "out") => ("package" package "out")
> +         (list (package-name package) package output)
> +         ;; (package "output") => ("package:output" package "output")
> +         (list (string-append (package-name package) ":" output)
> +               package
> +               output)))

Rather write it as two separate clauses, without comments:

  (((? package? package) "out")
   …)
  (((? package? package) output)
   …)

Could you also add a test case in ‘tests/packages.scm’ that would look
up inputs by those labels?

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 13+ messages in thread

* [bug#65062] [PATCH core-updates 1/1] packages: Specify output in input label when it's not "out".
  2023-09-08 22:03       ` Ludovic Courtès
@ 2023-10-03  9:13         ` Hilton Chain via Guix-patches via
  0 siblings, 0 replies; 13+ messages in thread
From: Hilton Chain via Guix-patches via @ 2023-10-03  9:13 UTC (permalink / raw)
  To: Ludovic Courtès
  Cc: Josselin Poiret, Simon Tournier, Mathieu Othacehe,
	Tobias Geerinckx-Rice, Ricardo Wurmus, 65062, Christopher Baines

Hi Ludo,

On Sat, 09 Sep 2023 06:03:53 +0800,
Ludovic Courtès wrote:
>
> Hi,
>
> Hilton Chain <hako@ultrarare.space> skribis:
>
> >> Hilton Chain <hako@ultrarare.space> skribis:
> >>
> >> > * guix/packages.scm (add-input-label): Specify output when it's not "out".
> >>
> >> [...]
> >>
> >> > +         (list (string-append (package-name package) ":" output)
> >> > +               package
> >> > +               output)))
> >>
> >> The Grand Plan¹ is to eventually get rid of labels entirely (or almost:
> >> there’d still be input alists on the build side).  As such, I thought we
> >> shouldn’t worry too much about what the actual label is.  But perhaps
> >> you stumbled upon situations where this is a problem?  Could you
> >> describe them?
>
> [...]
>
> > My main concern is that currently modify-inputs, this-package-input
> > and this-package-native-input operate on input labels and there would
> > be duplicated labels if adding multiple outputs of a package.
> >
> > For modify-inputs, I think there's no approach to solve this without
> > also specifying labels in inputs.
>
> Yes, good point.
>
> Another, more radical approach, would be to change semantics, whereby
> (inputs (list p)) would mean that all the outputs of ‘p’, not just
> “out”, are taken as inputs.  That’d simplify inputs at the expense of
> precision, and (this-package-input NAME) would always be unambiguous.
>
> But maybe that’s too radical and uncertain.
>
> So all things considered, I guess you’re right and we should do what you
> propose.


Thank you!


> Minor issues:
>
> > --- a/guix/packages.scm
> > +++ b/guix/packages.scm
> > @@ -626,7 +626,13 @@ (define (add-input-label input)
> >      ((? package? package)
> >       (list (package-name package) package))
> >      (((? package? package) output)                ;XXX: ugly?
> > -     (list (package-name package) package output))
> > +     (if (string=? output "out")
> > +         ;; (package "out") => ("package" package "out")
> > +         (list (package-name package) package output)
> > +         ;; (package "output") => ("package:output" package "output")
> > +         (list (string-append (package-name package) ":" output)
> > +               package
> > +               output)))
>
> Rather write it as two separate clauses, without comments:
>
>   (((? package? package) "out")
>    …)
>   (((? package? package) output)
>    …)
>
> Could you also add a test case in ‘tests/packages.scm’ that would look
> up inputs by those labels?


I have thought about this patch again recently.


First of all, I didn't describe my own trouble clearly:

I wanted to put `this-package-input' into #$gcc:lib, but didn't know how.  Now I
understand that (ungexp (this-package-input "gcc") "lib") can be used and input
labels are not quite related...


And then I realised that there's too much extra work in package definitions for
the label change.


So, how about looking up inputs by specification (name + version + output), and
falling back to input labels?  I think this can address the issue regarding
multiple outputs and versions, while keeping compatible with existing behavior.

I'll send v2 for the change, with a different subject.  Though I haven't written
new tests for it, the existing (tests packages) passes when applied to master
and no package definition needs changing at least for building guix.


Thanks




^ permalink raw reply	[flat|nested] 13+ messages in thread

* [bug#65062] [PATCH v2 core-updates 0/2] packages: Lookup inputs by specification.
  2023-08-05  2:50 [bug#65062] [PATCH core-updates 0/1] Specify output in input label when it's not "out" Hilton Chain via Guix-patches via
  2023-08-05  2:53 ` [bug#65062] [PATCH core-updates 1/1] packages: " Hilton Chain via Guix-patches via
  2023-08-05  3:01 ` [bug#65062] [PATCH core-updates 0/1] " Hilton Chain via Guix-patches via
@ 2023-10-03  9:15 ` Hilton Chain via Guix-patches via
  2023-10-03  9:17   ` [bug#65062] [PATCH v2 core-updates 1/2] ui: package-specification->name+version+output: Move to (guix packages) Hilton Chain via Guix-patches via
  2023-10-03  9:17   ` [bug#65062] [PATCH v2 core-updates 2/2] packages: Lookup inputs by specification Hilton Chain via Guix-patches via
  2 siblings, 2 replies; 13+ messages in thread
From: Hilton Chain via Guix-patches via @ 2023-10-03  9:15 UTC (permalink / raw)
  To: 65062
  Cc: Hilton Chain, Hilton Chain, Ludovic Courtès, Josselin Poiret,
	Christopher Baines, Mathieu Othacehe, Ricardo Wurmus,
	Simon Tournier, Tobias Geerinckx-Rice

*** BLURB HERE ***

Hilton Chain (2):
  ui: package-specification->name+version+output: Move to (guix packages).
  packages: Lookup inputs by specification.

 guix/packages.scm  | 95 ++++++++++++++++++++++++++++++++++++++--------
 guix/ui.scm        | 21 ----------
 tests/packages.scm | 17 +++++++++
 tests/ui.scm       | 17 ---------
 4 files changed, 97 insertions(+), 53 deletions(-)


base-commit: 70b0f2b9134b2db286f707835394798de039c277
--
2.41.0




^ permalink raw reply	[flat|nested] 13+ messages in thread

* [bug#65062] [PATCH v2 core-updates 1/2] ui: package-specification->name+version+output: Move to (guix packages).
  2023-10-03  9:15 ` [bug#65062] [PATCH v2 core-updates 0/2] packages: Lookup inputs by specification Hilton Chain via Guix-patches via
@ 2023-10-03  9:17   ` Hilton Chain via Guix-patches via
  2023-10-03  9:17   ` [bug#65062] [PATCH v2 core-updates 2/2] packages: Lookup inputs by specification Hilton Chain via Guix-patches via
  1 sibling, 0 replies; 13+ messages in thread
From: Hilton Chain via Guix-patches via @ 2023-10-03  9:17 UTC (permalink / raw)
  To: 65062
  Cc: Hilton Chain, Hilton Chain, Ludovic Courtès, Josselin Poiret,
	Christopher Baines, Mathieu Othacehe, Ricardo Wurmus,
	Simon Tournier, Tobias Geerinckx-Rice

* guix/ui.scm (package-specification->name+version+output): Move it to...
* guix/packages.scm (package-specification->name+version+output): ...here.
* tests/ui.scm (package-specification->name+version+output): Move it to...
* tests/packages.scm (package-specification->name+version+output): ...here.
---
 guix/packages.scm  | 23 +++++++++++++++++++++++
 guix/ui.scm        | 21 ---------------------
 tests/packages.scm | 17 +++++++++++++++++
 tests/ui.scm       | 17 -----------------
 4 files changed, 40 insertions(+), 38 deletions(-)

diff --git a/guix/packages.scm b/guix/packages.scm
index f70fad695e..b004882cc6 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -52,6 +52,7 @@ (define-module (guix packages)
   #:use-module (ice-9 regex)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-9 gnu)
+  #:use-module (srfi srfi-11)
   #:use-module (srfi srfi-26)
   #:use-module (srfi srfi-34)
   #:use-module (srfi srfi-35)
@@ -117,6 +118,8 @@ (define-module (guix packages)
             deprecated-package
             package-field-location
 
+            package-specification->name+version+output
+
             this-package-input
             this-package-native-input
 
@@ -783,6 +786,26 @@ (define (package-field-location package field)
         #f)))
     (_ #f)))
 
+(define* (package-specification->name+version+output spec
+                                                     #:optional (output "out"))
+  "Parse package specification SPEC and return three value: the specified
+package name, version number (or #f), and output name (or OUTPUT).  SPEC may
+optionally contain a version number and an output name, as in these examples:
+
+  guile
+  guile@2.0.9
+  guile:debug
+  guile@2.0.9:debug
+"
+  (let*-values (((name sub-drv)
+                 (match (string-rindex spec #\:)
+                   (#f    (values spec output))
+                   (colon (values (substring spec 0 colon)
+                                  (substring spec (+ 1 colon))))))
+                ((name version)
+                 (package-name->name+version name)))
+    (values name version sub-drv)))
+
 (define-syntax-rule (this-package-input name)
   "Return the input NAME of the package being defined--i.e., an input
 from the ‘inputs’ or ‘propagated-inputs’ field.  Native inputs are not
diff --git a/guix/ui.scm b/guix/ui.scm
index 6f2d4fe245..0cc121f048 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -118,7 +118,6 @@ (define-module (guix ui)
             package-synopsis-string
             string->recutils
             package->recutils
-            package-specification->name+version+output
 
             pager-wrapped-port
             with-paginated-output-port
@@ -2098,26 +2097,6 @@ (define (delete-generation* store profile generation)
           (generation-file-name profile generation))
   (delete-generation store profile generation))
 
-(define* (package-specification->name+version+output spec
-                                                     #:optional (output "out"))
-  "Parse package specification SPEC and return three value: the specified
-package name, version number (or #f), and output name (or OUTPUT).  SPEC may
-optionally contain a version number and an output name, as in these examples:
-
-  guile
-  guile@2.0.9
-  guile:debug
-  guile@2.0.9:debug
-"
-  (let*-values (((name sub-drv)
-                 (match (string-rindex spec #\:)
-                   (#f    (values spec output))
-                   (colon (values (substring spec 0 colon)
-                                  (substring spec (+ 1 colon))))))
-                ((name version)
-                 (package-name->name+version name)))
-    (values name version sub-drv)))
-
 \f
 ;;;
 ;;; Command-line option processing.
diff --git a/tests/packages.scm b/tests/packages.scm
index 2b4f9f8e90..be9188ceb1 100644
--- a/tests/packages.scm
+++ b/tests/packages.scm
@@ -1926,6 +1926,23 @@ (define compressors '(("gzip"  . "gz")
                                     "-p" (derivation->output-path prof2)
                                     "--search-paths"))))))
 
+(test-equal "package-specification->name+version+output"
+  '(("guile" #f "out")
+    ("guile" "2.0.9" "out")
+    ("guile" #f "debug")
+    ("guile" "2.0.9" "debug")
+    ("guile-cairo" "1.4.1" "out"))
+  (map (lambda (spec)
+         (call-with-values
+             (lambda ()
+               (package-specification->name+version+output spec))
+           list))
+       '("guile"
+         "guile@2.0.9"
+         "guile:debug"
+         "guile@2.0.9:debug"
+         "guile-cairo@1.4.1")))
+
 (test-equal "specification->package when not found"
   'quit
   (catch 'quit
diff --git a/tests/ui.scm b/tests/ui.scm
index 438acae525..7bd948bd14 100644
--- a/tests/ui.scm
+++ b/tests/ui.scm
@@ -100,23 +100,6 @@ (define guile-2.0.9
     (package-description-string
      (dummy-package "foo" (description "b•ll•t")))))
 
-(test-equal "package-specification->name+version+output"
-  '(("guile" #f "out")
-    ("guile" "2.0.9" "out")
-    ("guile" #f "debug")
-    ("guile" "2.0.9" "debug")
-    ("guile-cairo" "1.4.1" "out"))
-  (map (lambda (spec)
-         (call-with-values
-             (lambda ()
-               (package-specification->name+version+output spec))
-           list))
-       '("guile"
-         "guile@2.0.9"
-         "guile:debug"
-         "guile@2.0.9:debug"
-         "guile-cairo@1.4.1")))
-
 (test-equal "integer"
   '(1)
   (string->generations "1"))
-- 
2.41.0





^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [bug#65062] [PATCH v2 core-updates 2/2] packages: Lookup inputs by specification.
  2023-10-03  9:15 ` [bug#65062] [PATCH v2 core-updates 0/2] packages: Lookup inputs by specification Hilton Chain via Guix-patches via
  2023-10-03  9:17   ` [bug#65062] [PATCH v2 core-updates 1/2] ui: package-specification->name+version+output: Move to (guix packages) Hilton Chain via Guix-patches via
@ 2023-10-03  9:17   ` Hilton Chain via Guix-patches via
  2023-12-20 21:26     ` [bug#65062] [PATCH core-updates] " Ludovic Courtès
  1 sibling, 1 reply; 13+ messages in thread
From: Hilton Chain via Guix-patches via @ 2023-10-03  9:17 UTC (permalink / raw)
  To: 65062
  Cc: Hilton Chain, Hilton Chain, Ludovic Courtès, Josselin Poiret,
	Christopher Baines, Mathieu Othacehe, Ricardo Wurmus,
	Simon Tournier, Tobias Geerinckx-Rice

* guix/packages.scm (specification->inputs): New procedure.
(lookup-input,replace-input): Use it.
(delete-input): New procedure.
(modify-inputs)[delete]: Use it.
---
 guix/packages.scm | 72 +++++++++++++++++++++++++++++++++++++----------
 1 file changed, 57 insertions(+), 15 deletions(-)

diff --git a/guix/packages.scm b/guix/packages.scm
index b004882cc6..45552bfb7f 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -1173,15 +1173,49 @@ (define (transitive-inputs inputs)
       ((input rest ...)
        (loop rest (cons input result) propagated first? seen)))))
 
+(define (specification->inputs spec inputs)
+  "Lookup inputs specified by SPEC among INPUTS, an input list.  Return an input
+list consists of all matching inputs, or '().  SPEC may be a package name,
+optionally containing a version number or an output name, as in these examples:
+
+  guile
+  guile@2.0.9
+  guile:debug
+  guile@2.0.9:debug
+
+If SPEC does not specify a version number, all versions are matched; if SPEC
+does not specify an output, all outputs are matched.
+
+SPEC can be an input label as well."
+  (let ((name version sub-drv
+              (package-specification->name+version+output spec #f)))
+    (filter-map
+     (lambda (input)
+       (match input
+         (((? string? label) (? package? package) . outputs)
+          (and (or (and (string=? name (package-name package))
+                        (when version
+                          (string-prefix? version (package-version package)))
+                        (when sub-drv
+                          (and (not (null? outputs))
+                               (string=? sub-drv (first outputs)))))
+                   ;; fallback to input label
+                   (string=? label spec))
+               input))
+         ;; not a package
+         (((? string? label) _ . _)
+          (and (string=? label spec)
+               input))))
+     inputs)))
+
 (define (lookup-input inputs name)
   "Lookup NAME among INPUTS, an input list."
   ;; Note: Currently INPUTS is assumed to be an input list that contains input
   ;; labels.  In the future, input labels will be gone and this procedure will
   ;; check package names.
-  (match (assoc-ref inputs name)
-    ((obj) obj)
-    ((obj _) obj)
-    (#f #f)))
+  (let ((candidates (specification->inputs name inputs)))
+    (and (not (null? candidates))
+         (second (first candidates)))))
 
 (define (lookup-package-input package name)
   "Look up NAME among PACKAGE's inputs.  Return it if found, #f otherwise."
@@ -1202,17 +1236,25 @@ (define (lookup-package-direct-input package name)
 otherwise."
   (lookup-input (package-direct-inputs package) name))
 
+(define (delete-input name inputs)
+  "Delete input NAME within INPUTS."
+  (let ((to-delete (specification->inputs name inputs)))
+    (lset-difference equal? inputs to-delete)))
+
 (define (replace-input name replacement inputs)
   "Replace input NAME by REPLACEMENT within INPUTS."
-  (map (lambda (input)
-         (match input
-           (((? string? label) _ . outputs)
-            (if (string=? label name)
-                (match replacement        ;does REPLACEMENT specify an output?
-                  ((_ _) (cons label replacement))
-                  (_     (cons* label replacement outputs)))
-                input))))
-       inputs))
+  (let ((to-replace (specification->inputs name inputs)))
+    (append
+     (lset-difference equal? inputs to-replace)
+     (if (null? to-replace)
+         '()
+         (map (lambda (input)
+                (match input
+                  ((label _ . outputs)
+                   (match replacement   ;does REPLACEMENT specify an output?
+                     ((_ _) (cons label replacement))
+                     (_     (cons* label replacement outputs))))))
+              to-replace)))))
 
 (define-syntax prepend
   (lambda (s)
@@ -1244,10 +1286,10 @@ (define-syntax modify-inputs
     ;; 'package-inputs' & co., is actually an alist with labels.  Eventually,
     ;; it will operate on list of inputs without labels.
     ((_ inputs (delete name) clauses ...)
-     (modify-inputs (alist-delete name inputs)
+     (modify-inputs (delete-input name inputs)
                     clauses ...))
     ((_ inputs (delete names ...) clauses ...)
-     (modify-inputs (fold alist-delete inputs (list names ...))
+     (modify-inputs (fold delete-input inputs (list names ...))
                     clauses ...))
     ((_ inputs (prepend lst ...) clauses ...)
      (modify-inputs (append (map add-input-label (list lst ...)) inputs)
-- 
2.41.0





^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [bug#65062] [PATCH core-updates] packages: Lookup inputs by specification.
  2023-10-03  9:17   ` [bug#65062] [PATCH v2 core-updates 2/2] packages: Lookup inputs by specification Hilton Chain via Guix-patches via
@ 2023-12-20 21:26     ` Ludovic Courtès
  0 siblings, 0 replies; 13+ messages in thread
From: Ludovic Courtès @ 2023-12-20 21:26 UTC (permalink / raw)
  To: Hilton Chain
  Cc: Josselin Poiret, Simon Tournier, Mathieu Othacehe,
	Tobias Geerinckx-Rice, Ricardo Wurmus, 65062, Christopher Baines

Hi,

Hilton Chain <hako@ultrarare.space> skribis:

> * guix/packages.scm (specification->inputs): New procedure.
> (lookup-input,replace-input): Use it.
> (delete-input): New procedure.
> (modify-inputs)[delete]: Use it.

I’ve been thinking about this change lately.

The problem we have now is that it looks like input labels are gone, but
they’re not; in particular ‘modify-inputs’ preserves labels, which is a
source of confusion.  For instance, if you do:

  (modify-inputs x
    (replace "openmpi" mpich))

then ‘mpich’ remains associated with the “openmpi” label.  Ugh.

So I sympathize with the goal.  I think we can do something simpler
though:

>  (define (lookup-input inputs name)
>    "Lookup NAME among INPUTS, an input list."
>    ;; Note: Currently INPUTS is assumed to be an input list that contains input
>    ;; labels.  In the future, input labels will be gone and this procedure will
>    ;; check package names.
> -  (match (assoc-ref inputs name)
> -    ((obj) obj)
> -    ((obj _) obj)
> -    (#f #f)))
> +  (let ((candidates (specification->inputs name inputs)))
> +    (and (not (null? candidates))
> +         (second (first candidates)))))

How about:

  (find (match-lambda
          ((_ (? package? package) . _)
           (string=? (package-name package) name))
          (_ #f))
        inputs)

?

That way, ‘lookup-input’ would honor package names and ignore labels.

> +(define (delete-input name inputs)
> +  "Delete input NAME within INPUTS."
> +  (let ((to-delete (specification->inputs name inputs)))
> +    (lset-difference equal? inputs to-delete)))

And we do something similar here.

Thus, no need to fiddle with specifications.

How does that sound?

Now, I think this is the way forward, but I also think it’s going to
break many packages and workflows (‘--with-input’…).  So it should go
hand in hand with an effort to fully remove labels in Guix.

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-12-20 21:28 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-05  2:50 [bug#65062] [PATCH core-updates 0/1] Specify output in input label when it's not "out" Hilton Chain via Guix-patches via
2023-08-05  2:53 ` [bug#65062] [PATCH core-updates 1/1] packages: " Hilton Chain via Guix-patches via
2023-08-22 16:00   ` Ludovic Courtès
2023-08-24  3:42     ` Hilton Chain via Guix-patches via
2023-08-25 11:10       ` Josselin Poiret via Guix-patches via
2023-09-08 22:03       ` Ludovic Courtès
2023-10-03  9:13         ` Hilton Chain via Guix-patches via
2023-08-05  3:01 ` [bug#65062] [PATCH core-updates 0/1] " Hilton Chain via Guix-patches via
2023-08-05  3:19   ` Hilton Chain via Guix-patches via
2023-10-03  9:15 ` [bug#65062] [PATCH v2 core-updates 0/2] packages: Lookup inputs by specification Hilton Chain via Guix-patches via
2023-10-03  9:17   ` [bug#65062] [PATCH v2 core-updates 1/2] ui: package-specification->name+version+output: Move to (guix packages) Hilton Chain via Guix-patches via
2023-10-03  9:17   ` [bug#65062] [PATCH v2 core-updates 2/2] packages: Lookup inputs by specification Hilton Chain via Guix-patches via
2023-12-20 21:26     ` [bug#65062] [PATCH core-updates] " Ludovic Courtès

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.