import: print: Improve origin method name guesswork.
authorLudovic Courtès <ludo@gnu.org>
Thu, 25 Mar 2021 21:41:05 +0000 (22:41 +0100)
committerLudovic Courtès <ludo@gnu.org>
Thu, 25 Mar 2021 23:04:04 +0000 (00:04 +0100)
Fixes <https://bugs.gnu.org/47375>.
Reported by Léo Le Bouter <lle-bout@zaclys.net>.

* guix/import/print.scm (package->code): For METHOD, use 'variable-name'
preferably, and call 'procedure-name' as a last resort.

guix/import/print.scm

index a2ab810..dcc38ab 100644 (file)
@@ -79,7 +79,16 @@ when evaluated."
           (file-name (origin-file-name source))
           (patches   (origin-patches source)))
       `(origin
-         (method ,(procedure-name method))
+         ;; Since 'procedure-name' returns the procedure name within the
+         ;; module where it's defined, not its public name.  Thus, try hard to
+         ;; find its public name and use 'procedure-name' as a last resort.
+         (method ,(or (any (lambda (module)
+                             (variable-name method module))
+                           '((guix download)
+                             (guix git-download)
+                             (guix hg-download)
+                             (guix svn-download)))
+                      (procedure-name method)))
          (uri (string-append ,@(match (factorize-uri uri version)
                                  ((? string? uri) (list uri))
                                  (factorized factorized))))