I find myself needing this functionality while exploring configuration
support in xmonad, so I am (finally) revisiting this patch.

The attached patch, rather than simply moving the two relevant
procedures from (gnu packages version-control), instead replaces them
with a single new procedure, named 'transitive-input-references', in
(guix packages). I think the new procedure addresses the concerns raised
previously.

On Wed, 22 Jul 2015 15:20:11 +0200
l...@gnu.org (Ludovic Courtès) wrote:

> Eric Bavier <ericbav...@openmailbox.org> skribis:
> 
> > From 6282f668d3cadb9f24f045a0c6992eda9fbe6d5d Mon Sep 17 00:00:00 2001
> > From: Eric Bavier <bav...@member.fsf.org>
> > Date: Tue, 21 Jul 2015 20:45:54 -0500
> > Subject: [PATCH 5/6] guix: Move package-transitive-propagated-labels* and
> >  package-propagated-input-refs to (guix packages).
> >
> > * gnu/packages/version-control.scm (package-transitive-propagated-labels*)
> >   (package-propagated-input-refs): Move from here...
> > * guix/packages.scm: ...to here.
> 
[...]
> 
> > +(define (package-propagated-input-refs inputs packages)
> 
> Should be “references”, not “refs.”

Sure.

> 
> > +  "Return a list of (assoc-ref INPUTS <package-name>) for each package in
> > +PACKAGES and their transitive propagated inputs."
> 
> Maybe mention that this assumes that each input uses the package name as
> the label.

This is not the case with the new transitive-input-references.  Labels
may be arbitrary strings.  This behavior is checked in the new test
case.

> 
> > +  (map (lambda (l)
> > +         `(assoc-ref ,inputs ,l))
> > +       (delete-duplicates               ;XXX: efficiency
> > +        (append-map package-transitive-propagated-labels*
> > +                    packages))))
> 
> The quadratic ‘delete-duplicates’ is going to be a problem sooner or
> later.

The new procedure makes use of 'transitive-inputs' and so benefits from
its optimizations.
 
> Also, could you add one or two tests?

Done.

> 
> I understand this is needed in some cases, but it is not really nice (or
> “really not nice”?).

I would go with "really not nice"

> I would rather avoid propagating the use of these
> constructs,

No pun intended? ;)

> but OTOH, I have nothing better to propose currently.

For Perl, my idea is to wrap each module somehow, so that perl gets the
appropriate 'use lib "/gnu/store/..."' when it loads each module.
Preferably the solution would also work with store deduplication.
I've not yet confirmed this is even feasible, so anyone with more perl
knowledge should chime in.

Our haskell modules install files into a "package.conf.d" subdirectory,
and these files actually keep references to all haskell modules that
were configured in the environment when it was built.  I'm baffled why
GHC does not make use of this information for dependency resolution when
it loads libraries.  Perhaps we could hack our GHC to do so.

`~Eric


From c7932475b95f22f891169b7f315366e2602fb4f5 Mon Sep 17 00:00:00 2001
From: Eric Bavier <bav...@member.fsf.org>
Date: Tue, 21 Jul 2015 20:45:54 -0500
Subject: [PATCH 5/6] guix: packages: Add transitive-input-references.

* guix/packages.scm (transitive-input-references): New procedure.
* gnu/packages/version-control.scm (package-transitive-propagated-labels*)
  (package-propagated-input-refs): Delete.
  (git)[arguments]: Adjust to transitive-input-references.
---
 gnu/packages/version-control.scm | 28 ++++++----------------------
 guix/packages.scm                | 14 ++++++++++++++
 tests/packages.scm               | 17 +++++++++++++++++
 3 files changed, 37 insertions(+), 22 deletions(-)

diff --git a/gnu/packages/version-control.scm b/gnu/packages/version-control.scm
index 8d8003f..3c0571b 100644
--- a/gnu/packages/version-control.scm
+++ b/gnu/packages/version-control.scm
@@ -98,24 +98,6 @@ changes to project files over time.  It supports both a 
distributed workflow
 as well as the classic centralized workflow.")
     (license gpl2+)))
 
-(define (package-transitive-propagated-labels* package)
-  "Return a list of the input labels of PACKAGE and its transitive inputs."
-  (let ((name (package-name package)))
-    `(,name
-      ,@(map (match-lambda
-               ((label (? package? _) . _)
-                label))
-             (package-transitive-propagated-inputs package)))))
-
-(define (package-propagated-input-refs inputs packages)
-  "Return a list of (assoc-ref INPUTS <package-name>) for each package in
-PACKAGES and their propagated inputs."
-  (map (lambda (l)
-         `(assoc-ref ,inputs ,l))
-       (delete-duplicates                  ;XXX: efficiency
-        (append-map package-transitive-propagated-labels*
-                    packages))))
-
 (define-public git
   ;; Keep in sync with 'git-manpages'!
   (package
@@ -238,11 +220,13 @@ PACKAGES and their propagated inputs."
                 `("PERL5LIB" ":" prefix
                   ,(map (lambda (o) (string-append o "/lib/perl5/site_perl"))
                         (list
-                         ,@(package-propagated-input-refs
+                         ,@(transitive-input-references
                             'inputs
-                            (list perl-authen-sasl
-                                  perl-net-smtp-ssl
-                                  perl-io-socket-ssl))))))
+                            (map (lambda (l)
+                                   (assoc l (inputs)))
+                                 '("perl-authen-sasl"
+                                   "perl-net-smtp-ssl"
+                                   "perl-io-socket-ssl")))))))
 
               ;; Tell 'git-submodule' where Perl is.
               (wrap-program git-sm
diff --git a/guix/packages.scm b/guix/packages.scm
index 3983d14..053803f 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -93,6 +93,8 @@
             package-output
             package-grafts
 
+            transitive-input-references
+
             %supported-systems
             %hydra-supported-systems
             supported-package?
@@ -579,6 +581,18 @@ for the host system (\"native inputs\"), and not target 
inputs."
 recursively."
   (transitive-inputs (package-propagated-inputs package)))
 
+(define (transitive-input-references alist inputs)
+  "Return a list of (assoc-ref ALIST <label>) for each (<label> <package> . _)
+in INPUTS and their transitive propagated inputs."
+  (define label
+    (match-lambda
+      ((label . _)
+       label)))
+
+  (map (lambda (input)
+         `(assoc-ref ,alist ,(label input)))
+       (transitive-inputs inputs)))
+
 (define-syntax define-memoized/v
   (lambda (form)
     "Define a memoized single-valued unary procedure with docstring.
diff --git a/tests/packages.scm b/tests/packages.scm
index 3cb532d..00a0998 100644
--- a/tests/packages.scm
+++ b/tests/packages.scm
@@ -207,6 +207,23 @@
            (member i s)
            (member u s)))))
 
+(test-assert "transitive-input-references"
+  (let* ((a (dummy-package "a"))
+         (b (dummy-package "b"))
+         (c (dummy-package "c"
+              (inputs `(("a" ,a)))
+              (propagated-inputs `(("boo" ,b)))))
+         (d (dummy-package "d"
+              (inputs `(("c*" ,c)))))
+         (keys (map (match-lambda
+                      (('assoc-ref 'l key)
+                       key))
+                    (pk 'refs (transitive-input-references
+                               'l (package-inputs d))))))
+    (and (= (length keys) 2)
+         (member "c*" keys)
+         (member "boo" keys))))
+
 (test-equal "package-transitive-supported-systems, implicit inputs"
   %supported-systems
 
-- 
2.4.3

Reply via email to