summaryrefslogtreecommitdiff
path: root/guix/packages.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2019-01-25 10:05:31 +0100
committerLudovic Courtès <ludo@gnu.org>2019-01-25 14:06:37 +0100
commit3e223a22a70138b8c57e742ad8ec737131249820 (patch)
tree63c1ec9cf5e89a487b473b5cb578039d580f9917 /guix/packages.scm
parentc6e33df90f2c10046bee1f0bb2e4eb7dc1688d20 (diff)
downloadpatches-3e223a22a70138b8c57e742ad8ec737131249820.tar
patches-3e223a22a70138b8c57e742ad8ec737131249820.tar.gz
packages: Add 'package-closure'.
* guix/packages.scm (package-closure): New procedure. * tests/packages.scm ("package-closure"): New test.
Diffstat (limited to 'guix/packages.scm')
-rw-r--r--guix/packages.scm25
1 files changed, 24 insertions, 1 deletions
diff --git a/guix/packages.scm b/guix/packages.scm
index e4c2ac3be5..f191327718 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2014, 2015, 2017, 2018 Mark H Weaver <mhw@netris.org>
;;; Copyright © 2015 Eric Bavier <bavier@member.fsf.org>
;;; Copyright © 2016 Alex Kost <alezost@gmail.com>
@@ -133,6 +133,7 @@
bag-transitive-host-inputs
bag-transitive-build-inputs
bag-transitive-target-inputs
+ package-closure
default-guile
default-guile-derivation
@@ -798,6 +799,28 @@ dependencies are known to build on SYSTEM."
"Return the \"target inputs\" of BAG, recursively."
(transitive-inputs (bag-target-inputs bag)))
+(define* (package-closure packages #:key (system (%current-system)))
+ "Return the closure of PACKAGES on SYSTEM--i.e., PACKAGES and the list of
+packages they depend on, recursively."
+ (let loop ((packages packages)
+ (visited vlist-null)
+ (closure (list->setq packages)))
+ (match packages
+ (()
+ (set->list closure))
+ ((package . rest)
+ (if (vhash-assq package visited)
+ (loop rest visited closure)
+ (let* ((bag (package->bag package system))
+ (dependencies (filter-map (match-lambda
+ ((label (? package? package) . _)
+ package)
+ (_ #f))
+ (bag-direct-inputs bag))))
+ (loop (append dependencies rest)
+ (vhash-consq package #t visited)
+ (fold set-insert closure dependencies))))))))
+
(define* (package-mapping proc #:optional (cut? (const #f)))
"Return a procedure that, given a package, applies PROC to all the packages
depended on and returns the resulting package. The procedure stops recursion