[bug#75137,4/4] transformations: ‘package-with-upstream-version’ can preserve archive type.

Message ID a07fb528e941d820625cbad3d6effd5a44a1e724.1735296761.git.ludo@gnu.org
State New
Headers
Series 'package-with-upstream-version' can preserve archive type |

Commit Message

Ludovic Courtès Dec. 27, 2024, 10:56 a.m. UTC
  Fixes a discrepancy for ‘url-fetch’ packages where upstream provides
several source tarballs.  For example, for ‘xorg-server’,
‘package-with-upstream-version’ would pick the “tar.gz” tarball even
though the package definition uses “tar.xz”.  It now picks “tar.xz” by
default.

* guix/transformations.scm (package-with-upstream-version):
Add #:preserve-archive-type?.  Call ‘preferred-upstream-source’ to honor
it.

Change-Id: Iefa007aba339d81709faf82b7c52a5a2c7a6aad7
---
 guix/transformations.scm | 44 +++++++++++++++++++++++-----------------
 1 file changed, 25 insertions(+), 19 deletions(-)
  

Patch

diff --git a/guix/transformations.scm b/guix/transformations.scm
index 131b8564f8..2887d91a34 100644
--- a/guix/transformations.scm
+++ b/guix/transformations.scm
@@ -33,6 +33,7 @@  (define-module (guix transformations)
   #:autoload   (guix git) (git-checkout git-checkout? git-checkout-url)
   #:autoload   (guix upstream) (upstream-source
                                 package-latest-release
+                                preferred-upstream-source
                                 upstream-source-version
                                 upstream-source-signature-urls)
   #:autoload   (guix cpu) (current-cpu
@@ -865,12 +866,14 @@  (define (upstream-source-without-signatures source)
 (define* (package-with-upstream-version p #:optional version
                                         #:key
                                         (preserve-patches? #f)
-                                        (authenticate? #t))
+                                        (authenticate? #t)
+                                        (preserve-archive-type? #t))
   "Return package P changed to use the given upstream VERSION or, if VERSION
 is #f, the latest known upstream version.  When PRESERVE-PATCHES? is true,
 preserve patches and snippets found in the source of P, provided it's an
 origin.  When AUTHENTICATE? is false, disable OpenPGP signature verification
-of upstream source code."
+of upstream source code.  When PRESERVE-ARCHIVE-TYPE? is true, use the same
+archive type as P's source (gz, xz, zstd, etc.)"
   (let ((source (and=> (package-latest-release p #:version version)
                        (if authenticate?
                            identity
@@ -899,24 +902,27 @@  (define* (package-with-upstream-version p #:optional version
                       (upstream-source-version source)
                       (package-version p)))
 
-           (unless (pair? (upstream-source-signature-urls source))
-             (warning (G_ "cannot authenticate source of '~a', version ~a~%")
-                      (package-name p)
-                      (upstream-source-version source)))
+           (let ((source (if preserve-archive-type?
+                             (preferred-upstream-source source p)
+                             source)))
+             (unless (pair? (upstream-source-signature-urls source))
+               (warning (G_ "cannot authenticate source of '~a', version ~a~%")
+                        (package-name p)
+                        (upstream-source-version source)))
 
-           ;; TODO: Take 'upstream-source-input-changes' into account.
-           (package
-             (inherit p)
-             (version (upstream-source-version source))
-             (source (if (and preserve-patches?
-                              (origin? (package-source p)))
-                         ;; Inherit P's origin so snippets and patches are
-                         ;; applied as if we had run 'guix refresh -u'.
-                         (origin
-                           (inherit (package-source p))
-                           (method upstream-fetch)
-                           (uri source))
-                         source)))))))
+             ;; TODO: Take 'upstream-source-input-changes' into account.
+             (package
+               (inherit p)
+               (version (upstream-source-version source))
+               (source (if (and preserve-patches?
+                                (origin? (package-source p)))
+                           ;; Inherit P's origin so snippets and patches are
+                           ;; applied as if we had run 'guix refresh -u'.
+                           (origin
+                             (inherit (package-source p))
+                             (method upstream-fetch)
+                             (uri source))
+                           source))))))))
 
 (define (transform-package-latest specs)
   "Return a procedure that rewrites package graphs such that those in SPECS