Subject: [bug#49196] [PATCH v4 2/3] import: utils: Skip not found packages.

From: zimoun <[email-masked]>
Date: Mon, 28 Jun 2021 18:20:13 +0200

From: Sarah Morgensen <[email-masked]>

* guix/import/utils.scm (recursive-import): Skip packages when the
package returned by 'repo->guix-package' is false.
* tests/import-utils.scm: New tests.
---
 guix/import/utils.scm  | 26 ++++++++++++++------------
 tests/import-utils.scm | 28 ++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 12 deletions(-)

diff --git a/guix/import/utils.scm b/guix/import/utils.scm
index d817318a91..7f2e7ecb46 100644
--- a/guix/import/utils.scm
+++ b/guix/import/utils.scm
@@ -8,6 +8,7 @@
 ;;; Copyright © 2020 Helio Machado <[email-masked]>
 ;;; Copyright © 2020 Martin Becze <[email-masked]>
 ;;; Copyright © 2021 Maxim Cournoyer <[email-masked]>
+;;; Copyright © 2021 Sarah Morgensen <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -471,15 +472,16 @@ to obtain the Guix package name corresponding to the upstream name."
                                    (name (list name #f))) dependencies)))
       (make-node name version package normalized-deps)))
 
-  (map node-package
-       (topological-sort (list (lookup-node package-name version))
-                         (lambda (node)
-                           (map (lambda (name-version)
-                                  (apply lookup-node name-version))
-                                (remove (lambda (name-version)
-                                          (apply exists? name-version))
-                                        (node-dependencies node))))
-                         (lambda (node)
-                           (string-append
-                            (node-name node)
-                            (or (node-version node) ""))))))
+  (filter-map
+   node-package
+   (topological-sort (list (lookup-node package-name version))
+                     (lambda (node)
+                       (map (lambda (name-version)
+                              (apply lookup-node name-version))
+                            (remove (lambda (name-version)
+                                      (apply exists? name-version))
+                                    (node-dependencies node))))
+                     (lambda (node)
+                       (string-append
+                        (node-name node)
+                        (or (node-version node) ""))))))
diff --git a/tests/import-utils.scm b/tests/import-utils.scm
index 874816442e..7c6c782917 100644
--- a/tests/import-utils.scm
+++ b/tests/import-utils.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2015, 2017 Ricardo Wurmus <[email-masked]>
 ;;; Copyright © 2016 Ben Woodcroft <[email-masked]>
 ;;; Copyright © 2020 Martin Becze <[email-masked]>
+;;; Copyright © 2021 Sarah Morgensen <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -64,6 +65,33 @@
                                '())))
                     #:guix-name identity))
 
+(test-equal "recursive-import: skip false packages (toplevel)"
+  '()
+  (recursive-import "foo"
+                    #:repo 'repo
+                    #:repo->guix-package
+                    (match-lambda*
+                      (("foo" #:version #f #:repo 'repo)
+                       (values #f '())))
+                    #:guix-name identity))
+
+(test-equal "recursive-import: skip false packages (dependency)"
+  '((package
+      (name "foo")
+      (inputs `(("bar" ,bar)))))
+  (recursive-import "foo"
+                    #:repo 'repo
+                    #:repo->guix-package
+                    (match-lambda*
+                      (("foo" #:version #f #:repo 'repo)
+                       (values '(package
+                                  (name "foo")
+                                  (inputs `(("bar" ,bar))))
+                               '("bar")))
+                      (("bar" #:version #f #:repo 'repo)
+                       (values #f '())))
+                    #:guix-name identity))
+
 (test-assert "alist->package with simple source"
   (let* ((meta '(("name" . "hello")
                  ("version" . "2.10")
-- 
2.32.0