all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Efraim Flashner <efraim@flashner.co.il>
To: 67503@debbugs.gnu.org
Cc: Efraim Flashner <efraim@flashner.co.il>,
	Katherine Cox-Buday <cox.katherine.e+guix@gmail.com>
Subject: [bug#67503] [PATCH 2/2] guix: import: Report go version for go importer.
Date: Tue, 28 Nov 2023 12:21:07 +0200	[thread overview]
Message-ID: <7a558e7d4aef26af09a8050b29c591f03a514494.1701166089.git.efraim@flashner.co.il> (raw)
In-Reply-To: <cover.1701166089.git.efraim@flashner.co.il>

* guix/import/go.scm (go-package, go.mod-go-version): New procedures.
(go-module->guix-package): Add the #:go keyword in the generated package
definition if the required go is newer than the default go.

Change-Id: I8d005740a442330ac307a40a53764c803ceffc4f
---
 guix/import/go.scm | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/guix/import/go.scm b/guix/import/go.scm
index 940cdac4b0..dd9298808d 100644
--- a/guix/import/go.scm
+++ b/guix/import/go.scm
@@ -29,6 +29,7 @@ (define-module (guix import go)
   #:use-module (guix git)
   #:use-module (guix hash)
   #:use-module (guix i18n)
+  #:use-module ((guix utils) #:select (version>?))
   #:use-module (guix diagnostics)
   #:use-module (guix import utils)
   #:use-module (guix import json)
@@ -93,6 +94,11 @@ (define-module (guix import go)
 
 ;;; Code:
 
+(define (go-package)
+  "Return the 'go' package.  This is a lazy reference so that we don't
+depend on (gnu packages golang)."
+  (module-ref (resolve-interface '(gnu packages golang)) 'go))
+
 (define http-fetch*
   ;; Like http-fetch, but memoized and returning the body as a string.
   (memoize (lambda args
@@ -314,7 +320,7 @@ (define (parse-go.mod content)
   (define-peg-pattern with all (or (and module-path version) file-path))
   (define-peg-pattern replace all (and original => with EOL))
   (define-peg-pattern replace-top body
-    (and (ignore "replace") 
+    (and (ignore "replace")
          (or (and block-start (* (or replace block-line)) block-end) replace)))
 
   ;; RetractSpec = ( Version | "[" Version "," Version "]" ) newline .
@@ -378,6 +384,17 @@ (define (go.mod-requirements go.mod)
 ;; Prevent inlining of this procedure, which is accessed by unit tests.
 (set! go.mod-requirements go.mod-requirements)
 
+(define (go.mod-go-version go.mod)
+  "Return the minimum version of go required to specified by GO.MOD."
+  (let ((go-version (go.mod-directives go.mod 'go)))
+    (if (null? go-version)
+      ;; If the go directive is missing, go 1.16 is assumed.
+      '(version "1.16")
+      (flatten go-version))))
+
+;; Prevent inlining of this procedure, which is accessed by unit tests.
+(set! go.mod-go-version go.mod-go-version)
+
 (define-record-type <vcs>
   (%make-vcs url-prefix root-regex type)
   vcs?
@@ -610,6 +627,7 @@ (define* (go-module->guix-package module-path #:key
                     available-versions
                     module-path))
          (content (fetch-go.mod goproxy module-path version*))
+         (min-go-version (second (go.mod-go-version (parse-go.mod content))))
          (dependencies+versions (go.mod-requirements (parse-go.mod content)))
          (dependencies (if pin-versions?
                            dependencies+versions
@@ -634,10 +652,13 @@ (define* (go-module->guix-package module-path #:key
          ,(vcs->origin vcs-type vcs-repo-url version*))
         (build-system go-build-system)
         (arguments
-         '(#:import-path ,module-path
-           ,@(if (string=? module-path-sans-suffix root-module-path)
-                 '()
-                 `(#:unpack-path ,root-module-path))))
+         (list ,@(if (version>? min-go-version (package-version (go-package)))
+                     `(#:go ,(string->number min-go-version))
+                     '())
+               #:import-path ,module-path
+               ,@(if (string=? module-path-sans-suffix root-module-path)
+                     '()
+                     `(#:unpack-path ,root-module-path))))
         ,@(maybe-propagated-inputs
            (map (match-lambda
                   ((name version)
-- 
Efraim Flashner   <efraim@flashner.co.il>   רנשלפ םירפא
GPG key = A28B F40C 3E55 1372 662D  14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted





  parent reply	other threads:[~2023-11-28 10:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-28 10:18 [bug#67503] [PATCH 0/2] Improvements to the go importer Efraim Flashner
2023-11-28 10:21 ` [bug#67503] [PATCH 1/2] guix: import: Don't include indirect dependencies in go Efraim Flashner
2023-11-28 10:21 ` Efraim Flashner [this message]
2024-10-31 13:39 ` [bug#67503] Improvements to the go importer (bumping) Steve George

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=7a558e7d4aef26af09a8050b29c591f03a514494.1701166089.git.efraim@flashner.co.il \
    --to=efraim@flashner.co.il \
    --cc=67503@debbugs.gnu.org \
    --cc=cox.katherine.e+guix@gmail.com \
    /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.