From patchwork Mon May 27 20:07:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Vollmert X-Patchwork-Id: 14099 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 672DB1701A; Mon, 27 May 2019 21:08:06 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id DBB9216CC8 for ; Mon, 27 May 2019 21:08:05 +0100 (BST) Received: from localhost ([127.0.0.1]:50153 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVLuf-0004MV-G6 for patchwork@mira.cbaines.net; Mon, 27 May 2019 16:08:05 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51466) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVLud-0004MM-BM for guix-patches@gnu.org; Mon, 27 May 2019 16:08:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hVLuc-0006bK-At for guix-patches@gnu.org; Mon, 27 May 2019 16:08:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:40674) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hVLuc-0006b8-8b for guix-patches@gnu.org; Mon, 27 May 2019 16:08:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hVLuc-00005G-23 for guix-patches@gnu.org; Mon, 27 May 2019 16:08:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#35935] [PATCH] guix: import: simplify recursive import Resent-From: Robert Vollmert Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 27 May 2019 20:08:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 35935 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 35935@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.155898766832764 (code B ref -1); Mon, 27 May 2019 20:08:01 +0000 Received: (at submit) by debbugs.gnu.org; 27 May 2019 20:07:48 +0000 Received: from localhost ([127.0.0.1]:54218 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hVLuN-0008WO-Q5 for submit@debbugs.gnu.org; Mon, 27 May 2019 16:07:48 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37056) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hVLuL-0008WA-LS for submit@debbugs.gnu.org; Mon, 27 May 2019 16:07:46 -0400 Received: from lists.gnu.org ([209.51.188.17]:51510) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hVLuG-0006FD-KK for submit@debbugs.gnu.org; Mon, 27 May 2019 16:07:40 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51438) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVLuF-0004MC-D6 for guix-patches@gnu.org; Mon, 27 May 2019 16:07:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hVLuE-0006Cm-Bj for guix-patches@gnu.org; Mon, 27 May 2019 16:07:39 -0400 Received: from mx1.mailbox.org ([2001:67c:2050:104:0:1:25:1]:59276) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hVLuE-0006AD-3m for guix-patches@gnu.org; Mon, 27 May 2019 16:07:38 -0400 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id 6EA654C4B8; Mon, 27 May 2019 22:07:35 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id u6BsX2mUdSP8; Mon, 27 May 2019 22:07:34 +0200 (CEST) From: Robert Vollmert Date: Mon, 27 May 2019 22:07:31 +0200 Message-Id: <20190527200731.59990-1-rob@vllmrt.net> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Robert Vollmert Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches 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: Simplify recursive-import. --- 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)))