diff mbox series

[bug#57460,15/20] refresh: Allow updating to a specific version (script)

Message ID c92a92ef44327cf8da217629c7b50a216dc2917f.1661691694.git.h.goebel@crazy-compilers.com
State New
Headers show
Series Refresh to specific version | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git-branch success View Git branch
cbaines/applying patch success
cbaines/issue success View issue
cbaines/comparison success View comparision
cbaines/git-branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Hartmut Goebel Aug. 28, 2022, 1:18 p.m. UTC
* guix/scripts/refresh.scm(options->packages)[args-packages]: Handle version
  specification in package name arguments.
  (update-package): Add keyword-argument 'version' and pass it on to called
  functions.
  (guix-refresh): When updating, pass the specified version (if any) to
  update-package.
  [package-list-without-versions, package-list-with-versions]: New functions.
---
 guix/scripts/refresh.scm | 40 +++++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)

Comments

M Aug. 28, 2022, 1:26 p.m. UTC | #1
On 28-08-2022 15:18, Hartmut Goebel wrote:
> +                          (let* ((name version (package-name->name+version spec)))
> +                            (list (specification->package name) version)))
Nitpick: there is only a single clause, so 'let' would suffice, no need 
for let*.
Ludovic Courtès Sept. 24, 2022, 9:45 a.m. UTC | #2
Hartmut Goebel <h.goebel@crazy-compilers.com> skribis:

> * guix/scripts/refresh.scm(options->packages)[args-packages]: Handle version
>   specification in package name arguments.
>   (update-package): Add keyword-argument 'version' and pass it on to called
>   functions.
>   (guix-refresh): When updating, pass the specified version (if any) to
>   update-package.
>   [package-list-without-versions, package-list-with-versions]: New functions.

[...]

>                           (('argument . spec)
>                            ;; Take either the specified version or the
>                            ;; latest one.
> -                          (specification->package spec))
> +                          (let* ((name version (package-name->name+version spec)))
> +                            (list (specification->package name) version)))

That changes the semantics of ‘guix refresh’.  Until now, “guix refresh
guile@2.0” or “guix refresh -l guile@2.0” would look specifically at
Guile 2.0.  Now, “guix refresh -l guile@2.0” would report dependents of
Guile 3.0.

So instead of reusing the version string that shows up here, I’d suggest
adding a new command-line option, say -T/--target-version.  The downside
is that it wouldn’t work when multiple packages are specified on the
command line.

Another option would be to introduce special syntax, like an equal sign:

  guix refresh guile=3.0.4
  guix refresh guile@2.0=2.0.8

For that we’d introduce a new ‘specification->package-update’ that would
return a <package-update> record with two fields: the package to
upgrade, and the target version.

WDYT?

> +  (define (package-list-without-versions packages)
> +    (map (match-lambda
> +               ((package version) package)
> +               (package package))
> +              packages))
> +
> +  (define (package-list-with-versions packages)
> +    (map (match-lambda
> +               ((package version) (list package version))
> +               (package (list package #f)))
> +              packages))

I always find it a bad sign when one has to write specific list-fiddling
procedures; usually it indicates we’re missing a record type or
something.

Ludo’.
diff mbox series

Patch

diff --git a/guix/scripts/refresh.scm b/guix/scripts/refresh.scm
index 14329751f8..441e71a6e4 100644
--- a/guix/scripts/refresh.scm
+++ b/guix/scripts/refresh.scm
@@ -9,6 +9,7 @@ 
 ;;; Copyright © 2019 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2020 Simon Tournier <zimon.toutoune@gmail.com>
 ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
+;;; Copyright © 2022 Hartmut Goebel <h.goebel@crazy-compilers.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -224,7 +225,8 @@  update would trigger a complete rebuild."
                          (('argument . spec)
                           ;; Take either the specified version or the
                           ;; latest one.
-                          (specification->package spec))
+                          (let* ((name version (package-name->name+version spec)))
+                            (list (specification->package name) version)))
                          (('expression . exp)
                           (read/eval-package-expression exp))
                          (_ #f))
@@ -298,7 +300,7 @@  update would trigger a complete rebuild."
            (G_ "no updater for ~a~%")
            (package-name package)))
 
-(define* (update-package store package updaters
+(define* (update-package store package version updaters
                          #:key (key-download 'interactive) warn?)
   "Update the source file that defines PACKAGE with the new version.
 KEY-DOWNLOAD specifies a download policy for missing OpenPGP keys; allowed
@@ -307,7 +309,7 @@  warn about packages that have no matching updater."
   (if (lookup-updater package updaters)
       (let ((version output source
                      (package-update store package updaters
-                                     #:key-download key-download))
+                                     #:key-download key-download #:version version))
             (loc (or (package-field-location package 'version)
                      (package-location package))))
         (when version
@@ -523,6 +525,18 @@  all are dependent packages: ~{~a~^ ~}~%")
       (lists
        (concatenate lists))))
 
+  (define (package-list-without-versions packages)
+    (map (match-lambda
+               ((package version) package)
+               (package package))
+              packages))
+
+  (define (package-list-with-versions packages)
+    (map (match-lambda
+               ((package version) (list package version))
+               (package (list package #f)))
+              packages))
+
   (let* ((opts            (parse-options))
          (update?         (assoc-ref opts 'update?))
          (updaters        (options->updaters opts))
@@ -540,12 +554,13 @@  all are dependent packages: ~{~a~^ ~}~%")
     (with-error-handling
       (with-store store
         (run-with-store store
+          (begin
           (mlet %store-monad ((packages (options->packages opts)))
             (cond
              (list-dependent?
-              (list-dependents packages))
+              (list-dependents (package-list-without-versions packages)))
              (list-transitive?
-              (list-transitive packages))
+              (list-transitive (package-list-without-versions packages)))
              (update?
               (parameterize ((%openpgp-key-server
                               (or (assoc-ref opts 'key-server)
@@ -558,13 +573,16 @@  all are dependent packages: ~{~a~^ ~}~%")
                                   (string-append (config-directory)
                                                  "/upstream/trustedkeys.kbx"))))
                 (for-each
-                 (cut update-package store <> updaters
-                      #:key-download key-download
-                      #:warn? warn?)
-                 packages)
+                 (cut apply
+                      (lambda (package version)
+                        (update-package store package version updaters
+                                        #:key-download key-download
+                                        #:warn? warn?))
+                      <>)
+                 (values (package-list-with-versions packages)))
                 (return #t)))
              (else
               (for-each (cut check-for-package-update <> updaters
                              #:warn? warn?)
-                        packages)
-              (return #t)))))))))
+                        (package-list-without-versions packages))
+              (return #t))))))))))