[PATCH rust-team 1/2] import: crate: Fix find-package-version.

  • Done
  • quality assurance status badge
Details
2 participants
  • Efraim Flashner
  • Herman Rimm
Owner
unassigned
Submitted by
Herman Rimm
Severity
normal
H
H
Herman Rimm wrote on 11 Jan 15:37 +0100
(address . guix-patches@gnu.org)
9fab183f6a0ee9be09769e7f776f0b9c615b2c97.1736606198.git.herman@rimm.ee
Fixes bug from 5ce1512b0f68cf39cb399623a14302f309c06129, where the
earliest existing package (if any) was returned instead. See also:


* guix/import/crate.scm (crate->guix-package)[find-package-version]:
Invert boolean expression.

Change-Id: I1d05f55a027241e7c5f62cc98a50a09b5639bdcf
---
guix/import/crate.scm | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

Toggle diff (21 lines)
diff --git a/guix/import/crate.scm b/guix/import/crate.scm
index b4806c8bb22..a7134b85722 100644
--- a/guix/import/crate.scm
+++ b/guix/import/crate.scm
@@ -335,9 +335,9 @@ (define* (crate->guix-package
(find-packages-by-name
(crate-name->package-name name))))
(match-lambda* (((semver1 yanked1) (semver2 yanked2))
- (or (and yanked1 (not yanked2))
- (and (eq? yanked1 yanked2)
- (semver<? semver1 semver2))))))))
+ (and (or (not yanked1) yanked2)
+ (or (not (eq? yanked1 yanked2))
+ (semver>? semver1 semver2))))))))
(and (not (eq? #f version))
(match-let (((semver yanked) version))
(list (semver->string semver) yanked)))))

base-commit: 986245daca2fb50d58cf0f2b9273f0d670d38af2
--
2.47.1
H
H
Herman Rimm wrote on 11 Jan 15:38 +0100
[PATCH rust-team 2/2] import: crate: Refactor find-package-version.
(address . 75496@debbugs.gnu.org)
991ead37c954cea75fff524f1fad2c8d88c8e5bf.1736606198.git.herman@rimm.ee
* guix/import/crate.scm (crate->guix-package)[find-package-version]:
Move to top-level.
[dependency-name+version+yanked]: Adjust.
(find-package-version): Take allow-yanked? argument. Use (let) loop,
match, if instead of map, filter, min-element.

Change-Id: I1d05f55a027241e7c5f62cc98a50a09b5639bdcf
---
guix/import/crate.scm | 55 ++++++++++++++++++++++---------------------
1 file changed, 28 insertions(+), 27 deletions(-)

