unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Simon Tournier <zimon.toutoune@gmail.com>
To: 63647@debbugs.gnu.org
Cc: Stephen Paul Weber <singpolyma@singpolyma.net>,
	Simon Tournier <zimon.toutoune@gmail.com>
Subject: [bug#63647] [PATCH v2 3/3] guix: import: go: Use correct tag for go module in subdirectory.
Date: Thu, 25 May 2023 17:41:12 +0200	[thread overview]
Message-ID: <27b0652df204a77a5b38554a95128fb54ca64dd9.1685029183.git.zimon.toutoune@gmail.com> (raw)
In-Reply-To: <a520128590d4b67af4c2b22ae167590b99e449dd.1685029183.git.zimon.toutoune@gmail.com>

From: Stephen Paul Weber <singpolyma@singpolyma.net>

* guix/import/go.scm (vcs->origin): New argument module-path-subdirectory.
Use it to get Git tag as described by <https://go.dev/ref/mod>.

Signed-off-by: Simon Tournier <zimon.toutoune@gmail.com>
---
 guix/import/go.scm | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)

diff --git a/guix/import/go.scm b/guix/import/go.scm
index c6258296f6..f02c098f1c 100644
--- a/guix/import/go.scm
+++ b/guix/import/go.scm
@@ -6,6 +6,7 @@
 ;;; Copyright © 2021-2022 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
 ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
+;;; Copyright © 2022 Stephen Paul Weber <singpolyma@singpolyma.net>
 ;;; Copyright © 2021, 2023 Simon Tournier <zimon.toutoune@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
@@ -522,28 +523,34 @@ (define* (git-checkout-hash url reference algorithm)
       (nix-base32-string->bytevector
        "0000000000000000000000000000000000000000000000000000"))))
 
-(define (vcs->origin vcs-type vcs-repo-url version)
+(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))
+            ;; A module in a subdirectory has a tag prefixed by this
+            ;; subdirectory.  See <https://go.dev/ref/mod>.
+            (tag-prefix     (if (string=? module-path-subdirectory "") ;
+                                ""
+                                (string-append
+                                 (substring module-path-subdirectory 1) "/")))
+            (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)
+                             `(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
@@ -621,12 +628,17 @@ (define* (go-module->guix-package module-path #:key
                            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))
@@ -637,7 +649,7 @@ (define* (go-module->guix-package module-path #:key
         (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.38.1





  parent reply	other threads:[~2023-05-25 15:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-22 16:04 [bug#63647] [PATCH 0/2] Fix annoyance with "guix import go" Simon Tournier
2023-05-22 16:08 ` [bug#63647] [PATCH 1/2] guix: import: go: Sort hint about available versions Simon Tournier
2023-05-22 16:08 ` [bug#63647] [PATCH 2/2] guix: import: go: Catch Git error Simon Tournier
2023-05-25 15:41 ` [bug#63647] [PATCH v2 1/3] guix: import: go: Sort hint about available versions Simon Tournier
2023-05-25 15:41   ` [bug#63647] [PATCH v2 2/3] guix: import: go: Catch Git error Simon Tournier
2023-05-25 15:41   ` Simon Tournier [this message]
2023-05-25 16:07 ` [bug#63647] [PATCH v3 1/3] guix: import: go: Sort hint about available versions Simon Tournier
2023-05-25 16:07   ` [bug#63647] [PATCH v3 2/3] guix: import: go: Catch Git error Simon Tournier
2023-06-05 12:45     ` [bug#63647] [PATCH 0/2] Fix annoyance with "guix import go" Ludovic Courtès
2023-06-06  6:21       ` Simon Tournier
2023-06-06 15:42         ` Ludovic Courtès
2023-05-25 16:07   ` [bug#63647] [PATCH v3 3/3] guix: import: go: Use correct tag for go module in subdirectory Simon Tournier
2023-06-05 12:43   ` [bug#63647] [PATCH 0/2] Fix annoyance with "guix import go" Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=27b0652df204a77a5b38554a95128fb54ca64dd9.1685029183.git.zimon.toutoune@gmail.com \
    --to=zimon.toutoune@gmail.com \
    --cc=63647@debbugs.gnu.org \
    --cc=singpolyma@singpolyma.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).