all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [bug#51496] [patch] gnu: transformations: apply with-source transformations to inputs
@ 2021-10-30  1:11 Ahmad Jarara
       [not found] ` <handler.51496.B.163555633215206.ack@debbugs.gnu.org>
  2021-12-03  2:01 ` bug#51496: Working on another attempt with package-mapping Ahmad Jarara
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Jarara @ 2021-10-30  1:11 UTC (permalink / raw)
  To: 51496


[-- Attachment #1.1: Type: text/plain, Size: 0 bytes --]



[-- Attachment #1.2: Type: text/html, Size: 151 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gnu-transformations-apply-with-source-transformation.patch --]
[-- Type: text/x-patch; name="0001-gnu-transformations-apply-with-source-transformation.patch", Size: 4124 bytes --]

From 234f84e6ae32131b06c86419a1c763667f1cee4e Mon Sep 17 00:00:00 2001
From: Ahmad Jarara <git@ajarara.io>
Date: Fri, 29 Oct 2021 21:04:06 -0400
Subject: [PATCH] gnu: transformations: apply with-source transformations to
 inputs

This patch allows for this to behave as expected:

guile build guile-ssh \
    --with-source=../guile-ssh \
    --with-source=../libssh`

Previously only the first transformation took effect.
---
 guix/transformations.scm  | 40 ++++++++++++++++++++++++++++-----------
 tests/transformations.scm | 23 ++++++++++++++++++++++
 2 files changed, 52 insertions(+), 11 deletions(-)

diff --git a/guix/transformations.scm b/guix/transformations.scm
index 5ae1977cb2..08e7d0777f 100644
--- a/guix/transformations.scm
+++ b/guix/transformations.scm
@@ -145,18 +145,36 @@ (define new-sources
                         (string-drop uri (+ 1 index))))))))
          sources))
 
+  (define (inject-when-applicable pkg)
+    (match (assoc-ref new-sources (package-name pkg))
+      ((version source)
+       (package-with-source pkg source version))
+      (#f
+       pkg)))
+
+  (define (inject-new-sources pkg)
+    (define (inject-new-sources-for-input input)
+      (list (car input) (inject-new-sources (cadr input))))
+    (let ((new-inputs (map inject-new-sources-for-input (package-inputs pkg)))
+          (new-native-inputs (map inject-new-sources-for-input (package-native-inputs pkg)))
+          (new-propagated-inputs (map inject-new-sources-for-input (package-propagated-inputs pkg)))
+          (new-pkg (inject-when-applicable pkg)))
+      (if (not
+           (and (eq? new-inputs (package-inputs pkg))
+                (eq? new-native-inputs (package-native-inputs pkg))
+                (eq? new-propagated-inputs (package-propagated-inputs pkg))
+                (eq? new-pkg pkg)))
+          (package
+            (inherit new-pkg)
+            (inputs new-inputs)
+            (native-inputs new-native-inputs)
+            (propagated-inputs new-propagated-inputs))
+          pkg)))
+
   (lambda (obj)
-    (let loop ((sources  new-sources)
-               (result   '()))
-      (match obj
-        ((? package? p)
-         (match (assoc-ref sources (package-name p))
-           ((version source)
-            (package-with-source p source version))
-           (#f
-            p)))
-        (_
-         obj)))))
+    (if (package? obj)
+        (inject-new-sources obj)
+        obj)))
 
 (define (evaluate-replacement-specs specs proc)
   "Parse SPECS, a list of strings like \"guile=guile@2.1\" and return a list
diff --git a/tests/transformations.scm b/tests/transformations.scm
index 09839dc1c5..868bcbdf7b 100644
--- a/tests/transformations.scm
+++ b/tests/transformations.scm
@@ -145,6 +145,29 @@ (define-module (test-transformations)
                        (add-to-store store (basename s) #t
                                      "sha256" s)))))))
 
+(test-assert "options->transformation, with-source, applied to package input"
+  (let* ((d (dummy-package "bar"))
+         (p (dummy-package "foo"
+              (inputs `(("bar" ,d)))))
+         (s (search-path %load-path "guix.scm"))
+         (f (string-append "bar=" s))
+         (t (options->transformation `((with-source . ,f)))))
+    (with-store store
+      (let* ((new (t p)))
+        (and (not
+              (string=? (derivation-file-name
+                         (package-derivation store p))
+                        (derivation-file-name
+                         (package-derivation store new))))
+             (string=? (derivation-file-name
+                        (package-derivation store p))
+                       (derivation-file-name
+                        (package-derivation
+                         store
+                         (package
+                           (inherit new)
+                           (inputs (package-inputs p)))))))))))
+
 (test-assert "options->transformation, with-input"
   (let* ((p (dummy-package "guix.scm"
               (inputs `(("foo" ,(specification->package "coreutils"))

base-commit: 89d8417b371f3918f0508bbc561675ec100a6add
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-12-03  2:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-30  1:11 [bug#51496] [patch] gnu: transformations: apply with-source transformations to inputs Ahmad Jarara
     [not found] ` <handler.51496.B.163555633215206.ack@debbugs.gnu.org>
2021-11-01  2:09   ` [bug#51496] Acknowledgement ([patch] gnu: transformations: apply with-source transformations to inputs) Ahmad Jarara
2021-12-03  2:01 ` bug#51496: Working on another attempt with package-mapping Ahmad Jarara

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.