GNU bug report logs - #49591
[PATCH] import: go: Handle multiple go-import meta tags.

Previous Next

Package: guix-patches;

Reported by: Sarah Morgensen <iskarian <at> mgsn.dev>

Date: Fri, 16 Jul 2021 02:03:02 UTC

Severity: normal

Tags: patch

Done: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 49591 in the body.
You can then email your comments to 49591 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#49591; Package guix-patches. (Fri, 16 Jul 2021 02:03:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Sarah Morgensen <iskarian <at> mgsn.dev>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Fri, 16 Jul 2021 02:03:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Sarah Morgensen <iskarian <at> mgsn.dev>
To: guix-patches <at> gnu.org
Subject: [PATCH] import: go: Handle multiple go-import meta tags.
Date: Thu, 15 Jul 2021 19:01:52 -0700
* guix/import/go.scm (fetch-module-meta-data): Parse all go-import meta
tags and return the first 'module-meta' with a matching import prefix.
[go-import->module-meta]: Extract parsing into new procedure.
---
Hello Guix,

It seems sometimes a module's go-get page contains multiple

  <meta name="go-import" ...>

tags, for example the 'bazil.org/fuse' module. This causes a backtrace when
attempting to import such a module:

-----8<---------------cut here---------------start------------->8---
$ guix import go bazil.org/fuse
following redirection to `https://bazil.org/fuse/?go-get=1'...
Backtrace:
           5 (primitive-load "/home/sarah/.config/guix/current/bin/g…")
In guix/ui.scm:
   2182:7  4 (run-guix . _)
  2145:10  3 (run-guix-command _ . _)
In guix/scripts/import.scm:
   120:11  2 (guix-import . _)
In guix/scripts/import/go.scm:
   118:27  1 (guix-import-go . _)
In guix/import/go.scm:
    467:4  0 (go-module->guix-package _ #:goproxy _ #:version _ # _)

guix/import/go.scm:467:4: In procedure go-module->guix-package:
Throw to key `match-error' with args `("match" "no matching pattern" ((content "bazil.org/bazil git https://github.com/bazil/bazil") (content "bazil.org/fuse git https://github.com/bazil/fuse") (content "bazil.org/bolt-mount git https://github.com/bazil/bolt-mount") (content "bazil.org/zipfs git https://github.com/bazil/zipfs") (content "bazil.org/plop git https://github.com/bazil/plop")))'.
--8<---------------cut here---------------end--------------->8---

This patch makes the importer parse all such tags and search for one with an
import prefix that is a prefix of the module-path we are looking for.

(I attempted to add a unit test but could not figure out how to make the
record type accessible to the test script.)

--
Sarah

 guix/import/go.scm | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/guix/import/go.scm b/guix/import/go.scm
index d8f838f635..182db0ecfb 100644
--- a/guix/import/go.scm
+++ b/guix/import/go.scm
@@ -460,17 +460,21 @@ Optionally include a VERSION string to append to the name."
   "Retrieve the module meta-data from its landing page.  This is necessary
 because goproxy servers don't currently provide all the information needed to
 build a package."
+  (define (go-import->module-meta content-text)
+    (match (string-split content-text #\space)
+      ((root-path vcs repo-url)
+       (make-module-meta root-path (string->symbol vcs)
+                         (strip-.git-suffix/maybe repo-url)))))
   ;; <meta name="go-import" content="import-prefix vcs repo-root">
   (let* ((meta-data (http-fetch* (format #f "https://~a?go-get=1" module-path)))
          (select (sxpath `(// head (meta (@ (equal? (name "go-import"))))
                               // content))))
     (match (select (html->sxml meta-data #:strict? #t))
       (() #f)                           ;nothing selected
-      (((content content-text))
-       (match (string-split content-text #\space)
-         ((root-path vcs repo-url)
-          (make-module-meta root-path (string->symbol vcs)
-                            (strip-.git-suffix/maybe repo-url))))))))
+      ((('content content-text) ..1)
+       (find (lambda (meta)
+               (string-prefix? (module-meta-import-prefix meta) module-path))
+             (map go-import->module-meta content-text))))))
 
 (define (module-meta-data-repo-url meta-data goproxy)
   "Return the URL where the fetcher which will be used can download the

base-commit: 01d7e8c2782f61e741f8beff7888adfbdb61779d
-- 
2.31.1





Information forwarded to guix-patches <at> gnu.org:
bug#49591; Package guix-patches. (Sun, 18 Jul 2021 03:32:02 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
To: Sarah Morgensen via Guix-patches via <guix-patches <at> gnu.org>
Cc: Sarah Morgensen <iskarian <at> mgsn.dev>, 49591-done <at> debbugs.gnu.org
Subject: Re: [bug#49591] [PATCH] import: go: Handle multiple go-import meta
 tags.
Date: Sat, 17 Jul 2021 23:31:31 -0400
Hello again,

Sarah Morgensen via Guix-patches via <guix-patches <at> gnu.org> writes:

> * guix/import/go.scm (fetch-module-meta-data): Parse all go-import meta
> tags and return the first 'module-meta' with a matching import prefix.
> [go-import->module-meta]: Extract parsing into new procedure.
> ---
> Hello Guix,
>
> It seems sometimes a module's go-get page contains multiple
>
>   <meta name="go-import" ...>
>
> tags, for example the 'bazil.org/fuse' module. This causes a backtrace when
> attempting to import such a module:
>
> $ guix import go bazil.org/fuse
> following redirection to `https://bazil.org/fuse/?go-get=1'...
> Backtrace:
>            5 (primitive-load "/home/sarah/.config/guix/current/bin/g…")
> In guix/ui.scm:
>    2182:7  4 (run-guix . _)
>   2145:10  3 (run-guix-command _ . _)
> In guix/scripts/import.scm:
>    120:11  2 (guix-import . _)
> In guix/scripts/import/go.scm:
>    118:27  1 (guix-import-go . _)
> In guix/import/go.scm:
>     467:4  0 (go-module->guix-package _ #:goproxy _ #:version _ # _)
>
> guix/import/go.scm:467:4: In procedure go-module->guix-package:
> Throw to key `match-error' with args `("match" "no matching pattern" ((content "bazil.org/bazil git https://github.com/bazil/bazil") (content "bazil.org/fuse git https://github.com/bazil/fuse") (content "bazil.org/bolt-mount git https://github.com/bazil/bolt-mount") (content "bazil.org/zipfs git https://github.com/bazil/zipfs") (content "bazil.org/plop git https://github.com/bazil/plop")))'.
>
>
> This patch makes the importer parse all such tags and search for one with an
> import prefix that is a prefix of the module-path we are looking for.

Good catch, LGTM!

> (I attempted to add a unit test but could not figure out how to make the
> record type accessible to the test script.)

I started adding a new fixture for fixtures-go-bazil-org-fuse-test, but
but I'm rusty as to where all these bits are pulled from.  Perhaps it
could be nice to add it, but otherwise it seems better in the mean time
to fix apply this fix as-is.

Committed with 5eba9c0960.

Thank you!

Closing.

Maxim




Reply sent to Maxim Cournoyer <maxim.cournoyer <at> gmail.com>:
You have taken responsibility. (Sun, 18 Jul 2021 03:32:02 GMT) Full text and rfc822 format available.

Notification sent to Sarah Morgensen <iskarian <at> mgsn.dev>:
bug acknowledged by developer. (Sun, 18 Jul 2021 03:32:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 15 Aug 2021 11:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 226 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.