[PATCH] inferior: Support querying package replacements.

  • Done
  • quality assurance status badge
Details
2 participants
  • Ludovic Courtès
  • Christopher Baines
Owner
unassigned
Submitted by
Christopher Baines
Severity
normal
C
C
Christopher Baines wrote on 24 Apr 2021 07:45
(address . guix-patches@gnu.org)
20210424054509.7740-1-mail@cbaines.net
I'm looking at this to help with adding support for looking up package
replacements to store in the Guix Data Service.

* guix/inferior.scm (inferior-package-replacement): New procedure.
---
guix/inferior.scm | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)

Toggle diff (40 lines)
diff --git a/guix/inferior.scm b/guix/inferior.scm
index eb457f81f9..19607724c0 100644
--- a/guix/inferior.scm
+++ b/guix/inferior.scm
@@ -90,6 +90,7 @@
inferior-package-native-search-paths
inferior-package-transitive-native-search-paths
inferior-package-search-paths
+ inferior-package-replacement
inferior-package-provenance
inferior-package-derivation
@@ -462,6 +463,25 @@ package."
(define inferior-package-transitive-native-search-paths
(cut %inferior-package-search-paths <> 'package-transitive-native-search-paths))
+(define (inferior-package-replacement package)
+ (match (inferior-package-field
+ package
+ '(compose (match-lambda
+ ((? package? package)
+ (let ((id (object-address package)))
+ (hashv-set! %package-table id package)
+ (list id
+ (package-name package)
+ (package-version package))))
+ (#f #f))
+ package-replacement))
+ (#f #f)
+ ((id name version)
+ (inferior-package (inferior-package-inferior package)
+ name
+ version
+ id))))
+
(define (inferior-package-provenance package)
"Return a \"provenance sexp\" for PACKAGE, an inferior package. The result
is similar to the sexp returned by 'package-provenance' for regular packages."
--
2.30.1
L
L
Ludovic Courtès wrote on 3 May 2021 22:50
(name . Christopher Baines)(address . mail@cbaines.net)(address . 47986@debbugs.gnu.org)
87bl9rv8wc.fsf@gnu.org
Hi,

Christopher Baines <mail@cbaines.net> skribis:

Toggle quote (5 lines)
> I'm looking at this to help with adding support for looking up package
> replacements to store in the Guix Data Service.
>
> * guix/inferior.scm (inferior-package-replacement): New procedure.

Could you add a docstring and ideally a test? (There might be
complications for the test, let’s see how it goes.)

Thanks!

Ludo’.
C
C
Christopher Baines wrote on 14 May 2021 10:42
[PATCH v2] inferior: Support querying package replacements.
(address . 47986@debbugs.gnu.org)
20210514084200.5896-1-mail@cbaines.net
I'm looking at this to help with adding support for looking up package
replacements to store in the Guix Data Service.

* guix/inferior.scm (inferior-package-replacement): New procedure.
* tests/inferior.scm ("inferior-package-replacement"): New test.
---
guix/inferior.scm | 22 ++++++++++++++++++++++
tests/inferior.scm | 18 ++++++++++++++++++
2 files changed, 40 insertions(+)

Toggle diff (78 lines)
diff --git a/guix/inferior.scm b/guix/inferior.scm
index eb457f81f9..7c8e478f2a 100644
--- a/guix/inferior.scm
+++ b/guix/inferior.scm
@@ -90,6 +90,7 @@
inferior-package-native-search-paths
inferior-package-transitive-native-search-paths
inferior-package-search-paths
+ inferior-package-replacement
inferior-package-provenance
inferior-package-derivation
@@ -462,6 +463,27 @@ package."
(define inferior-package-transitive-native-search-paths
(cut %inferior-package-search-paths <> 'package-transitive-native-search-paths))
+(define (inferior-package-replacement package)
+ "Return the replacement for PACKAGE. This will either be an inferior
+package, or #f."
+ (match (inferior-package-field
+ package
+ '(compose (match-lambda
+ ((? package? package)
+ (let ((id (object-address package)))
+ (hashv-set! %package-table id package)
+ (list id
+ (package-name package)
+ (package-version package))))
+ (#f #f))
+ package-replacement))
+ (#f #f)
+ ((id name version)
+ (inferior-package (inferior-package-inferior package)
+ name
+ version
+ id))))
+
(define (inferior-package-provenance package)
"Return a \"provenance sexp\" for PACKAGE, an inferior package. The result
is similar to the sexp returned by 'package-provenance' for regular packages."
diff --git a/tests/inferior.scm b/tests/inferior.scm
index f227e0b749..864bab86da 100644
--- a/tests/inferior.scm
+++ b/tests/inferior.scm
@@ -26,6 +26,7 @@
#:use-module (gnu packages)
#:use-module (gnu packages bootstrap)
#:use-module (gnu packages guile)
+ #:use-module (gnu packages sqlite)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-34)
#:use-module (srfi srfi-64)
@@ -260,6 +261,23 @@
(list (inferior-package-derivation %store guile "x86_64-linux")
(inferior-package-derivation %store guile "armhf-linux")))))
+(test-equal "inferior-package-replacement"
+ (package-derivation %store
+ (or (package-replacement sqlite) sqlite)
+ "x86_64-linux")
+ (let* ((inferior (open-inferior %top-builddir
+ #:command "scripts/guix"))
+ (packages (inferior-packages inferior)))
+ (match (lookup-inferior-packages inferior
+ (package-name sqlite)
+ (package-version sqlite))
+ ((inferior-sqlite rest ...)
+ (inferior-package-derivation %store
+ (or (inferior-package-replacement
+ inferior-sqlite)
+ inferior-sqlite)
+ "x86_64-linux")))))
+
(test-equal "inferior-package->manifest-entry"
(manifest-entry->list (package->manifest-entry
(first (find-best-packages-by-name "guile" #f))))
--
2.30.1
C
C
Christopher Baines wrote on 14 May 2021 10:45
Re: bug#47986: [PATCH] inferior: Support querying package replacements.
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 47986@debbugs.gnu.org)
87y2chd7pw.fsf@cbaines.net
Ludovic Courtès <ludo@gnu.org> writes:

Toggle quote (10 lines)
> Christopher Baines <mail@cbaines.net> skribis:
>
>> I'm looking at this to help with adding support for looking up package
>> replacements to store in the Guix Data Service.
>>
>> * guix/inferior.scm (inferior-package-replacement): New procedure.
>
> Could you add a docstring and ideally a test? (There might be
> complications for the test, let’s see how it goes.)

I've sent an update patch now.

Maybe the test should search out for a package without a replacement, as
well as a package with a replacement, so that it tests both cases, but I
just went with a simpler approach for now.
-----BEGIN PGP SIGNATURE-----

iQKlBAEBCgCPFiEEPonu50WOcg2XVOCyXiijOwuE9XcFAmCeOKtfFIAAAAAALgAo
aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNF
ODlFRUU3NDU4RTcyMEQ5NzU0RTBCMjVFMjhBMzNCMEI4NEY1NzcRHG1haWxAY2Jh
aW5lcy5uZXQACgkQXiijOwuE9XcWNA//c4pagZOJaaNS5gWu7WLrALeB/fS7E7Jn
5TJqbyud4lW2+M9AV8UHjLiF3VyoZNoNPDJZosLw6SkVLXgMbQQWnpklQnuU3Xt6
k3IHXDevS2Y4WuMpVWuOyvvaKoI0DniJ2NlXGKc/3R1FRysqUkxPe3hiPH0X+J+h
A4zGHDdVTVii97YJxXaVwovR3Q9VTTAWWIPG8BvNZJfsgbwcgxEy40zo5rYkv3tS
Eb1xA6B9S0K1obkWczVQIHHdJAhkONTf1/7NSRCvmlFjgvnKthbbn26k01CGG1yT
O0hjgs2je/mrxZe3xEjiF/V3hQ0Wfc42c9VYfTZ6QjuSNZsydD2/sQo9tMRNtmt4
jQ66Xb5NTzhyW03eNlpJMA/Dq91pDVQUvzMDkzDOsEvfGYdkwemVY8hycb51RmU0
RoHQSuSkpRBg01Ouy0YUBeqrqKmZfTI1LF90WuC/oPWZZpnyTUwCjw5df8kAQQHw
+1Fv8HDpXS8+U6sh4jfTxZ7kSDs901Zx1LygN6EOdrDpgEwwEUz3t2TGugxqBNYz
uOMfNvvu4JRIIe0CoEVIFReJSxRjx0J9bfxXXgjunxivVRrTGMupPz4ILklv4ML7
Ad9hTq0SxoXkQ7FC4jiEyuc/PJT20Kil/OGRg8rNcHon0Os6ob2X07hDsOrE9u08
AYoVlto25WI=
=oGeG
-----END PGP SIGNATURE-----

L
L
Ludovic Courtès wrote on 15 May 2021 12:11
(name . Christopher Baines)(address . mail@cbaines.net)(address . 47986@debbugs.gnu.org)
87eee8l30z.fsf_-_@gnu.org
Hi,

Christopher Baines <mail@cbaines.net> skribis:

Toggle quote (6 lines)
> I'm looking at this to help with adding support for looking up package
> replacements to store in the Guix Data Service.
>
> * guix/inferior.scm (inferior-package-replacement): New procedure.
> * tests/inferior.scm ("inferior-package-replacement"): New test.

[...]

Toggle quote (17 lines)
> +(test-equal "inferior-package-replacement"
> + (package-derivation %store
> + (or (package-replacement sqlite) sqlite)
> + "x86_64-linux")
> + (let* ((inferior (open-inferior %top-builddir
> + #:command "scripts/guix"))
> + (packages (inferior-packages inferior)))
> + (match (lookup-inferior-packages inferior
> + (package-name sqlite)
> + (package-version sqlite))
> + ((inferior-sqlite rest ...)
> + (inferior-package-derivation %store
> + (or (inferior-package-replacement
> + inferior-sqlite)
> + inferior-sqlite)
> + "x86_64-linux")))))

Problem is that this test assumes sqlite has a replacement. Maybe
precede it:

(unless (package-replacement sqlite)
(test-skip 1))

and remove (or (package-replacement …) …) and similar.

That way we’ll notice when the test is skipped.

Otherwise LGTM, thanks!

Ludo’.
C
C
Christopher Baines wrote on 15 May 2021 13:15
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 47986-done@debbugs.gnu.org)
87v97kcknu.fsf@cbaines.net
Ludovic Courtès <ludo@gnu.org> writes:

Toggle quote (39 lines)
> Hi,
>
> Christopher Baines <mail@cbaines.net> skribis:
>
>> I'm looking at this to help with adding support for looking up package
>> replacements to store in the Guix Data Service.
>>
>> * guix/inferior.scm (inferior-package-replacement): New procedure.
>> * tests/inferior.scm ("inferior-package-replacement"): New test.
>
> [...]
>
>> +(test-equal "inferior-package-replacement"
>> + (package-derivation %store
>> + (or (package-replacement sqlite) sqlite)
>> + "x86_64-linux")
>> + (let* ((inferior (open-inferior %top-builddir
>> + #:command "scripts/guix"))
>> + (packages (inferior-packages inferior)))
>> + (match (lookup-inferior-packages inferior
>> + (package-name sqlite)
>> + (package-version sqlite))
>> + ((inferior-sqlite rest ...)
>> + (inferior-package-derivation %store
>> + (or (inferior-package-replacement
>> + inferior-sqlite)
>> + inferior-sqlite)
>> + "x86_64-linux")))))
>
> Problem is that this test assumes sqlite has a replacement. Maybe
> precede it:
>
> (unless (package-replacement sqlite)
> (test-skip 1))
>
> and remove (or (package-replacement …) …) and similar.
>
> That way we’ll notice when the test is skipped.

Sure, I've made those changes now.

Toggle quote (2 lines)
> Otherwise LGTM, thanks!

Great, I've pushed this as 97d615b1761c2054561057f6b56e2a0caed13aa4.
-----BEGIN PGP SIGNATURE-----

iQKlBAEBCgCPFiEEPonu50WOcg2XVOCyXiijOwuE9XcFAmCfrWVfFIAAAAAALgAo
aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNF
ODlFRUU3NDU4RTcyMEQ5NzU0RTBCMjVFMjhBMzNCMEI4NEY1NzcRHG1haWxAY2Jh
aW5lcy5uZXQACgkQXiijOwuE9XfMIQ/+JoHBgVeivemNtbdN1V6osf3AU0xsjGUW
owJyEdX/5wOA/g8O55J0AgeFSXM94esj2yE2Vw/6iEXOZrfRKgSNn6SWFN5g4sAD
5e1HJRtb+BK23vkFv5EE5DfwE36UQHl6yb5d5IfNVyP3sOVwc255yEZfO4FUEEGD
nVdNBeLXAG+CyAKn8jSIKFaDX5l7/ZU87P4bGA1n0nyzrc50BP6p8mhLt6tNq/rP
0mMPjZ6sArMckT75N2JselVdcl+6z41jk6Inw418duDBKEK3Ke1m1Xzdnu2TPzzC
WqEjQujW9ahxVkUaTPkKMJAoRvTj+oW9T0pGGV0043AkO+3xK7kdj89NYpj8ZbwS
Awq1p9/8GKJL1e2OrY/sKAQb9z18sd51gFqh2Tii7nmYthU2YOoLUfb+ioSFpKAS
YEFLfwg6Jb5TmDOtoz3F4igT4RzS3z98HkgHv80TvtvqkgvZhzuak7Z38DwS6Eky
AOW2iumaurQEAdA4YAQsFbYpp2ykstLl3TqJ2yaZ6r3B9aQb0Md45QM6sJiVhhan
Lf2/jTGSIfi2nrj+3I6rzlLvVQn1G9mme2aV9w/zMGQ+DwhLFyo2pKhJb6X3ET7m
lr1/d44R2wioP9faJblvVvMdj2ey6f0kasJC135n2Mng8+bY1PPD/nEno8PqU5ya
DH/ZhXP1V7g=
=iRQA
-----END PGP SIGNATURE-----

Closed
?