From c1db66fa0a17ee81e084038007db556626875bc4 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sun, 9 Jan 2022 22:36:38 +0100 Subject: import: go: Correctly report diagnostics upon version mismatch. * guix/import/go.scm (strip-v-prefix, ensure-v-prefix) (validate-version): New procedures. (go-module->guix-package): Use 'validate-version' when defining 'version*'. Remove 'else' clause in SRFI-34 guard. --- guix/import/go.scm | 60 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 21 deletions(-) (limited to 'guix/import/go.scm') diff --git a/guix/import/go.scm b/guix/import/go.scm index c7673e6a1a..d00c13475a 100644 --- a/guix/import/go.scm +++ b/guix/import/go.scm @@ -3,7 +3,7 @@ ;;; Copyright © 2020 Helio Machado <0x2b3bfa0+guix@googlemail.com> ;;; Copyright © 2021 François Joulaud ;;; Copyright © 2021 Maxim Cournoyer -;;; Copyright © 2021 Ludovic Courtès +;;; Copyright © 2021-2022 Ludovic Courtès ;;; Copyright © 2021 Xinglu Chen ;;; Copyright © 2021 Sarah Morgensen ;;; Copyright © 2021 Simon Tournier @@ -41,6 +41,7 @@ (define-module (guix import go) #:autoload (guix base32) (bytevector->nix-base32-string) #:autoload (guix build utils) (mkdir-p) #:autoload (gcrypt hash) (hash-algorithm sha256) + #:use-module (ice-9 format) #:use-module (ice-9 match) #:use-module (ice-9 peg) #:use-module (ice-9 rdelim) @@ -54,6 +55,7 @@ (define-module (guix import go) #:use-module (srfi srfi-11) #:use-module (srfi srfi-26) #:use-module (srfi srfi-34) + #:use-module (srfi srfi-35) #:use-module (sxml match) #:use-module ((sxml xpath) #:renamer (lambda (s) (if (eq? 'filter s) @@ -569,6 +571,34 @@ (define (vcs->origin vcs-type vcs-repo-url version) (formatted-message (G_ "unsupported vcs type '~a' for package '~a'") vcs-type vcs-repo-url))))) +(define (strip-v-prefix version) + "Strip from VERSION the \"v\" prefix that Go uses." + (string-trim version #\v)) + +(define (ensure-v-prefix version) + "Add a \"v\" prefix to VERSION if it does not already have one." + (if (string-prefix? "v" version) + version + (string-append "v" version))) + +(define (validate-version version available-versions module-path) + "Raise an error if VERSION is not among AVAILABLE-VERSIONS, unless VERSION +is a pseudo-version. Return VERSION." + ;; Pseudo-versions do not appear in the versions list; skip the + ;; following check. + (if (or (go-pseudo-version? version) + (member version available-versions)) + version + (raise + (make-compound-condition + (formatted-message (G_ "version ~a of ~a is not available~%") + version module-path available-versions) + (condition (&fix-hint + (hint (format #f (G_ "Pick one of the following \ +available versions:~{ ~a~}.") + (map strip-v-prefix + available-versions))))))))) + (define* (go-module->guix-package module-path #:key (goproxy "https://proxy.golang.org") version @@ -577,17 +607,11 @@ (define* (go-module->guix-package module-path #:key The meta-data is fetched from the GOPROXY server and https://pkg.go.dev/. 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*) - (member version* available-versions)) - (error (format #f "error: version ~s is not available -hint: use one of the following available versions ~a\n" - version* available-versions)))) + (version* (validate-version + (or (and version (ensure-v-prefix version)) + (go-module-version-string goproxy module-path)) ;latest + available-versions + module-path)) (content (fetch-go.mod goproxy module-path version*)) (dependencies+versions (go.mod-requirements (parse-go.mod content))) (dependencies (if pin-versions? @@ -628,10 +652,10 @@ (define* (go-module->guix-package module-path #:key (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 @@ -651,12 +675,6 @@ (define go-module->guix-package* (uri->string (http-get-error-uri c)) (http-get-error-code c) (http-get-error-reason c)) - (values #f '())) - (else - (warning (G_ "Failed to import package ~s. -reason: ~s.~%") - package-name - (exception-args c)) (values #f '()))) (apply go-module->guix-package args))))) -- cgit v1.2.3