transformations: ‘package-with-upstream-version’ can preserve archive type.

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
This commit is contained in:
Ludovic Courtès 2024-12-27 11:49:20 +01:00
parent 1b1b921d61
commit c8797e81fb
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -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