Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: go list reports all dependencies as indirect with workspaces #66789

Closed
CHC383 opened this issue Apr 11, 2024 · 4 comments
Closed

cmd/go: go list reports all dependencies as indirect with workspaces #66789

CHC383 opened this issue Apr 11, 2024 · 4 comments
Assignees
Labels
GoCommand cmd/go modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@CHC383
Copy link

CHC383 commented Apr 11, 2024

Go version

go version go1.22.2 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/xxx/Library/Caches/go-build'
GOENV='/Users/xxx/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/xxx/go/pkg/mod'
GONOPROXY='bitbucket.org/labscale'
GONOSUMDB='bitbucket.org/labscale'
GOOS='darwin'
GOPATH='/Users/xxx/go'
GOPRIVATE='bitbucket.org/labscale'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.22.2/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.22.2/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/wc/l5mz01h92p58tgq77kn1c6pr0000gn/T/go-build1746990975=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Tried to run go list -f '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' -m xxx to get the direct dependencies of one module on a workspace with multiple modules

What did you see happen?

The command outputs nothing, i.e. all direct dependencies of the module are discovered as indirect dependencies

What did you expect to see?

The command should show the direct dependencies of the module

@seankhliao
Copy link
Member

can you provide a complete reproducer?

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Apr 12, 2024
@adonovan
Copy link
Member

I tried running this command (with xxx=all) from within golang.org/x/tools, both with and without a go.work file:

With:

xtools$ head -n 1 go.mod 
module golang.org/x/tools
xtools$ cat go.work
go 1.19

use ./gopls
use .
xtools$ go list -f '{{.Path}} main={{.Main}} indirect={{.Indirect}}' -m all
golang.org/x/tools main=true indirect=false
golang.org/x/tools/gopls main=true indirect=false
github.com/BurntSushi/toml main=false indirect=true
github.com/frankban/quicktest main=false indirect=true
github.com/google/go-cmdtest main=false indirect=true
github.com/google/go-cmp main=false indirect=true
github.com/google/renameio main=false indirect=true
github.com/google/safehtml main=false indirect=true
github.com/jba/printsrc main=false indirect=true
github.com/jba/templatecheck main=false indirect=true
github.com/kr/pretty main=false indirect=true
github.com/kr/text main=false indirect=true
github.com/rogpeppe/go-internal main=false indirect=true
github.com/yuin/goldmark main=false indirect=true
golang.org/x/crypto main=false indirect=true
golang.org/x/exp/typeparams main=false indirect=true
golang.org/x/mod main=false indirect=true
golang.org/x/net main=false indirect=true
golang.org/x/sync main=false indirect=true
golang.org/x/sys main=false indirect=true
golang.org/x/telemetry main=false indirect=true
golang.org/x/term main=false indirect=true
golang.org/x/text main=false indirect=true
golang.org/x/vuln main=false indirect=true
gopkg.in/check.v1 main=false indirect=true
gopkg.in/yaml.v3 main=false indirect=true
honnef.co/go/tools main=false indirect=true
mvdan.cc/gofumpt main=false indirect=true
mvdan.cc/unparam main=false indirect=true
mvdan.cc/xurls/v2 main=false indirect=true

Without go.work:

xtools$ go list -f '{{.Path}} main={{.Main}} indirect={{.Indirect}}' -m all
golang.org/x/tools main=true indirect=false
github.com/google/go-cmp main=false indirect=true
github.com/yuin/goldmark main=false indirect=false
golang.org/x/crypto main=false indirect=true
golang.org/x/mod main=false indirect=false
golang.org/x/net main=false indirect=false
golang.org/x/sync main=false indirect=false
golang.org/x/sys main=false indirect=true
golang.org/x/telemetry main=false indirect=false
golang.org/x/term main=false indirect=true
golang.org/x/text main=false indirect=true

I am surprised that golang.org/x/sync is considered indirect in the first case but a direct dependency in the second case, as it is required, without an // indirect comment, by both go.mod files in the workspace, e.g.:

xtools$ grep sync go.mod
require golang.org/x/sync v0.7.0

Perhaps @matloob can shed some light on it.

@seankhliao seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go modules and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Apr 12, 2024
@seankhliao seankhliao changed the title cmd/go: go list Indirect Dependencies Doesn't Work on Worksapce cmd/go: go list reports all dependencies as indirect with workspaces Apr 12, 2024
@matloob
Copy link
Contributor

matloob commented Apr 18, 2024

Ah it looks like we just never set the direct field in the requirements structure for workspaces. The reason the main modules had the correct direct value is because the moduleInfo function just bypasses checking direct and creates the module struct through a different code path which doesn't set the indirect field.

I've prepared a CL (580256) to fix this... Just need to add some tests and I'll mail it out

@gopherbot
Copy link

Change https://go.dev/cl/580256 mentions this issue: cmd/go/internal/modload: compute direct in workspace mode

@matloob matloob self-assigned this Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants