diff options
Diffstat (limited to 'guix/import/utils.scm')
-rw-r--r-- | guix/import/utils.scm | 95 |
1 files changed, 39 insertions, 56 deletions
diff --git a/guix/import/utils.scm b/guix/import/utils.scm index 516c0cfaa2..84503ab907 100644 --- a/guix/import/utils.scm +++ b/guix/import/utils.scm @@ -1,9 +1,10 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2012, 2013, 2018 Ludovic Courtès <ludo@gnu.org> +;;; Copyright © 2012, 2013, 2018, 2019 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2016 Jelle Licht <jlicht@fsfe.org> ;;; Copyright © 2016 David Craven <david@craven.ch> ;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net> ;;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com> +;;; Copyright © 2019 Robert Vollmert <rob@vllmrt.net> ;;; ;;; This file is part of GNU Guix. ;;; @@ -51,6 +52,7 @@ url-fetch guix-hash-url + package-names->package-inputs maybe-inputs maybe-native-inputs package->definition @@ -235,6 +237,9 @@ into a proper sentence and by using two spaces between sentences." cleaned 'pre ". " 'post))) (define* (package-names->package-inputs names #:optional (output #f)) + "Given a list of PACKAGE-NAMES, and an optional OUTPUT, tries to generate a +quoted list of inputs, as suitable to use in an 'inputs' field of a package +definition." (map (lambda (input) (cons* input (list 'unquote (string->symbol input)) (or (and output (list output)) @@ -286,7 +291,7 @@ package value." (map (lambda (spec) (let-values (((pkg out) (specification->package+output spec))) (match out - (("out") (list (package-name pkg) pkg)) + ("out" (list (package-name pkg) pkg)) (_ (list (package-name pkg) pkg out))))) specs)) @@ -378,57 +383,35 @@ separated by PRED." #:allow-other-keys) "Generate a stream of package expressions for PACKAGE-NAME and all its dependencies." - (receive (package . dependencies) - (repo->guix-package package-name repo) - (if (not package) - stream-null - - ;; Generate a lazy stream of package expressions for all unknown - ;; dependencies in the graph. - (let* ((make-state (lambda (queue done) - (cons queue done))) - (next (match-lambda - (((next . rest) . done) next))) - (imported (match-lambda - ((queue . done) done))) - (done? (match-lambda - ((queue . done) - (zero? (length queue))))) - (unknown? (lambda* (dependency #:optional (done '())) - (and (not (member dependency - done)) - (null? (find-packages-by-name - (guix-name dependency)))))) - (update (lambda (state new-queue) - (match state - (((head . tail) . done) - (make-state (lset-difference - equal? - (lset-union equal? new-queue tail) - done) - (cons head done))))))) - (stream-cons - package - (stream-unfold - ;; map: produce a stream element - (lambda (state) - (repo->guix-package (next state) repo)) - - ;; predicate - (negate done?) - - ;; generator: update the queue - (lambda (state) - (receive (package . dependencies) - (repo->guix-package (next state) repo) - (if package - (update state (filter (cut unknown? <> - (cons (next state) - (imported state))) - (car dependencies))) - ;; TODO: Try the other archives before giving up - (update state (imported state))))) - - ;; initial state - (make-state (filter unknown? (car dependencies)) - (list package-name)))))))) + (define (exists? dependency) + (not (null? (find-packages-by-name (guix-name dependency))))) + (define initial-state (list #f (list package-name) (list))) + (define (step state) + (match state + ((prev (next . rest) done) + (define (handle? dep) + (and + (not (equal? dep next)) + (not (member dep done)) + (not (exists? dep)))) + (receive (package . dependencies) (repo->guix-package next repo) + (list + (if package package '()) ;; default #f on failure would interrupt + (if package + (lset-union equal? rest (filter handle? (car dependencies))) + rest) + (cons next done)))) + ((prev '() done) + (list #f '() done)))) + + ;; Generate a lazy stream of package expressions for all unknown + ;; dependencies in the graph. + (stream-unfold + ;; map: produce a stream element + (match-lambda ((latest queue done) latest)) + ;; predicate + (match-lambda ((latest queue done) latest)) + ;; generator: update the queue + step + ;; initial state + (step initial-state))) |