google / go-licenses

A lightweight tool to report on the licenses used by a Go package and its dependencies. Highlight! Versioned external URL to licenses can be found at the same time.
Apache License 2.0
824 stars 125 forks source link

go-licenses doesn't work when installed with versioned go #193

Closed heppu closed 1 year ago

heppu commented 1 year ago

When I use "versioned go binary" like instructed in https://go.dev/doc/manage-install go-licenses doesn't work.

Steps to produce:

go install golang.org/dl/go1.20.1@latest
go1.20.1 download
go1.20.1 install github.com/google/go-licenses@v1.6.0
git clone https://github.com/google/go-licenses 
cd go-licenses
go1.20.1 mod download
go-licenses report github.com/google/go-licenses

This will produces just a list of errors and no license info:

E0309 15:49:30.676554   52440 library.go:117] Package context does not have module info. Non go modules projects are no longer supported. For feedback, refer to https://github.com/google/go-licenses/issues/128.
E0309 15:49:30.676605   52440 library.go:117] Package encoding/csv does not have module info. Non go modules projects are no longer supported. For feedback, refer to https://github.com/google/go-licenses/issues/128.
E0309 15:49:30.676613   52440 library.go:117] Package errors does not have module info. Non go modules projects are no longer supported. For feedback, refer to https://github.com/google/go-licenses/issues/128.
...

Env diff:

$ diff <(go env) <(go1.20.1 env)
19c19
< GOROOT="/usr/lib/go"
---
> GOROOT="/home/heppu/sdk/go1.20.1"
22c22
< GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
---
> GOTOOLDIR="/home/heppu/sdk/go1.20.1/pkg/tool/linux_amd64"
39c39
< GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1963812511=/tmp/go-build -gno-record-gcc-switches"
---
> GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3997467010=/tmp/go-build -gno-record-gcc-switches"

How ever using go run does seem to work:

$ go1.20.1 run github.com/google/go-licenses@latest report github.com/google/go-licenses
github.com/emirpasic/gods,https://github.com/emirpasic/gods/blob/v1.12.0/LICENSE,BSD-2-Clause
github.com/go-logr/logr,https://github.com/go-logr/logr/blob/v1.2.0/LICENSE,Apache-2.0
github.com/golang/groupcache/lru,https://github.com/golang/groupcache/blob/41bb18bfe9da/LICENSE,Apache-2.0
github.com/google/go-licenses,https://github.com/google/go-licenses/blob/HEAD/LICENSE,Apache-2.0
...
Bobgy commented 1 year ago

The root cause seems to be https://github.com/google/go-licenses/issues/149#issue-1372297269

heppu commented 1 year ago

Indeed doing:

GOROOT=$(go1.20.1 env GOROOT) go-licenses report github.com/google/go-licenses

does seem to fix issue.

Bobgy commented 1 year ago

Duplicates https://github.com/google/go-licenses/issues/149#issue-1372297269