cmd/go: 'go list' should set the 'GoMod' field to reflect -modfile #36220
Labels
FrozenDueToAge
modules
NeedsFix
The path to resolution is known, but the work has not been done.
release-blocker
Milestone
The
-modfile
flag added for #34506 allows users to substitute an arbitrary file in place of thego.mod
file found at the module root. We (@jayconrod, @matloob, and I) were talking through the implications of that this morning, and realized that that has a very subtle interaction withgo env GOMOD
,go list
, and tools in general.With Go 1.13, tools may execute either
go env GOMOD
go list -m -f '{{.GoMod}}'
to discover the location of the main module'sgo.mod
file, and (if in a module) may executedirname $(go env GOMOD)
in order to locate the module root.The
go env
command does not support the-modfile
flag, so if someone sets, say,GOFLAGS=-modfile=/tmp/foo.mod
, thengo env GOMOD
will continue to report thego.mod
file found in the module root, rather than the one in use. That seems fine.However,
go list
does support the-modfile
flag, so it should report the replacementgo.mod
file in theGoMod
field. Today it does not.(Tools that need to locate the directory containing the main module should already be using the
Dir
field fromgo list
, rather than theGoMod
field.)Today I see:
However, that should probably instead be:
CC @heschik @dmitshur (in case this affects
goimports
and/orgodoc
)The text was updated successfully, but these errors were encountered: