diff mbox series

[bug#55242,10/10] guix: import: go: Better handling of /v2 in the module path.

Message ID 20220503114301.9524-10-attila@lendvai.name
State New
Headers show
Series None | expand

Commit Message

Attila Lendvai May 3, 2022, 11:43 a.m. UTC
* guix/import/go.scm (module-path->repository-root): Delete version param.
(*module-path->import-path*): New mapping, initialized with a small db of
projects.
(go-module->guix-package): Return packages with #:unpack-path when needed.
---
 guix/import/go.scm | 93 +++++++++++++++++++++++++++-------------------
 1 file changed, 54 insertions(+), 39 deletions(-)

Comments

M May 9, 2022, 8:39 p.m. UTC | #1
Attila Lendvai schreef op di 03-05-2022 om 13:43 [+0200]:
> +(define *module-path->import-path*

In (Guile) Scheme (at least as used in the Scheme code I've seen),
*earmuffs* are typically used for mutable variables, not for global
constants.  Though guix/self.scm uses *system-modules* for not-really-
constant-but-not-mutated lexical variables so maybe ...

FWIW, I would write (define %module-path->import-path ...) here, not
that it really matters.

> +  ;; There's no other way to derive this information, at least that I know of.
> +  '(("github.com/google/go-cmp" . "github.com/google/go-cmp/cmp")
> +    ("github.com/sergi/go-diff" . "github.com/sergi/go-diff/diffmatchpatch")
> +    ("github.com/davecgh/go-spew" . "github.com/davecgh/go-spew/spew")
> +    ("github.com/beorn7/perks" . "github.com/beorn7/perks/quantile")
> +    ("github.com/census-instrumentation/opencensus-proto" .
> +     "github.com/census-instrumentation/opencensus-proto/gen-go")))

About the ‘is this controversional’ bit: these kind of mappings and
sets have precedent, see e.g. 'known-vcs' in (guix import cran),
%builtin-mods in (guix import minetest), default-r-packages in (guix
import cran).

Greetings,
Maxime.
diff mbox series

Patch

diff --git a/guix/import/go.scm b/guix/import/go.scm
index 25d424c1ac..fbed3ca88b 100644
--- a/guix/import/go.scm
+++ b/guix/import/go.scm
@@ -75,6 +75,7 @@  (define-module (guix import go)
   #:use-module (srfi srfi-26)
   #:use-module (srfi srfi-34)
   #:use-module (srfi srfi-35)
+  #:use-module (srfi srfi-71) ; let*
   #:use-module (sxml match)
   #:use-module ((sxml xpath) #:renamer (lambda (s)
                                          (if (eq? 'filter s)
@@ -608,19 +609,15 @@  (define (vcs-qualified-module-path->root-repo-url module-path)
       (vcs-qualified-module-path->root-repo-url module-path)
       module-path))
 
-(define* (go-module->guix-package-name module-path #:optional version)
-  "Converts a module's path to the canonical Guix format for Go packages.
-Optionally include a VERSION string to append to the name."
+(define* (go-module->guix-package-name module-path)
+  "Converts a module's path to the canonical Guix format for Go packages."
   ;; Map dot, slash, underscore and tilde characters to hyphens.
   (let ((module-path* (string-map (lambda (c)
                                     (if (member c '(#\. #\/ #\_ #\~))
                                         #\-
                                         c))
                                   module-path)))
-    (string-downcase (string-append "go-" module-path*
-                                    (if version
-                                        (string-append "-" version)
-                                        "")))))
+    (string-downcase (string-append "go-" module-path*))))
 
 (define (strip-.git-suffix/maybe repo-url)
   "Strip a repository URL '.git' suffix from REPO-URL if hosted at GitHub."
@@ -771,6 +768,14 @@  (define (validate-version version available-versions module-path)
 available versions:~{ ~a~}.")
                                   (map strip-v-prefix
                                        available-versions)))))))))
+(define *module-path->import-path*
+  ;; There's no other way to derive this information, at least that I know of.
+  '(("github.com/google/go-cmp" . "github.com/google/go-cmp/cmp")
+    ("github.com/sergi/go-diff" . "github.com/sergi/go-diff/diffmatchpatch")
+    ("github.com/davecgh/go-spew" . "github.com/davecgh/go-spew/spew")
+    ("github.com/beorn7/perks" . "github.com/beorn7/perks/quantile")
+    ("github.com/census-instrumentation/opencensus-proto" .
+     "github.com/census-instrumentation/opencensus-proto/gen-go")))
 
 (define* (go-module->guix-package module-path #:key
                                   (goproxy "https://proxy.golang.org")
@@ -864,38 +869,48 @@  (define* (go-module->guix-package module-path #:key
 major-version: ~S"
                meta-data raw-subdir module-subdirectory major-version)
     (log.debug " dependencies:~%~S" dependencies+versions)
-    (values
-     `(package
-        (name ,guix-name)
-        (version ,(strip-v-prefix version*))
-        (source
-         ,(vcs->origin vcs-type vcs-repo-url vcs-tag))
-        (build-system go-build-system)
-        (arguments
-         '(#:tests? #false ; some packages have unrecorded dependencies needed only by their tests
-           #:import-path ,module-path
-           ,@(if module-subdirectory
-                 `(#:unpack-path ,module-root-path)
-                 '())))
-        ,@(maybe-propagated-inputs
-           (map (match-lambda
-                  ((name version)
-                   (go-module->guix-package-name name (strip-v-prefix version)))
-                  (name
-                   (go-module->guix-package-name name)))
-                dependencies))
-        (home-page ,(format #f "https://~a" module-root-path))
-        (synopsis ,synopsis)
-        (description ,(and=> description beautify-description))
-        (license ,(match (list->licenses licenses)
-                    (() #f)                       ;unknown license
-                    ((license)                    ;a single license
-                     license)
-                    ((license ...)                ;a list of licenses
-                     `(list ,@license)))))
-     (if pin-versions?
-         dependencies+versions
-         dependencies))))
+    (let* ((import-path unpack-path
+            (if module-subdirectory
+                (values module-path module-root-path)
+                (let ((import-path (assoc-ref *module-path->import-path*
+                                              module-path)))
+                  (if import-path
+                      (begin
+                        (log.debug "matched as an import-path exception: ~S" import-path)
+                        (values import-path module-path))
+                      (values module-path #f))))))
+      (values
+       `(package
+          (name ,guix-name)
+          (version ,(strip-v-prefix version*))
+          (source
+           ,(vcs->origin vcs-type vcs-repo-url vcs-tag))
+          (build-system go-build-system)
+          (arguments
+           '(#:import-path ,import-path
+             ,@(if unpack-path
+                   `(#:unpack-path ,unpack-path)
+                   '())))
+          ,@(maybe-propagated-inputs
+             (map (match-lambda
+                    ((name version)
+                     (list (go-module->guix-package-name name)
+                           (strip-v-prefix version)))
+                    (name
+                     (go-module->guix-package-name name)))
+                  dependencies))
+          (home-page ,(format #f "https://~a" module-root-path))
+          (synopsis ,synopsis)
+          (description ,(and=> description beautify-description))
+          (license ,(match (list->licenses licenses)
+                      (() #f)                       ;unknown license
+                      ((license)                    ;a single license
+                       license)
+                      ((license ...)                ;a list of licenses
+                       `(list ,@license)))))
+       (if pin-versions?
+           dependencies+versions
+           dependencies)))))
 
 (define (go-module->guix-package* . args)
   ;; Disable output buffering so that the following warning gets printed