summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--guix/import/go.scm31
-rw-r--r--tests/go.scm6
2 files changed, 29 insertions, 8 deletions
diff --git a/guix/import/go.scm b/guix/import/go.scm
index 940cdac4b05..dd9298808de 100644
--- a/guix/import/go.scm
+++ b/guix/import/go.scm
@@ -29,6 +29,7 @@
29 #:use-module (guix git) 29 #:use-module (guix git)
30 #:use-module (guix hash) 30 #:use-module (guix hash)
31 #:use-module (guix i18n) 31 #:use-module (guix i18n)
32 #:use-module ((guix utils) #:select (version>?))
32 #:use-module (guix diagnostics) 33 #:use-module (guix diagnostics)
33 #:use-module (guix import utils) 34 #:use-module (guix import utils)
34 #:use-module (guix import json) 35 #:use-module (guix import json)
@@ -93,6 +94,11 @@
93 94
94;;; Code: 95;;; Code:
95 96
97(define (go-package)
98 "Return the 'go' package. This is a lazy reference so that we don't
99depend on (gnu packages golang)."
100 (module-ref (resolve-interface '(gnu packages golang)) 'go))
101
96(define http-fetch* 102(define http-fetch*
97 ;; Like http-fetch, but memoized and returning the body as a string. 103 ;; Like http-fetch, but memoized and returning the body as a string.
98 (memoize (lambda args 104 (memoize (lambda args
@@ -314,7 +320,7 @@ comment, or unknown) and is followed by the indicated data."
314 (define-peg-pattern with all (or (and module-path version) file-path)) 320 (define-peg-pattern with all (or (and module-path version) file-path))
315 (define-peg-pattern replace all (and original => with EOL)) 321 (define-peg-pattern replace all (and original => with EOL))
316 (define-peg-pattern replace-top body 322 (define-peg-pattern replace-top body
317 (and (ignore "replace") 323 (and (ignore "replace")
318 (or (and block-start (* (or replace block-line)) block-end) replace))) 324 (or (and block-start (* (or replace block-line)) block-end) replace)))
319 325
320 ;; RetractSpec = ( Version | "[" Version "," Version "]" ) newline . 326 ;; RetractSpec = ( Version | "[" Version "," Version "]" ) newline .
@@ -378,6 +384,17 @@ DIRECTIVE."
378;; Prevent inlining of this procedure, which is accessed by unit tests. 384;; Prevent inlining of this procedure, which is accessed by unit tests.
379(set! go.mod-requirements go.mod-requirements) 385(set! go.mod-requirements go.mod-requirements)
380 386
387(define (go.mod-go-version go.mod)
388 "Return the minimum version of go required to specified by GO.MOD."
389 (let ((go-version (go.mod-directives go.mod 'go)))
390 (if (null? go-version)
391 ;; If the go directive is missing, go 1.16 is assumed.
392 '(version "1.16")
393 (flatten go-version))))
394
395;; Prevent inlining of this procedure, which is accessed by unit tests.
396(set! go.mod-go-version go.mod-go-version)
397
381(define-record-type <vcs> 398(define-record-type <vcs>
382 (%make-vcs url-prefix root-regex type) 399 (%make-vcs url-prefix root-regex type)
383 vcs? 400 vcs?
@@ -610,6 +627,7 @@ When VERSION is unspecified, the latest version available is used."
610 available-versions 627 available-versions
611 module-path)) 628 module-path))
612 (content (fetch-go.mod goproxy module-path version*)) 629 (content (fetch-go.mod goproxy module-path version*))
630 (min-go-version (second (go.mod-go-version (parse-go.mod content))))
613 (dependencies+versions (go.mod-requirements (parse-go.mod content))) 631 (dependencies+versions (go.mod-requirements (parse-go.mod content)))
614 (dependencies (if pin-versions? 632 (dependencies (if pin-versions?
615 dependencies+versions 633 dependencies+versions
@@ -634,10 +652,13 @@ When VERSION is unspecified, the latest version available is used."
634 ,(vcs->origin vcs-type vcs-repo-url version*)) 652 ,(vcs->origin vcs-type vcs-repo-url version*))
635 (build-system go-build-system) 653 (build-system go-build-system)
636 (arguments 654 (arguments
637 '(#:import-path ,module-path 655 (list ,@(if (version>? min-go-version (package-version (go-package)))
638 ,@(if (string=? module-path-sans-suffix root-module-path) 656 `(#:go ,(string->number min-go-version))
639 '() 657 '())
640 `(#:unpack-path ,root-module-path)))) 658 #:import-path ,module-path
659 ,@(if (string=? module-path-sans-suffix root-module-path)
660 '()
661 `(#:unpack-path ,root-module-path))))
641 ,@(maybe-propagated-inputs 662 ,@(maybe-propagated-inputs
642 (map (match-lambda 663 (map (match-lambda
643 ((name version) 664 ((name version)
diff --git a/tests/go.scm b/tests/go.scm
index a70a0ddbf57..d2e8846b30c 100644
--- a/tests/go.scm
+++ b/tests/go.scm
@@ -1,6 +1,6 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2021 François Joulaud <francois.joulaud@radiofrance.com> 2;;; Copyright © 2021 François Joulaud <francois.joulaud@radiofrance.com>
3;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev> 3;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
4;;; 4;;;
5;;; This file is part of GNU Guix. 5;;; This file is part of GNU Guix.
6;;; 6;;;
@@ -387,7 +387,7 @@ require github.com/kr/pretty v0.2.1
387 "0sjjj9z1dhilhpc8pq4154czrb79z9cm044jvn75kxcjv6v5l2m5")))) 387 "0sjjj9z1dhilhpc8pq4154czrb79z9cm044jvn75kxcjv6v5l2m5"))))
388 (build-system go-build-system) 388 (build-system go-build-system)
389 (arguments 389 (arguments
390 '(#:import-path "github.com/go-check/check")) 390 (list #:import-path "github.com/go-check/check"))
391 (propagated-inputs 391 (propagated-inputs
392 `(("go-github-com-kr-pretty" ,go-github-com-kr-pretty))) 392 `(("go-github-com-kr-pretty" ,go-github-com-kr-pretty)))
393 (home-page "https://github.com/go-check/check") 393 (home-page "https://github.com/go-check/check")