[PATCH core-updates] packages: Lookup inputs by specification.

  • Open
  • quality assurance status badge
Details
3 participants
  • Josselin Poiret
  • Hilton Chain
  • Ludovic Courtès
Owner
unassigned
Submitted by
Hilton Chain
Severity
normal

Debbugs page

H
H
Hilton Chain wrote on 4 Aug 2023 19:50
[PATCH core-updates 0/1] Specify output in input label when it's not "out".
(address . guix-patches@gnu.org)(name . Hilton Chain)(address . hako@ultrarare.space)
cover.1691202289.git.hako@ultrarare.space
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':
Toggle snippet (10 lines)
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>)))

With the patch appiled, `pcre:static' has the label "pcre:static", while
`pcre' stays "pcre":
Toggle snippet (10 lines)
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>)))

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
H
H
Hilton Chain wrote on 4 Aug 2023 19:53
[PATCH core-updates 1/1] packages: Specify output in input label when it's not "out".
(address . 65062@debbugs.gnu.org)(name . Hilton Chain)(address . hako@ultrarare.space)
b6c9adca21cc4418219b51532c2f0a9bddb208f0.1691202289.git.hako@ultrarare.space
* guix/packages.scm (add-input-label): Specify output when it's not "out".
---
guix/packages.scm | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

Toggle diff (21 lines)
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
H
H
Hilton Chain wrote on 4 Aug 2023 20:01
Re: [PATCH core-updates 0/1] Specify output in input label when it's not "out".
(address . 65062@debbugs.gnu.org)
87il9ui44r.wl-hako@ultrarare.space
On Sat, 05 Aug 2023 10:50:32 +0800,
Hilton Chain wrote:
Toggle quote (14 lines)
>
> 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'.
H
H
Hilton Chain wrote on 4 Aug 2023 20:19
87h6pei3bh.wl-hako@ultrarare.space
tags 65062 moreinfo
thanks

