bug#52362: [PATCH v3] guix: import: go: Use correct tag for go module in subdirectory.

2022-02-28 Thread Nicolas Goaziou
Hello,

I tested v3 of this change, which looks great.

Unfortunately, when running

  ./pre-inst-env guix import go --recursive rclone

I get the following backtrace:

--8<---cut here---start->8---
following redirection to 
`https://github.com/qingstor/qingstor-sdk-go?go-get=1'...
Backtrace:
In ice-9/boot-9.scm:
  1752:10 19 (with-exception-handler _ _ #:unwind? _ # _)
In guix/scripts/import/go.scm:
   114:22 18 (_)
In guix/import/utils.scm:
   509:23 17 (recursive-import _ #:repo->guix-package _ #:guix-name _ …)
In srfi/srfi-1.scm:
   586:29 16 (map1 _)
   586:29 15 (map1 _)
   586:29 14 (map1 _)
   586:29 13 (map1 _)
   586:29 12 (map1 _)
   586:29 11 (map1 _)
   586:17 10 (map1 (("github.com/yunify/qingstor-sdk-go/v3" #f) (…) …))
In guix/import/utils.scm:
   497:33  9 (lookup-node "github.com/yunify/qingstor-sdk-go/v3" #f)
In guix/memoization.scm:
 98:0  8 (mproc "github.com/yunify/qingstor-sdk-go/v3" #:version …)
In unknown file:
   7 (_ # …)
   6 (_ # …)
In ice-9/boot-9.scm:
724:2  5 (call-with-prompt _ _ #)
  1752:10  4 (with-exception-handler _ _ #:unwind? _ # _)
In ice-9/eval.scm:
   293:34  3 (_ #(#(#(#(#(#(#(#(#(#(#(#) …) …) …) …) …) …) …) …) …) …))
In unknown file:
   2 (substring "github.com/yunify/qingstor-sdk-go" 35 #)
In ice-9/boot-9.scm:
  1685:16  1 (raise-exception _ #:continuable? _)
  1683:16  0 (raise-exception _ #:continuable? _)

ice-9/boot-9.scm:1683:16: In procedure raise-exception:
Value out of range 0 to< 33: 35
--8<---cut here---end--->8---

Do you know why it is failing like this?

Regards,
-- 
Nicolas Goaziou





bug#52362: [PATCH v3] guix: import: go: Use correct tag for go module in subdirectory.

2022-01-15 Thread Stephen Paul Weber
https://go.dev/ref/mod says a module in a subdirectory has a tag prefixed with
the subdirectory.

* guix/import/go.scm (version+subdirectory->tag-prefix): New variable.
(vcs->origin): New argument module-path-subdirectory.
---
 guix/import/go.scm | 36 +---
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/guix/import/go.scm b/guix/import/go.scm
index d00c13475a..f2ea9dbbae 100644
--- a/guix/import/go.scm
+++ b/guix/import/go.scm
@@ -521,28 +521,37 @@ tag."
   `(tag-or-commit . ,reference)
 (file-hash* checkout #:algorithm algorithm #:recursive? #true)))
 
-(define (vcs->origin vcs-type vcs-repo-url version)
+(define (version+subdirectory->tag-prefix subdirectory)
+  (if (string=? subdirectory "")
+  ""
+  (string-append (substring subdirectory 1) "/")))
+
+(define (vcs->origin vcs-type vcs-repo-url module-path-subdirectory version)
   "Generate the `origin' block of a package depending on what type of source
 control system is being used."
   (case vcs-type
 ((git)
- (let ((plain-version? (string=? version (go-version->git-ref version)))
-   (v-prefixed?(string-prefix? "v" version)))
+ (let* ((plain-version? (string=? version (go-version->git-ref version)))
+(v-prefixed?(string-prefix? "v" version))
+(tag-prefix (version+subdirectory->tag-prefix
+ module-path-subdirectory))
+(git-commit (if plain-version?
+(string-append tag-prefix version)
+(go-version->git-ref version
`(origin
   (method git-fetch)
   (uri (git-reference
 (url ,vcs-repo-url)
-;; This is done because the version field of the package,
-;; which the generated quoted expression refers to, has been
-;; stripped of any 'v' prefixed.
 (commit ,(if (and plain-version? v-prefixed?)
- '(string-append "v" version)
+ (if (string=? module-path-subdirectory "")
+ '(string-append "v" version)
+ `(string-append ,tag-prefix "v" version))
  '(go-version->git-ref version)
   (file-name (git-file-name name version))
   (sha256
(base32
 ,(bytevector->nix-base32-string
-  (git-checkout-hash vcs-repo-url (go-version->git-ref version)
+  (git-checkout-hash vcs-repo-url git-commit
  (hash-algorithm sha256
 ((hg)
  `(origin
@@ -618,12 +627,17 @@ When VERSION is unspecified, the latest version available 
is used."
dependencies+versions
(map car dependencies+versions)))
  (module-path-sans-suffix
-  (match:prefix (string-match "([\\./]v[0-9]+)?$" module-path)))
+   (if (string-prefix? "gopkg.in" module-path)
+   module-path
+   (match:prefix (string-match "([\\./]v[0-9]+)?$" module-path
  (guix-name (go-module->guix-package-name module-path))
- (root-module-path (module-path->repository-root module-path))
+ (root-module-path (module-path->repository-root 
module-path-sans-suffix))
  ;; The VCS type and URL are not included in goproxy information. For
  ;; this we need to fetch it from the official module page.
  (meta-data (fetch-module-meta-data root-module-path))
+ (module-path-subdirectory
+   (substring module-path-sans-suffix
+ (string-length (module-meta-import-prefix meta-data
  (vcs-type (module-meta-vcs meta-data))
  (vcs-repo-url (module-meta-data-repo-url meta-data goproxy))
  (synopsis (go-package-synopsis module-path))
@@ -634,7 +648,7 @@ When VERSION is unspecified, the latest version available 
is used."
 (name ,guix-name)
 (version ,(strip-v-prefix version*))
 (source
- ,(vcs->origin vcs-type vcs-repo-url version*))
+ ,(vcs->origin vcs-type vcs-repo-url module-path-subdirectory 
version*))
 (build-system go-build-system)
 (arguments
  '(#:import-path ,module-path
-- 
2.30.2