From patchwork Tue May 3 11:43:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Attila Lendvai X-Patchwork-Id: 39101 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 50B8727BBEA; Tue, 3 May 2022 12:46:17 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id B1A9427BBE9 for ; Tue, 3 May 2022 12:46:16 +0100 (BST) Received: from localhost ([::1]:47284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlqyt-0004xj-Kg for patchwork@mira.cbaines.net; Tue, 03 May 2022 07:46:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38618) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlqwn-0003h6-Uv for guix-patches@gnu.org; Tue, 03 May 2022 07:44:06 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:44948) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlqwn-0002S9-MH for guix-patches@gnu.org; Tue, 03 May 2022 07:44:05 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nlqwn-0005Qn-Kk for guix-patches@gnu.org; Tue, 03 May 2022 07:44:05 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#55242] [PATCH 10/10] guix: import: go: Better handling of /v2 in the module path. Resent-From: Attila Lendvai Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 03 May 2022 11:44:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55242 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 55242@debbugs.gnu.org Cc: Attila Lendvai Received: via spool by 55242-submit@debbugs.gnu.org id=B55242.165157821920782 (code B ref 55242); Tue, 03 May 2022 11:44:05 +0000 Received: (at 55242) by debbugs.gnu.org; 3 May 2022 11:43:39 +0000 Received: from localhost ([127.0.0.1]:38837 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nlqwM-0005P3-Nu for submit@debbugs.gnu.org; Tue, 03 May 2022 07:43:39 -0400 Received: from mail-ed1-f45.google.com ([209.85.208.45]:40825) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nlqwH-0005NR-SW for 55242@debbugs.gnu.org; Tue, 03 May 2022 07:43:34 -0400 Received: by mail-ed1-f45.google.com with SMTP id p18so19515047edr.7 for <55242@debbugs.gnu.org>; Tue, 03 May 2022 04:43:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WXH0lfHok3sajpelue/NTp/Aq+/ANt0daCtjJoY8NiQ=; b=lW93FENB5dut+jBVYhm9T7fnoR7nq7mtSfPdoW9+hJcD/gjRtkLpp2NIGFMgcNLhHD orTw9vgSn/odIHFSHEwDkXCFNDfZJZ1mn5YUMM1LrU8ZmaEZW8LIMf6hu+GZ8vHR5Ha7 +zdykBaLqacJkrAkDZjzY5XqV5FV13rmqVKLfTIitLvItbekuTmecjz36CXhs1axdNGD gwIjEuENysL7DT3wx+RVRUyk5YC5FKy2Ehr6xNsipX7Ijzj806ildMtSsBXTvuXaJgq2 TnkffYzKRe6S2I4Bx1rtfcoY9gsE88kHZ2ELZPLdFJYlPVRKQSfhlN9OPWOrQ1HKJqqU ho6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=WXH0lfHok3sajpelue/NTp/Aq+/ANt0daCtjJoY8NiQ=; b=Qeyqdf8joN+T5nUEZcX10Rvxu2x57XUH4OCIELpDLHsTyBU9K/2qUZG8oqqub3GsJc fqdB/jQRXPIFyyGQHYz+eCX61aRdzR4i6JW0WLDJZRhjyl+YZsBoxmEkhVWCZB7OThDy AIM2IW60oarMUku6mY/XfJf91Rb0JgFNshF0aLhC1rztyiikyTFhbWUUT/TB0nPjcYWU PLt5zOwOuDvNUYbrBSaa/sMGIrZZ8BORru77dyLwEDUMMHVrVbS85xgSlWIqoRyY2YCh FShIk7yyBeak2fCyPJVcBzoNcFKDUC9brRKthR8FhmlxTdeMXrNNdDePyDitof9zosJq 1hsg== X-Gm-Message-State: AOAM533d18uz5yS2DGt1x18iPUwRzxGb8zuGEMB1w244dUjZntWes0pH e1C+29nskizcaFnPFSr+7SCadFYUi/8= X-Google-Smtp-Source: ABdhPJxq8zJKA+q8yYqWM0U0Rq5fCAP8ieqKOiSjtlctFfQzcSQwDze9NVShvyImm3Ap/AJPcJSwXg== X-Received: by 2002:a05:6402:1f0b:b0:427:b390:2020 with SMTP id b11-20020a0564021f0b00b00427b3902020mr13306474edb.70.1651578208208; Tue, 03 May 2022 04:43:28 -0700 (PDT) Received: from lelap.local (catv-89-132-245-188.catv.fixed.vodafone.hu. [89.132.245.188]) by smtp.gmail.com with ESMTPSA id k13-20020a05640212cd00b0042617ba63d6sm7766964edx.96.2022.05.03.04.43.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 04:43:27 -0700 (PDT) From: Attila Lendvai Date: Tue, 3 May 2022 13:43:01 +0200 Message-Id: <20220503114301.9524-10-attila@lendvai.name> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220503114301.9524-2-attila@lendvai.name> References: <20220503114301.9524-2-attila@lendvai.name> MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/import/go.scm (module-path->repository-root): Delete version param. (*module-path->import-path*): New mapping, initialized with a small db of projects. (go-module->guix-package): Return packages with #:unpack-path when needed. --- guix/import/go.scm | 93 +++++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 39 deletions(-) diff --git a/guix/import/go.scm b/guix/import/go.scm index 25d424c1ac..fbed3ca88b 100644 --- a/guix/import/go.scm +++ b/guix/import/go.scm @@ -75,6 +75,7 @@ (define-module (guix import go) #:use-module (srfi srfi-26) #:use-module (srfi srfi-34) #:use-module (srfi srfi-35) + #:use-module (srfi srfi-71) ; let* #:use-module (sxml match) #:use-module ((sxml xpath) #:renamer (lambda (s) (if (eq? 'filter s) @@ -608,19 +609,15 @@ (define (vcs-qualified-module-path->root-repo-url module-path) (vcs-qualified-module-path->root-repo-url module-path) module-path)) -(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." +(define* (go-module->guix-package-name module-path) + "Converts a module's path to the canonical Guix format for Go packages." ;; Map dot, slash, underscore and tilde characters to hyphens. (let ((module-path* (string-map (lambda (c) (if (member c '(#\. #\/ #\_ #\~)) #\- c)) module-path))) - (string-downcase (string-append "go-" module-path* - (if version - (string-append "-" version) - ""))))) + (string-downcase (string-append "go-" module-path*)))) (define (strip-.git-suffix/maybe repo-url) "Strip a repository URL '.git' suffix from REPO-URL if hosted at GitHub." @@ -771,6 +768,14 @@ (define (validate-version version available-versions module-path) available versions:~{ ~a~}.") (map strip-v-prefix available-versions))))))))) +(define *module-path->import-path* + ;; There's no other way to derive this information, at least that I know of. + '(("github.com/google/go-cmp" . "github.com/google/go-cmp/cmp") + ("github.com/sergi/go-diff" . "github.com/sergi/go-diff/diffmatchpatch") + ("github.com/davecgh/go-spew" . "github.com/davecgh/go-spew/spew") + ("github.com/beorn7/perks" . "github.com/beorn7/perks/quantile") + ("github.com/census-instrumentation/opencensus-proto" . + "github.com/census-instrumentation/opencensus-proto/gen-go"))) (define* (go-module->guix-package module-path #:key (goproxy "https://proxy.golang.org") @@ -864,38 +869,48 @@ (define* (go-module->guix-package module-path #:key major-version: ~S" meta-data raw-subdir module-subdirectory major-version) (log.debug " dependencies:~%~S" dependencies+versions) - (values - `(package - (name ,guix-name) - (version ,(strip-v-prefix version*)) - (source - ,(vcs->origin vcs-type vcs-repo-url vcs-tag)) - (build-system go-build-system) - (arguments - '(#:tests? #false ; some packages have unrecorded dependencies needed only by their tests - #:import-path ,module-path - ,@(if module-subdirectory - `(#:unpack-path ,module-root-path) - '()))) - ,@(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" module-root-path)) - (synopsis ,synopsis) - (description ,(and=> description beautify-description)) - (license ,(match (list->licenses licenses) - (() #f) ;unknown license - ((license) ;a single license - license) - ((license ...) ;a list of licenses - `(list ,@license))))) - (if pin-versions? - dependencies+versions - dependencies)))) + (let* ((import-path unpack-path + (if module-subdirectory + (values module-path module-root-path) + (let ((import-path (assoc-ref *module-path->import-path* + module-path))) + (if import-path + (begin + (log.debug "matched as an import-path exception: ~S" import-path) + (values import-path module-path)) + (values module-path #f)))))) + (values + `(package + (name ,guix-name) + (version ,(strip-v-prefix version*)) + (source + ,(vcs->origin vcs-type vcs-repo-url vcs-tag)) + (build-system go-build-system) + (arguments + '(#:import-path ,import-path + ,@(if unpack-path + `(#:unpack-path ,unpack-path) + '()))) + ,@(maybe-propagated-inputs + (map (match-lambda + ((name version) + (list (go-module->guix-package-name name) + (strip-v-prefix version))) + (name + (go-module->guix-package-name name))) + dependencies)) + (home-page ,(format #f "https://~a" module-root-path)) + (synopsis ,synopsis) + (description ,(and=> description beautify-description)) + (license ,(match (list->licenses licenses) + (() #f) ;unknown license + ((license) ;a single license + license) + ((license ...) ;a list of licenses + `(list ,@license))))) + (if pin-versions? + dependencies+versions + dependencies))))) (define (go-module->guix-package* . args) ;; Disable output buffering so that the following warning gets printed