all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: 47310@debbugs.gnu.org
Cc: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Subject: [bug#47310] [PATCH 4/4] import: go: Append version to symbol name in the pinned version mode.
Date: Mon, 22 Mar 2021 00:20:22 -0400	[thread overview]
Message-ID: <20210322042022.17385-4-maxim.cournoyer@gmail.com> (raw)
In-Reply-To: <20210322042022.17385-1-maxim.cournoyer@gmail.com>

This allows importing packages with complicated version specific dependency
chains without the package symbol names colliding.

* doc/guix.texi (Invoking guix import): Document the --pin-versions option.
Mention that a specific version can be imported.  Remove the experimental
warning.
* guix/import/go.scm (go-module->guix-package-name)[version]: Add optional
argument.
(go-module->guix-package): Conditionally use dependencies whose symbol include
their version, based no the value of the PIN-VERSIONS? argument.
* guix/import/utils.scm (package->definition): Add a new case where the full
version string is appended to the package symbol.
* guix/scripts/import.scm (guix-import): Correctly print forms starting
with '(define-public [...]'.
* guix/scripts/import/go.scm (guix-import-go): Conditionally include the
version in the package symbols defined.
---
 doc/guix.texi              | 14 +++++++++++---
 guix/import/go.scm         | 34 +++++++++++++++++++++++-----------
 guix/import/utils.scm      |  7 +++++--
 guix/scripts/import.scm    |  3 ++-
 guix/scripts/import/go.scm | 17 ++++++++++-------
 5 files changed, 51 insertions(+), 24 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 386169b2a5..be20215638 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -11520,13 +11520,13 @@ Select the given repository (a repository name).  Possible values include:
 Import metadata for a Go module using
 @uref{https://proxy.golang.org, proxy.golang.org}.
 
-This importer is highly experimental. See the source code for more info
-about the current state.
-
 @example
 guix import go gopkg.in/yaml.v2
 @end example
 
+It is possible to use a package specification with a @code{@VERSION}
+suffix to import a specific version.
+
 Additional options include:
 
 @table @code
@@ -11535,6 +11535,14 @@ Additional options include:
 Traverse the dependency graph of the given upstream package recursively
 and generate package expressions for all those packages that are not yet
 in Guix.
+@item --pin-versions
+When using this option, the importer preserves the exact versions of the
+Go modules dependencies instead of using their latest available
+versions.  This can be useful when attempting to import packages that
+recursively depend on former versions of themselves to build.  When
+using this mode, the symbol of the package is made by appending the
+version to its name, so that multiple versions of the same package can
+coexist.
 @end table
 @end table
 
diff --git a/guix/import/go.scm b/guix/import/go.scm
index 2376336265..d8b6fddac5 100644
--- a/guix/import/go.scm
+++ b/guix/import/go.scm
@@ -427,13 +427,17 @@ hence the need to derive this information."
       (vcs-qualified-module-path->root-repo-url module-path)
       module-path))
 