On Sat, 05 Aug 2023 11:01:40 +0800,
Hilton Chain wrote:
Toggle quote (3 lines)
> 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.
L
L
Ludovic Courtès wrote on 22 Aug 2023 09:00
Re: [bug#65062] [PATCH core-updates 1/1] packages: Specify output in input label when it's not "out".
(name . Hilton Chain)(address . hako@ultrarare.space)
875y575apr.fsf@gnu.org
Hi,

Hilton Chain <hako@ultrarare.space> skribis:

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

[...]

Toggle quote (4 lines)
> + (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’.

H
H
Hilton Chain wrote on 23 Aug 2023 20:42
(name . Ludovic Courtès)(address . ludo@gnu.org)
87msyhumwj.wl-hako@ultrarare.space
Hi Ludo,

On Wed, 23 Aug 2023 00:00:00 +0800,
Ludovic Courtès wrote:
Toggle quote (24 lines)
>
> 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:
Toggle snippet (6 lines)
(setenv "TZDIR"
(search-input-directory
(if #$(%current-target-system) native-inputs inputs)
"/share/zoneinfo"))

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
J
J
Josselin Poiret wrote on 25 Aug 2023 04:10
87a5ufv0mv.fsf@jpoiret.xyz
Hi everyone,

Hilton Chain <hako@ultrarare.space> writes:

Toggle quote (10 lines)
> 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
-----BEGIN PGP SIGNATURE-----

iQHEBAEBCgAuFiEEOSSM2EHGPMM23K8vUF5AuRYXGooFAmTojAgQHGRldkBqcG9p
cmV0Lnh5egAKCRBQXkC5Fhcaih8fC/9t4wp3lE4SvliqkkR8o6Qr8+HzzWh/8oQy
6hE8O0vouu5kcdGVxoENYVKteiGedFTmvKS1r5CCVJ5WwcMy91UlDf53L2jrnXLW
2sE62Pd7OhlOGTXECONvKLTwDsAn9HXrqdHWwh1gFFTGHrQ6w13wRUc/WVCKeYEA
1ESEYNpqQqGDY7MDVgKIXHTbNqUSP5TE4fjwzu5pZ9KN6cd6lyCRkqI2x4LpzD51
smDnxvzbfv97wMQWRVUWZR8SU3hDdf1t8m3E5kpuogI8O+2qjfNEgAwMnUZUYjhK
Ubnn1xGPjrON5ZIYZzLouAqhgyWeztXjTNrfdFOfY9t0sQ6VnNaYY/d7j1L9YIC5
F0LLnHwOg0IHbzPvGOkBM7PmdhwBtuQFVHXJiLKz6pG1npcmWOfKDnv2bmGkbR3X
aJ1nAs+ILa3M1j5X5CRp3GfY/6CUo/i7I2T2pEmf9gGCnG0uOs23EruWnhEqku8C
UyJAnDw+DqI2g5F5P3mXR0OyTP33UhU=
=zp3K
-----END PGP SIGNATURE-----

L
L
Ludovic Courtès wrote on 8 Sep 2023 15:03
(name . Hilton Chain)(address . hako@ultrarare.space)
87msxw1fw6.fsf@gnu.org
Hi,

Hilton Chain <hako@ultrarare.space> skribis:

Toggle quote (16 lines)
>> 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?

[...]

Toggle quote (7 lines)
> 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:

Toggle quote (15 lines)
> --- 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’.
H
H
Hilton Chain wrote on 3 Oct 2023 02:13
(name . Ludovic Courtès)(address . ludo@gnu.org)
87jzs4vzk1.wl-hako@ultrarare.space
Hi Ludo,

On Sat, 09 Sep 2023 06:03:53 +0800,
Ludovic Courtès wrote:
Toggle quote (43 lines)
>
> 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!


Toggle quote (28 lines)
> 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
H
H
Hilton Chain wrote on 3 Oct 2023 02:15
[PATCH v2 core-updates 0/2] packages: Lookup inputs by specification.
(address . 65062@debbugs.gnu.org)(name . Hilton Chain)(address . hako@ultrarare.space)
cover.1696323536.git.hako@ultrarare.space
*** 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
H
H
Hilton Chain wrote on 3 Oct 2023 02:17
[PATCH v2 core-updates 1/2] ui: package-specification->name+version+output: Move to (guix packages).
(address . 65062@debbugs.gnu.org)(name . Hilton Chain)(address . hako@ultrarare.space)
2b6bc0121a38d6aecf11536cc7e0c630d8eeaaa9.1696323536.git.hako@ultrarare.space
* 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(-)

Toggle diff (145 lines)
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)))
-
;;;
;;; 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
H
H
Hilton Chain wrote on 3 Oct 2023 02:17
[PATCH v2 core-updates 2/2] packages: Lookup inputs by specification.
(address . 65062@debbugs.gnu.org)(name . Hilton Chain)(address . hako@ultrarare.space)
dac85ddb4c5637ab522b4b37f926f00af567cc33.1696323536.git.hako@ultrarare.space
* 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(-)

Toggle diff (108 lines)
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
H
H
Hilton Chain wrote on 3 Oct 2023 02:19
control message for bug #65062
(address . control@debbugs.gnu.org)
87il7ovz9g.wl-hako@ultrarare.space
retitle 65062 [PATCH core-updates] packages: Lookup inputs by specification.
quit
L
L
Ludovic Courtès wrote on 20 Dec 2023 13:26
Re: bug#65062: [PATCH core-updates] packages: Lookup inputs by specification.
(name . Hilton Chain)(address . hako@ultrarare.space)
87msu4ftus.fsf_-_@gnu.org
Hi,

Hilton Chain <hako@ultrarare.space> skribis:

Toggle quote (5 lines)
> * 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:

Toggle quote (13 lines)
> (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.

Toggle quote (5 lines)
> +(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’.
?
Your comment

Commenting via the web interface is currently disabled.

To comment on this conversation send an email to 65062@patchwise.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 65062
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