From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id KDKsFxiLamTorAAASxT56A (envelope-from ) for ; Sun, 21 May 2023 23:20:24 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id aJ3PFhiLamSPcAEAG6o9tA (envelope-from ) for ; Sun, 21 May 2023 23:20:24 +0200 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 D1BAC37967 for ; Sun, 21 May 2023 23:20:23 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q0qTF-0004Q3-9K; Sun, 21 May 2023 17:20:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q0qTD-0004PV-6A for guix-patches@gnu.org; Sun, 21 May 2023 17:20:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q0qTC-0000Mt-UL for guix-patches@gnu.org; Sun, 21 May 2023 17:20:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q0qTC-0001I0-CA for guix-patches@gnu.org; Sun, 21 May 2023 17:20:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#63631] [PATCH] import: go: Handle subpackage versioning correctly. Resent-From: Timo Wilken Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 21 May 2023 21:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 63631 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 63631@debbugs.gnu.org, 54097@debbugs.gnu.org Cc: wolf@wolfsden.cz, Timo Wilken X-Debbugs-Original-To: guix-patches@gnu.org, 54097@debbugs.gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16847039844910 (code B ref -1); Sun, 21 May 2023 21:20:02 +0000 Received: (at submit) by debbugs.gnu.org; 21 May 2023 21:19:44 +0000 Received: from localhost ([127.0.0.1]:32932 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q0qSt-0001H8-L6 for submit@debbugs.gnu.org; Sun, 21 May 2023 17:19:44 -0400 Received: from lists.gnu.org ([209.51.188.17]:54220) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q0qSs-0001H0-BJ for submit@debbugs.gnu.org; Sun, 21 May 2023 17:19:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q0qSs-0004OJ-4y for guix-patches@gnu.org; Sun, 21 May 2023 17:19:42 -0400 Received: from mx2.mythic-beasts.com ([2a00:1098:0:82:1000:0:2:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q0qSq-0000Kb-8d for guix-patches@gnu.org; Sun, 21 May 2023 17:19:41 -0400 Received: by mailhub-hex-d.mythic-beasts.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1q0qSo-00C6Wa-E8; Sun, 21 May 2023 22:19:38 +0100 From: Timo Wilken Date: Sun, 21 May 2023 23:18:08 +0200 Message-Id: <6dd1de3dd4d968876fa55f5126056834c77b0244.1684703258.git.guix@twilken.net> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BlackCat-Spam-Score: 9 Received-SPF: pass client-ip=2a00:1098:0:82:1000:0:2:1; envelope-from=guix@twilken.net; helo=mx2.mythic-beasts.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1684704024; a=rsa-sha256; cv=none; b=cKvAlLRHH6QDIc/c4z5F5MfR8jn42k3k48RY7LzyhxVfQ305kR7v0SjsnrEEveF/bgymgB crwnL9626bS1pK9+9PhbM1cGiLeWAoTaJTBraaHuU5XKsay3nFElFUEcobyh1huc268I9+ qnyyimKiqQQPuML+0f+LZzJ2Qsbl2rEdzGV190k7oCkHAcg+YSHk7csn4iIFpEite2dKWf ZPsbEOB72EGa407Us83rYYpfd7QNBAJeLO7ah52g3Rs3Qjk04CcK7sYC7jWm2cip4IBsDb 7C/0u7a4Ao0v5EiQTL9iko83wq5GO4UcrwpD6qSDK4djj7wQR5uFtTZtF6rnMQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1684704024; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=xtmAXy8cYR3t8NfF4JdBI97OUbFNtxatHUvcqvuIrlM=; b=R/OBw/X8KkSDaNXrXJl3zwT7j+JI5wW58VslI5QktVUhbCPFZhZXKNHjcy22IHM0BtN6RY N5ai04OOa+NqUFg+RElqMTl9j2bShIHZidZ0kXTID4FHKTEQIKt1qOUKO+ztgKhpn+WklR Z4XPsY5fMUvxcLY7dbGGdpfqBslBtBWfNVWSTodN7nreFq/U9CTdd7QULH8SnpYTy8AcMU jd3CU0YI9exNF/OMxYjk9703vNLLX8LPb1kTbGxuFZwqWy/8w2wu+k74IddaIClBrHQis9 rcmrqAQC36UF/lREEMz+L+sj6zZFCkpEiB8ZuzQsQMg+IX0i1FkfJp2YoHW+TA== X-Migadu-Spam-Score: -1.31 X-Spam-Score: -1.31 X-Migadu-Queue-Id: D1BAC37967 X-Migadu-Scanner: scn0.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-TUID: imlIk62R30Is Some Go source repositories (notably the Google Cloud SDK) contain multiple submodules and use a `refs/tags//' tagging scheme. Fixes . * guix/import/go.scm (vcs->origin): Accept a module-path-suffix. (go-module->guix-package): Use the new parameter. --- Here's a patch that fixes the reported issue (bug#54097) for me. I've only tested this on the github.com/googleapis/google-cloud-go/compute package so far, though it seems to work there. Perhaps others have more testcases? I don't know enough about Go tooling to use it, so I've just patched the Guile logic of the importer. (I don't write Go, I just want to package stuff written in it.) In terms of performance, at least the repo contents are apparently cached by the first `git-checkout-hash' call, even if it fails, so the second call doesn't have to redownload them. guix/import/go.scm | 56 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/guix/import/go.scm b/guix/import/go.scm index 0357e6a1eb..652ac58b6f 100644 --- a/guix/import/go.scm +++ b/guix/import/go.scm @@ -7,6 +7,7 @@ ;;; Copyright © 2021 Xinglu Chen ;;; Copyright © 2021 Sarah Morgensen ;;; Copyright © 2021 Simon Tournier +;;; Copyright © 2023 Timo Wilken ;;; ;;; This file is part of GNU Guix. ;;; @@ -89,6 +90,7 @@ (define-module (guix import go) ;;; TODO list ;;; - get correct hash in vcs->origin for Mercurial and Subversion +;;; - handle subdir/vX.Y versioning in vcs->origin for Mercurial and Subversion ;;; Code: @@ -513,29 +515,54 @@ (define* (git-checkout-hash url reference algorithm) `(tag-or-commit . ,reference))))) (file-hash* checkout #:algorithm algorithm #:recursive? #true))) -(define (vcs->origin vcs-type vcs-repo-url version) +(define (vcs->origin vcs-type vcs-repo-url module-path-suffix version) "Generate the `origin' block of a package depending on what type of source control system is being used." (case vcs-type ((git) - (let ((plain-version? (string=? version (go-version->git-ref version))) - (v-prefixed? (string-prefix? "v" version))) + (let ((v-prefixed? (string-prefix? "v" version)) + (path-prefixed? #f) + (trimmed-path-suffix (string-trim-both module-path-suffix #\/)) + (checkout-hash (false-if-git-not-found + (git-checkout-hash + vcs-repo-url + (go-version->git-ref version) + (hash-algorithm sha256))))) + ;; If `checkout-hash' is false, that must mean that a tag named after + ;; the version doesn't exist. Some repos that contain submodules use a + ;; / tagging scheme instead, so try that. + (unless checkout-hash + (when (string=? "" trimmed-path-suffix) + ;; If this isn't a submodule, / tagging makes no sense. + ;; Tell the user we couldn't find the original version. + (raise + (formatted-message (G_ "could not find git reference '~a' in repository '~a'") + (go-version->git-ref version) vcs-repo-url))) + (set! path-prefixed? #t) + (set! checkout-hash (git-checkout-hash + vcs-repo-url + (go-version->git-ref + (string-append trimmed-path-suffix "/" version)) + (hash-algorithm sha256)))) `(origin (method git-fetch) (uri (git-reference (url ,vcs-repo-url) - ;; This is done because the version field of the package, - ;; which the generated quoted expression refers to, has been - ;; stripped of any 'v' prefixed. - (commit ,(if (and plain-version? v-prefixed?) - '(string-append "v" version) - '(go-version->git-ref version))))) + ;; The 'v' is prepended again because the version field of + ;; the package, which the generated quoted expression refers + ;; to, has been stripped of any 'v' prefixed. + (commit (go-version->git-ref + ,(cond + (path-prefixed? + `(string-append + ,trimmed-path-suffix "/" + ,@(if v-prefixed? '("v" version) '(version)))) + (v-prefixed? '(string-append "v" version)) + (else 'version)))))) (file-name (git-file-name name version)) (sha256 (base32 - ,(bytevector->nix-base32-string - (git-checkout-hash vcs-repo-url (go-version->git-ref version) - (hash-algorithm sha256)))))))) + ,(bytevector->nix-base32-string checkout-hash)))))) ((hg) `(origin (method hg-fetch) @@ -614,6 +641,9 @@ (define* (go-module->guix-package module-path #:key (match:prefix (string-match "([\\./]v[0-9]+)?$" module-path))) (guix-name (go-module->guix-package-name module-path)) (root-module-path (module-path->repository-root module-path)) + (module-path-suffix ; subdirectory inside the source repo + (substring module-path-sans-suffix + (string-prefix-length root-module-path module-path-sans-suffix))) ;; The VCS type and URL are not included in goproxy information. For ;; this we need to fetch it from the official module page. (meta-data (fetch-module-meta-data root-module-path)) @@ -627,7 +657,7 @@ (define* (go-module->guix-package module-path #:key (name ,guix-name) (version ,(strip-v-prefix version*)) (source - ,(vcs->origin vcs-type vcs-repo-url version*)) + ,(vcs->origin vcs-type vcs-repo-url module-path-suffix version*)) (build-system go-build-system) (arguments '(#:import-path ,module-path base-commit: e499cb2c12d7f1c6d2f004364c9cc7bdb7e38cd5 -- 2.40.1