Toggle diff (89 lines)
diff --git a/guix/import/crate.scm b/guix/import/crate.scm
index a7134b85722..d790126ef6e 100644
--- a/guix/import/crate.scm
+++ b/guix/import/crate.scm
@@ -7,6 +7,7 @@
;;; Copyright © 2023 Simon Tournier <zimon.toutoune@gmail.com>
;;; Copyright © 2023, 2024 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2023, 2024 David Elsing <david.elsing@posteo.net>
+;;; Copyright © 2025 Herman Rimm <herman@rimm.ee>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -290,6 +291,31 @@ (define (nonyanked-crate-versions crate)
(not (crate-version-yanked? entry)))
(crate-versions crate)))
+(define (find-package-version name range allow-yanked?)
+ "Find the latest existing package that fulfills the SemVer RANGE. If
+ALLOW-YANKED? is #t, include packages marked as yanked at a lower
+priority."
+ (set! range (string->semver-range range))
+ (let loop ((packages (find-packages-by-name
+ (crate-name->package-name name)))
+ (semver #f)
+ (yanked? #f))
+ (match packages
+ ((pkg packages ...)
+ (let ((pkg-yanked? (assoc-ref (package-properties pkg)
+ 'crate-version-yanked?)))
+ (if (or allow-yanked? (not pkg-yanked?))
+ (let ((pkg-semver (string->semver (package-version pkg))))
+ (if (and (or (not semver)
+ (and yanked? (not pkg-yanked?))
+ (and (eq? yanked? pkg-yanked?)
+ (semver>? pkg-semver semver)))
+ (semver-range-contains? range pkg-semver))
+ (loop packages pkg-semver pkg-yanked?)
+ (loop packages semver yanked?)))
+ (loop packages semver yanked?))))
+ (() (and semver (list (semver->string semver) yanked?))))))
+
(define* (crate->guix-package
crate-name
#:key version include-dev-deps? allow-yanked? #:allow-other-keys)
@@ -316,32 +342,6 @@ (define* (crate->guix-package
(or version
(crate-latest-version crate))))
- ;; Find the highest existing package that fulfills the semver <range>.
- ;; Packages previously marked as yanked take lower priority.
- (define (find-package-version name range)
- (let* ((semver-range (string->semver-range range))
- (version
- (min-element
- (filter (match-lambda ((semver yanked)
- (and
- (or allow-yanked? (not yanked))
- (semver-range-contains? semver-range semver))))
- (map (lambda (pkg)
- (let ((version (package-version pkg)))
- (list
- (string->semver version)
- (assoc-ref (package-properties pkg)
- 'crate-version-yanked?))))
- (find-packages-by-name
- (crate-name->package-name name))))
- (match-lambda* (((semver1 yanked1) (semver2 yanked2))
- (and (or (not yanked1) yanked2)
- (or (not (eq? yanked1 yanked2))
- (semver>? semver1 semver2))))))))
- (and (not (eq? #f version))
- (match-let (((semver yanked) version))
- (list (semver->string semver) yanked)))))
-
;; Find the highest version of a crate that fulfills the semver <range>.
;; If no matching non-yanked version has been found and allow-yanked? is #t,
;; also consider yanked packages.
@@ -361,7 +361,8 @@ (define* (crate->guix-package
(define (dependency-name+version+yanked dep)
(let* ((name (crate-dependency-id dep))
(req (crate-dependency-requirement dep))
- (existing-version (find-package-version name req)))
+ (existing-version
+ (find-package-version name req allow-yanked?)))
(if (and existing-version (not (second existing-version)))
(cons name existing-version)
(let* ((crate (lookup-crate* name))
--
2.47.1
H
H
Herman Rimm wrote on 11 Jan 16:56 +0100
Re: bug#75496: Acknowledgement ([PATCH rust-team 1/2] import: crate: Fix find-package-version.)
(address . 75496@debbugs.gnu.org)
z2xhrlh7mzs3c6uu2mpnlvvuihgo2afshzuo5lcm74ejbip7ep@nqkue6qdej3k
Hello,

Can [PATCH 1/2] be applied/merged to the master branch as well?

Cheers,
Herman
E
E
Efraim Flashner wrote 3 days ago
(name . Herman Rimm)(address . herman@rimm.ee)
Z5X7oMlfkV9Ch69P@3900XT
On Sat, Jan 11, 2025 at 04:56:42PM +0100, Herman Rimm wrote:
Toggle quote (7 lines)
> Hello,
>
> Can [PATCH 1/2] be applied/merged to the master branch as well?
>
> Cheers,
> Herman

They both can be applied to master.

It took me a while to remember what this was about, but I have seen
package updates that downgraded dependent crates to older versions. I'm
going to miss preferring older versions (that are easier to package)
when it comes to new crates, but it's definitely a change we need.

Patches pushed!

--
Efraim Flashner <efraim@flashner.co.il> ????? ?????
GPG key = A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEoov0DD5VE3JmLRT3Qarn3Mo9g1EFAmeV+5wACgkQQarn3Mo9
g1HOdBAAoEQybuQ9SpQMT424M7XqLJJA05wbg82VqeV/COgvdvgeLfvV5IwQCD6P
r/MV/gnPHRiH/g0AMmg6I3VpfESf0OvtgHvWkPTRR8tOc3a37xF7nTxpRQNOl4s8
XJzxiw45dSBZBAcdPGkOnhqJi1O8YGzIxsE1lVyVErw2RDBAde9M3naT/TVQ6qZG
7UFo6w1B009MAfG1L/tCfCSKYHPYDNtwKZEJSHh0FTRIXQ3MoTdNzpldRmMRvyLg
49o9/EWfxYXEn78Ce/E2od11dttmhDFOhNtvEwQFwDg+f2sUgqpYMqZIUjobFsWf
0lpQRosxc1YpXLxnhsuKAoL6evmCkggjE02xHcqgY9uDMdQex5EeqARIfO2KY+aS
91YPldaK6P33fCLgqT7JXUfljUf7tpMXaikUXeakVQYNOA8LJZUWXWaNkU49WIol
e4Hl6U9ZIB9GQaNUSDxPavz9p0/N/YT3HSBifOUuRIWP5OUIj+9H+nPou7YMtCsZ
iBDOFvOUKtxNxKLtDq5BjKtFOUp/RTP2nmeuuzNF8o6MxneMLIhGu4onJRKdo9q+
m1+7cBLDjXnvvUXmKcmQbKtIX595TMGEHPlNz71ZC6ZIRTWKz6KxH1rc9SZCCf/w
sRFvr5zVpbKqtnUCVFPHlNJXtERiWeLefg8RPjwMUTXl6nr7wSo=
=9hDK
-----END PGP SIGNATURE-----


Closed
?
Your comment

Commenting via the web interface is currently disabled.

To comment on this conversation send an email to 75496@debbugs.gnu.org

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