-(define (go-module->guix-package-name module-path)
-  "Converts a module's path to the canonical Guix format for Go packages."
+(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."
   (string-downcase (string-append "go-" (string-replace-substring
                                          (string-replace-substring
                                           module-path
                                           "." "-")
-                                         "/" "-"))))
+                                         "/" "-")
+                                  (if version
+                                      (string-append "-" version)
+                                      ""))))
 
 (define (strip-.git-suffix/maybe repo-url)
   "Strip a repository URL '.git' suffix from REPO-URL if hosted at GitHub."
@@ -572,6 +576,8 @@ When VERSION is unspecified, the latest version available is used."
   (let* ((available-versions (go-module-available-versions goproxy module-path))
          (version* (or version
                        (go-module-version-string goproxy module-path))) ;latest
+         ;; Elide the "v" prefix Go uses.
+         (strip-v-prefix (cut string-trim <> #\v))
          ;; Pseudo-versions do not appear in the versions list; skip the
          ;; following check.
          (_ (unless (or (go-pseudo-version? version*)
@@ -581,7 +587,9 @@ hint: use one of the following available versions ~a\n"
                              version* available-versions))))
          (content (fetch-go.mod goproxy module-path version*))
          (dependencies+versions (parse-go.mod content))
-         (dependencies (map car dependencies+versions))
+         (dependencies (if pin-versions?
+                           dependencies+versions
+                           (map car dependencies+versions)))
          (guix-name (go-module->guix-package-name module-path))
          (root-module-path (module-path->repository-root module-path))
          ;; The VCS type and URL are not included in goproxy information. For
@@ -595,23 +603,27 @@ hint: use one of the following available versions ~a\n"
     (values
      `(package
         (name ,guix-name)
-        ;; Elide the "v" prefix Go uses
-        (version ,(string-trim version* #\v))
+        (version ,(strip-v-prefix version*))
         (source
          ,(vcs->origin vcs-type vcs-repo-url version*))
         (build-system go-build-system)
         (arguments
          '(#:import-path ,root-module-path))
-        ,@(maybe-propagated-inputs (map go-module->guix-package-name
-                                        dependencies))
+        ,@(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" root-module-path))
         (synopsis ,synopsis)
         (description ,(and=> description beautify-description))
         (license ,(match (list->licenses licenses)
-                    (() #f)             ;unknown license
-                    ((license)          ;a single license
+                    (() #f)                        ;unknown license
+                    ((license)                     ;a single license
                      license)
-                    ((license ...)      ;a list of licenses
+                    ((license ...)     ;a list of licenses
                      `(list ,@license)))))
      (if pin-versions?
          dependencies+versions
diff --git a/guix/import/utils.scm b/guix/import/utils.scm
index 21fafad388..21352841b8 100644
--- a/guix/import/utils.scm
+++ b/guix/import/utils.scm
@@ -273,8 +273,9 @@ snippet generated is for regular inputs."
   (maybe-inputs package-names output #:type 'propagated))
 
 (define* (package->definition guix-package #:optional append-version?/string)
-  "If APPEND-VERSION?/STRING is #t, append the package's major+minor
-version. If APPEND-VERSION?/string is a string, append this string."
+  "If APPEND-VERSION?/STRING is #t, append the package's major+minor version.
+If it is the symbol 'full, append the package's complete version.  If
+APPEND-VERSION?/string is a string, append this string."
   (match guix-package
     ((or
       ('package ('name name) ('version version) . rest)
@@ -286,6 +287,8 @@ version. If APPEND-VERSION?/string is a string, append this string."
                          (string-append name "-" append-version?/string))
                         ((eq? append-version?/string #t)
                          (string-append name "-" (version-major+minor version)))
+                        ((eq? 'full append-version?/string)
+                         (string-append name "-" version))
                         (else name)))
         ,guix-package))))
 
diff --git a/guix/scripts/import.scm b/guix/scripts/import.scm
index 1d2b45d942..98554ef79b 100644
--- a/guix/scripts/import.scm
+++ b/guix/scripts/import.scm
@@ -119,7 +119,8 @@ Run IMPORTER with ARGS.\n"))
                                             (current-output-port))))))
            (match (apply (resolve-importer importer) args)
              ((and expr (or ('package _ ...)
-                            ('let _ ...)))
+                            ('let _ ...)
+                            ('define-public _ ...)))
               (print expr))
              ((? list? expressions)
               (for-each (lambda (expr)
diff --git a/guix/scripts/import/go.scm b/guix/scripts/import/go.scm
index 33d2470ce1..04b07f80cc 100644
--- a/guix/scripts/import/go.scm
+++ b/guix/scripts/import/go.scm
@@ -22,9 +22,11 @@
   #:use-module (guix utils)
   #:use-module (guix scripts)
   #:use-module (guix import go)
+  #:use-module (guix import utils)
   #:use-module (guix scripts import)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-11)
+  #:use-module (srfi srfi-26)
   #:use-module (srfi srfi-37)
   #:use-module (ice-9 match)
   #:use-module (ice-9 format)
@@ -94,7 +96,12 @@ that are not yet in Guix"))
                              (('argument . value)
                               value)
                              (_ #f))
-                           (reverse opts))))
+                           (reverse opts)))
+         ;; Append the full version to the package symbol name when using
+         ;; pinned versions.
+         (package->definition* (if (assoc-ref opts 'pin-versions?)
+                                   (cut package->definition <> 'full)
+                                   package->definition)))
     (match args
       ((spec)                         ;e.g., github.com/golang/protobuf@v1.3.1
        (receive (name version)
@@ -106,18 +113,14 @@ that are not yet in Guix"))
                                 (assoc-ref opts 'pin-versions?))))
            (if (assoc-ref opts 'recursive)
                ;; Recursive import.
-               (map (match-lambda
-                      ((and ('package ('name name) . rest) pkg)
-                       `(define-public ,(string->symbol name)
-                          ,pkg))
-                      (_ #f))
+               (map package->definition*
                     (apply go-module-recursive-import arguments))
                ;; Single import.
                (let ((sexp (apply go-module->guix-package arguments)))
                  (unless sexp
                    (leave (G_ "failed to download meta-data for module '~a'~%")
                           module-name))
-                 sexp)))))
+                 (package->definition* sexp))))))
       (()
        (leave (G_ "too few arguments~%")))
       ((many ...)
-- 
2.30.1





  parent reply	other threads:[~2021-03-22  4:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-22  4:10 [bug#47310] [PATCH 0/4] Improve parsing of synopsis and description, add pinned versions mode Maxim Cournoyer
2021-03-22  4:20 ` [bug#47310] [PATCH 1/4] import: utils: Refactor maybe-inputs and add maybe-propagated-inputs Maxim Cournoyer
2021-03-22  4:20   ` [bug#47310] [PATCH 2/4] import: go: Improve synopsis and description parsing Maxim Cournoyer
2021-03-22  4:20   ` [bug#47310] [PATCH 3/4] import: go: Add an option to use pinned versions Maxim Cournoyer
2021-04-10  3:13     ` bug#47310: " Maxim Cournoyer
2021-03-22  4:20   ` Maxim Cournoyer [this message]
2021-04-10 20:54 ` [bug#47310] [PATCH 0/4] go importer: Better synopsis and descriptions, pinned versions mode Ludovic Courtès
2021-04-11  0:57   ` Maxim Cournoyer
     [not found] ` <20210414120939.mmvprjaz6636kz4h@noop.avalenn.eu>
     [not found]   ` <87czusjtpc.fsf@gmail.com>
2021-04-18 10:31     ` go-build-system possible improvments François
2021-04-21  2:00       ` Maxim Cournoyer
2021-04-22 16:36         ` François
2021-04-24  3:30           ` Maxim Cournoyer

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

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

  git send-email \
    --in-reply-to=20210322042022.17385-4-maxim.cournoyer@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=47310@debbugs.gnu.org \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.