diff mbox

[bug#57460,00/19] Refresh to specific version

Message ID e179efe1-44aa-4000-d052-8e170d115a2e@crazy-compilers.com
State New
Headers show

Commit Message

Hartmut Goebel Nov. 1, 2022, 3:58 p.m. UTC
Hi Ludo,

attached please find a new patch addressing this and implementing a 
record time. (Thanks for the tip, this makes the code muche easier.)

Comments

Ludovic Courtès Nov. 22, 2022, 7:33 a.m. UTC | #1
Hi Hartmut

Hartmut Goebel <h.goebel@crazy-compilers.com> skribis:

> From c748a25193d8f9ee29b9d281f542fb1d0d3f4ec1 Mon Sep 17 00:00:00 2001
> Message-Id: <c748a25193d8f9ee29b9d281f542fb1d0d3f4ec1.1667318125.git.h.goebel@crazy-compilers.com>
> From: Hartmut Goebel <h.goebel@crazy-compilers.com>
> Date: Fri, 24 Jun 2022 20:40:57 +0200
> Subject: [PATCH v2] refresh: Allow updating to a specific version.
>
> * guix/scripts/refresh.scm (options->packages)[args-packages]: Handle version
>   specification in package name arguments.
>   (update-package): Add #:version argument 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.

Thanks for this updated patch!


[...]

> -(define (options->packages opts)
> +(define (options->package-specs opts)
>    "Return the list of packages requested by OPTS, honoring options like
>  '--recursive'."

In Guix, “package spec” refers to the syntax that
‘specification->package’ accepts, like “guile” or “guile@2.2”.  So we’ll
have to use another name throughout.  How about “update spec” or
“refresh spec” for the string, and just “update” for the record?

> +(define-record-type* <package-spec> package-spec make-package-spec
> +  package-spec?
> +  (package   package-spec-package) ; package
> +  (target    package-spec-target)) ; target version

Since there are just two fields, it may be simpler to use SRFI-9:

  (define-record-type <update>
    (update package version)
    update?
    (package update-package)
    (version update-version))

Thanks,
Ludo’.
diff mbox

Patch

From c748a25193d8f9ee29b9d281f542fb1d0d3f4ec1 Mon Sep 17 00:00:00 2001
Message-Id: <c748a25193d8f9ee29b9d281f542fb1d0d3f4ec1.1667318125.git.h.goebel@crazy-compilers.com>
From: Hartmut Goebel <h.goebel@crazy-compilers.com>
Date: Fri, 24 Jun 2022 20:40:57 +0200
Subject: [PATCH v2] refresh: Allow updating to a specific version.

* guix/scripts/refresh.scm (options->packages)[args-packages]: Handle version
  specification in package name arguments.
  (update-package): Add #:version argument 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 | 49 ++++++++++++++++++++++++++++++----------
 1 file changed, 37 insertions(+), 12 deletions(-)

diff --git a/guix/scripts/refresh.scm b/guix/scripts/refresh.scm
index 14329751f8..8333d1783c 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.
 ;;;
@@ -33,6 +34,7 @@ 
   #:use-module (guix utils)
   #:use-module (guix packages)
   #:use-module (guix profiles)
+  #:use-module (guix records)
   #:use-module (guix upstream)
   #:use-module (guix graph)
   #:use-module (guix scripts graph)
@@ -181,7 +183,7 @@  specified with `--select'.\n"))
   (newline)
   (show-bug-report-information))
 
-(define (options->packages opts)
+(define (options->package-specs opts)
   "Return the list of packages requested by OPTS, honoring options like
 '--recursive'."
   (define core-package?
@@ -224,7 +226,7 @@  update would trigger a complete rebuild."
                          (('argument . spec)
                           ;; Take either the specified version or the
                           ;; latest one.
-                          (specification->package spec))
+                          (specification->package-spec spec))
                          (('expression . exp)
                           (read/eval-package-expression exp))
                          (_ #f))
@@ -254,6 +256,25 @@  update would trigger a complete rebuild."
       (with-monad %store-monad
         (return packages))))
 
+
+;;;
+;;; Utilities.
+;;;
+
+(define-record-type* <package-spec> package-spec make-package-spec
+  package-spec?
+  (package   package-spec-package) ; package
+  (target    package-spec-target)) ; target version
+
+(define (specification->package-spec spec)
+  "Given SPEC, a package name like \"guile@2.0=2.0.8\", return a
+<package-spec> record with two fields: the package to upgrade, and the
+target version."
+  (match (string-rindex spec #\=)
+    (#f  (make-package-spec (specification->package spec) #f))
+    (idx (make-package-spec (specification->package (substring spec 0 idx))
+                            (substring spec (1+ idx))))))
+
 
 ;;;
 ;;; Updates.
@@ -298,7 +319,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 +328,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
@@ -540,12 +561,12 @@  all are dependent packages: ~{~a~^ ~}~%")
     (with-error-handling
       (with-store store
         (run-with-store store
-          (mlet %store-monad ((packages (options->packages opts)))
+          (mlet %store-monad ((package-specs (options->package-specs opts)))
             (cond
              (list-dependent?
-              (list-dependents packages))
+              (list-dependents (map package-spec-package package-specs)))
              (list-transitive?
-              (list-transitive packages))
+              (list-transitive (map package-spec-package package-specs)))
              (update?
               (parameterize ((%openpgp-key-server
                               (or (assoc-ref opts 'key-server)
@@ -558,13 +579,17 @@  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)
+                 (lambda (package-spec)
+                   (update-package store
+                                   (package-spec-package package-spec)
+                                   (package-spec-target package-spec)
+                                   updaters
+                                   #:key-download key-download
+                                   #:warn? warn?))
+                 package-specs)
                 (return #t)))
              (else
               (for-each (cut check-for-package-update <> updaters
                              #:warn? warn?)
-                        packages)
+                        (map package-spec-package package-specs))
               (return #t)))))))))
-- 
2.30.6