sharlatan pushed a commit to branch go-team
in repository guix.
commit 9e7d7cf56101ef70bf4c2aa2b14f2bf93e105252
Author: Christina O'Donnell <[email protected]>
AuthorDate: Sat Mar 16 10:26:05 2024 +0000
build-system/go: Add subdir parameter to go-version->git-ref.
This implements logic to handle cases where Go can have multiple modules
at different versions within a single repository. It distinguishes their
releases by using tags along with their subdirectories. See
https://go.dev/ref/mod#vcs-version.
* guix/build-system/go.scm (go-version->git-ref): Add <#:subdir> keyword
parameter and extend condition checks.
Change-Id: I68bc9e785e49877bb0b756de8458308549f4c957
Co-authored-by: Sharlatan Hellseher <[email protected]>
Signed-off-by: Sharlatan Hellseher <[email protected]>
---
guix/build-system/go.scm | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/guix/build-system/go.scm b/guix/build-system/go.scm
index f4231df4ec..e39502991b 100644
--- a/guix/build-system/go.scm
+++ b/guix/build-system/go.scm
@@ -58,11 +58,13 @@
"([0-9A-Fa-f]{12})" ;commit hash
"(\\+incompatible)?$"))) ;optional +incompatible tag
-(define (go-version->git-ref version)
+(define* (go-version->git-ref version #:key subdir)
"Parse VERSION, a \"pseudo-version\" as defined at
<https://golang.org/ref/mod#pseudo-versions>, and extract the commit hash from
it, defaulting to full VERSION (stripped from the \"+incompatible\" suffix if
-present) if a pseudo-version pattern is not recognized."
+present) if a pseudo-version pattern is not recognized. If SUBDIR is
+specified and this is not a pseudo-version, then this will prefix SUBDIR/ to
+the returned tag; when VERSION misses 'v' prefix use SUBDIR/v instead."
;; A module version like v1.2.3 is introduced by tagging a revision in the
;; underlying source repository. Untagged revisions can be referred to
;; using a "pseudo-version" like v0.0.0-yyyymmddhhmmss-abcdefabcdef, where
@@ -80,7 +82,13 @@ present) if a pseudo-version pattern is not recognized."
(match (regexp-exec %go-pseudo-version-rx version)))
(if match
(match:substring match 2)
- version)))
+ (cond
+ ((and subdir (string-prefix? "v" version))
+ (string-append subdir "/" version))
+ ((and subdir (not (string-prefix? "v" version)))
+ (string-append subdir "/v" version))
+ (else
+ version)))))
(define (go-pseudo-version? version)
"True if VERSION is a Go pseudo-version, i.e., a version string made of a