From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id OE9OIK0cWGDcSQAA0tVLHw (envelope-from ) for ; Mon, 22 Mar 2021 04:27:25 +0000 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id SPcSHK0cWGBWKgAAB5/wlQ (envelope-from ) for ; Mon, 22 Mar 2021 04:27:25 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 0C13710BCE for ; Mon, 22 Mar 2021 05:27:25 +0100 (CET) Received: from localhost ([::1]:44916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOCA0-00044G-7I for larch@yhetil.org; Mon, 22 Mar 2021 00:27:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOC3s-0007HO-3e for guix-patches@gnu.org; Mon, 22 Mar 2021 00:21:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:44286) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lOC3q-000124-Qv for guix-patches@gnu.org; Mon, 22 Mar 2021 00:21:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lOC3q-0005tq-Mg for guix-patches@gnu.org; Mon, 22 Mar 2021 00:21:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#47310] [PATCH 4/4] import: go: Append version to symbol name in the pinned version mode. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 22 Mar 2021 04:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47310 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 47310@debbugs.gnu.org Cc: Maxim Cournoyer Received: via spool by 47310-submit@debbugs.gnu.org id=B47310.161638684622615 (code B ref 47310); Mon, 22 Mar 2021 04:21:02 +0000 Received: (at 47310) by debbugs.gnu.org; 22 Mar 2021 04:20:46 +0000 Received: from localhost ([127.0.0.1]:55828 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lOC3Z-0005sb-QG for submit@debbugs.gnu.org; Mon, 22 Mar 2021 00:20:46 -0400 Received: from mail-qv1-f42.google.com ([209.85.219.42]:38448) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lOC3U-0005ru-OO for 47310@debbugs.gnu.org; Mon, 22 Mar 2021 00:20:42 -0400 Received: by mail-qv1-f42.google.com with SMTP id t5so8065714qvs.5 for <47310@debbugs.gnu.org>; Sun, 21 Mar 2021 21:20:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5wPZpTUdLlzl7ct1KPNgprUvMeIORWb5BGSuBXVERgI=; b=uMVj5Wd4Cpss0TrGPYmWIDcrHXxSH9ERrKRxUHKlRe7rzOQbPRv1Y5wCJVdKyojYqm 4VlnZaiDcCOIWynIoYBc5v5G8zk1zpirSaIEDvRZ80pedHOHxRSgm5PYh9miU3vX0sHp 8geSA3PiC2FnG2rk+nCnr1DsYEzwlfFF1xBw76spaIjs9FNCJHUwRkNNi2ALPPVtV3HW 1KhXLnGTpfetuloQHzrQ3hClmAcykSpkyfTTChhsmMbxR7jr9378nyOwgHi0rMNfdM0C 6txRIH+eK1D8nZsEBg9vqORkpKRakXsjvtntn+T/ZEY7u3j3dwsi2tcyp4NzCeS3sGfj lyHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5wPZpTUdLlzl7ct1KPNgprUvMeIORWb5BGSuBXVERgI=; b=VdOwg/QZAzlsuV98mnWCKJhyQTzQFYhJUVRy/HOSA55XMEo5a1TRy32Fj9E7wsoIuV IEl8lG6CJ/kE90rRcdxzE2BuSIpbimSHC3KQ2lDgIgVR81t2PIuiKm2iJ8peaTyb1Pau uhmZLZLHoZBSyRWkzgjcT561uJQxxqEp6mL5Ylvfcqcdb6hg4wN/2K1ngVCN+mSBa4Lj WZI6wEgJnlICmshcWr2m6KwdCyIqDx2SaUQyIkIpZoVj/hnLzjqZ6KaOBQEtaQz+fTUX uM8ei50Kv+9AuaVOslJaGmGd0uay1op7Cr3acOLXDlslTItkC+ObJOuNY1jKnsra+bWb 9NHw== X-Gm-Message-State: AOAM531agiE6oSaKLhItLZ1onhauiG2uVjv37nECClKeYqeHqLwH89jo h21O9j32cAH8IKQe8STSVRPNUnjUkVg= X-Google-Smtp-Source: ABdhPJwZLmDK9PbUkdTPKMYECfXaoIZaUUtK1ozFK3PGS7jIV2kO6/K95GdUh5oRuYgIqLE+EUuuJA== X-Received: by 2002:ad4:584d:: with SMTP id de13mr19764048qvb.17.1616386835016; Sun, 21 Mar 2021 21:20:35 -0700 (PDT) Received: from localhost.localdomain (dsl-10-134-34.b2b2c.ca. [72.10.134.34]) by smtp.gmail.com with ESMTPSA id z8sm8340478qtn.12.2021.03.21.21.20.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 21:20:34 -0700 (PDT) From: Maxim Cournoyer Date: Mon, 22 Mar 2021 00:20:22 -0400 Message-Id: <20210322042022.17385-4-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210322042022.17385-1-maxim.cournoyer@gmail.com> References: <20210322042022.17385-1-maxim.cournoyer@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1616387245; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=5wPZpTUdLlzl7ct1KPNgprUvMeIORWb5BGSuBXVERgI=; b=ffzrvvm4wuaPk/lfZJMPcdZqLuWCw7TOjPiB9wzbP2Cl9PNX1LBmKc1X748YZgjmQ9T1LH qHD/7/D5CzIMT6mmwgXkv80lR50ItYsY4dDdX0qgjr2ErvZ+ionmsKUlKjOWCfSh/ZxXre pAUWz23LLsuTyxQL6Xhwi9wVP7USzmUhzQhajKIhB8lV2dp0kPNhfSpWsBXe1lPyVS/h2l 8Zf+YPtWDWIqkTBJ3q+e61YLzTmQcA6O+6d6wcenWtRvBuV1j5iYlII4zlFd/dBSGWS9AK a2XQKAB/Ehhm0y8trRs33lENlORxtqEBmuvdy1lF3RlMQO0P3GbFCKLy0KgQLQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1616387245; a=rsa-sha256; cv=none; b=k3aeprehA6xxe5dXJzyH+0IauBbt8LkOULq1nWa/5K2kp5zgTvdMTtpm0H+4wxTwC+cq0L V+kQVaPbspmNYMPrVdBpq7wM/gcnSYTuvLzEQEJPyDTy0XNZWNKUQcJFImlDfNn2fI72UV VQelCcKhTfxNFGQd++Ub/9WLL/6uoPvKh7K1Y+1PLqgvPyIb/BXoac3E8NWv6hsl3+Ctek OL6XYqkfPJm8UVgYhYqRqwq2KsGcf+iHhkK+kabruKxHTp3mFL6tj5TXUr3hoT2FBAkhcO mBrwTKeNzp4efureZ8CVl1kewNvlOv6zcwPDvhzu0oqLWfl5x6ZglI+tNljyDA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20161025 header.b=uMVj5Wd4; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: 2.68 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20161025 header.b=uMVj5Wd4; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 0C13710BCE X-Spam-Score: 2.68 X-Migadu-Scanner: scn0.migadu.com X-TUID: ZJS6XEhysODH 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