Subject: [PATCH] packages: Match renamed origin fields.

From: Herman Rimm <[email-masked]>
Date: Thu, 2 Jan 2025 22:03:30 +0100

* guix/packages.scm (print-origin, origin->derivation): Use
match-record.

Change-Id: Ia554dd3264f51e549df51f767c754040b3dc7611
---
Hello,

Three tests in (tests packages) fail as before:
"package-source-derivation, local-file"
"package-source-derivation, origin, sha512"
"package-source-derivation, origin, sha3-512"

Cheers,
Herman

 guix/packages.scm | 59 ++++++++++++++++++++++-------------------------
 1 file changed, 28 insertions(+), 31 deletions(-)

diff --git a/guix/packages.scm b/guix/packages.scm
index ff9fbd84709..6088457b20b 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -11,6 +11,7 @@
 ;;; Copyright © 2022 jgart <[email-masked]>
 ;;; Copyright © 2023 Simon Tournier <[email-masked]>
 ;;; Copyright © 2024 Janneke Nieuwenhuizen <[email-masked]>
+;;; Copyright © 2025 Herman Rimm <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -359,12 +360,10 @@ (define-syntax-rule (origin fields ...)
 
 (define (print-origin origin port)
   "Write a concise representation of ORIGIN to PORT."
-  (match origin
-    (($ <origin> uri method hash file-name patches)
-     (simple-format port "#<origin ~s ~a ~s ~a>"
-                    uri hash
-                    (force patches)
-                    (number->string (object-address origin) 16)))))
+  (match-record origin <origin> (uri method hash file-name patches)
+    (simple-format port "#<origin ~s ~a ~s ~a>"
+                   uri hash patches
+                   (number->string (object-address origin) 16))))
 
 (set-record-type-printer! <origin> print-origin)
 
@@ -2151,31 +2150,29 @@ (define-gexp-compiler (package-compiler (package <package>) system target)
 (define* (origin->derivation origin
                              #:optional (system (%current-system)))
   "Return the derivation corresponding to ORIGIN."
-  (match origin
-    (($ <origin> uri method hash name (= force ()) #f)
-     ;; No patches, no snippet: this is a fixed-output derivation.
-     (method uri
-             (content-hash-algorithm hash)
-             (content-hash-value hash)
-             name #:system system))
-    (($ <origin> uri method hash name (= force (patches ...)) snippet
-                 flags inputs (modules ...) guile-for-build)
-     ;; Patches and/or a snippet.
-     (mlet %store-monad ((source (method uri
-                                         (content-hash-algorithm hash)
-                                         (content-hash-value hash)
-                                         name #:system system))
-                         (guile  (package->derivation (or guile-for-build
-                                                          (default-guile))
-                                                      system
-                                                      #:graft? #f)))
-       (patch-and-repack source patches
-                         #:inputs inputs
-                         #:snippet snippet
-                         #:flags flags
-                         #:system system
-                         #:modules modules
-                         #:guile-for-build guile)))))
+  (match-record origin <origin>
+    (uri method hash file-name patches patch-flags patch-inputs
+     patch-guile snippet modules)
+    (let* ((hash-algo (content-hash-algorithm hash))
+           (hash      (content-hash-value hash))
+           (source    (method uri hash-algo hash file-name
+                              #:system system)))
+      (if (or snippet (pair? patches))
+          (mlet %store-monad
+              ((guile (package->derivation (or patch-guile
+                                               (default-guile))
+                                           system
+                                           #:graft? #f))
+               (source source))
+            (patch-and-repack source patches
+                              #:inputs patch-inputs
+                              #:snippet snippet
+                              #:flags patch-flags
+                              #:system system
+                              #:modules modules
+                              #:guile-for-build guile))
+          ;; This is a fixed-output derivation.
+          source))))
 
 (define-gexp-compiler (origin-compiler (origin <origin>) system target)
   ;; Compile ORIGIN to a derivation for SYSTEM.  This is used when referring

base-commit: 5d7455bb580eed41a4fa7c20b71eaccad9f49e73
-- 
2.45.2