Message ID | bfb6cb47bc6e2a05846653ca0b07470d4ae8ae05.1710584715.git.cdo@mutix.org |
---|---|
State | New |
Headers | show |
Series | [bug#69827,1/3] build-system/go: Add subdir parameter to go-version->git-ref. | expand |
Hi,
These three patches above allow the go importer to automatically import
modules that are located in a monorepo where the submodules are
versioned independently. See https://go.dev/ref/mod#vcs-version:
> If a module is defined in a subdirectory within the repository, that
is, the module subdirectory portion of the module path is not empty,
then each tag name must be prefixed with the module subdirectory,
followed by a slash. For example, the module golang.org/x/tools/gopls is
defined in the gopls subdirectory of the repository with root path
golang.org/x/tools. The version v0.4.0 of that module must have the tag
named gopls/v0.4.0 in that repository.
After this change, I am able to import github.com/gohugio/hugo and its
400 odd dependencies with much fewer failures.
I'll submit those patches separately once I've tested them.
Kind regards,
Christina
PS. This is my first time sending a patch series to debbugs, so I almost
certainly did something wrong. Feedback on that would be appreciated.
Hi, Just a clarifying question. Do we definitely need to know anything about the folder structure where go.mod governs the module definition? There is an API https://pkg.go.dev/ where the most of go projects are registered, would it be easier just query it directly? Thanks, Oleg
diff --git a/guix/build-system/go.scm b/guix/build-system/go.scm index 0934fded07..94c5439dd1 100644 --- a/guix/build-system/go.scm +++ b/guix/build-system/go.scm @@ -56,11 +56,12 @@ (define %go-pseudo-version-rx "([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." +<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. If SUBDIR is specified and this is not a +pseudo-version, then this will prefix SUBDIR/ to the returned tag." ;; 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 @@ -78,7 +79,9 @@ (define (go-version->git-ref version) (match (regexp-exec %go-pseudo-version-rx version))) (if match (match:substring match 2) - version))) + (if subdir + (string-append subdir "/" version) + version)))) (define (go-pseudo-version? version) "True if VERSION is a Go pseudo-version, i.e., a version string made of a