From: Robert Vollmert <rob@vllmrt.net>
To: 35935@debbugs.gnu.org
Cc: Robert Vollmert <rob@vllmrt.net>
Subject: [bug#35935] [PATCH] guix: import: Simplify recursive import.
Date: Sun, 2 Jun 2019 22:19:46 +0200 [thread overview]
Message-ID: <20190602201946.84145-1-rob@vllmrt.net> (raw)
In-Reply-To: <20190527200731.59990-1-rob@vllmrt.net>
This simplifies the logic of recursive-import, intending no
major functional changes. The package import function is no
longer called twice per package. Failed imports now make it
to the package stream as '() instead of #f.
* guix/import/utils.scm (recursive-import): Simplify.
---
guix/import/utils.scm | 86 ++++++++++++++++---------------------------
1 file changed, 32 insertions(+), 54 deletions(-)
diff --git a/guix/import/utils.scm b/guix/import/utils.scm
index 516c0cfaa2..ff548b809a 100644
--- a/guix/import/utils.scm
+++ b/guix/import/utils.scm
@@ -378,57 +378,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)))
--
2.20.1 (Apple Git-117)
prev parent reply other threads:[~2019-06-02 20:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-27 20:07 [bug#35935] [PATCH] guix: import: simplify recursive import Robert Vollmert
2019-06-02 19:52 ` Ludovic Courtès
2019-06-02 20:23 ` Robert Vollmert
2019-06-03 19:56 ` Oleg Pykhalov
2019-06-03 19:59 ` Robert Vollmert
2019-06-03 20:31 ` bug#35935: " Oleg Pykhalov
2019-06-02 20:19 ` Robert Vollmert [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190602201946.84145-1-rob@vllmrt.net \
--to=rob@vllmrt.net \
--cc=35935@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.