Commit b36f22bf authored by Bryan C. Mills's avatar Bryan C. Mills

cmd/go: populate available module information for packages in vendor mode

Updates #33848

Change-Id: I10b4c79faef8bc3dee2ceba14d496fa049e84fb2
Reviewed-on: https://go-review.googlesource.com/c/go/+/202977
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarJay Conrod <jayconrod@google.com>
parent 05ee5065
...@@ -119,14 +119,8 @@ func moduleInfo(m module.Version, fromBuildList bool) *modinfo.ModulePublic { ...@@ -119,14 +119,8 @@ func moduleInfo(m module.Version, fromBuildList bool) *modinfo.ModulePublic {
info.GoVersion = loaded.goVersion[m.Path] info.GoVersion = loaded.goVersion[m.Path]
} }
if cfg.BuildMod == "vendor" { // completeFromModCache fills in the extra fields in m using the module cache.
// The vendor directory doesn't contain enough information to reconstruct completeFromModCache := func(m *modinfo.ModulePublic) {
// anything more about the module.
return info
}
// complete fills in the extra fields in m.
complete := func(m *modinfo.ModulePublic) {
if m.Version != "" { if m.Version != "" {
if q, err := Query(m.Path, m.Version, "", nil); err != nil { if q, err := Query(m.Path, m.Version, "", nil); err != nil {
m.Error = &modinfo.ModuleError{Err: err.Error()} m.Error = &modinfo.ModuleError{Err: err.Error()}
...@@ -152,13 +146,21 @@ func moduleInfo(m module.Version, fromBuildList bool) *modinfo.ModulePublic { ...@@ -152,13 +146,21 @@ func moduleInfo(m module.Version, fromBuildList bool) *modinfo.ModulePublic {
} }
if !fromBuildList { if !fromBuildList {
complete(info) completeFromModCache(info) // Will set m.Error in vendor mode.
return info return info
} }
r := Replacement(m) r := Replacement(m)
if r.Path == "" { if r.Path == "" {
complete(info) if cfg.BuildMod == "vendor" {
// It's tempting to fill in the "Dir" field to point within the vendor
// directory, but that would be misleading: the vendor directory contains
// a flattened package tree, not complete modules, and it can even
// interleave packages from different modules if one module path is a
// prefix of the other.
} else {
completeFromModCache(info)
}
return info return info
} }
...@@ -178,9 +180,11 @@ func moduleInfo(m module.Version, fromBuildList bool) *modinfo.ModulePublic { ...@@ -178,9 +180,11 @@ func moduleInfo(m module.Version, fromBuildList bool) *modinfo.ModulePublic {
info.Replace.Dir = filepath.Join(ModRoot(), r.Path) info.Replace.Dir = filepath.Join(ModRoot(), r.Path)
} }
} }
complete(info.Replace) if cfg.BuildMod != "vendor" {
info.Dir = info.Replace.Dir completeFromModCache(info.Replace)
info.GoMod = filepath.Join(info.Dir, "go.mod") info.Dir = info.Replace.Dir
info.GoMod = filepath.Join(info.Dir, "go.mod")
}
return info return info
} }
......
...@@ -21,6 +21,11 @@ stdout '.*[/\\]vendor[/\\]rsc.io[/\\]quote[/\\]v3' ...@@ -21,6 +21,11 @@ stdout '.*[/\\]vendor[/\\]rsc.io[/\\]quote[/\\]v3'
! stderr 'finding' ! stderr 'finding'
! stderr 'lookup disabled' ! stderr 'lookup disabled'
# 'go list' should provide the original replacement directory as the module's
# replacement path.
go list -mod=vendor -f '{{with .Module}}{{with .Replace}}{{.Path}}{{end}}{{end}}' rsc.io/quote/v3
stdout '.*[/\\]not-rsc.io[/\\]quote[/\\]v3'
# The same module can't be used as two different paths. # The same module can't be used as two different paths.
cd multiple-paths cd multiple-paths
! go mod vendor ! go mod vendor
...@@ -58,4 +63,4 @@ require ( ...@@ -58,4 +63,4 @@ require (
rsc.io/quote/v3 v3.0.0 rsc.io/quote/v3 v3.0.0
not-rsc.io/quote/v3 v3.0.0 not-rsc.io/quote/v3 v3.0.0
) )
replace not-rsc.io/quote/v3 => rsc.io/quote/v3 v3.0.0 replace not-rsc.io/quote/v3 => rsc.io/quote/v3 v3.0.0
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment