[PATCH] import: utils: 'recursive-import' skips unfound packages
(address . guix-patches@gnu.org)
* guix/import/utils.scm (recursive-import): Skip packages when the
package returned by repo->guix-package is false.
* guix/import/go.scm (go-module-recursive-import): Explicitly return
false in 'repo->guix-package' when packages are not found.
* tests/import-utils.scm ("recursive-import: skip false packages"): New
test.
---
Hello Guix,
While trying to recursively import a go package I encountered the following
error when it was unable to find one of the dependencies:
Toggle snippet (34 lines)
$ ./pre-inst-env guix import go -r git.sr.ht/~sircmpwn/aerc
guix import: warning: Failed to import package "github.com/brunnre8/go.notmuch".
reason: "https://pkg.go.dev/github.com/brunnre8/go.notmuch" could not be fetched: HTTP error 404 ("Not Found").
This package and its dependencies won't be imported.
following redirection to `https://github.com/ProtonMail/go-crypto?go-get=1'...
following redirection to `https://github.com/jtolio/gls?go-get=1'...
Backtrace:
In srfi/srfi-1.scm:
586:29 19 (map1 ((package (name "go-github-com-rivo-uniseg") …) …))
586:29 18 (map1 ((package (name "go-github-com-mattn-go-r…") …) …))
586:29 17 (map1 ((package (name "go-github-com-miolini-da…") …) …))
586:29 16 (map1 ((package (name "go-github-com-riywo-logi…") …) …))
586:29 15 (map1 ((package (name "go-github-com-neelance-a…") …) …))
586:29 14 (map1 ((package (name "go-github-com-neelance-s…") …) …))
586:29 13 (map1 ((package (name "go-github-com-shurcool-go") …) …))
586:29 12 (map1 ((package (name "go-github-com-shurcool-h…") …) …))
586:29 11 (map1 ((package (name "go-github-com-shurcool-v…") …) …))
586:29 10 (map1 ((package (name "go-github-com-gopherjs-g…") …) …))
586:29 9 (map1 ((package (name "go-github-com-jtolds-gls") # …) …))
586:29 8 (map1 ((package (name "go-github-com-smartystre…") …) …))
586:29 7 (map1 ((package (name "go-github-com-smartystre…") …) …))
586:29 6 (map1 ((package (name "go-github-com-google-go-…") …) …))
586:29 5 (map1 ((package (name "go-google-golang-org-pro…") …) …))
586:29 4 (map1 ((package (name "go-github-com-golang-pro…") …) …))
586:29 3 (map1 ((package (name "go-google-golang-org-app…") …) …))
586:29 2 (map1 ((package (name "go-github-com-protonmail…") …) …))
586:17 1 (map1 (() (package (name "go-git-sr-ht-~sircmpwn…") …)))
In guix/import/utils.scm:
280:2 0 (package->definition _ _)
guix/import/utils.scm:280:2: In procedure package->definition:
Throw to key `match-error' with args `("match" "no matching pattern" ())'.
It seems like several importers (gem, egg, go) expect to be able to return #f or
'() in #:repo->guix-package when a package is not found (while printing a
warning to the user) but recursive-import doesn't look like it handles it. I
suppose this worked before but was silently broken at some point. This patch
(re-)enables this behavior. I added a test for this as well.
Hope this helps,
Sarah
guix/import/go.scm | 3 ++-
guix/import/utils.scm | 14 ++++++++------
tests/import-utils.scm | 18 ++++++++++++++++++
3 files changed, 28 insertions(+), 7 deletions(-)
Toggle diff (97 lines)
diff --git a/guix/import/go.scm b/guix/import/go.scm
index d110954664..c859098492 100644
--- a/guix/import/go.scm
+++ b/guix/import/go.scm
@@ -5,6 +5,7 @@
;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;; Copyright © 2021 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
+;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -651,7 +652,7 @@ This package and its dependencies won't be imported.~%")
(uri->string (http-get-error-uri c))
(http-get-error-code c)
(http-get-error-reason c))
- (values '() '())))
+ (values #f '())))
(receive (package-sexp dependencies)
(go-module->guix-package* name #:goproxy goproxy
#:version version
diff --git a/guix/import/utils.scm b/guix/import/utils.scm
index d817318a91..49f38cfa2a 100644
--- a/guix/import/utils.scm
+++ b/guix/import/utils.scm
@@ -8,6 +8,7 @@
;;; Copyright © 2020 Helio Machado <0x2b3bfa0+guix@googlemail.com>
;;; Copyright © 2020 Martin Becze <mjbecze@riseup.net>
;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -469,16 +470,17 @@ to obtain the Guix package name corresponding to the upstream name."
(normalized-deps (map (match-lambda
((name version) (list name version))
(name (list name #f))) dependencies)))
- (make-node name version package normalized-deps)))
+ (and package
+ (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))))
+ (filter-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)
diff --git a/tests/import-utils.scm b/tests/import-utils.scm
index 874816442e..1b728104e0 100644
--- a/tests/import-utils.scm
+++ b/tests/import-utils.scm
@@ -2,6 +2,7 @@
;;; Copyright © 2015, 2017 Ricardo Wurmus <rekado@elephly.net>
;;; Copyright © 2016 Ben Woodcroft <donttrustben@gmail.com>
;;; Copyright © 2020 Martin Becze <mjbecze@riseup.net>
+;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -64,6 +65,23 @@
'())))
#:guix-name identity))
+(test-equal "recursive-import: skip false packages"
+ '((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")
base-commit: acfa55a581ca4e688ee4b8f860fe365b1f153ef9
--
2.31.1