[bug#63647,0/2] Fix annoyance with "guix import go"

Message ID cover.1684771100.git.zimon.toutoune@gmail.com
Headers
Series Fix annoyance with "guix import go" |

Message

Simon Tournier May 22, 2023, 4:04 p.m. UTC
Hi,

As reported in [1], the Go importer returns backtrace.  This patch fixes
that.  The first patch is about sorting the versions.  The second is about
warn but not exit.  It allows to have a first draft when applying recursive
importer.

Compare (first patch),

--8<---------------cut here---------------start------------->8---
$ guix import go go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc@0.41
guix import: error: version v0.41 of go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc is not available

hint: Pick one of the following available versions: 0.26.0 0.36.0 0.15.0 0.41.0-rc.1 0.40.0 0.37.0 0.33.0 0.20.0 0.24.0 0.23.0 0.41.0 0.26.1 0.41.1 0.22.0
0.18.0 0.21.0 0.12.0 0.36.4 0.19.0 0.25.0 0.27.0 0.36.2 0.34.0 0.14.0 0.36.3 0.31.0 0.15.1 0.36.1 0.41.0-rc.2 0.32.0 0.28.0 0.35.0 0.42.0-rc.1 0.13.0
0.17.0 0.29.0 0.30.0 0.39.0 0.38.0 0.16.0.

$ ./pre-inst-env guix import go go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc@0.41
guix import: error: version v0.41 of go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc is not available

hint: Pick one of the following available versions: 0.42.0-rc.1 0.41.1 0.41.0-rc.2 0.41.0-rc.1 0.41.0 0.40.0 0.39.0 0.38.0 0.37.0 0.36.4 0.36.3 0.36.2 0.36.1
0.36.0 0.35.0 0.34.0 0.33.0 0.32.0 0.31.0 0.30.0 0.29.0 0.28.0 0.27.0 0.26.1 0.26.0 0.25.0 0.24.0 0.23.0 0.22.0 0.21.0 0.20.0 0.19.0 0.18.0 0.17.0
0.16.0 0.15.1 0.15.0 0.14.0 0.13.0 0.12.0.
--8<---------------cut here---------------end--------------->8---

Then instead of,

--8<---------------cut here---------------start------------->8---
$ guix import go go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc
Backtrace:
          14 (primitive-load "/home/simon/.config/guix/current/bin/guix")
In guix/ui.scm:
   2300:7 13 (run-guix . _)
  2263:10 12 (run-guix-command _ . _)
In guix/scripts/import.scm:
    89:11 11 (guix-import . _)
In ice-9/boot-9.scm:
  1752:10 10 (with-exception-handler _ _ #:unwind? _ #:unwind-for-type _)
In guix/scripts/import/go.scm:
   116:29  9 (_)
In ice-9/exceptions.scm:
   406:15  8 (go-module->guix-package* . _)
In ice-9/boot-9.scm:
  1752:10  7 (with-exception-handler _ _ #:unwind? _ #:unwind-for-type _)
In guix/import/go.scm:
   511:19  6 (go-module->guix-package "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" #:goproxy _ #:version _ # _)
In guix/git.scm:
    291:4  5 (update-cached-checkout _ #:ref _ #:recursive? _ #:check-out? _ #:starting-commit _ #:log-port _ #:cache-directory _)
   277:19  4 (resolve _)
In git/reference.scm:
     60:8  3 (_ _ _)
In git/bindings.scm:
     77:2  2 (raise-git-error _)
In ice-9/boot-9.scm:
  1685:16  1 (raise-exception _ #:continuable? _)
  1683:16  0 (raise-exception _ #:continuable? _)

ice-9/boot-9.scm:1683:16: In procedure raise-exception:
Git error: reference 'refs/tags/v0.41.1' not found
--8<---------------cut here---------------end--------------->8---

Now it returns (second patch),

--8<---------------cut here---------------start------------->8---
$ ./pre-inst-env guix import go go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc
guix import: warning: Git error: reference 'refs/tags/v0.41.1' not found in https://github.com/open-telemetry/opentelemetry-go-contrib
(define-public go-go-opentelemetry-io-contrib-instrumentation-google-golang-org-grpc-otelgrpc
  (package
    (name
     "go-go-opentelemetry-io-contrib-instrumentation-google-golang-org-grpc-otelgrpc")
    (version "0.41.1")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url
                     "https://github.com/open-telemetry/opentelemetry-go-contrib")
                    (commit (string-append "v" version))))
              (file-name (git-file-name name version))
              (sha256
               (base32
                "0000000000000000000000000000000000000000000000000000"))))
    (build-system go-build-system)
    (arguments
     '(#:import-path
       "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"))
    (propagated-inputs `(("go-gopkg-in-yaml-v3" ,go-gopkg-in-yaml-v3)
                         ("go-google-golang-org-genproto" ,go-google-golang-org-genproto)
                         ("go-google-golang-org-appengine" ,go-google-golang-org-appengine)
                         ("go-golang-org-x-text" ,go-golang-org-x-text)
                         ("go-golang-org-x-sys" ,go-golang-org-x-sys)
                         ("go-golang-org-x-oauth2" ,go-golang-org-x-oauth2)
                         ("go-golang-org-x-net" ,go-golang-org-x-net)
                         ("go-github-com-pmezard-go-difflib" ,go-github-com-pmezard-go-difflib)
                         ("go-github-com-golang-protobuf" ,go-github-com-golang-protobuf)
                         ("go-github-com-go-logr-stdr" ,go-github-com-go-logr-stdr)
                         ("go-github-com-go-logr-logr" ,go-github-com-go-logr-logr)
                         ("go-github-com-davecgh-go-spew" ,go-github-com-davecgh-go-spew)
                         ("go-cloud-google-com-go-compute-metadata" ,go-cloud-google-com-go-compute-metadata)
                         ("go-cloud-google-com-go-compute" ,go-cloud-google-com-go-compute)
                         ("go-google-golang-org-protobuf" ,go-google-golang-org-protobuf)
                         ("go-google-golang-org-grpc" ,go-google-golang-org-grpc)
                         ("go-go-opentelemetry-io-otel-trace" ,go-go-opentelemetry-io-otel-trace)
                         ("go-go-opentelemetry-io-otel-metric" ,go-go-opentelemetry-io-otel-metric)
                         ("go-go-opentelemetry-io-otel" ,go-go-opentelemetry-io-otel)
                         ("go-github-com-stretchr-testify" ,go-github-com-stretchr-testify)))
    (home-page
     "https://go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc")
    (synopsis #f)
    (description #f)
    (license license:asl2.0)))[env]
--8<---------------cut here---------------end--------------->8---


Cheers,
simon


Simon Tournier (2):
  guix: import: go: Sort hint about available versions.
  guix: import: go: Catch Git error.

 guix/import/go.scm | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)


base-commit: 849286ba66c96534bddc04df1a47d5692cbc977e
  

Comments

Fabio Natali Sept. 5, 2024, 11:27 a.m. UTC | #1
Hi All,

I've been recently trying to update Restic with 'guix import go
--recursive github.com/restic/restic'. (I wasn't expecting this to be an
easy task, by the way. I knew there are difficulties that have kept us
on an old version for a long time. https://issues.guix.gnu.org/63019)

Apparently, the import fails on those Go repositories that use a
subdirectory/subpackage structure - which brought me to this thread.

I was wondering if any of the patches proposed here (or in related
#52362, #63001, #64035, #64036) might be worth some final clean up and
merge - even if it addresses a subset of the problems?

Thanks, cheers, Fabio.
  
Fabio Natali Sept. 5, 2024, 11:39 a.m. UTC | #2
Hi All,

I've been recently trying to update Restic with 'guix import go
--recursive github.com/restic/restic'. (I wasn't expecting this to be an
easy task, by the way. I knew there are difficulties that have kept us
on an old version for a long time. https://issues.guix.gnu.org/63019)

Apparently, the import fails on those Go repositories that use a
subdirectory/subpackage structure - which brought me to this thread.

I was wondering if any of the patches proposed here (or in related
#52362, #63001, #64035, #64036) might be worth some final clean up and
merge - even if it addresses a subset of the problems?

Thanks, cheers, Fabio.
  
Sharlatan Hellseher Sept. 7, 2024, 1:44 p.m. UTC | #3
Hi,

Please see this <https://issues.guix.gnu.org/69827> issue which I try to
merge on go-branch.

--
Oleg
  
Sharlatan Hellseher Feb. 14, 2025, 1:25 a.m. UTC | #4
Hi,

It looks like we achieved improvements in importer already
which covers this issue.

I'd vote for closing this and open a fresh thread after importing
more packages. I did import 1700+ already without much trouble.

Oleg
  
Simon Tournier Feb. 20, 2025, 10:42 a.m. UTC | #5
Hi Oleg,

On Fri, 14 Feb 2025 at 01:25, Sharlatan Hellseher <sharlatanus@gmail.com> wrote:

> It looks like we achieved improvements in importer already 
> which covers this issue.
>
> I'd vote for closing this and open a fresh thread after importing 
> more packages. I did import 1700+ already without much trouble.

Cool!

If I read correctly, “[PATCH v3 2/3] guix: import: go: Catch Git error“
is somehow included with 57fa06352e9f4019298ffda3c066bab7538c8906.

What about these two other patches

--8<---------------cut here---------------start------------->8---
[PATCH v3 1/3] guix: import: go: Sort hint about available versions.

* guix/import/go.scm (validate-version): Sort available versions.
---
 guix/import/go.scm | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
--8<---------------cut here---------------end--------------->8---

and

--8<---------------cut here---------------start------------->8---
[PATCH v3 3/3] guix: import: go: Use correct tag for go module in subdirectory.

* guix/import/go.scm (vcs->origin): New argument module-path-subdirectory.
Use it to get Git tag as described by <https://go.dev/ref/mod>.

Co-authored-by: Simon Tournier <zimon.toutoune@gmail.com>
--8<---------------cut here---------------end--------------->8---

?

Cheers,
simon
  
Sharlatan Hellseher Feb. 20, 2025, 2:12 p.m. UTC | #6
Hi Simon

--8<---------------cut here---------------start------------->8---
[PATCH v3 3/3] guix: import: go: Use correct tag for go module in subdirectory.

* guix/import/go.scm (vcs->origin): New argument module-path-subdirectory.
Use it to get Git tag as described by <https://go.dev/ref/mod>.

Co-authored-by: Simon Tournier <zimon.toutoune@gmail.com>
--8<---------------cut here---------------end--------------->8---

It's on master already

a8d5d087086 * import/go: Add diagnostics.
296c78aab64 * import/go: Account for monorepo modules in the Go importer.
18a77fb3f85 * build-system/go: Add subdir parameter to go-version->git-ref.

Implemented by Christina O'Donnell <cdo@mutix.org>

By running this "go import github.com/moby/sys/mountinfo" produces this
package definittion:

--8<---------------cut here---------------start------------->8---
(define-public go-github-com-moby-sys-mountinfo
  (package
    (name "go-github-com-moby-sys-mountinfo")
    (version "0.7.2")
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
             (url "https://github.com/moby/sys")
             (commit (go-version->git-ref version
                                          #:subdir "mountinfo"))))
       (file-name (git-file-name name version))
       (sha256
        (base32 "1i1phx1kk9qa4jf1i1nl23d3f6k9fn2w46274cl76cqw9hjqg868"))))
    (build-system go-build-system)
    (arguments
     (list
      #:import-path "github.com/moby/sys/mountinfo"
      #:unpack-path "github.com/moby/sys"))
    (propagated-inputs (list go-golang-org-x-sys))
    (home-page "https://github.com/moby/sys")
    (synopsis #f)
    (description
     "Package mountinfo provides a set of functions to retrieve information about OS
mounts.")
    (license license:asl2.0)))
--8<---------------cut here---------------end--------------->8---

Which reflects Golang packaging requirements for Git tags submodules:

--8<---------------cut here---------------start------------->8---
git clone https://github.com/moby/sys
git -C sys tag --list
capability/v0.2.0
capability/v0.3.0
capability/v0.4.0
mount/v0.1.0
mount/v0.1.1
mount/v0.2.0
mount/v0.3.0
mount/v0.3.1
mount/v0.3.2
mount/v0.3.3
mount/v0.3.4
mountinfo/v0.1.0
mountinfo/v0.1.2
mountinfo/v0.1.3
mountinfo/v0.2.0
mountinfo/v0.3.0
mountinfo/v0.3.1
mountinfo/v0.4.0
mountinfo/v0.4.1
mountinfo/v0.5.0
mountinfo/v0.6.0
mountinfo/v0.6.1
mountinfo/v0.6.2
mountinfo/v0.7.0
mountinfo/v0.7.1
mountinfo/v0.7.2
reexec/v0.1.0
sequential/v0.5.0
sequential/v0.6.0
signal/v0.5.0
signal/v0.6.0
signal/v0.7.0
signal/v0.7.1
symlink/v0.1.0
symlink/v0.2.0
symlink/v0.3.0
user/v0.1.0
user/v0.2.0
user/v0.3.0
userns/v0.1.0
--8<---------------cut here---------------end--------------->8---

I guess this one is no longer required (please ensure me ;-)

--8<---------------cut here---------------start------------->8---
[PATCH v3 1/3] guix: import: go: Sort hint about available versions.

* guix/import/go.scm (validate-version): Sort available versions.
---
 guix/import/go.scm | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
--8<---------------cut here---------------end--------------->8---

---
Oleg