summaryrefslogtreecommitdiff
path: root/guix/import/go.scm
diff options
context:
space:
mode:
Diffstat (limited to 'guix/import/go.scm')
-rw-r--r--guix/import/go.scm37
1 files changed, 31 insertions, 6 deletions
diff --git a/guix/import/go.scm b/guix/import/go.scm
index 0357e6a1eb..dd9298808d 100644
--- a/guix/import/go.scm
+++ b/guix/import/go.scm
@@ -7,6 +7,7 @@
;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
;;; Copyright © 2021 Simon Tournier <zimon.toutoune@gmail.com>
+;;; Copyright © 2023 Efraim Flashner <efraim@flashner.co.il>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -28,6 +29,7 @@
#: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)
@@ -92,6 +94,11 @@
;;; 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
@@ -293,7 +300,10 @@ comment, or unknown) and is followed by the indicated data."
;; The following directives may all be used solo or in a block
;; RequireSpec = ModulePath Version newline .
- (define-peg-pattern require all (and module-path version EOL))
+ (define-peg-pattern require all
+ (and module-path version
+ ;; We don't want the transitive dependencies.
+ (not-followed-by (and (* WS) "//" (* WS) "indirect")) EOL))
(define-peg-pattern require-top body
(and (ignore "require")
(or (and block-start (* (or require block-line)) block-end) require)))
@@ -310,7 +320,7 @@ comment, or unknown) and is followed by the indicated data."
(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 .
@@ -374,6 +384,17 @@ DIRECTIVE."
;; 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?
@@ -606,6 +627,7 @@ When VERSION is unspecified, the latest version available is used."
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
@@ -630,10 +652,13 @@ When VERSION is unspecified, the latest version available is used."
,(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)